dz333n / wcecl

Run Windows CE applications on desktop Windows
MIT License
154 stars 21 forks source link

Fix cmd.exe ungraceful exit #35

Closed TheNNX closed 6 months ago

TheNNX commented 7 months ago

It seems that WinCE has GetCurrentProcess inlined to return 0x42. Because this is not the case with Win32, TerminateProcess(0x42, ...) fails, cmd.exe returns from a noreturn function, and executes some random code it should not execute, which causes it to crash.

int WINAPI WinMain(
    HINSTANCE hInstance,
    HINSTANCE hPrevInstance,
    LPTSTR lpCmdLine,
    int nCmdShow)
{
    HANDLE result = GetCurrentProcess();
    printf("%lx\n", (int)result);
    return (int)result;
}

gets compiled to:

_WinMain:
  000110C4: 6A 42              push        42h
  000110C6: 68 3C 10 01 00     push        offset ??_C@_04OBABDBEP@?$CFlx?6?$AA@
  000110CB: E8 32 02 00 00     call        _printf
  000110D0: 59                 pop         ecx
  000110D1: 59                 pop         ecx
  000110D2: 6A 42              push        42h
  000110D4: 58                 pop         eax
  000110D5: C3                 ret