Skip to content

Commit

Permalink
Add GetCommandLine().
Browse files Browse the repository at this point in the history
Note that we don't free() the malloc()ed command_line buffer. This is modern
Windows, the operating system will do that for us anyway once the target
process terminates.
  • Loading branch information
nmlgc committed Aug 21, 2015
1 parent 64d691b commit f0db87b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/kernel32_dll.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const w32u8_pair_t kernel32_pairs[] = {
{"GetEnvironmentVariableA", GetEnvironmentVariableU},
{"GetFileAttributesA", GetFileAttributesU},
{"GetFileAttributesExA", GetFileAttributesExU},
{"GetCommandLineA", GetCommandLineU},
{"GetModuleFileNameA", GetModuleFileNameU},
{"GetPrivateProfileIntA", GetPrivateProfileIntU},
{"GetStartupInfoA", GetStartupInfoU},
Expand Down Expand Up @@ -455,6 +456,20 @@ DWORD WINAPI FormatMessageU(
return ret;
}

LPSTR WINAPI GetCommandLineU(
VOID
)
{
static char *command_line = NULL;
if(!command_line) {
const wchar_t *command_line_w = GetCommandLineW();
WCSLEN_DEC(command_line_w);
command_line = (char*)malloc(command_line_w_len);
StringToUTF8(command_line, command_line_w, command_line_w_len);
}
return command_line;
}

DWORD WINAPI GetCurrentDirectoryU(
DWORD nBufferLength,
LPSTR lpBuffer
Expand Down
6 changes: 6 additions & 0 deletions src/kernel32_dll.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ DWORD WINAPI FormatMessageU(
#undef FormatMessage
#define FormatMessage FormatMessageU

LPSTR WINAPI GetCommandLineU(
VOID
);
#undef GetCommandLine
#define GetCommandLine GetCommandLineU

DWORD WINAPI GetCurrentDirectoryU(
DWORD nBufferLength,
LPSTR lpBuffer
Expand Down
1 change: 1 addition & 0 deletions win32_utf8.def
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ EXPORTS
FindFirstFileU
FindNextFileU
FormatMessageU
GetCommandLineU
GetCurrentDirectoryU
GetEnvironmentVariableU
GetFileAttributesU
Expand Down

0 comments on commit f0db87b

Please sign in to comment.