flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
b1528932 13 Mar 2011, 17:10
it require either overlapped or number_of_transferred. Otherwise how would you know how many data you read?
|
|||
![]() |
|
Overflowz 13 Mar 2011, 18:30
same problem with this.
Code: format PE GUI 4.0 include 'WIN32AX.INC' entry main section '.data' data readable writeable hFile dd ? fSize dd ? buffer dd ? rbytes dd ? fname db "test.txt",0 section '.text' code readable executable proc main invoke CreateFile,fname,GENERIC_READ,FILE_SHARE_READ+FILE_SHARE_WRITE,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL+FILE_FLAG_OVERLAPPED,0 mov [hFile],eax xor ecx,ecx invoke GetFileSize,eax,ecx mov [fSize],eax invoke ReadFile,[hFile],buffer,[fSize],rbytes,0 invoke MessageBox,0,buffer,buffer,MB_OK+MB_ICONINFORMATION ret endp section '.idata' import data readable library user32,'user32.dll',\ kernel32,'kernel32.dll' include 'API\USER32.INC' include 'API\KERNEL32.INC' section '.reloc' fixups data discardable readable |
|||
![]() |
|
Picnic 14 Mar 2011, 09:16
Hi,
Unless you dynamically allocate bytes using the api to get a dwpointer, buffer must be delcared. Code: section '.data' data readable writeable hFile dd ? fSize dd ? buffer rb 1024 rbytes dd ? fname db "test.txt",0 section '.text' code readable executable proc main invoke CreateFile,fname,GENERIC_READ,FILE_SHARE_READ+FILE_SHARE_WRITE,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0 mov [hFile],eax xor ecx,ecx invoke GetFileSize,eax,ecx mov [fSize],eax invoke ReadFile,[hFile],buffer,[fSize],rbytes,0 invoke MessageBox,0,buffer,fname,MB_OK+MB_ICONINFORMATION ret endp |
|||
![]() |
|
Overflowz 14 Mar 2011, 10:43
Picnic
Thank you! I got it now and isn't better way to allocate memory space for file ? like GlobalAlloc or LocalAlloc ? I don't know what difference are between them.. Because I need to work with files more than 100MB+ |
|||
![]() |
|
Picnic 14 Mar 2011, 11:16
Overflowz wrote: Picnic You're welcome. Yes i think it's the only way for such big files. Search windows section about dynamic memory allocation to read about the differences. Don't forget, error checking for each api function! Code: section '.data' data readable writeable hFile dd ? fSize dd ? hHeap dd ? buffer dd ? rbytes dd ? fname db "test.txt",0 section '.text' code readable executable proc main invoke CreateFile,fname,GENERIC_READ,FILE_SHARE_READ+FILE_SHARE_WRITE,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0 mov [hFile],eax xor ecx,ecx invoke GetFileSize,eax,ecx mov [fSize],eax invoke GetProcessHeap mov [hHeap], eax invoke HeapAlloc, [hHeap], HEAP_ZERO_MEMORY, [fSize] mov [buffer], eax invoke ReadFile,[hFile],[buffer],[fSize],rbytes,0 invoke MessageBox,0,[buffer],fname,MB_OK+MB_ICONINFORMATION invoke HeapFree, [hHeap], 0, [buffer] ret endp p.s. HeapAlloc usage, hope it runs, i'm at the office ![]() |
|||
![]() |
|
Overflowz 14 Mar 2011, 17:06
What's difference between HeapAlloc/GlobalAlloc/LocalAlloc functions ?
|
|||
![]() |
|
SFeLi 15 Mar 2011, 06:06
GlobalAlloc and LocalAlloc functions are using HeapAlloc (which is forwarded to NTDLL.RtlAllocateHeap) to allocate memory. There was a difference between Global/Local in 16-bit world (Win 3.1), but now both do the same thing.
|
|||
![]() |
|
Overflowz 15 Mar 2011, 10:54
SFeLi
Got it, thanks for info ![]() |
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.