Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Execute return wrong values on x64bit #24

Open
MohamedAlaaJameel opened this issue Jul 31, 2022 · 1 comment
Open

Execute return wrong values on x64bit #24

MohamedAlaaJameel opened this issue Jul 31, 2022 · 1 comment

Comments

@MohamedAlaaJameel
Copy link

realreturn
the function return value = 0x0166DCB00900

execute function return value =0xDCB00900

as you can see there are missing bytes .
bad return
the problem in GetExitCodeThread function return , I don't know how to fix that.
bad return code

var keyAddress = sharp.Assembly.Execute<IntPtr>(gameFunc, CallingConventions.MicrosoftX64, new dynamic[] { ecx });
@JamesMenetrey

@JamesMenetrey
Copy link
Owner

Hey @MohamedAlaaJameel,

Sorry for the late reply. According to Microsoft's docs, the second parameter of the function GetExitCodeThread is of type LPDWORD, which is a pointer of a DWORD (32-bit unsigned integer).

Since your return value does not store in a 32-bit value, the cast overflows the value. You can see this with this code:

long val = 0x0166DCB00900;
Console.WriteLine($"{(int)val:X8}"); // Print DCB00900

Unfortunately, there is no implementation of GetExitCodeThread that returns a 64-bit value, at least not that I'm aware of. I propose these workarounds:

  • If you control the code of the function that is called, store a pointer of the 64-bit value and read it afterwards.
  • If you don't control the function's code, you need to write some assembly code that calls the function and stores the result in a pre-allocated buffer, then read that buffer.

I'm going to fix the definition of that P/Invoke function to make it obvious (uint instead of IntPtr). Thanks for the report. I keep this issue open until I have fixed it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants