Solved C++ Mid Function Hooking/Codecaving Tutorial

Hexui Undetected CSGO Cheats Sinkicheat PUBG Cheat

Brackston

Newbie
Full Member
Dec 2, 2013
9
144
0
Hi! I have been following your tutorials for a little while now and have not been having much trouble until now. My issue is that the code I inject in this tutorial crashes the game whenever I try and fire my weapon. I get a successful inject. I was able to get .dll injection to work with the signature scanning tutorial and get my modifications to successfully work. The issue I think I am having is in the byte count or code with the memory lines. I will just go ahead and show you. I have uploaded screenshots to show you what I see on my screen.

I have found the ammo decrement and you can see it here in this picture. OllyDB ammo ss.PNG

I can get a single signature by scanning just the decrement line and and the 1 line below it. This screenshot shows the highlighted lines used in the scan and results. Ollydbg ammo sig scan ss.PNG

From looking at the screenshot above I notice that from the starting line to where I want to end is 6 bytes away.

FF OE
8D 74 24 | 24

My reasoning here is that the jump is 5 bytes which would leave the final 24 unaccounted for. You have to change this to be included or the game may crash because it will not know how to handle that last byte.

in fleeps tutorial his count was seven so I had to change the number in the code to match my set of variables. which can be seen here

finally we get to what is my version of the set of instructions in the asm section of the code. I write out the original instruction and change what I want to change. That can be seen here. Ollydbg replacement code in c++.PNG


Thanks for all your great work. You make this stuff very easy to follow. I feel like I am really close to getting this solved and am just missing some minor details. I have followed many of your other tutorials with great success. Thanks again.
 

Attachments

Last edited:

c5

Kim Kong Trasher
Dank Tier VIP
Dank Tier Donator
Jul 19, 2012
1,187
12,638
76
Step through the code and make sure it jumps back to the right position.

Also I don't see the purpose of hooking here, if you can simply do a one byte patch on the code itself. DEC -> INC
 

Truth

Meme Tier VIP
Dank Tier Donator
Nov 14, 2012
337
2,628
2
Just looking at the tutorial.. the asm you got is

C++:
_asm lea esi, [esp+0x24]
When it should be

C++:
__asm mov edi, [esp+0x24]
With the 2 underscores

Also you are missing the push edi :D

Hope this helps

Edit: Also you only have 1 underscore for the
C++:
_declspec
should be 2 underscores

Though I am not sure if it matters but I assume so :D
 
Last edited:

Brackston

Newbie
Full Member
Dec 2, 2013
9
144
0
Thanks for the reply. I know my asm instructions don't match the tutorial exactly, but that is because my lines of asm in ollydbg are slightly different than the ones used in the tutorial.
I will write out and show the comparison.

Tutorial: original code from olly:

__asm DEC [ESI]
__asm push edi
__asm move edi, [esp+0x14]

My ollydbg original code:

__asm DEC [ESI]
__asm lea esi, [esp+0x24]
there is a call line here, but I don't think it is relevant.

I didn't realize it was 2 underscores as well. I will test some things out and give your suggestion a try when I get done with my daily activities today. Thanks for the help.
 
Last edited:

Truth

Meme Tier VIP
Dank Tier Donator
Nov 14, 2012
337
2,628
2
I see yea.. didn't notice on that they was different.. thought you was following the tutorial. My mistake! (really tired) :p

Good luck!
 

Brackston

Newbie
Full Member
Dec 2, 2013
9
144
0
I uploaded the wrong screenshot earlier at the initiate hooks part of my post. I have updated the original screenshot to be accurate...sorry for the miscommunication.

it is still showing the wrong one in the attatched thumbnails, but you can just ignore that one. The correct one has been inserted into the post.
 
Last edited:

Brackston

Newbie
Full Member
Dec 2, 2013
9
144
0
Hey c5. Thanks for the help. I started sorting through the code and could not find anything wrong at all. I went through and rewrote each section at a time and then injected the dll after each change to try and troubleshoot this. I had no luck whatsoever until I rewrote the void InitiateHooks() section of the code. Once that part was rewritten everything was working fine. I am still not sure what the exact problem was though. I compared my new InitiateHooks() section with what I had before and they are exactly the same :confused:. I left the rewritten code pasted in the bottom of the post if you wanna look at it and compare it to my screenshot from earlier.

C++:
void InitiateHooks()
{

    DWORD ammoAddy = FindPattern("ac_client.exe", "\xFF\x0E\x8D\x74\x24\x24", "xxxxxx");

    ammoAddy += 0;
    MsgBoxAddy(ammoAddy);

    AmmoJmpBack = ammoAddy + 0x6;

    PlaceJMP((BYTE*)ammoAddy, (DWORD)InfiniteAmmo, 6);
The purpose for doing it this way was just so I could follow and learn the methods in the tutorial.

I am happy I was able to get it working and feel confident in applying it in other scenarios where needed.

Once again thanks for all your input and help.
 
Last edited by a moderator:

NTvalk

Hacker
Meme Tier VIP
Jul 6, 2013
499
3,108
8
Hey c5. Thanks for the help. I started sorting through the code and could not find anything wrong at all. I went through and rewrote each section at a time and then injected the dll after each change to try and troubleshoot this. I had no luck whatsoever until I rewrote the void InitiateHooks() section of the code. Once that part was rewritten everything was working fine. I am still not sure what the exact problem was though. I compared my new InitiateHooks() section with what I had before and they are exactly the same :confused:. I left the rewritten code pasted in the bottom of the post if you wanna look at it and compare it to my screenshot from earlier.


void InitiateHooks()
{

DWORD ammoAddy = FindPattern("ac_client.exe", "\xFF\x0E\x8D\x74\x24\x24", "xxxxxx");

ammoAddy += 0;
MsgBoxAddy(ammoAddy);

AmmoJmpBack = ammoAddy + 0x6;

PlaceJMP((BYTE*)ammoAddy, (DWORD)InfiniteAmmo, 6);

The purpose for doing it this way was just so I could follow and learn the methods in the tutorial.

I am happy I was able to get it working and feel confident in applying it in other scenarios where needed.

Once again thanks for all your input and help.
Good to see you got it working, but just so you know, as c5 stated above you can do this in another easier way.
You can just overwrite the DEC to an INC.
 

Rake

Cesspool Admin
Administrator
Jan 21, 2014
12,367
78,998
2,414
Hey c5. Thanks for the help. I started sorting through the code and could not find anything wrong at all. I went through and rewrote each section at a time and then injected the dll after each change to try and troubleshoot this. I had no luck whatsoever until I rewrote the void InitiateHooks() section of the code. Once that part was rewritten everything was working fine. I am still not sure what the exact problem was though. I compared my new InitiateHooks() section with what I had before and they are exactly the same :confused:. I left the rewritten code pasted in the bottom of the post if you wanna look at it and compare it to my screenshot from earlier.

C++:
void InitiateHooks()
{

    DWORD ammoAddy = FindPattern("ac_client.exe", "\xFF\x0E\x8D\x74\x24\x24", "xxxxxx");

    ammoAddy += 0;
    MsgBoxAddy(ammoAddy);

    AmmoJmpBack = ammoAddy + 0x6;

    PlaceJMP((BYTE*)ammoAddy, (DWORD)InfiniteAmmo, 6);
The purpose for doing it this way was just so I could follow and learn the methods in the tutorial.

I am happy I was able to get it working and feel confident in applying it in other scenarios where needed.

Once again thanks for all your input and help.
Please next time use the CPP tags when you're posting snippets. I've done it for you now, but keep it in mind for the next time please. :)
 
Attention! Before you post:

Read the How to Ask Questions Guide
99% of questions are answered in the Beginner's Guide, do it before asking a question.

No Hack Requests. Post in the correct section.  Search the forum first. Read the rules.

How to make a good post:

  • Fill out the form correctly
  • Tell us the game name & coding language
  • Post everything we need to know to help you
  • Ask specific questions, be descriptive
  • Post errors, line numbers & screenshots
  • Post code snippets using code tags
  • If it's a large project, zip it up and attach it

If you do not comply, your post may be deleted.  We want to help, please make a good post and we will do our best to help you.

Community Mods