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

Fix cmd.exe ungraceful exit #35

Merged
merged 1 commit into from
Apr 23, 2024
Merged

Fix cmd.exe ungraceful exit #35

merged 1 commit into from
Apr 23, 2024

Conversation

TheNNX
Copy link
Contributor

@TheNNX TheNNX commented Apr 23, 2024

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

@dz333n dz333n merged commit 34b81a8 into dz333n:master Apr 23, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants