Created
August 9, 2013 19:33
-
-
Save Chase-san/6196493 to your computer and use it in GitHub Desktop.
A simple custom unicode commandline launcher for Java. Converts the argument to hex code.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <wchar.h> | |
#include <windows.h> | |
/* | |
* Poor Mans Windows Java Unicode Command Line Passer. | |
* Easily uses up to 4kb of stack. | |
*/ | |
int main() { | |
int argc; | |
wchar_t** argv = CommandLineToArgvW(GetCommandLineW(),&argc); | |
wchar_t wjargs[1024]; | |
wcscat(wjargs,L"-jar "); | |
{ | |
wchar_t path[1024]; | |
wmemset(path,0,1024); | |
GetModuleFileNameW(NULL,path,1024); | |
//find last occurance of \, replace it with 0 (terminator) | |
for(int i=1023;i>=0;--i) { | |
if((int)path[i]==92) { | |
path[i] = 0; | |
break; | |
} | |
} | |
wcscat(wjargs,path); | |
} | |
//our jar file | |
wcscat(wjargs,L"\\hanami.jar"); | |
if(argc > 1) { | |
int len = wcslen(argv[1]); | |
wchar_t buf[6]; | |
//tell the program we are going to encode it in hex bytes | |
wcscat(wjargs,L" -x "); | |
for(int i=0;i<len;++i) { | |
swprintf(buf,L"%04x",(int)argv[1][i]); | |
wcscat(wjargs,buf); | |
} | |
} | |
ShellExecuteW(NULL,L"open",L"javaw.exe",wjargs,NULL,SW_SHOWNORMAL); | |
//TODO check if they even have java installed, if not, yell at them. | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment