Question

so I am looking through some source code and this one thing has stumped me. I'm kind of new to c++, so I'm having a hard time understanding what this is for. I don't really know what the following typedef is for, and how it is being used in the code below it.

typedef void (__fastcall *TSecType_long___SetData_t)(DWORD dwAddress, DWORD dwEDX, DWORD dwValue);

These are some values used for the method that uses this typedef.

const TSecType_long___SetData_t TSecType_long___SetData = reinterpret_cast<TSecType_long___SetData_t>(0x00518430); // 56 8B ? 8B ? ? ? ? ? 41 [3rd Result]

const DWORD *const pdwUserLocal = reinterpret_cast<const DWORD *const>(0x016A1234); // 8B ? ? ? ? ? 85 C9 74 ? 83 B8 ? ? ? ? 00 74 ? 8B ? ? ? ? ? 85 C0 7E ? 8B
const DWORD dwTeleportToggleOffset = 0x00008A94; // 8D ? ? ? ? ? 8B ? 8B ? E8 ? ? ? ? 85 ? 0F 85 ? ? ? ? 39 ? ? ? ? ?
const DWORD dwTeleportYOffset = 0x00008AAC; // 8D ? ? ? ? ? ? 8B ? E8 ? ? ? ? 6A ? 8B ? E8 ? ? ? ? 6A 00 68 ? ? ? ?
const DWORD dwTeleportXOffset = dwTeleportYOffset + 0x0C;

And for the method itself:

bool Teleport(_In_ int nX, _In_ int nY)
{
__try
{
    {

        DWORD dwUserLocal = *pdwUserLocal;
        TSecType_long___SetData(dwUserLocal + dwTeleportToggleOffset, NULL, 0);
        TSecType_long___SetData(dwUserLocal + dwTeleportXOffset, NULL, nX);
        TSecType_long___SetData(dwUserLocal + dwTeleportYOffset, NULL, nY);
        TSecType_long___SetData(dwUserLocal + dwTeleportToggleOffset, NULL, 1);
    }
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
    return false;
}
return true;
}
Was it helpful?

Solution

Working under the assumption that you know what a typedef is (it's taking a datatype and giving it another name), all that this is - is a function typedef. In other words, TSecType_long___SetData_t is a function that takes 3 DWORD arguments and returns a void.

In your case, someone has a-priori knowledge that the address 0x00518430 contains a function that can be called given the TSecType_long___SetData_t API. In order to make that address callable, the address is reinterpreted as the function datatype and assigned to the variable TSecType_long___SetData.

OTHER TIPS

Just like @chris said TSecType_long___SetData_t is just a declaration of a pointer to function, thus having parameters. And the following line:

const TSecType_long___SetData_t TSecType_long___SetData = einterpret_cast<TSecType_long___SetData_t>(0x00518430);

defines a variable of that type and assigns it a value, which in this case seems to be a hardcoded memory location (which I don't know where that comes from). All other occurrences are just simple function calls.
A little googling on function pointers should give you whatever you need to know about them.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top