Eddie
July 20th, 2005, 08:36
Ok, I'm a newb in both using API calls and reverse engineering who is attempting to build his own patch. What I'm trying to do is a program to read a string from another program. This has to be really easy and I already got the memory address of the string.
The hardest part for me is that I use Ada to write my programs, which is a great language until you have to interact with other things such the API calls. It is very strict on variable types and it can be really hard to convert from one type to another if you don't have the functions to do so, but well, I thing I got over this.
I based my first testing program in this guide: http://www.woodmann.com/fravia/natz_mp2.htm
And simplifying this is what I do:
- Calling FindWindow to get the window handle from the program which I want to read from. Works fine.
- Getting the process ID with the GetWindowThreadProcessId function. Works fine.
- Open a thread to that process using the OpenProcess function. Either by using the PROCESS_VM_READ or PROCESS_ALL_ACCESS flags it works fine.
- Using the ReadProcessMemory with the following parameters:
hProcess: The handle provided by the previous function.
lpBaseAddress: 16#0C38DF8C# The Hex value that points at the start of the string.
lpBuffer: String which I'm saving the returning value in.
nSize: 8 bytes. The string is longer, but I just want to get this to work atm.
lpNumberOfBytesRead: Null. I don't really need to know how many bytes I am reading atm because the function is not even working for me yet.
Guess what I get... It returns the value 0! Ok, then I try to use the GetLastError and FormatMessage functions attempting to have an idea of what is not working. What I get in my win would mean "Invalid controller", I don't know the exact error message in english as I'm not running an english version of windows. I don't remember the error code but I think it was 6.
I think I said almost everything... Oh, I tried this only in Win XP Home with admin rights.
Thanks a lot to whoever who could help me.
Regards~
The hardest part for me is that I use Ada to write my programs, which is a great language until you have to interact with other things such the API calls. It is very strict on variable types and it can be really hard to convert from one type to another if you don't have the functions to do so, but well, I thing I got over this.
I based my first testing program in this guide: http://www.woodmann.com/fravia/natz_mp2.htm
And simplifying this is what I do:
- Calling FindWindow to get the window handle from the program which I want to read from. Works fine.
- Getting the process ID with the GetWindowThreadProcessId function. Works fine.
- Open a thread to that process using the OpenProcess function. Either by using the PROCESS_VM_READ or PROCESS_ALL_ACCESS flags it works fine.
- Using the ReadProcessMemory with the following parameters:
hProcess: The handle provided by the previous function.
lpBaseAddress: 16#0C38DF8C# The Hex value that points at the start of the string.
lpBuffer: String which I'm saving the returning value in.
nSize: 8 bytes. The string is longer, but I just want to get this to work atm.
lpNumberOfBytesRead: Null. I don't really need to know how many bytes I am reading atm because the function is not even working for me yet.
Guess what I get... It returns the value 0! Ok, then I try to use the GetLastError and FormatMessage functions attempting to have an idea of what is not working. What I get in my win would mean "Invalid controller", I don't know the exact error message in english as I'm not running an english version of windows. I don't remember the error code but I think it was 6.
I think I said almost everything... Oh, I tried this only in Win XP Home with admin rights.
Thanks a lot to whoever who could help me.
Regards~