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

Windows does not pass arguments to the entrypoint directly #25

Open
TheNNX opened this issue Apr 13, 2024 · 2 comments
Open

Windows does not pass arguments to the entrypoint directly #25

TheNNX opened this issue Apr 13, 2024 · 2 comments

Comments

@TheNNX
Copy link
Contributor

TheNNX commented Apr 13, 2024

In Win32 applications, the entrypoint present in PE headers and invoked on program start does not have any parameters. Functions like WinMain are not the real entrypoint of the program - instead, a function (usually provided by the compiler) like WinMainCRTStartup is used to get things like command line arguments, initialise the C/C++ runtime, and to call the "higher-level entrypoint".

Judging by function names, programs compiled for WinCE seem to have a CRT startup routines, but they expect the arguments from the operating system. Because no arguments are provided by the OS, the program, for example, has no access to the command line arguments.

Compare stack traces with debug symbols between a Win32 application, and a WinCE one:

Win32:
obraz
WinCE (not showing anything above that in that stacktrace, as it seems that at least for solitaire.exe, CRT startup function is the only entrypoint - the main program loop is there):
obraz

Using a dirty hack that violates many best practices to call the entrypoint from COREDLL!DllMain, implementing some functions, clicking through a few stub messages, and making some other minor tweaks, it is possible to run WinCE cmd.exe, albeit it doesn't really work that great.
obraz

@dz333n
Copy link
Owner

dz333n commented Apr 13, 2024

Wow, this is so cool to see cmd.exe working. 🤯Thank you for your research!

@TheNNX
Copy link
Contributor Author

TheNNX commented Apr 14, 2024

Fixed for x86 in #28.

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

No branches or pull requests

2 participants