| View previous topic :: View next topic |
| Author |
Message |
cemow Newbie cheater
Reputation: 0
Joined: 22 Jan 2012 Posts: 10
|
Posted: Fri Feb 03, 2012 3:42 pm Post subject: C Code Help |
|
|
Hi everyone, I'm a mechatronic engineering student and I am trying to write a simple program to find datas inside file such as "fscanf()" function in C to reach datas from a .txt file just because I am curious about how this system works. I tried to use this function on Cheat Engine's Tutorial .exe file, but as expected It didn't work not like it works on .txt files. Can you help me how can I reach datas, like I want to reach 100 value in Cheat Engine Tutorial and change it by myself. My regards...
Just want to know how do I reach an .exe via C. |
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Fri Feb 03, 2012 6:15 pm Post subject: |
|
|
Try opening the file as binary.
Assuming that you are using fopen since you are using fscanf, open the file with:
| Code: | | FILE* f = fopen( "filename.exe", "rb+" ); |
_________________
- Retired. |
|
| Back to top |
|
 |
cemow Newbie cheater
Reputation: 0
Joined: 22 Jan 2012 Posts: 10
|
Posted: Fri Feb 03, 2012 8:33 pm Post subject: |
|
|
That didnt work. Here is my code
| Code: |
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
#include <windows.h>
int main()
{
int a;
FILE *fp;
fp = fopen("C:\\Program Files\\Cheat Engine 6.1\\Tutorial-i386.exe","rb+");
fscanf(fp, "%d", &a);
printf("%d", a);
fclose(fp);
system("PAUSE");
return 0;
}
|
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Fri Feb 03, 2012 8:57 pm Post subject: |
|
|
Can I ask what you are trying to accomplish with this? You aren't in the right direction at all with this:
| Code: | int a;
fscanf(fp, "%d", &a); |
This isn't scanning for anything other then what the address of 'a' is which isn't what you want. _________________
- Retired. |
|
| Back to top |
|
 |
cemow Newbie cheater
Reputation: 0
Joined: 22 Jan 2012 Posts: 10
|
Posted: Fri Feb 03, 2012 9:32 pm Post subject: |
|
|
I just wanted to be sure that the code can read .exe file. Now I got this my false, thought it is something like "scanf". Using
| Code: | int a;
fscanf(fp, "%d", a);
|
instead of
| Code: | int a;
fscanf(fp, "%d", &a);
|
solved my problem. Now does that mean I can read any value, any address from this .exe file? I guess the answer is no. Can you explain me what am I doing wrong here please?
By the way thank you Wiccaan  |
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Sat Feb 04, 2012 1:06 am Post subject: |
|
|
fscanf isn't going to scan the full file, it looks at the current buff position and attempts to read the given type into the variable. For example, you could read the first two bytes of a file header (MZ) using:
| Code: | FILE* f = fopen( "C:\\Tools\\CheatEngine62Beta4\\tutorial-i386.exe", "rb+" );
if( f == NULL ) return 0;
unsigned char pe_MZ[ 2 ];
fscanf( f, "%2s", pe_MZ );
fclose( f ); |
The file pointer is moved two after this occurs. _________________
- Retired. |
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 474
Joined: 09 May 2003 Posts: 25953 Location: The netherlands
|
Posted: Sat Feb 04, 2012 1:12 am Post subject: |
|
|
Also, just to be clear: Do you want to search data inside a file or inside a process ?
Those are two different things (unless you're on linux) _________________
Tools give you results. Knowledge gives you control.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
cemow Newbie cheater
Reputation: 0
Joined: 22 Jan 2012 Posts: 10
|
Posted: Sat Feb 04, 2012 7:37 am Post subject: |
|
|
Wiccaan, so I must create an array, dynamically or normally, to read all values and search between these variables? As you said that program displays same value when I make a for loop 10 times while I expected it to give me different values everytime.
Dark Byte, I guess I meant here process, not data, which I meant to change variables at a program while it is running. I prefer to use linux but Wine runs slowly than windows, so I am using windows right now. |
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Sat Feb 04, 2012 2:46 pm Post subject: |
|
|
| cemow wrote: | Wiccaan, so I must create an array, dynamically or normally, to read all values and search between these variables? As you said that program displays same value when I make a for loop 10 times while I expected it to give me different values everytime.
Dark Byte, I guess I meant here process, not data, which I meant to change variables at a program while it is running. I prefer to use linux but Wine runs slowly than windows, so I am using windows right now. |
If you are looking to scan inside a running process then using the code you are using now wont work. You need to read the memory of the process while it is running. _________________
- Retired. |
|
| Back to top |
|
 |
cemow Newbie cheater
Reputation: 0
Joined: 22 Jan 2012 Posts: 10
|
Posted: Sat Feb 04, 2012 3:00 pm Post subject: |
|
|
| How can I do this? I thought by this way I could reach memory addresses than could change variables. |
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Sat Feb 04, 2012 3:02 pm Post subject: |
|
|
You need to use API like:
- OpenProcess
- ReadProcessMemory
- WriteProcessMemory
- VirtualQueryEx _________________
- Retired. |
|
| Back to top |
|
 |
cemow Newbie cheater
Reputation: 0
Joined: 22 Jan 2012 Posts: 10
|
Posted: Sat Feb 04, 2012 3:12 pm Post subject: |
|
|
| So I need C# for this process(or maybe other Interface programs)? I thought I could change code manually, it shouldn't be that hard right? If you know links that shows an example of these functions or codes please? |
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
|
| Back to top |
|
 |
cemow Newbie cheater
Reputation: 0
Joined: 22 Jan 2012 Posts: 10
|
Posted: Sat Feb 04, 2012 4:57 pm Post subject: |
|
|
Thanks a lot Wiccaan, you really helped me . |
|
| Back to top |
|
 |
|