flat assembler
Message board for the users of flat assembler.

Index > Windows > ReadFile from kernel32 problem

Author
Thread Post new topic Reply to topic
Hunter13



Joined: 05 Jan 2005
Posts: 13
Hunter13 22 Jan 2005, 09:34
There is problem with ReadFile from Kernel32, I want read file to buffer but that store just first line.. Has got somebody idea how to do it?
Code:
format PE GUI 4.0 
entry start 

include 'Include\win32a.inc' 

b equ byte 
section '.code' code readable executable 

start: 
        invoke  OpenFile,szFile,FilePE
        mov     [FileHandle],eax
        invoke  ReadFile,FileBuffer,5012,BytesRead
        mov     eax,[BytesRead]
        mov     b[FileBuffer+eax],0
        invoke  MessageBox,0,FileBuffer,szMD,MB_TOPMOST
        invoke  CancelIo,[FileHandle] 

        invoke  ExitProcess,0 

section '.data' data readable writeable 

InternetHandle  dd ?
FileHandle      dd ?
BytesRead       dd ?
FileBuffer      rb 5012
fhandle         dd 0 

FilePE          db 'r',0
szFile          db 'easy.txt',0
szMD          db 'MSGBOX',0

section '.idata' import data readable writeable 

library user32,'USER32.DLL',\ 
          kernel32,'KERNEL32.DLL'

import  kernel32,\
        OpenFile,'OpenFile',\
        ReadFile,'ReadFile',\
        CancelIo,'CancelIo',\
        ExitProcess,'ExitProcess'

import  user32,\
        MessageBox,'MessageBoxA' 
    

_________________
beauty is anywhere welcome guest
Post 22 Jan 2005, 09:34
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Vasilev Vjacheslav



Joined: 11 Aug 2004
Posts: 392
Vasilev Vjacheslav 22 Jan 2005, 09:50
i have no idea, but try to use CreateFile instead of OpenFile, and CloseHandle instead of CancelIO
Post 22 Jan 2005, 09:50
View user's profile Send private message Reply with quote
mike.dld



Joined: 03 Oct 2003
Posts: 235
Location: Belarus, Minsk
mike.dld 22 Jan 2005, 10:51
Humm.... FilePE? What are you trying to do, read from some executable? In this case look inside it with some hex editor to see NULL bytes. MessageBox shows you text from buffer beginning till first NULL.
Post 22 Jan 2005, 10:51
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3499
Location: Bulgaria
JohnFound 22 Jan 2005, 12:52
OpenFile API needs 3 arguments:

Code:
HFILE OpenFile(
    LPCSTR lpFileName,    // pointer to filename 
    LPOFSTRUCT lpReOpenBuff, // pointer to buffer for file information  
    UINT uStyle  // action and attributes 
   );
    


In your use, only the filename is OK. It is strange, that it read something at all. Smile

Regards
Post 22 Jan 2005, 12:52
View user's profile Send private message Visit poster's website ICQ Number 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.