主题:请问如何用汇编取得某一文件大小
rock001
[专家分:40] 发布于 2007-03-27 09:30:00
如题,应该用哪个API函数呢?具体格式如何
谢谢!
回复列表 (共3个回复)
沙发
jhkdiy [专家分:1620] 发布于 2007-03-27 21:54:00
GetFileSize
The GetFileSize function retrieves the size of a specified file.
This function stores the file size in a DWORD value. To retrieve a file size that is larger than a DWORD value, use the GetFileSizeEx function.
DWORD GetFileSize(
HANDLE hFile, // handle to file
LPDWORD lpFileSizeHigh // high-order word of file size
);
Parameters
hFile
[in] Handle to the file whose size is to be returned. This handle must have been created with either GENERIC_READ or GENERIC_WRITE access to the file.
lpFileSizeHigh
[out] Pointer to the variable where the high-order word of the file size is returned. This parameter can be NULL if the application does not require the high-order word.
Return Values
If the function succeeds, the return value is the low-order doubleword of the file size, and, if lpFileSizeHigh is non-NULL, the function puts the high-order doubleword of the file size into the variable pointed to by that parameter.
If the function fails and lpFileSizeHigh is NULL, the return value is INVALID_FILE_SIZE. To get extended error information, call GetLastError.
If the function fails and lpFileSizeHigh is non-NULL, the return value is INVALID_FILE_SIZE and GetLastError will return a value other than NO_ERROR.
Remarks
You cannot use the GetFileSize function with a handle of a nonseeking device such as a pipe or a communications device. To determine the file type for hFile, use the GetFileType function.
The GetFileSize function retrieves the uncompressed size of a file. Use the GetCompressedFileSize function to obtain the compressed size of a file.
板凳
jhkdiy [专家分:1620] 发布于 2007-03-27 21:55:00
汇编实现如下:
[code]
invoke CreateFile,_lpszFile,GENERIC_READ,FILE_SHARE_READ,0,\
OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0
.if eax != INVALID_HANDLE_VALUE
mov @hFile,eax
invoke GetFileSize,eax,NULL
add dwFileSizeLow,eax
adc dwFileSizeHigh,0
invoke CloseHandle,@hFile
.endif
[/code]
3 楼
def [专家分:3380] 发布于 2007-03-30 19:10:00
DOS 里面:
;CX=属性
;DS:SI=ASCIIZ文件名
mov dx,0
mov bx,0
mov ax,716ch
int 21h
jc loadfl_error
push ax
;DS:DX=34字节结构lfnattrib
mov bx,ax
mov ax,71a6h
int 21h
pop ax
mov bx,ax
mov ax,3e00h
int 21h
则lfnattrib的20-27四字节就是文件长度.
我来回复