Solved Why is this function within my asm function crashing my game?

Hexui Undetected CSGO Cheats PUBG Accounts

Lunoz

Newbie
Full Member
Jun 18, 2015
18
102
0
C++:
DWORD addy2;
_declspec (naked) void Interact()
{
	addy2 = nextAddress();
	//__asm mov addy2, edi // This is disabled until I can figure out why the above line crashes my game.


	__asm push edi
	__asm mov ecx, esi
	__asm call eax
	__asm jmp(InteractF)

}
This is a jumped too function. If I take out the nextAddress() function, everything runs fine. I know the (nextAddress) function itself is not at fault because I linked it to a hot key earlier, and it did exactly as it should returning the value that it should each cycle (returns a DWORD address, cycling through 6 different addresses).

I'm assuming there is some kind of syntactical error not being detected here. I only need the next-address function to be called when this assembly is called.
 
Last edited:

Solaire

Respected Hacker
Dank Tier VIP
Dec 15, 2013
1,051
16,353
62
C++:
DWORD addy2;
_declspec (naked) void Interact()
{
    addy2 = nextAddress();
    //__asm mov addy2, edi // This is disabled until I can figure out why the above line crashes my game.


    __asm push edi
    __asm mov ecx, esi
    __asm call eax
    __asm jmp(InteractF)

}
This is a jumped too function. If I take out the nextAddress() function, everything runs fine. I know the (nextAddress) function itself is not at fault because I linked it to a hot key earlier, and it did exactly as it should returning the value that it should each cycle (returns a DWORD address, cycling through 6 different addresses).

I'm assuming there is some kind of syntactical error not being detected here. I only need the next-address function to be called when this assembly is called.
The function call probably messes with the registers. Do this:

C++:
__asm pushfd
__asm pushad
addy2 = nextAddress();
__asm popad
__asm popfd
 

Lunoz

Newbie
Full Member
Jun 18, 2015
18
102
0
Works perfectly! Thank you!

Apparently I need to learn more about the differences between the stack and the registers... I thought the registers were the ESI, EAX, EDI, etc, I thought the stack was what those sat on. Still not entirely sure where the push/pop come into play, even though I know what they do by definition.
 

till0sch

Respected Hacker
Dank Tier VIP
Dank Tier Donator
Oct 14, 2012
1,104
12,593
51
Works perfectly! Thank you!

Apparently I need to learn more about the differences between the stack and the registers... I thought the registers were the ESI, EAX, EDI, etc, I thought the stack was what those sat on. Still not entirely sure where the push/pop come into play, even though I know what they do by definition.
The arguments get pushed ontk the stack, you were right with the registers too but if not your registers make this crash it is esp, the stack pointer pointing at it which gets changed.
Your hooked function uses esp fot its arguments and stack variables so restoring everything is necessary because otherwise when esp changes, the program looks for it at the wrong addresses
 

Lunoz

Newbie
Full Member
Jun 18, 2015
18
102
0
Yes but the thing that confuses me is that you talk about pushing them onto the stack, or popping them off... removing them, restoring them. Where do they sit when they're not on the stack? If you remove them with a pop, and want to push them back, where do they go in between this? Like Krampus said my registers were getting messed up, so they get pushed, letting my function run, then popping them back into place. Where are they going? I have no idea how to visualize this in my head. There's the stack, the registers (on the stack?), and...?
 

Rake

I'm not your friend
Administrator
Jan 21, 2014
13,000
79,068
2,467
The registers reside on the CPU, the stack resides in RAM(virtual memory in the RAM).

push ecx = put what ECX holds on the top of the stack

pop eax = put the value on top of the stack into eax

The values don't go anywhere between that. There is a stack frame between the EBP and the ESP, when working in one function all the variables are stored in the the stack frame setup by that function. when you jump to another function the ESP is changed so you are working with a different stack frame. The code can jump between stack frames or also push and pop values to save values between other sections of code. Not a perfect explanation but I hope you get the idea
 
Community Mods