0

I'm trying to edit pointer's value with dll but it crashes the program. Pointer is 100% correct (checked and tested with cheat engine). My goal is to change its value to 1 (I can do it via cheat engine, but I need to convert it to code).

typedef void(__fastcall* _wh)(int val);
_wh wh;
uintptr_t FinalAddress(uintptr_t ptr, std::vector<DWORD> offsets)
{
    uintptr_t addr = ptr;
    for (unsigned int i = 0; i < offsets.size(); ++i)
    {
        addr = *(uintptr_t*)addr;
        addr += offsets[i];
    }
    return addr; // returns the main pointer from needed assets
}
DWORD WINAPI HackThread(HMODULE hModule)
{
    AllocConsole();
    FILE* f;
    freopen_s(&f, "CONOUT$", "w", stdout);

    std::cout << "dll injected\n" << std::endl;

    uintptr_t moduleBase = (uintptr_t)GetModuleHandle(L"Soria2.pl.exe");
    uintptr_t adres = FinalAddress(moduleBase + 0x267D94, {0xC, 0x66C});
    wh = (_wh)adres; // access the pointer's pointer to edit the value;
    std::cout << wh;
    
    while (true)
    {
        if (GetAsyncKeyState(VK_SHIFT) & 1)
        {
            wh(1);
        }
        Sleep(10);
    }
    fclose(f);
    FreeConsole();
    FreeLibraryAndExitThread(hModule, 0);
    return 0;
}
Andreas Wenzel
  • 22,760
  • 4
  • 24
  • 39
matrioh4
  • 1
  • 1
  • How did you check that the address is correct? ProcessHacker is a good tool. Do not forget about ASLR – dgrandm Jun 26 '20 at 00:35
  • Are you sure that the DLL injection itself works? I do not see any DLL injection code in the code you posted. How are you performing the DLL injection? Are you using `CreateRemoteThread` or some other technique? – Andreas Wenzel Jun 26 '20 at 00:36
  • @AndreasWenzel; @dgrandm injection works I just did not include this part of the code. I printed the address and pasted it to Cheat Engine. Adress is correct because once I change its value to 1 it does the thing. – matrioh4 Jun 26 '20 at 07:39

1 Answers1

0

Ok I've figured it out. It turned out that the thing I wanted was just a variable and I wanted to call the function. This part was problematic:

wh = (_wh)adres; // access the pointer's pointer to edit the value;

I changed it to:

int* wallHack = (int*)adres

and simply changed the value to:

*wallhack = 1
matrioh4
  • 1
  • 1