2022-06-03 09:31:16 +00:00
|
|
|
|
2022-06-02 23:36:04 +00:00
|
|
|
#include <locale.h>
|
2022-06-03 02:02:19 +00:00
|
|
|
#include <stdbool.h>
|
2022-06-03 09:31:16 +00:00
|
|
|
#include <stdlib.h>
|
2022-06-03 02:02:19 +00:00
|
|
|
|
2022-06-03 09:31:16 +00:00
|
|
|
#include "win32.h"
|
2022-06-03 02:02:19 +00:00
|
|
|
|
|
|
|
extern int main(int argc, char** argv);
|
|
|
|
|
|
|
|
// Some shell32.lib related crap
|
|
|
|
DECLSPEC_IMPORT LPWSTR GetCommandLineW();
|
|
|
|
DECLSPEC_IMPORT LPWSTR* CommandLineToArgvW(LPCWSTR lpCmdLine, int* pNumArgs);
|
|
|
|
|
|
|
|
static size_t count_wide_chars(const wchar_t* str) {
|
2022-06-03 02:04:02 +00:00
|
|
|
size_t len = 0;
|
|
|
|
while (str[len] != 0) len++;
|
|
|
|
return len;
|
2022-06-03 02:02:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool convert_wide_chars_to_ansi(char* out, const wchar_t* str, size_t len) {
|
2022-06-03 02:04:02 +00:00
|
|
|
for (size_t i = 0; i < len; i++) {
|
|
|
|
wchar_t ch = *str++;
|
|
|
|
if (ch <= 0 && ch > 0x7F) {
|
|
|
|
*out++ = 0;
|
|
|
|
return false;
|
|
|
|
}
|
2022-06-03 02:02:19 +00:00
|
|
|
|
2022-06-03 02:04:02 +00:00
|
|
|
*out++ = ch;
|
|
|
|
}
|
2022-06-03 02:02:19 +00:00
|
|
|
|
2022-06-03 02:04:02 +00:00
|
|
|
*out++ = 0;
|
|
|
|
return true;
|
2022-06-03 02:02:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void mainCRTStartup() {
|
2022-06-03 02:04:02 +00:00
|
|
|
HANDLE heap = GetProcessHeap();
|
|
|
|
if (heap == NULL) {
|
|
|
|
ExitProcess(-42069);
|
|
|
|
}
|
2022-06-03 02:02:19 +00:00
|
|
|
|
2022-06-03 02:04:02 +00:00
|
|
|
int arg_count;
|
|
|
|
LPWSTR* args_wide = CommandLineToArgvW(GetCommandLineW(), &arg_count);
|
|
|
|
if (!args_wide) {
|
|
|
|
ExitProcess(-69420);
|
|
|
|
}
|
2022-06-03 02:02:19 +00:00
|
|
|
|
2022-06-03 02:04:02 +00:00
|
|
|
char** args = HeapAlloc(heap, 0, arg_count * sizeof(char*));
|
|
|
|
if (arg_count == 0) {
|
|
|
|
arg_count = 1;
|
|
|
|
args[0] = "";
|
|
|
|
}
|
2022-06-03 02:02:19 +00:00
|
|
|
|
2022-06-03 02:04:02 +00:00
|
|
|
// Convert wide chars into ANSI
|
|
|
|
for (int i = 0; i < arg_count; i++) {
|
|
|
|
size_t wide_len = count_wide_chars(args_wide[i]) + 1;
|
|
|
|
args[i] = HeapAlloc(heap, 0, wide_len);
|
2022-06-03 02:02:19 +00:00
|
|
|
|
2022-06-03 02:04:02 +00:00
|
|
|
convert_wide_chars_to_ansi(args[i], args_wide[i], wide_len);
|
|
|
|
}
|
2022-06-02 05:18:26 +00:00
|
|
|
|
2022-06-03 09:31:16 +00:00
|
|
|
_os_heap heap_data = {
|
|
|
|
.handle = heap,
|
|
|
|
};
|
|
|
|
_heap_setup(&heap_data);
|
|
|
|
|
|
|
|
srand(0);
|
2022-06-03 02:04:02 +00:00
|
|
|
setlocale(LC_ALL, "C");
|
|
|
|
int exit_code = main(arg_count, args);
|
2022-06-02 05:18:26 +00:00
|
|
|
|
2022-06-03 02:04:02 +00:00
|
|
|
ExitProcess(exit_code);
|
2022-06-02 05:18:26 +00:00
|
|
|
}
|
2022-06-03 09:31:16 +00:00
|
|
|
|
|
|
|
// This symbol is required to be present if we're using floating-point
|
|
|
|
// numbers
|
|
|
|
int _fltused=0;
|