Rob-- / memoryjs

Read and write process memory in Node.js (Windows API functions exposed via Node bindings)
MIT License
632 stars 86 forks source link

callFunction() freezes with no exception #75

Closed bernie-g closed 3 years ago

bernie-g commented 3 years ago

I'm trying to call a function with a single boolean argument and a void return type and the function just seems to freeze and not do anything.

Here's my code (with added types):


const args: FunctionArg[] = [{ type: T_BOOL, value: true }];
const result = callFunction(
      gameAssembly.modBaseAddr,
      args,
      T_VOID,
      13576672
    );```
Rob-- commented 3 years ago

What exactly is callFunction referencing? Is 13576672 supposed to be 0x13576672 by any chance? The documentation states the first argument should also be the handle of the process you open, not the base address of a module

bernie-g commented 3 years ago

The address I just converted from hex to an int, so it should be fine.

I changed it to use the process handle and now the game just crashes, although it's more than likely because of my inexperience with this stuff.

Here's my code now:

    const args: FunctionArg[] = [{ type: T_BOOL, value: true }];
    const result = callFunction(amongUs?.handle, args, T_VOID, 0xcf29e0);

When I il2cpp dumped the game it said the RVA of this method was 0xcf29e0, which is what I'm using.

The crash report from the unity log reporter says: Write to location 00CF29E0 caused an access violation.

Rob-- commented 3 years ago

Can you paste the decompiled function as well (just curious)? And if it's the RVA, try passing amongUs?.modBaseAddr + 0xcf29e0 as the address, you need to get the absolute address in memory

bernie-g commented 3 years ago

Well il2cppdumper doesn't decompile the functions, it only gives their signatures. The function is this:

    // RVA: 0xCF29E0 Offset: 0xCF11E0 VA: 0x10CF29E0
    public void ChangeGamePublic(bool JKJKFOOKPCD) { }

I tried the snippet you sent and it still crashes with the same error.

Rob-- commented 3 years ago

Oops, change amongUs?.modBaseAddr to the base address of the module this function lies in, probably GameAssembly.dll

bernie-g commented 3 years ago

Sweet, that stops the crashing. Now it just doesn't do anything and returns { exitCode: 4279337192 }.

bernie-g commented 3 years ago

Oh shoot, it works! I was calling a slightly different method. Thank you so much!