flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
vid 27 Mar 2006, 14:36
post your binary so we can see if it crashes on other computers. because probably the bug is on your's side.
|
|||
![]() |
|
Barf 27 Mar 2006, 15:24
Code: format PE GUI 4.0 entry start include 'C:\Program Files\FASM\INCLUDE\win32a.inc' section '.data' data readable writeable hsFile dd 0 haSpace dd 0 asSize dd 0 sfname db 'game.esp',0 etFC db 'Otwarcie pliku game.esp nie powiodBo si.',0 etMA db 'Alokacja pamici nie powiodBa si.',0 section '.code' code readable executable start: invoke CreateFile, sfname, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 cmp eax, INVALID_HANDLE_VALUE je err_fc mov [hsFile], eax invoke GetFileSize, [hsFile], 0 cmp eax, 0ffffffffh je err_fc mov [asSize], eax invoke GlobalAlloc, GMEM_FIXED, [asSize] test eax, eax jz err_ma mov [haSpace], eax invoke ReadFile, [hsFile], [haSpace], [asSize], 0, 0 test eax, eax jz err_fc jmp fin err_fc: invoke MessageBox, 0, etFC, etFC, MB_OK jmp fin err_ma: invoke MessageBox, 0 etMA, etMA, MB_OK fin: invoke GlobalFree, [hsFile] invoke ExitProcess, 0 section '.idata' import data readable writeable library k32, 'KERNEL32.DLL',\ u32, 'USER32.DLL' import k32,\ ExitProcess,'ExitProcess',\ GetModuleHandle, 'GetModuleHandleA',\ GetModuleFileName, 'GetModuleFileNameA',\ CreateFile, 'CreateFileA',\ GetFileSize, 'GetFileSize',\ GlobalAlloc, 'GlobalAlloc',\ ReadFile, 'ReadFile',\ GlobalFree, 'GlobalFree' import u32,\ MessageBox, 'MessageBoxA' Sorry, now i found that READFILE makes problem, but i need help anyway ![]() |
|||
![]() |
|
lilljocke 27 Mar 2006, 16:18
When i coding something with CreateFile i sometimes must Write FILE_SHARE_READ OR FILE_SHARE_WRITE. Mabye this will help.
etFC db 'Otwarcie pliku game.esp nie powiodBo si.',0 etMA db 'Alokacja pamici nie powiodBa si.',0 section '.code' code readable executable start: invoke CreateFile, sfname, GENERIC_READ, FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 cmp eax, INVALID_HANDLE_VALUE je err_fc mov [hsFile], eax invoke GetFileSize, [hsFile], 0 cmp eax, 0ffffffffh je err_fc mov [asSize], eax invoke GlobalAlloc, GMEM_FIXED, [asSize] test eax, eax jz err_ma mov [haSpace], eax invoke ReadFile, [hsFile], [haSpace], [asSize], 0, 0 test eax, eax jz err_fc jmp fin err_fc: invoke MessageBox, 0, etFC, etFC, MB_OK jmp fin err_ma: invoke MessageBox, 0 etMA, etMA, MB_OK fin: invoke GlobalFree, [hsFile] invoke ExitProcess, 0 section '.idata' import data readable writeable library k32, 'KERNEL32.DLL',\ u32, 'USER32.DLL' import k32,\ ExitProcess,'ExitProcess',\ GetModuleHandle, 'GetModuleHandleA',\ GetModuleFileName, 'GetModuleFileNameA',\ CreateFile, 'CreateFileA',\ GetFileSize, 'GetFileSize',\ GlobalAlloc, 'GlobalAlloc',\ ReadFile, 'ReadFile',\ GlobalFree, 'GlobalFree' import u32,\ MessageBox, 'MessageBoxA' |
|||
![]() |
|
Barf 27 Mar 2006, 16:26
no. That is not that what causes error :/
|
|||
![]() |
|
RedGhost 27 Mar 2006, 23:04
two problems:
A) from MSDN If lpOverlapped is NULL, lpNumberOfBytesRead cannot be NULL. you are passing lpOverlapped as NULL aswell as lpNumberOfBytesRead B) you are using GlobalFree on your file handle, you should be using GlobalFree on your pointer to allocated memory and CloseHandle on your file handle working version: Code: format PE GUI 4.0 entry start include '%fasminc%\win32a.inc' section '.data' data readable writeable hsFile dd 0 haSpace dd 0 asSize dd 0 asBytesRead dd 0 sfname db 'ok.txt',0 etFC db 'Otwarcie pliku game.esp nie powiodBo si.',0 etMA db 'Alokacja pamici nie powiodBa si.',0 section '.code' code readable executable start: invoke CreateFile, sfname, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 cmp eax, INVALID_HANDLE_VALUE je err_fc mov [hsFile], eax invoke GetFileSize, [hsFile], 0 cmp eax, 0ffffffffh je err_fc mov [asSize], eax invoke GlobalAlloc, GMEM_FIXED, [asSize] test eax, eax jz err_ma mov [haSpace], eax invoke ReadFile, [hsFile], [haSpace], [asSize], asBytesRead, 0 ;needs lpNumberOfBytesRead test eax, eax jz err_fc ;invoke MessageBox, 0, [haSpace], 0, 0 ;show contents of file jmp fin err_fc: invoke MessageBox, 0, etFC, etFC, MB_OK jmp fin err_ma: invoke MessageBox, 0 etMA, etMA, MB_OK fin: invoke CloseHandle, [hsFile] ;close file handle (no memory leak) invoke GlobalFree, [haSpace] ;free memory invoke ExitProcess, 0 section '.idata' import data readable writeable library k32, 'KERNEL32.DLL',\ u32, 'USER32.DLL' import k32,\ ExitProcess,'ExitProcess',\ GetModuleHandle, 'GetModuleHandleA',\ GetModuleFileName, 'GetModuleFileNameA',\ CreateFile, 'CreateFileA',\ GetFileSize, 'GetFileSize',\ GlobalAlloc, 'GlobalAlloc',\ ReadFile, 'ReadFile',\ GlobalFree, 'GlobalFree',\ CloseHandle, 'CloseHandle' import u32,\ MessageBox, 'MessageBoxA' _________________ redghost.ca |
|||
![]() |
|
Barf 28 Mar 2006, 12:18
thanx. Now works ok
|
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.