|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
HighVoltage How do I cheat? Reputation: 0
Joined: 04 Dec 2023 Posts: 8
|
Posted: Sun Nov 17, 2024 12:30 pm Post subject: Feature Request: Pass Compiler Flags or Switches to TinyCC |
|
|
While celua.txt does specify Lua functions like compile() and compileFiles() for C code compilation via TCC, it doesn't specify a way to let you pass compilation flags / compiler switches to it.
Some compilers like GCC might allow you to specify switches using #pragma directives, but TCC doesn't do that; so, I propose adding a Lua function to push/pop compiler flags before invoking TCC. (Alternatively, the $c/$ccode braces themselves could be extended to take in a list of compiler flags, in addition to nodebug and kernelmode.
How could this be useful? Well, at the very least, it'd let the user select their C standard (e.g., C11/GNU11 rather than the default C99). Also, it'd let us treat warnings as errors and configure the optimization level.
Thanks.
|
|
Back to top |
|
|
ParkourPenguin I post too much Reputation: 147
Joined: 06 Jul 2014 Posts: 4570
|
Posted: Sun Nov 17, 2024 1:26 pm Post subject: |
|
|
Edit: Official reference is outdated; ignore this post
TCC implements ANSI C, most of C99, some GNU C extensions, and miscellaneous TCC extensions. C11 / C17 / C23 are unsupported.
GCC options -Ox, -fx, and -mx are ignored: there are no optimization levels to control.
There is -Werror to make warnings errors, but to hackers, that gets in the way more than it helps. It looks like there aren't even that many warnings.
Official reference:
https://bellard.org/tcc/tcc-doc.html
_________________
I don't know where I'm going, but I'll figure it out when I get there.
Last edited by ParkourPenguin on Sun Nov 17, 2024 2:26 pm; edited 1 time in total |
|
Back to top |
|
|
HighVoltage How do I cheat? Reputation: 0
Joined: 04 Dec 2023 Posts: 8
|
Posted: Sun Nov 17, 2024 1:34 pm Post subject: |
|
|
ParkourPenguin wrote: | TCC implements ANSI C, most of C99, some GNU C extensions, and miscellaneous TCC extensions. C11 / C17 / C23 are unsupported.
|
TCC has had a "-std=c11" option for a while now, not to mention that various linker options (-llib, _ldir, static, -soname, etc.) would be nice to have, too. Sure, TCC's C11 compliance might be incomplete, but so is GCC's and that of any other mainstream compiler.
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 465
Joined: 09 May 2003 Posts: 25570 Location: The netherlands
|
Posted: Sun Nov 17, 2024 2:22 pm Post subject: |
|
|
I can add it, but don't expect miracles.
e.g: C11's native threading support (creating threads and thread local storage) is absent
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
|
HighVoltage How do I cheat? Reputation: 0
Joined: 04 Dec 2023 Posts: 8
|
Posted: Sun Nov 17, 2024 5:50 pm Post subject: |
|
|
Dark Byte wrote: | I can add it, but don't expect miracles.
e.g: C11's native threading support (creating threads and thread local storage) is absent |
Thanks, Dark Byte; I appreciate it!
|
|
Back to top |
|
|
HighVoltage How do I cheat? Reputation: 0
Joined: 04 Dec 2023 Posts: 8
|
Posted: Wed Nov 27, 2024 3:54 pm Post subject: |
|
|
Dark Byte wrote: | I can add it, but don't expect miracles.
e.g: C11's native threading support (creating threads and thread local storage) is absent |
C.E. 7.6 (Beta) no longer has the issue with WinAPI headers, and the setCustomTCCParameters() function also seems to be working as intended.
However, I've found a new bug with CRT functions in 32-bit mode: IAT.printf or *stdout point to nowhere in memory, causing segfaults or access violation.
I tried using #pragma comment(lib, msvcrt) and even tried copying .def and .dll files from SysWOW64 to the /lib subdirectory in Cheat Engine's root (that's where TCC looks first), to no avail. I even tried using msvcrt40/msvcrt20 and ucrtbase.dll. Also, I tried finding _CRIT_INIT to manually call it, but nothing worked out.
I originally thought the issue is "-nostdlib" being passed via tcclib.pas. Yet, even after I compiled TCC myself to ignore -nostdlib, the error still persisted. I think this is a linker issue in the tcc64-32 cross-compiler.
The code below successfully compiles and prints to the allocated console IF Cheat Engine is attached to a 64-bit target; in 32-bit targets, it does compile, but the IAT table (if you follow the inspect_me symbol) leads to nowhere for msvcrt.dll:
Code: |
[ENABLE]
globalalloc(inspect_me, $100)
//createthread(inspect_me)
inspect_me:
{$c}
#pragma comment(lib, "msvcrt")
#include <windows.h>
#include <stdio.h>
{$asm}
{$ccode}
AllocConsole();
MessageBox(NULL, TEXT("Win32 calls backs like MessageBox work."), TEXT("test"), MB_OK);
freopen("CONOUT$", "w", stdout);
printf("Won't print because IAT.printf and others point nowhere.");
{$asm}
ret
[DISABLE]
|
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 465
Joined: 09 May 2003 Posts: 25570 Location: The netherlands
|
Posted: Thu Nov 28, 2024 7:23 am Post subject: |
|
|
Looks like it's picking the printf implementation in a 64 bit ntdll.dll that's not even loaded in the target process
edit:
it's the pragma that causes the issue of no error, as it loads msvcrt into CE and not into the target process
and besides that it looks like 'stdout' is problematic
edit2:
after including #stdio.h add this code:
Code: |
extern FILE iob[];
#undef __iob_func
#define __iob_func() (iob)
|
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
|
HighVoltage How do I cheat? Reputation: 0
Joined: 04 Dec 2023 Posts: 8
|
Posted: Thu Nov 28, 2024 1:24 pm Post subject: |
|
|
Dark Byte wrote: | Looks like it's picking the printf implementation in a 64 bit ntdll.dll that's not even loaded in the target process
edit:
it's the pragma that causes the issue of no error, as it loads msvcrt into CE and not into the target process
and besides that it looks like 'stdout' is problematic
edit2:
after including #stdio.h add this code:
Code: |
extern FILE iob[];
#undef __iob_func
#define __iob_func() (iob)
|
|
Thanks, that solves the stdout/stdin/stderr problem.
Weirdly enough, while stdout and printf (correctly) gets picked up as msvcrt.iob and msvcrt.printf, freopen() gets picked up from ucrtbase.freopen (if both MSVCRT and UCRTBASE happen to be present in the target process); this mixing of CRTs leads to crashing.
When I manually replace the address at IAT.freopen from ucrtbase.freopen to msvcrt.freopen, everything works properly, and it does indeed print the message on a 32-bit target; however, there doesn't seem to be an "easy" way to make TCC pick up msvcrt.freopen by default, even with `extern __cdecl freopen(...)`, #undef freopen, using _tfreopen_s or _wfreopen_s. Unfortunately, static linking is not an option as '-lmsvcrt' and '-static' are completely broken in TCC itself (they even mention it in the TODO file in TCC's folder). I ended up resorting to `IAT.freopen: dq msvcrt.freopen` in AutoAssembler.
Here are two additional bugs I've discovered in C.E. 7.6 (Beta):
- Any sort of {c}/{ccode} or Lua's compile() functions are broken on the 32-bit version of Cheat Engine, saying "<<Access Violation>>
- On 64-bit Cheat Engine, saving a {c}/{ccode} with /* multi-line */ comments will cause <<Access Violation>> the next time you open said script and attempt to scroll down on it; removing the /* */ fixes it.
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 465
Joined: 09 May 2003 Posts: 25570 Location: The netherlands
|
Posted: Thu Nov 28, 2024 7:17 pm Post subject: |
|
|
registersymbol might help making it take priority over other implementations
for 32-bit I likely forgot to compile the most recent tcc for 32 bit origins:
https://cheatengine.org/download/beta/11292024/tcc32-32.zip
the multiline comment thing I haven't been able to reproduce.
Perhaps there's something inside the multiline comment that triggers it ?
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|