Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


C Code Help

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
cemow
Newbie cheater
Reputation: 0

Joined: 22 Jan 2012
Posts: 10

PostPosted: Fri Feb 03, 2012 3:42 pm    Post subject: C Code Help Reply with quote

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
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Fri Feb 03, 2012 6:15 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
cemow
Newbie cheater
Reputation: 0

Joined: 22 Jan 2012
Posts: 10

PostPosted: Fri Feb 03, 2012 8:33 pm    Post subject: Reply with quote

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
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Fri Feb 03, 2012 8:57 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
cemow
Newbie cheater
Reputation: 0

Joined: 22 Jan 2012
Posts: 10

PostPosted: Fri Feb 03, 2012 9:32 pm    Post subject: Reply with quote

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 Very Happy
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Sat Feb 04, 2012 1:06 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
Dark Byte
Site Admin
Reputation: 474

Joined: 09 May 2003
Posts: 25953
Location: The netherlands

PostPosted: Sat Feb 04, 2012 1:12 am    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
cemow
Newbie cheater
Reputation: 0

Joined: 22 Jan 2012
Posts: 10

PostPosted: Sat Feb 04, 2012 7:37 am    Post subject: Reply with quote

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
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Sat Feb 04, 2012 2:46 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
cemow
Newbie cheater
Reputation: 0

Joined: 22 Jan 2012
Posts: 10

PostPosted: Sat Feb 04, 2012 3:00 pm    Post subject: Reply with quote

How can I do this? I thought by this way I could reach memory addresses than could change variables.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Sat Feb 04, 2012 3:02 pm    Post subject: Reply with quote

You need to use API like:
- OpenProcess
- ReadProcessMemory
- WriteProcessMemory
- VirtualQueryEx

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
cemow
Newbie cheater
Reputation: 0

Joined: 22 Jan 2012
Posts: 10

PostPosted: Sat Feb 04, 2012 3:12 pm    Post subject: Reply with quote

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
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Sat Feb 04, 2012 4:51 pm    Post subject: Reply with quote

cemow wrote:
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?


No you can use C and C++ for this, no need to change languages. Just use MSDN as a reference to learn from:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms684320%28v=vs.85%29.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/ms681674%28v=vs.85%29.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/ms680553%28v=vs.85%29.aspx
http://msdn.microsoft.com/en-us/library/windows/desktop/aa366907%28v=vs.85%29.aspx

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
cemow
Newbie cheater
Reputation: 0

Joined: 22 Jan 2012
Posts: 10

PostPosted: Sat Feb 04, 2012 4:57 pm    Post subject: Reply with quote

Thanks a lot Wiccaan, you really helped me Smile.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites