News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Open File to TextBox

Started by Cyrus, November 15, 2007, 07:11:02 AM

Previous topic - Next topic

Cyrus

Thanks again to all who help here. I'm getting better I promise lol.

Well I've got myself in a pinch. I'm attempting to open an exe file and read it. Then display it in a Textbox/Editbox in hex format. Much like your garden variety hex editors like winhex. here's my code:

invoke CreateFile,addr cFile,GENERIC_READ or GENERIC_WRITE,0,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0
mov fHandle,eax
invoke GetFileSize,fHandle,0
mov fSize,eax
invoke GlobalAlloc,0,fSize
mov memptr,eax
invoke ReadFile,fHandle,memptr,fSize,offset bread,0
mov ebx,memptr
invoke atodw,ebx
mov ebx,eax
invoke dw2hex,ebx,addr buffer
invoke SetWindowText,hEdit1,addr buffer
invoke GlobalFree,memptr
invoke CloseHandle,fHandle


Now of course I have tried variations of this like addr and no addr etc. I'm not quite sure what to do. Another problem I seem to have is that the sendmessage to the textbox is zero terminated or readfile im not sure. So reading an exe you only get MZ chr(90). If my code can be modified to do this can i get some help? Or maybe some example code that will do this? Even a point in the right direction would be appreciated. Thanks.

zooba

I think you'll find the call to atodw is unnecessary. If you are intending to display the hex values, treat memptr as a pointer to an array of bytes. Then you'll need to loop through the entire array, reading the value at memptr+some offset, and using dw2hex to convert it to hex.

You'll need a buffer at least three times the size of the file (two characters and a space per byte) to fill with the hex version of the file.

These is an example called HEXDUMP that comes with MASM32. That will probably help.

Cheers,

Zooba :U

Cyrus

Perfect, an example was all i needed. My thanks!