flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > I have macro in this macro two macro like LoadFile.Troubles

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 598
Roman
If i use macro I , a get troubles. But if i use LoadingFile this work correct ! Why ?
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
mov ebx,FileName2
mov ebp,Buf2
LoadingFile ebx,ebp ;this second LoadingFile get me size of file 1999335668 bytes !!!
}

    


Last edited by Roman on 19 Sep 2014, 13:12; edited 3 times in total
Post 19 Sep 2014, 09:21
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 598
Roman
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?
Post 19 Sep 2014, 09:24
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
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 Wink

> 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 !!! Shocked
[!] "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
Post 19 Sep 2014, 10:07
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 598
Roman
in ebx pointer to text name. in ebp = buffer
Post 19 Sep 2014, 11:40
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.