flat assembler
Message board for the users of flat assembler.
Index
> Windows > convert bytes from readfile to hexadecimal |
Author |
|
typedef 24 May 2014, 20:24
You specified a DWORD which will contain 4 bytes. You want to use a BYTE instead.
First read the size of the file, and iterate through all the bytes one by one. OR NOTE: The largest data type is the best to use. Code: iterations = filesize / sizeof.DWORD; remaining= filesize MOD sizeof.DWORD; DWORD buffer; for(i = 0; i < iterations; i++) { read_File(hFile, buffer, sizeof.DWORD); // You just read 4 bytes here for(x = 0; i < sizeof.DWORD; x++) printf(".02X%", buffer[i]); } Then you check if there are any remaining bytes, if so, read those remaining bytes. In this case will be less than 4 (sizeof.DWORD) |
|||
24 May 2014, 20:24 |
|
patchariadog 24 May 2014, 20:38
I still don't quiet understand. this looks like c++ code so it is hard to compile. also I know how to loop through the file, I just don't get why I can't read 8kb in a buffer and then convert that at once. I know if you do this for text files it works. I am just trying to figure out the fastest way to open a file and read it and display its hexadecimal.
thanks for all the help |
|||
24 May 2014, 20:38 |
|
typedef 24 May 2014, 21:27
This will print DWORDs because of the way you are pointing to your data.
Code: cinvoke wsprintfA,buffer1,"%X",[filebuffer] It seems like you want to convert the bytes all at once. Here is an API to do that for you ALL AT ONCE. You'll have to do the memory allocations yourself. http://msdn.microsoft.com/en-us/library/windows/desktop/aa379887(v=vs.85).aspx Code: format pe gui 4.0 include 'win32ax.inc' entry main section '.data' data readable writeable bin_data db 'hello world in hexadecimal' ; binary data bin_data_len = $ - bin_data BUF_LEN = 1024 pszHexBuffer db BUF_LEN dup(0) ; will contain converted bytes in hex. Twice the size of the original buffer at least (Read documentation about the last _In_Out parameter) dwBuffLen dd BUF_LEN section '.code' code readable executable main: push dwBuffLen push pszHexBuffer push 0x0000000b ; CRYPT_STRING_HEXASCIIADDR push bin_data_len push bin_data call [CryptBinaryToStringA] push 0 push 0 push pszHexBuffer push 0 call [MessageBoxA] push 0 call [ExitProcess] section '.idata' import data readable library user32,'user32.dll',\ kernel32,'kernel32.dll',\ crypto, 'Crypt32.dll' import crypto,\ CryptBinaryToStringA,'CryptBinaryToStringA' include 'api/user32.inc' include 'api/kernel32.inc' |
|||
24 May 2014, 21:27 |
|
patchariadog 25 May 2014, 02:28
Hi typedef
thank you so much that is exactly what I was looking for I had no clue about that api I was wondering if there is a way to separate the data after I get all the data in the one string so I could have memory address string, hex string and ascii string basically I am trying to ask if there is a substring function for assembly/ if this were c++ I would usually do something like this Code: ;str contains the data std::string address = str.substr (0,4); std::string hex = str.substr (8,32); std::string ascii = str.substr (42,16); ;print it however ;then I would just loop through using a counter I have yet to figure out how to substring in assembly thanks |
|||
25 May 2014, 02:28 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.