ASSEMBLY DTA 文件属性、大小、名称等
ASSEMBLY DTA file attributes, size, name etc
我正在为一个学校项目使用程序集,简而言之,我的作业需要找到与给定扩展名(*.txt、*.exe 等)匹配的文件,并打印出该文件的大小、日期、文件名称等。到目前为止,我已经成功找到文件并设置了 DTA。当涉及到文件名时,一切都很好,但是当我必须打印出大小或日期时,我很挣扎。我假设它们是二进制的,对吗?我如何将它们从二进制解码为不可理解的格式?
;This is my DTA start----------------------------------
DTA db 15h dup (0)
fatt db 0 <-------------
ftime db 0,0 <------------ how do I decode these????
fdate db 0,0 <-------------
fsize db 4 dup (0) <-----------
fname db 13 dup (0)
;DTA end-----------------------------------------
那是我的代码,但它很乱,而且还在进行中。
.model small
.stack 100h
.data
;This DTA start----------------------------------
DTA db 15h dup (0)
fatt db 0
ftime db 0,0
fdate db 0,0
fsize db 4 dup (0)
fname db 13 dup (0)
;DTA end-----------------------------------------
extension db 12 dup (0)
sourceFHandle dw ?
testas db "C:\ATI\",0
directory db 64 dup (0)
writefile db "C:\menulis.txt",0
writehandle dw ?
buffer db 20 dup (?)
simbolis db ?
.code
START:
mov ax, @data
mov es, ax ; es kad galetume naudot stosb funkcija: Store AL at address ES:(E)DI
mov si, 81h ; programos paleidimo parametrai rasomi segmente es pradedant 129 (arba 81h) baitu
call skip_spaces
_2:
;; extension nuskaitymas
lea di, extension
call read_filename ; perkelti is parametro i eilute
cmp byte ptr es:[extension], '$' ; jei nieko nenuskaite
jne _3
_3:
;; directory nusk
lea di, directory
call read_filename ; perkelti is parametro i eilute
push ds
push si
mov ax, @data
mov ds, ax
;nustatom DTA
mov ah,1ah
mov dx, offset DTA
int 21h
;; rasymui sukuria faila
mov dx, offset writefile ; ikelti i dx destF - failo pavadinima
mov ah, 3ch ; isvalo/sukuria faila - komandos kodas
xor cx,cx ; normal - no attributes
int 21h ; INT 21h / AH= 3Ch - create or truncate file.
; Jei nebus isvalytas - tai perrasines senaji,
; t.y. jei pries tai buves failas ilgesnis - like
; CF set on error AX = error code.
; atidaro faila
mov dx,offset writefile
mov al,2
mov ah,3dh
int 21h
mov writehandle,ax
;keicia direktorija
mov ah,3bh
mov dx,offset directory
int 21h
;iesko failo
mov ah,4eh
mov cx,0
lea dx,extension
int 21h
call write_to_file
;raso i faila duomenis
; lea dx,fname
; mov bx,writehandle
; mov ah,40h
; mov cx, 13
;int 21h
find_next:
mov ah,4fh
lea dx,extension
int 21h
call write_to_file
;uzdaryti faila
mov ah,3eh
mov bx,writehandle
int 21h
mov ah,9h
mov dx,offset directory
int 21h
mov ah, 4ch
mov al, 0
int 21h
;; procedures
skip_spaces PROC near
skip_spaces_loop:
cmp byte ptr ds:[si], ' '
jne skip_spaces_end
inc si
jmp skip_spaces_loop
skip_spaces_end:
ret
skip_spaces ENDP
read_filename PROC near
push ax
call skip_spaces
read_filename_start:
cmp byte ptr ds:[si], 13 ; jei nera parametru
je read_filename_end ; tai taip, tai baigtas failo vedimas
cmp byte ptr ds:[si], ' ' ; jei tarpas
jne read_filename_next ; tai praleisti visus tarpus, ir sokti prie kito
read_filename_end:
mov al, 0 ; irasyti 0 gale
stosb ; Store AL at address ES:(E)DI, di = di + 1
pop ax
ret
read_filename_next:
lodsb ; uzkrauna kita simboli
stosb ; Store AL at address ES:(E)DI, di = di + 1
jmp read_filename_start
read_filename ENDP
write_to_file PROC near
lea dx,fname
mov bx,writehandle
mov ah,40h
mov cx,13
int 21h
ret
write_to_file ENDP
end START
忘记了。看起来其他人也一样。我记得,大小只是一个 32 位数字。您应该能够找到一些数字文本例程来执行此操作。时间和日期有点奇怪。让我看看我能找到什么……
</p>
<pre><code>; es:di points to text buffer
mov ax, [date]
and ax, 1E0h ; month
shr ax, 5
call show_2_dec
mov al, '/'
stosb
mov ax, [date] ; again
and ax, 1Fh ; day
call show_2_dec
mov al, '/'
stosb
mov ax, [date] ; again
and ax, 0FE00h ; year
shr ax, 9
add ax, 50h ; Y2K problem?
call show_2_dec
mov al, 0 ; or '$' - terminator
stosb
; and print it
; new buffer in es:di?
mov ax, [time]
and ax, 0F800h ; hours
shr ax, 0Bh
call show_2_dec
mov al, ':'
stosb
mov ax, [time]
and ax, 7E0h ; minutes
shr ax, 5
call show_2_dec
mov al, ':'
stosb
mov ax, [time]
and ax, 1Fh ; seconds/2
shl ax, 1 ; seconds
call show_2_dec
; terminate and print
;
show_2_dec:
aam
xchg al, ah
or ax, 3030h
stosb
mov al, ah
stosb
ret
这是来自 Nasm 语法(不应该打扰你吗?)而不是我是如何做到的,所以可能存在复制错误,但幸运的话会让你指向正确的方向(?)
我正在为一个学校项目使用程序集,简而言之,我的作业需要找到与给定扩展名(*.txt、*.exe 等)匹配的文件,并打印出该文件的大小、日期、文件名称等。到目前为止,我已经成功找到文件并设置了 DTA。当涉及到文件名时,一切都很好,但是当我必须打印出大小或日期时,我很挣扎。我假设它们是二进制的,对吗?我如何将它们从二进制解码为不可理解的格式?
;This is my DTA start----------------------------------
DTA db 15h dup (0)
fatt db 0 <-------------
ftime db 0,0 <------------ how do I decode these????
fdate db 0,0 <-------------
fsize db 4 dup (0) <-----------
fname db 13 dup (0)
;DTA end-----------------------------------------
那是我的代码,但它很乱,而且还在进行中。
.model small
.stack 100h
.data
;This DTA start----------------------------------
DTA db 15h dup (0)
fatt db 0
ftime db 0,0
fdate db 0,0
fsize db 4 dup (0)
fname db 13 dup (0)
;DTA end-----------------------------------------
extension db 12 dup (0)
sourceFHandle dw ?
testas db "C:\ATI\",0
directory db 64 dup (0)
writefile db "C:\menulis.txt",0
writehandle dw ?
buffer db 20 dup (?)
simbolis db ?
.code
START:
mov ax, @data
mov es, ax ; es kad galetume naudot stosb funkcija: Store AL at address ES:(E)DI
mov si, 81h ; programos paleidimo parametrai rasomi segmente es pradedant 129 (arba 81h) baitu
call skip_spaces
_2:
;; extension nuskaitymas
lea di, extension
call read_filename ; perkelti is parametro i eilute
cmp byte ptr es:[extension], '$' ; jei nieko nenuskaite
jne _3
_3:
;; directory nusk
lea di, directory
call read_filename ; perkelti is parametro i eilute
push ds
push si
mov ax, @data
mov ds, ax
;nustatom DTA
mov ah,1ah
mov dx, offset DTA
int 21h
;; rasymui sukuria faila
mov dx, offset writefile ; ikelti i dx destF - failo pavadinima
mov ah, 3ch ; isvalo/sukuria faila - komandos kodas
xor cx,cx ; normal - no attributes
int 21h ; INT 21h / AH= 3Ch - create or truncate file.
; Jei nebus isvalytas - tai perrasines senaji,
; t.y. jei pries tai buves failas ilgesnis - like
; CF set on error AX = error code.
; atidaro faila
mov dx,offset writefile
mov al,2
mov ah,3dh
int 21h
mov writehandle,ax
;keicia direktorija
mov ah,3bh
mov dx,offset directory
int 21h
;iesko failo
mov ah,4eh
mov cx,0
lea dx,extension
int 21h
call write_to_file
;raso i faila duomenis
; lea dx,fname
; mov bx,writehandle
; mov ah,40h
; mov cx, 13
;int 21h
find_next:
mov ah,4fh
lea dx,extension
int 21h
call write_to_file
;uzdaryti faila
mov ah,3eh
mov bx,writehandle
int 21h
mov ah,9h
mov dx,offset directory
int 21h
mov ah, 4ch
mov al, 0
int 21h
;; procedures
skip_spaces PROC near
skip_spaces_loop:
cmp byte ptr ds:[si], ' '
jne skip_spaces_end
inc si
jmp skip_spaces_loop
skip_spaces_end:
ret
skip_spaces ENDP
read_filename PROC near
push ax
call skip_spaces
read_filename_start:
cmp byte ptr ds:[si], 13 ; jei nera parametru
je read_filename_end ; tai taip, tai baigtas failo vedimas
cmp byte ptr ds:[si], ' ' ; jei tarpas
jne read_filename_next ; tai praleisti visus tarpus, ir sokti prie kito
read_filename_end:
mov al, 0 ; irasyti 0 gale
stosb ; Store AL at address ES:(E)DI, di = di + 1
pop ax
ret
read_filename_next:
lodsb ; uzkrauna kita simboli
stosb ; Store AL at address ES:(E)DI, di = di + 1
jmp read_filename_start
read_filename ENDP
write_to_file PROC near
lea dx,fname
mov bx,writehandle
mov ah,40h
mov cx,13
int 21h
ret
write_to_file ENDP
end START
忘记了。看起来其他人也一样。我记得,大小只是一个 32 位数字。您应该能够找到一些数字文本例程来执行此操作。时间和日期有点奇怪。让我看看我能找到什么……
</p>
<pre><code>; es:di points to text buffer
mov ax, [date]
and ax, 1E0h ; month
shr ax, 5
call show_2_dec
mov al, '/'
stosb
mov ax, [date] ; again
and ax, 1Fh ; day
call show_2_dec
mov al, '/'
stosb
mov ax, [date] ; again
and ax, 0FE00h ; year
shr ax, 9
add ax, 50h ; Y2K problem?
call show_2_dec
mov al, 0 ; or '$' - terminator
stosb
; and print it
; new buffer in es:di?
mov ax, [time]
and ax, 0F800h ; hours
shr ax, 0Bh
call show_2_dec
mov al, ':'
stosb
mov ax, [time]
and ax, 7E0h ; minutes
shr ax, 5
call show_2_dec
mov al, ':'
stosb
mov ax, [time]
and ax, 1Fh ; seconds/2
shl ax, 1 ; seconds
call show_2_dec
; terminate and print
;
show_2_dec:
aam
xchg al, ah
or ax, 3030h
stosb
mov al, ah
stosb
ret
这是来自 Nasm 语法(不应该打扰你吗?)而不是我是如何做到的,所以可能存在复制错误,但幸运的话会让你指向正确的方向(?)