View previous topic :: View next topic |
Author |
Message |
Thiago Newbie cheater Reputation: 0
Joined: 30 Jan 2017 Posts: 18
|
Posted: Sun Feb 05, 2017 5:15 am Post subject: C++ Inject Opcode |
|
|
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 |
|
|
Dark Byte Site Admin Reputation: 458
Joined: 09 May 2003 Posts: 25291 Location: The netherlands
|
Posted: Sun Feb 05, 2017 5:45 am Post subject: |
|
|
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 |
|
|
Thiago Newbie cheater Reputation: 0
Joined: 30 Jan 2017 Posts: 18
|
Posted: Sun Feb 05, 2017 6:21 am Post subject: |
|
|
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 |
|
|
Dark Byte Site Admin Reputation: 458
Joined: 09 May 2003 Posts: 25291 Location: The netherlands
|
Posted: Sun Feb 05, 2017 8:39 am Post subject: |
|
|
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 |
|
|
Thiago Newbie cheater Reputation: 0
Joined: 30 Jan 2017 Posts: 18
|
Posted: Sun Feb 05, 2017 10:03 am Post subject: |
|
|
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 ".
Description: |
|
Filesize: |
23.43 KB |
Viewed: |
11248 Time(s) |
|
_________________
I'm newbie ... |
|
Back to top |
|
|
Zanzer I post too much Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
Posted: Sun Feb 05, 2017 10:09 am Post subject: |
|
|
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 |
|
|
Thiago Newbie cheater Reputation: 0
Joined: 30 Jan 2017 Posts: 18
|
Posted: Sun Feb 05, 2017 10:10 am Post subject: |
|
|
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 |
|
|
Zanzer I post too much Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
Posted: Sun Feb 05, 2017 10:18 am Post subject: |
|
|
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 |
|
|
Stylo Grandmaster Cheater Supreme Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Sun Feb 05, 2017 10:24 am Post subject: |
|
|
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 |
|
|
Thiago Newbie cheater Reputation: 0
Joined: 30 Jan 2017 Posts: 18
|
Posted: Sun Feb 05, 2017 10:37 am Post subject: |
|
|
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 |
|
|
Zanzer I post too much Reputation: 126
Joined: 09 Jun 2013 Posts: 3278
|
Posted: Sun Feb 05, 2017 12:47 pm Post subject: |
|
|
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 |
|
|
Thiago Newbie cheater Reputation: 0
Joined: 30 Jan 2017 Posts: 18
|
Posted: Sun Feb 05, 2017 5:48 pm Post subject: |
|
|
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 |
|
|
|