marco0999 Cheater Reputation: 0
Joined: 28 Jun 2020 Posts: 29 Location: Italy
|
Posted: Wed Jul 27, 2022 5:36 am Post subject: Change a variable value inside a function hooked with detour |
|
|
Hi,
I have succefully hooked this function with detours:
Assembly code:
Code: | .text:00431580 ; =============== S U B R O U T I N E =======================================
.text:00431580
.text:00431580
.text:00431580 sub_431580 proc near ; CODE XREF: sub_4311E0+3F↑p
.text:00431580 mov eax, dword_2C215C8
.text:00431585 push esi ; char
.text:00431586 xor esi, esi
.text:00431588 mov byte_2C3C448, 0
.text:0043158F cmp [eax+14h], esi
.text:00431592 jnz short loc_4315A3
.text:00431594 push offset aJoystickIsNotA ; "Joystick is not active\n"
.text:00431599 call sub_426A40
.text:0043159E add esp, 4
.text:004315A1 pop esi
.text:004315A2 retn
.text:004315A3 ; ---------------------------------------------------------------------------
.text:004315A3
.text:004315A3 loc_4315A3: ; CODE XREF: sub_431580+12↑j
.text:004315A3 push edi ; char
.text:004315A4 call ds:joyGetNumDevs
.text:004315AA mov edi, eax
.text:004315AC cmp edi, esi
.text:004315AE jnz short loc_4315C0
.text:004315B0 push offset aJoystickNotFou ; "...joystick not found (driver not prese"...
.text:004315B5 call sub_426A40
.text:004315BA add esp, 4
.text:004315BD pop edi
.text:004315BE pop esi
.text:004315BF retn
.text:004315C0 ; ---------------------------------------------------------------------------
.text:004315C0
.text:004315C0 loc_4315C0: ; CODE XREF: sub_431580+2E↑j
.text:004315C0 mov uJoyID, esi
.text:004315C6 cmp edi, esi
.text:004315C8 jle short loc_43162B
.text:004315CA mov esi, ds:joyGetPosEx |
Pseudocode:
Code: | char *sub_431580()
{
char *result; // eax
signed int v1; // eax
signed int v2; // edi
MMRESULT v3; // eax
MMRESULT v4; // eax
byte_2C3C448 = 0;
if ( !*(_DWORD *)(dword_2C215C8 + 20) )
return sub_426A40("Joystick is not active\n");
v1 = joyGetNumDevs();
v2 = v1;
if ( !v1 )
return sub_426A40("...joystick not found (driver not present)\n");
uJoyID = 0;
if ( v1 > 0 )
{
while ( 1 )
{
memset(&pji, 0, 0x34u);
pji.dwSize = 52;
pji.dwFlags = 1024;
v3 = joyGetPosEx(uJoyID, &pji);
if ( !v3 )
break;
if ( (signed int)++uJoyID >= v2 )
return sub_426A40("...joystick not found (no valid joysticks - 0x%X)\n", v3);
}
} |
]but I need to change the value this this variable inside the code:
Code: | .data:02C3C44C uJoyID dd ? ; DATA XREF: sub_431580:loc_4315C0↑w |
that actually is assegned to 0.
Here my code:
Code: | typedef char * (__fastcall *HookInitJoytWolfram) ();
char * __fastcall HookInitJoySubWolfram()
{
HookInitJoytWolfram originalFunction = (HookInitJoytWolfram)AddressOfHookDamageFunction;
LF::Log_Update("Init Joystick and change the default controller");
UINT* JoyIndexDevice = (UINT*)0x02C3C44C;
*JoyIndexDevice = 3;
return originalFunction();
} |
but the value seem not change becouse I suppose my is not the right way to change the value.
Can you please help me ?
|
|