[CLOSED] Cheat Engine {$CCODE} imports

Memory scanning, code injection, debugger internals and other gamemodding related discussion
Post Reply
User avatar
Horse4Horse
Expert Cheater
Expert Cheater
Posts: 79
Joined: Thu Aug 02, 2018 7:54 pm
Reputation: 30

[CLOSED] Cheat Engine {$CCODE} imports

Post by Horse4Horse »

I'm making a simple C section for matrix multiplications for object rotation in 3d. It works in lua as a PoC.
The problem is, what I'm already encountered every time I worked with C code sections in CE - for some reason CE prefers to use "ntoskrnl' over "ucrtbase" for functions like "memset", "memove", etc.
I already had to deal with it in the pervious cheat in this way:

Code: Select all

{$c}
#define NO_OLDNAMES
#include <windows.h>
typedef HWND(WINAPI *GETFOREGROUNDWINDOW)(void);
GETFOREGROUNDWINDOW pfnGetForegroundWindow;
{$asm}
{$ccode}
HMODULE hModuleUser32 = LoadLibrary("User32.dll");
pfnGetForegroundWindow = (GETFOREGROUNDWINDOW)GetProcAddress(hModuleUser32, "GetForegroundWindow");
{$asm}
So it won't compile to call "win32kbase.GetForegroundWindow".

I also tried:

Code: Select all

extern __declspec(dllimport) HWND __stdcall GetForegroundWindow();
And it worked, but when I tried the same thing with:

Code: Select all

extern __declspec(dllimport) SHORT __stdcall GetKeyState();
It still called win32kbase.
As an example, this is the previous cheat I made for the game "Exanima" x64 version:
[Link]

And now, when I'm dealing with matrixes, compiler automatically uses memset's and memmove's and I can't control where it gets them from.
So the main question is - how to deal with imports in a proper way?
Last edited by Horse4Horse on Wed Aug 21, 2024 5:22 pm, edited 1 time in total.

User avatar
Horse4Horse
Expert Cheater
Expert Cheater
Posts: 79
Joined: Thu Aug 02, 2018 7:54 pm
Reputation: 30

Re: Cheat Engine {$CCODE} imports

Post by Horse4Horse »

Answer from the Dark Byte himself:
registersymbol the correct symbol with a different name first (different script, or lua block)

e.g registerSymbol('ucrtbase_memset', getAddress('ucrtbase.memset'))

and then in your ccode you can call ucrtbase_memset
But because I never specified memset myself in the code and compiler did it, so I just redefined it to:

Code: Select all

registerSymbol('memset', getAddress('ucrtbase.memset'))

Post Reply

Who is online

Users browsing this forum: No registered users