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++ Inject Opcode

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

Joined: 30 Jan 2017
Posts: 18

PostPosted: Sun Feb 05, 2017 5:15 am    Post subject: C++ Inject Opcode Reply with quote

What's wrong with my code:

Code:


BYTE jnp[3] = "\x7B\x22";

DWORD JNPAddr = 0x0044DD8C;

HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, HS4LProcess(L"main.exe"));

WriteProcessMemory(hProcess, (LPVOID)JNPAddr, &jnp, 3, NULL);

 


It insists to crash and I don't know what the heck I'm doing wrong.

_________________
I'm newbie ...


Last edited by Thiago on Sun Feb 05, 2017 10:09 am; edited 2 times in total
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Sun Feb 05, 2017 5:45 am    Post subject: Reply with quote

WriteProcessMemory(hProcess, (LPVOID)JNPAddr, &jnp, 2, NULL);
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Thiago
Newbie cheater
Reputation: 0

Joined: 30 Jan 2017
Posts: 18

PostPosted: Sun Feb 05, 2017 6:21 am    Post subject: Reply with quote

It stops from crashing, but the opcode is not being written, I've checked the addresses and stuff but nothing yet.
_________________
I'm newbie ...
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 458

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

PostPosted: Sun Feb 05, 2017 8:39 am    Post subject: Reply with quote

you're sure the original code isn't 7b 22 ? (because if writing fails then it should also have failed on that 3 bytes)

anyhow, try using virtualprotectex to make the memory writable first

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Thiago
Newbie cheater
Reputation: 0

Joined: 30 Jan 2017
Posts: 18

PostPosted: Sun Feb 05, 2017 10:03 am    Post subject: Reply with quote

This is the original instructions, without messing with it.

After writting the code to give permissions it works, but only jumps one instruction away from the jmp, causing the program to crash.

I think it's because it's vanishing the opcode " 22 " instead of just modifying the " 7B " to a " EB ".



Screenshot_86.png
 Description:
 Filesize:  23.43 KB
 Viewed:  11239 Time(s)

Screenshot_86.png



_________________
I'm newbie ...
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Sun Feb 05, 2017 10:09 am    Post subject: Reply with quote

That shows the address is the dynamic address: main.exe+4DD8C
Your code is using the static address: 0x0044DDB0
Open Cheat Engine and go to address 0044DDB0 in memory view
That's where you're writing
Back to top
View user's profile Send private message
Thiago
Newbie cheater
Reputation: 0

Joined: 30 Jan 2017
Posts: 18

PostPosted: Sun Feb 05, 2017 10:10 am    Post subject: Reply with quote

Quote:
That shows your address is the dynamic address: main.exe+4DD8C
Your code is using the static address: 0x0044DDB0


I noticed I forget to change it before uploading the question, but now I've edited it.

_________________
I'm newbie ...
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Sun Feb 05, 2017 10:18 am    Post subject: Reply with quote

There is still a huge difference between those addresses.
Go read up on dynamic vs static.
In memory viewer, go to address 0044DD8C.
It's not the same place as in your screenshot.
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Sun Feb 05, 2017 10:24 am    Post subject: Reply with quote

Why are you writing 3 bytes from the buffer when there's actually 2 bytes?
and if I'm correct, the buffer argument you pass is the address of the local variable of the buffer instead the address of the buffer itself
shouldn't it be
Code:

WriteProcessMemory(hProcess, (LPVOID)JNPAddr, jnp, 2, NULL);

_________________
Stylo
Back to top
View user's profile Send private message
Thiago
Newbie cheater
Reputation: 0

Joined: 30 Jan 2017
Posts: 18

PostPosted: Sun Feb 05, 2017 10:37 am    Post subject: Reply with quote

Quote:
Why are you writing 3 bytes from the buffer when there's actually 2 bytes?


I'm getting " A value of type " const char[3] cannot be used to initialize an entity of type BYTE [2] "

When putting the right size.

_________________
I'm newbie ...
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Sun Feb 05, 2017 12:47 pm    Post subject: Reply with quote

That's because strings are null terminated by a 0x00, and it's therefore three characters.
Code:
BYTE jnp[2] = { 0x7B, 0x22 };
Back to top
View user's profile Send private message
Thiago
Newbie cheater
Reputation: 0

Joined: 30 Jan 2017
Posts: 18

PostPosted: Sun Feb 05, 2017 5:48 pm    Post subject: Reply with quote

I see it, I finally found the error, I was missing one number in the address, just so it wrote to the wrong address, and it crashed the game, but now I got everything working properly.

Thanks for helping everyone.

_________________
I'm newbie ...
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