flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > I have macro in this macro two macro like LoadFile.Troubles |
Author |
|
Roman 19 Sep 2014, 09:24
But second file(1.bin) must be 5 kilobytes !!! Not 1999335668 bytes. But second LoadingFile (in macro I) , give me correct file name (1.bin)!
How fix this bug in macro I? |
|||
19 Sep 2014, 09:24 |
|
DOS386 19 Sep 2014, 10:07
Code: macro LoadingFile name,bufer { local chuu,fhand2,rbait2,flen2 invoke CreateFile,name,GENERIC_READ,3,0,OPEN_EXISTING,FILE_ATTRIBUTE_READONLY,0 mov [fhand2],eax mov [rbait2],0 mov [rbait2+4],0 mov [flen2],0 mov [flen2+4],0 jmp chuu fhand2 dd 0 rbait2 dd 0,0 flen2 dd 0,0 chuu: invoke GetFileSizeEx,[fhand2],flen2 invoke ReadFile,[fhand2],bufer,[flen2],rbait2,0 ;900000,rbait,0 invoke CloseHandle,[fhand2] .if eax =0 invoke MessageBox, NULL, "NotClosed", "ERROR",MB_OK or MB_ICONERROR mov eax,0 .endif .if [rbait2] =0 invoke MessageBox, NULL, name, "NotLoaded",MB_OK or MB_ICONERROR mov eax,0 .endif mov edx,[rbait2] } macro I chName,chBuf { LoadingFile chName,chBuf LoadingFile ebx,ebp ;this second LoadingFile get me size of file 1999335668 bytes !!! } > if i use LoadingFile this work correct [!] it will certainly crash if you feed in a too big file > local chuu,fhand2,rbait2,flen2 > jmp chuu [+] better: jmp @f [+] even better: brew local var's on the stack and don't use "local" and avoid the jump > invoke CreateFile,name,GENERIC_READ [!] maybe this call can fail ??? > invoke GetFileSizeEx,[fhand2],flen2 [!] result is UINT64 ... and you don't check it against 4 GiO [!] actually you don't use the result at all - call is absolutely useless > mov [rbait2+4],0 > invoke ReadFile,[fhand2],bufer,[flen2],rbait2,0 ;900000,rbait,0 [!] you don't check "flen2" against buffer size !!! very dangerous !!! [!] "rbait2" is only UINT32 - no need "rbait2+4" [!] you don't check EAX on return > invoke MessageBox, NULL, "NotClosed" [!] you should check the result from "CreateFile" opening ... and not proceed if opening fails ... your "NotClosed" MB doesn't really make sense > LoadingFile chName,chBuf > LoadingFile ebx,ebp ;this second LoadingFile get [!] what do you have in EBX & EBP ??? > me size of file 1999335668 bytes !!! [+] better FASM-compatible way to write: 1'999'335'668 ---- [!] you should comment about what this macro is supposed to do and to return in what registers [!] maybe a subroutine would be more suitable for this task than a macrooooo |
|||
19 Sep 2014, 10:07 |
|
Roman 19 Sep 2014, 11:40
in ebx pointer to text name. in ebp = buffer
|
|||
19 Sep 2014, 11:40 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.