I have question searched in google but without something that can help. How to get the binary stream from files ( especially executable files) using winapi (CreateFile , etc)????
I learned in these days how to read write files using Createfile, ReadFile, WriteFile , etc and all these WINAPI functions.
But ReadFile get me characters contains of files, and when I want to read exe files it get me a few bytes and that's it.
The reason of this behaviour is that the readfile read the file until get NULL and as you know the exe files have alot of NULL codes. So I must read the binary code of the exe file and do my process on it, this way is better.... but how to do it???
The reason of this behaviour is that the readfile read the file until get NULL
I think you misunderstood. ReadFile() reads in binary mode, the same as fstream.read() or in C fread(). You tell it how many bytes to read and it will read that many bytes, or until end-of-file. ReadFile() doesn't do text reads like c++ getline() or fgets().
If My guess is correct, I think you phrase the question wrong because of the way your saying that it reads contents of the file.. I think you mean read the instructions of an EXE file. Such as the OPCodes or I think what you mean by "EXE's have a lot of nulls" is that they have a lot of NOP's Aka No-Operations.
That's Assembly code. ReadFile doesn't do that for you. It opens the file as a text and reads the contents of that. It's the same as opening the EXE in Notepad and reading it. ReadFile reads in Binary MODE but doesn't actually read in the assembly of the file.
I'm also looking for a way to read/write Assembly to an exe. So.. :S If I find a way then I'll answer here until then I'll just be looking around.
Sorry gueys, I have misunderstood the way of the function work.
I have make a debug step by step and I have discoverd that the (ReadData) variable value contain the hole characters specified, but how to convert it to HEXADECIMAL?
Thanx gueys, I will complete the road by myselft.
Thank you all.
Just an observation. If you are reading a binary file, you should define ReadData as an unsigned char to accomodate binary values from 0 to 255. Otherwise, the ReadFile variable will contain negative values for any binary data over 127.