• R/O
  • SSH
  • HTTPS

exewrap: Commit


Commit MetaInfo

Revision22 (tree)
Time2015-07-21 12:50:15
Authorhirukawa_ryo

Log Message

v1.1.0
*対象JREのバージョンを1.2以上から1.5以上に変更しました。
*ウィルス誤検知に対処しました。
*JRE縮小機能を追加しました。
*メインクラスを指定するオプション -M を追加しました。
*アプリケーションと同じ場所にあるJREを検索しないようにする拡張フラグ NOSIDEBYSIDE を追加しました。
*スレッドでキャッチされない例外を無視する拡張フラグ IGNORE_UNCAUGHT_EXCEPTION を追加しました。

Change Summary

Incremental Difference

--- exewrap/trunk/exewrap/src/image_gui.c (revision 21)
+++ exewrap/trunk/exewrap/src/image_gui.c (revision 22)
@@ -20,7 +20,9 @@
2020 #include "include/loader.h"
2121 #include "include/notify.h"
2222 #include "include/message.h"
23+#include "include/trace.h"
2324
25+void OutputConsole(BYTE* buf, DWORD len);
2426 void OutputMessage(const char* text);
2527 UINT UncaughtException(const char* thread, const char* message, const char* trace);
2628
@@ -32,6 +34,7 @@
3234 SplashInit_t SplashInit;
3335 SplashLoadMemory_t SplashLoadMemory;
3436 HMODULE splashscreendll;
37+static HANDLE hConOut = NULL;
3538
3639
3740 INT WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR lpCmdLine, INT nCmdShow)
@@ -42,15 +45,29 @@
4245 char* relative_classpath;
4346 char* relative_extdirs;
4447 BOOL use_server_vm;
48+ BOOL use_side_by_side_jre;
4549 HANDLE synchronize_mutex_handle = NULL;
4650 char* ext_flags;
4751 BYTE* splash_screen_image = NULL;
4852 char* splash_screen_name = NULL;
49- char* vm_args_opt;
53+ char* vm_args_opt = NULL;
5054 char utilities[128];
5155 RESOURCE res;
5256 LOAD_RESULT result;
5357
58+ utilities[0] = '\0';
59+ #ifdef TRACE
60+ {
61+ const char* filename = StartTrace(FALSE);
62+ vm_args_opt = (char*)malloc(1024);
63+ sprintf(vm_args_opt, "-XX:+UnlockDiagnosticVMOptions -XX:+LogVMOutput -XX:LogFile=\"%s\" ", filename);
64+ if (GetResource("VMARGS", &res) != NULL)
65+ {
66+ strcat(vm_args_opt, res.buf);
67+ }
68+ }
69+ #endif
70+
5471 argv = get_args(&argc);
5572 result.msg = malloc(2048);
5673
@@ -58,7 +75,8 @@
5875 relative_extdirs = (char*)GetResource("EXTDIRS", NULL);
5976 ext_flags = (char*)GetResource("EXTFLAGS", NULL);
6077 use_server_vm = (ext_flags != NULL && strstr(ext_flags, "SERVER") != NULL);
61- InitializePath(relative_classpath, relative_extdirs, use_server_vm);
78+ use_side_by_side_jre = (ext_flags == NULL) || (strstr(ext_flags, "NOSIDEBYSIDE") == NULL);
79+ InitializePath(relative_classpath, relative_extdirs, use_server_vm, use_side_by_side_jre);
6280
6381 if (ext_flags != NULL && strstr(ext_flags, "SHARE") != NULL)
6482 {
@@ -97,8 +115,11 @@
97115 }
98116 }
99117
100- vm_args_opt = (char*)GetResource("VMARGS", NULL);
101- CreateJavaVM(vm_args_opt, use_server_vm, &err);
118+ if (vm_args_opt == NULL)
119+ {
120+ vm_args_opt = (char*)GetResource("VMARGS", NULL);
121+ }
122+ CreateJavaVM(vm_args_opt, use_server_vm, use_side_by_side_jre, &err);
102123 if (err != JNI_OK)
103124 {
104125 OutputMessage(GetJniErrorMessage(err, &result.msg_id, result.msg));
@@ -119,7 +140,6 @@
119140 }
120141 }
121142
122- utilities[0] = '\0';
123143 if (ext_flags == NULL || strstr(ext_flags, "IGNORE_UNCAUGHT_EXCEPTION") == NULL)
124144 {
125145 strcat(utilities, UTIL_UNCAUGHT_EXCEPTION_HANDLER);
@@ -184,10 +204,19 @@
184204
185205 NotifyClose();
186206
207+ #ifdef TRACE
208+ StopTrace();
209+ #endif
210+
187211 return result.msg_id;
188212 }
189213
190214
215+void OutputConsole(BYTE* buf, DWORD len)
216+{
217+}
218+
219+
191220 void OutputMessage(const char* text)
192221 {
193222 char buffer[MAX_PATH];
@@ -207,10 +236,9 @@
207236
208237 UINT UncaughtException(const char* thread, const char* message, const char* trace)
209238 {
210- char* buf;
211-
212- buf = malloc(16 * 1024);
213- sprintf(buf, "Exception in thread \"%s\" %s", thread, trace);
239+ //for message box
240+ char* buf = (char*)malloc(strlen(thread) + strlen(message) + 64);
241+ sprintf(buf, "Exception in thread \"%s\"\r\n%s", thread, message);
214242 OutputMessage(buf);
215243 free(buf);
216244
--- exewrap/trunk/exewrap/src/Makefile (revision 21)
+++ exewrap/trunk/exewrap/src/Makefile (revision 22)
@@ -1,4 +1,4 @@
1-INC = /I ..\include /I..\include\win32
1+INC = /I ..\include /I ..\include\win32
22 LIBS = kernel32.lib user32.lib advapi32.lib shell32.lib
33
44 CC = cl.exe
@@ -9,11 +9,13 @@
99
1010 !if ([@cl.exe 2>&1| @findstr "x64" > nul] == 0)
1111 ARCHITECTURE=x64
12+BITS=64
1213 BIN=..\bin\x64
1314 OBJ=..\obj\x64
1415 CRT=..\lib\crt\amd64
1516 !else
1617 ARCHITECTURE=x86
18+BITS=32
1719 BIN=..\bin\x86
1820 OBJ=..\obj\x86
1921 CRT=..\lib\crt
@@ -21,6 +23,7 @@
2123
2224 CFLAGS=\
2325 /nologo\
26+ /DEBUG\
2427 /MD\
2528 /W3\
2629 /O1\
@@ -43,9 +46,14 @@
4346 EXEWRAP_X86 : $(BIN)\exewrap.exe
4447 EXEWRAP_X64 : $(BIN)\exewrap.exe
4548
46-IMAGE_X86 : $(OBJ)\image_console.exe $(OBJ)\image_gui.exe $(OBJ)\image_service.exe
47-IMAGE_X64 : $(OBJ)\image_console.exe $(OBJ)\image_gui.exe $(OBJ)\image_service.exe
49+IMAGE_X86 : $(OBJ)\image_console.exe $(OBJ)\image_gui.exe $(OBJ)\image_service.exe \
50+ $(OBJ)\image_console_trace.exe $(OBJ)\image_gui_trace.exe $(OBJ)\image_service_trace.exe
51+IMAGE_X64 : $(OBJ)\image_console.exe $(OBJ)\image_gui.exe $(OBJ)\image_service.exe \
52+ $(OBJ)\image_console_trace.exe $(OBJ)\image_gui_trace.exe $(OBJ)\image_service_trace.exe
4853
54+JREMIN_X86 : $(BIN)\jremin.exe
55+JREMIN_X64 : $(BIN)\jremin.exe
56+
4957 CLEAN :
5058 @if exist $(OBJ)\..\x86 RMDIR /S /Q $(OBJ)\..\x86
5159 @if exist $(OBJ)\..\x64 RMDIR /S /Q $(OBJ)\..\x64
@@ -59,23 +67,30 @@
5967 $(BIN)\exewrap.exe : $(BIN) $(OBJ) $(OBJ)\exewrap.res $(OBJ)\exewrap.obj \
6068 $(OBJ)\jvm.obj $(OBJ)\loader.obj $(OBJ)\message.obj $(OBJ)\eventlog.obj \
6169 $(OBJ)\image_console.exe $(OBJ)\image_gui.exe $(OBJ)\image_service.exe \
70+ $(OBJ)\image_console_trace.exe \
6271 $(OBJ)\bindres.exe $(OBJ)\exewrap\core\ByteBufferInputStream.class $(OBJ)\exewrap\core\ExewrapClassLoader.class $(OBJ)\tool.jar
6372 $(LINK) $(LDFLAGS) /SUBSYSTEM:CONSOLE /MANIFEST:EMBED /OUT:$(BIN)\exewrap.exe $(OBJ)\exewrap.res $(OBJ)\exewrap.obj \
6473 $(OBJ)\jvm.obj $(OBJ)\loader.obj $(OBJ)\message.obj $(OBJ)\eventlog.obj $(LIBS)
65- $(OBJ)\bindres.exe $(BIN)\exewrap.exe VERSION_INFO resources\versioninfo.bin
66- $(OBJ)\bindres.exe -r $(BIN)\exewrap.exe IMAGE_CONSOLE_32 $(OBJ)\..\x86\image_console.exe
67- $(OBJ)\bindres.exe -r $(BIN)\exewrap.exe IMAGE_CONSOLE_64 $(OBJ)\..\x64\image_console.exe
68- $(OBJ)\bindres.exe -r $(BIN)\exewrap.exe IMAGE_GUI_32 $(OBJ)\..\x86\image_gui.exe
69- $(OBJ)\bindres.exe -r $(BIN)\exewrap.exe IMAGE_GUI_64 $(OBJ)\..\x64\image_gui.exe
70- $(OBJ)\bindres.exe -r $(BIN)\exewrap.exe IMAGE_SERVICE_32 $(OBJ)\..\x86\image_service.exe
71- $(OBJ)\bindres.exe -r $(BIN)\exewrap.exe IMAGE_SERVICE_64 $(OBJ)\..\x64\image_service.exe
72- $(OBJ)\bindres.exe $(BIN)\exewrap.exe BYTE_BUFFER_INPUT_STREAM $(OBJ)\exewrap\core\ByteBufferInputStream.class
73- $(OBJ)\bindres.exe $(BIN)\exewrap.exe PACK_INPUT_STREAM $(OBJ)\exewrap\core\PackInputStream.class
74- $(OBJ)\bindres.exe $(BIN)\exewrap.exe URL_CONNECTION $(OBJ)\exewrap\core\URLConnection.class
75- $(OBJ)\bindres.exe $(BIN)\exewrap.exe URL_STREAM_HANDLER $(OBJ)\exewrap\core\URLStreamHandler.class
76- $(OBJ)\bindres.exe $(BIN)\exewrap.exe EXEWRAP_CLASS_LOADER $(OBJ)\exewrap\core\ExewrapClassLoader.class
77- $(OBJ)\bindres.exe $(BIN)\exewrap.exe UTIL_JAR $(OBJ)\util.jar
78- $(OBJ)\bindres.exe $(BIN)\exewrap.exe JAR $(OBJ)\tool.jar
74+ $(OBJ)\bindres.exe $(BIN)\exewrap.exe VERSION_INFO resources\versioninfo.bin
75+ $(OBJ)\bindres.exe -r $(BIN)\exewrap.exe IMAGE_CONSOLE_32 $(OBJ)\..\x86\image_console.exe
76+ $(OBJ)\bindres.exe -r $(BIN)\exewrap.exe IMAGE_CONSOLE_64 $(OBJ)\..\x64\image_console.exe
77+ $(OBJ)\bindres.exe -r $(BIN)\exewrap.exe IMAGE_GUI_32 $(OBJ)\..\x86\image_gui.exe
78+ $(OBJ)\bindres.exe -r $(BIN)\exewrap.exe IMAGE_GUI_64 $(OBJ)\..\x64\image_gui.exe
79+ $(OBJ)\bindres.exe -r $(BIN)\exewrap.exe IMAGE_SERVICE_32 $(OBJ)\..\x86\image_service.exe
80+ $(OBJ)\bindres.exe -r $(BIN)\exewrap.exe IMAGE_SERVICE_64 $(OBJ)\..\x64\image_service.exe
81+ $(OBJ)\bindres.exe -r $(BIN)\exewrap.exe IMAGE_TRACE_CONSOLE_32 $(OBJ)\..\x86\image_console_trace.exe
82+ $(OBJ)\bindres.exe -r $(BIN)\exewrap.exe IMAGE_TRACE_CONSOLE_64 $(OBJ)\..\x64\image_console_trace.exe
83+ $(OBJ)\bindres.exe -r $(BIN)\exewrap.exe IMAGE_TRACE_GUI_32 $(OBJ)\..\x86\image_gui_trace.exe
84+ $(OBJ)\bindres.exe -r $(BIN)\exewrap.exe IMAGE_TRACE_GUI_64 $(OBJ)\..\x64\image_gui_trace.exe
85+ $(OBJ)\bindres.exe -r $(BIN)\exewrap.exe IMAGE_TRACE_SERVICE_32 $(OBJ)\..\x86\image_service_trace.exe
86+ $(OBJ)\bindres.exe -r $(BIN)\exewrap.exe IMAGE_TRACE_SERVICE_64 $(OBJ)\..\x64\image_service_trace.exe
87+ $(OBJ)\bindres.exe $(BIN)\exewrap.exe BYTE_BUFFER_INPUT_STREAM $(OBJ)\exewrap\core\ByteBufferInputStream.class
88+ $(OBJ)\bindres.exe $(BIN)\exewrap.exe PACK_INPUT_STREAM $(OBJ)\exewrap\core\PackInputStream.class
89+ $(OBJ)\bindres.exe $(BIN)\exewrap.exe URL_CONNECTION $(OBJ)\exewrap\core\URLConnection.class
90+ $(OBJ)\bindres.exe $(BIN)\exewrap.exe URL_STREAM_HANDLER $(OBJ)\exewrap\core\URLStreamHandler.class
91+ $(OBJ)\bindres.exe $(BIN)\exewrap.exe EXEWRAP_CLASS_LOADER $(OBJ)\exewrap\core\ExewrapClassLoader.class
92+ $(OBJ)\bindres.exe $(BIN)\exewrap.exe UTIL_JAR $(OBJ)\util.jar
93+ $(OBJ)\bindres.exe $(BIN)\exewrap.exe JAR $(OBJ)\tool.jar
7994
8095 $(OBJ)\exewrap.obj : $(OBJ) exewrap.c
8196 $(CC) $(CFLAGS) $(INC) /Fo$(OBJ)\exewrap.obj exewrap.c
@@ -95,12 +110,29 @@
95110 $(OBJ)\bindres.exe $(OBJ)\image_console.exe EXEWRAP_CLASS_LOADER $(OBJ)\exewrap\core\ExewrapClassLoader.class
96111 $(OBJ)\bindres.exe $(OBJ)\image_console.exe UTIL_JAR $(OBJ)\util.jar
97112
98-$(OBJ)\image_console.obj : $(OBJ) image_console.c
99- $(CC) $(CFLAGS) $(INC) /Fo$(OBJ)\image_console.obj image_console.c
113+$(OBJ)\image_console_trace.exe : $(OBJ) $(OBJ)\image_console.res $(OBJ)\image_console_trace.obj $(OBJ)\trace.obj \
114+ $(OBJ)\buffer.obj $(OBJ)\hde$(BITS).obj $(OBJ)\hook.obj $(OBJ)\trampoline.obj \
115+ $(OBJ)\jvm.obj $(OBJ)\loader.obj $(OBJ)\message.obj $(OBJ)\notify.obj $(OBJ)\eventlog.obj \
116+ $(OBJ)\bindres.exe $(OBJ)\exewrap\core\ByteBufferInputStream.class $(OBJ)\exewrap\core\PackInputStream.class $(OBJ)\exewrap\core\ExewrapClassLoader.class $(OBJ)\exewrap\core\URLConnection.class $(OBJ)\exewrap\core\URLStreamHandler.class $(OBJ)\util.jar
117+ $(LINK) $(LDFLAGS) /SUBSYSTEM:CONSOLE /MANIFEST:EMBED /OUT:$(OBJ)\image_console_trace.exe $(OBJ)\image_console_trace.obj $(OBJ)\trace.obj \
118+ $(OBJ)\buffer.obj $(OBJ)\hde$(BITS).obj $(OBJ)\hook.obj $(OBJ)\trampoline.obj \
119+ $(OBJ)\jvm.obj $(OBJ)\loader.obj $(OBJ)\message.obj $(OBJ)\notify.obj $(OBJ)\eventlog.obj $(LIBS)
120+ $(OBJ)\bindres.exe $(OBJ)\image_console_trace.exe BYTE_BUFFER_INPUT_STREAM $(OBJ)\exewrap\core\ByteBufferInputStream.class
121+ $(OBJ)\bindres.exe $(OBJ)\image_console_trace.exe PACK_INPUT_STREAM $(OBJ)\exewrap\core\PackInputStream.class
122+ $(OBJ)\bindres.exe $(OBJ)\image_console_trace.exe URL_CONNECTION $(OBJ)\exewrap\core\URLConnection.class
123+ $(OBJ)\bindres.exe $(OBJ)\image_console_trace.exe URL_STREAM_HANDLER $(OBJ)\exewrap\core\URLStreamHandler.class
124+ $(OBJ)\bindres.exe $(OBJ)\image_console_trace.exe EXEWRAP_CLASS_LOADER $(OBJ)\exewrap\core\ExewrapClassLoader.class
125+ $(OBJ)\bindres.exe $(OBJ)\image_console_trace.exe UTIL_JAR $(OBJ)\util.jar
100126
101127 $(OBJ)\image_console.res : $(OBJ) resources\image_console.rc resources\eventlog.bin
102128 $(RC) $(RCFLAGS) /fo$(OBJ)\image_console.res resources\image_console.rc
103129
130+$(OBJ)\image_console.obj : $(OBJ) image_console.c
131+ $(CC) $(CFLAGS) $(INC) /Fo$(OBJ)\image_console.obj image_console.c
132+
133+$(OBJ)\image_console_trace.obj : $(OBJ) image_console.c
134+ $(CC) $(CFLAGS) $(INC) /DTRACE /Fo$(OBJ)\image_console_trace.obj image_console.c
135+
104136 $(OBJ)\image_gui.exe : $(OBJ) $(OBJ)\image_gui.res $(OBJ)\image_gui.obj \
105137 $(OBJ)\jvm.obj $(OBJ)\loader.obj $(OBJ)\message.obj $(OBJ)\notify.obj $(OBJ)\eventlog.obj \
106138 $(OBJ)\bindres.exe $(OBJ)\exewrap\core\ByteBufferInputStream.class $(OBJ)\exewrap\core\PackInputStream.class $(OBJ)\exewrap\core\ExewrapClassLoader.class $(OBJ)\exewrap\core\URLConnection.class $(OBJ)\exewrap\core\URLStreamHandler.class $(OBJ)\util.jar
@@ -113,12 +145,29 @@
113145 $(OBJ)\bindres.exe $(OBJ)\image_gui.exe EXEWRAP_CLASS_LOADER $(OBJ)\exewrap\core\ExewrapClassLoader.class
114146 $(OBJ)\bindres.exe $(OBJ)\image_gui.exe UTIL_JAR $(OBJ)\util.jar
115147
116-$(OBJ)\image_gui.obj : $(OBJ) image_gui.c
117- $(CC) $(CFLAGS) $(INC) /Fo$(OBJ)\image_gui.obj image_gui.c
148+$(OBJ)\image_gui_trace.exe : $(OBJ) $(OBJ)\image_gui.res $(OBJ)\image_gui_trace.obj $(OBJ)\trace.obj \
149+ $(OBJ)\buffer.obj $(OBJ)\hde$(BITS).obj $(OBJ)\hook.obj $(OBJ)\trampoline.obj \
150+ $(OBJ)\jvm.obj $(OBJ)\loader.obj $(OBJ)\message.obj $(OBJ)\notify.obj $(OBJ)\eventlog.obj \
151+ $(OBJ)\bindres.exe $(OBJ)\exewrap\core\ByteBufferInputStream.class $(OBJ)\exewrap\core\PackInputStream.class $(OBJ)\exewrap\core\ExewrapClassLoader.class $(OBJ)\exewrap\core\URLConnection.class $(OBJ)\exewrap\core\URLStreamHandler.class $(OBJ)\util.jar
152+ $(LINK) $(LDFLAGS) /SUBSYSTEM:WINDOWS /MANIFEST:EMBED /OUT:$(OBJ)\image_gui_trace.exe $(OBJ)\image_gui.res $(OBJ)\image_gui_trace.obj $(OBJ)\trace.obj \
153+ $(OBJ)\buffer.obj $(OBJ)\hde$(BITS).obj $(OBJ)\hook.obj $(OBJ)\trampoline.obj \
154+ $(OBJ)\jvm.obj $(OBJ)\loader.obj $(OBJ)\message.obj $(OBJ)\notify.obj $(OBJ)\eventlog.obj $(LIBS)
155+ $(OBJ)\bindres.exe $(OBJ)\image_gui_trace.exe BYTE_BUFFER_INPUT_STREAM $(OBJ)\exewrap\core\ByteBufferInputStream.class
156+ $(OBJ)\bindres.exe $(OBJ)\image_gui_trace.exe PACK_INPUT_STREAM $(OBJ)\exewrap\core\PackInputStream.class
157+ $(OBJ)\bindres.exe $(OBJ)\image_gui_trace.exe URL_CONNECTION $(OBJ)\exewrap\core\URLConnection.class
158+ $(OBJ)\bindres.exe $(OBJ)\image_gui_trace.exe URL_STREAM_HANDLER $(OBJ)\exewrap\core\URLStreamHandler.class
159+ $(OBJ)\bindres.exe $(OBJ)\image_gui_trace.exe EXEWRAP_CLASS_LOADER $(OBJ)\exewrap\core\ExewrapClassLoader.class
160+ $(OBJ)\bindres.exe $(OBJ)\image_gui_trace.exe UTIL_JAR $(OBJ)\util.jar
118161
119162 $(OBJ)\image_gui.res : $(OBJ) resources\image_gui.rc resources\eventlog.bin
120163 $(RC) $(RCFLAGS) /fo$(OBJ)\image_gui.res resources\image_gui.rc
121164
165+$(OBJ)\image_gui.obj : $(OBJ) image_gui.c
166+ $(CC) $(CFLAGS) $(INC) /Fo$(OBJ)\image_gui.obj image_gui.c
167+
168+$(OBJ)\image_gui_trace.obj : $(OBJ) image_gui.c
169+ $(CC) $(CFLAGS) $(INC) /DTRACE /Fo$(OBJ)\image_gui_trace.obj image_gui.c
170+
122171 $(OBJ)\image_service.exe : $(OBJ) $(OBJ)\image_service.res $(OBJ)\image_service.obj \
123172 $(OBJ)\jvm.obj $(OBJ)\loader.obj $(OBJ)\message.obj $(OBJ)\eventlog.obj \
124173 $(OBJ)\bindres.exe $(OBJ)\exewrap\core\ByteBufferInputStream.class $(OBJ)\exewrap\core\PackInputStream.class $(OBJ)\exewrap\core\ExewrapClassLoader.class $(OBJ)\exewrap\core\URLConnection.class $(OBJ)\exewrap\core\URLStreamHandler.class $(OBJ)\util.jar
@@ -131,12 +180,29 @@
131180 $(OBJ)\bindres.exe $(OBJ)\image_service.exe EXEWRAP_CLASS_LOADER $(OBJ)\exewrap\core\ExewrapClassLoader.class
132181 $(OBJ)\bindres.exe $(OBJ)\image_service.exe UTIL_JAR $(OBJ)\util.jar
133182
134-$(OBJ)\image_service.obj : $(OBJ) image_service.c
135- $(CC) $(CFLAGS) $(INC) /Fo$(OBJ)\image_service.obj image_service.c
183+$(OBJ)\image_service_trace.exe : $(OBJ) $(OBJ)\image_service.res $(OBJ)\image_service_trace.obj $(OBJ)\trace.obj \
184+ $(OBJ)\buffer.obj $(OBJ)\hde$(BITS).obj $(OBJ)\hook.obj $(OBJ)\trampoline.obj \
185+ $(OBJ)\jvm.obj $(OBJ)\loader.obj $(OBJ)\message.obj $(OBJ)\eventlog.obj \
186+ $(OBJ)\bindres.exe $(OBJ)\exewrap\core\ByteBufferInputStream.class $(OBJ)\exewrap\core\PackInputStream.class $(OBJ)\exewrap\core\ExewrapClassLoader.class $(OBJ)\exewrap\core\URLConnection.class $(OBJ)\exewrap\core\URLStreamHandler.class $(OBJ)\util.jar
187+ $(LINK) $(LDFLAGS) /SUBSYSTEM:CONSOLE /MANIFEST:EMBED /OUT:$(OBJ)\image_service_trace.exe $(OBJ)\image_service.res $(OBJ)\image_service_trace.obj $(OBJ)\trace.obj \
188+ $(OBJ)\buffer.obj $(OBJ)\hde$(BITS).obj $(OBJ)\hook.obj $(OBJ)\trampoline.obj \
189+ $(OBJ)\jvm.obj $(OBJ)\loader.obj $(OBJ)\message.obj $(OBJ)\eventlog.obj $(LIBS)
190+ $(OBJ)\bindres.exe $(OBJ)\image_service_trace.exe BYTE_BUFFER_INPUT_STREAM $(OBJ)\exewrap\core\ByteBufferInputStream.class
191+ $(OBJ)\bindres.exe $(OBJ)\image_service_trace.exe PACK_INPUT_STREAM $(OBJ)\exewrap\core\PackInputStream.class
192+ $(OBJ)\bindres.exe $(OBJ)\image_service_trace.exe URL_CONNECTION $(OBJ)\exewrap\core\URLConnection.class
193+ $(OBJ)\bindres.exe $(OBJ)\image_service_trace.exe URL_STREAM_HANDLER $(OBJ)\exewrap\core\URLStreamHandler.class
194+ $(OBJ)\bindres.exe $(OBJ)\image_service_trace.exe EXEWRAP_CLASS_LOADER $(OBJ)\exewrap\core\ExewrapClassLoader.class
195+ $(OBJ)\bindres.exe $(OBJ)\image_service_trace.exe UTIL_JAR $(OBJ)\util.jar
136196
137197 $(OBJ)\image_service.res : $(OBJ) resources\image_service.rc resources\eventlog.bin
138198 $(RC) $(RCFLAGS) /fo$(OBJ)\image_service.res resources\image_service.rc
139199
200+$(OBJ)\image_service.obj : $(OBJ) image_service.c
201+ $(CC) $(CFLAGS) $(INC) /Fo$(OBJ)\image_service.obj image_service.c
202+
203+$(OBJ)\image_service_trace.obj : $(OBJ) image_service.c
204+ $(CC) $(CFLAGS) $(INC) /Fo$(OBJ)\image_service_trace.obj image_service.c
205+
140206 $(OBJ)\eventlog.obj : $(OBJ) eventlog.c
141207 $(CC) $(CFLAGS) $(INC) /Fo$(OBJ)\eventlog.obj eventlog.c
142208
@@ -152,6 +218,9 @@
152218 $(OBJ)\jvm.obj : $(OBJ) jvm.c
153219 $(CC) $(CFLAGS) $(INC) /Fo$(OBJ)\jvm.obj jvm.c
154220
221+$(OBJ)\trace.obj : $(OBJ) trace.c
222+ $(CC) $(CFLAGS) $(INC) /Fo$(OBJ)\trace.obj trace.c
223+
155224 $(OBJ)\bindres.exe : $(OBJ) $(OBJ)\bindres.obj
156225 $(LINK) $(LDFLAGS) /SUBSYSTEM:CONSOLE /OUT:$(OBJ)\bindres.exe $(OBJ)\bindres.obj $(LIBS)
157226
@@ -158,7 +227,25 @@
158227 $(OBJ)\bindres.obj : $(OBJ) bindres.c
159228 $(CC) $(CFLAGS) $(INC) /Fo$(OBJ)\bindres.obj bindres.c
160229
230+
161231 ###
232+### MinHook
233+###
234+
235+$(OBJ)\buffer.obj : minhook\src\buffer.c
236+ $(CC) $(CFLAGS) $(INC) /Fo$(OBJ)\buffer.obj minhook\src\buffer.c
237+
238+$(OBJ)\hook.obj : minhook\src\hook.c
239+ $(CC) $(CFLAGS) $(INC) /Fo$(OBJ)\hook.obj minhook\src\hook.c
240+
241+$(OBJ)\trampoline.obj : minhook\src\trampoline.c
242+ $(CC) $(CFLAGS) $(INC) /Fo$(OBJ)\trampoline.obj minhook\src\trampoline.c
243+
244+$(OBJ)\hde$(BITS).obj : minhook\src\HDE\hde$(BITS).c
245+ $(CC) $(CFLAGS) $(INC) /Fo$(OBJ)\hde$(BITS).obj minhook\src\HDE\hde$(BITS).c
246+
247+
248+###
162249 ### Java
163250 ###
164251
@@ -181,7 +268,7 @@
181268
182269 ### exewrap.util
183270
184-$(OBJ)\util.jar : $(OBJ) $(OBJ)\exewrap\util\EventLogHandler.class $(OBJ)\exewrap\util\EventLogStream.class $(OBJ)\exewrap\util\FileLogStream.class $(OBJ)\exewrap\util\UncaughtExceptionHandler.class
271+$(OBJ)\util.jar : $(OBJ) $(OBJ)\exewrap\util\EventLogHandler.class $(OBJ)\exewrap\util\EventLogStream.class $(OBJ)\exewrap\util\FileLogStream.class $(OBJ)\exewrap\util\UncaughtExceptionHandler.class $(OBJ)\exewrap\util\ConsoleOutputStream.class
185272 $(JAR) cvf $(OBJ)\util.jar -C $(OBJ) exewrap\util
186273
187274 $(OBJ)\exewrap\util\EventLogHandler.class : $(OBJ) java\exewrap\util\EventLogHandler.java
@@ -196,6 +283,9 @@
196283 $(OBJ)\exewrap\util\UncaughtExceptionHandler.class : $(OBJ) java\exewrap\util\UncaughtExceptionHandler.java
197284 $(JAVAC) -Xlint:none -source 1.5 -target 1.5 -sourcepath java -d $(OBJ) java\exewrap\util\UncaughtExceptionHandler.java
198285
286+$(OBJ)\exewrap\util\ConsoleOutputStream.class : $(OBJ) java\exewrap\util\ConsoleOutputStream.java
287+ $(JAVAC) -Xlint:none -source 1.5 -target 1.5 -sourcepath java -d $(OBJ) java\exewrap\util\ConsoleOutputStream.java
288+
199289 ### exewrap.tool
200290
201291 $(OBJ)\tool.jar : $(OBJ) $(OBJ)\exewrap\tool\JarProcessor.class $(OBJ)\exewrap\tool\PackOutputStream.class
@@ -207,3 +297,33 @@
207297 $(OBJ)\exewrap\tool\JarProcessor.class : $(OBJ) java\exewrap\tool\JarProcessor.java
208298 $(JAVAC) -Xlint:none -source 1.5 -target 1.5 -sourcepath java -d $(OBJ) java\exewrap\tool\JarProcessor.java
209299
300+### jeremin
301+
302+$(BIN)\jremin.exe : $(OBJ)\jremin.jar $(BIN)\exewrap.exe
303+ $(BIN)\exewrap.exe -o $(BIN)\jremin.exe -j $(OBJ)\jremin.jar -a "-Xmx1024m" -e "NOSIDEBYSIDE" \
304+ -p jremin \
305+ -V 1.1.0 \
306+ -v 1.1.0.0 \
307+ -d "Java Runtime Environment (JRE) Minimizer" \
308+ -c "Copyright (C) 2015 HIRUKAWA Ryo. All rights reserved."
309+
310+$(OBJ)\jremin.jar : $(OBJ) $(OBJ)\jremin\Jremin.class $(OBJ)\jremin\Trace.class $(OBJ)\jremin\classes.txt
311+ $(JAR) cvfe $(OBJ)\jremin.jar jremin.JreMin -C $(OBJ) jremin
312+
313+$(OBJ)\jremin\JreMin.class : $(OBJ) java\jremin\JreMin.java
314+ $(JAVAC) -Xlint:none -source 1.5 -target 1.5 -sourcepath java -d $(OBJ) java\jremin\JreMin.java
315+
316+$(OBJ)\jremin\Trace.class : $(OBJ) java\jremin\Trace.java
317+ $(JAVAC) -Xlint:none -source 1.5 -target 1.5 -sourcepath java -d $(OBJ) java\jremin\Trace.java
318+
319+$(OBJ)\jremin\classes.txt : $(OBJ) $(OBJ)\agent.exe
320+ $(OBJ)\agent.exe > $(OBJ)\jremin\classes.txt
321+
322+$(OBJ)\agent.exe : $(OBJ) $(OBJ)\agent.jar
323+ $(BIN)\exewrap.exe -o $(OBJ)\agent.exe -j $(OBJ)\agent.jar -e "NOSIDEBYSIDE" -a "-javaagent:$(OBJ)\agent.jar"
324+
325+$(OBJ)\agent.jar : $(OBJ) $(OBJ)\jremin\agent\Agent.class java\jremin\agent\manifest.txt
326+ $(JAR) cvfm $(OBJ)\agent.jar java\jremin\agent\manifest.txt -C $(OBJ) jremin
327+
328+$(OBJ)\jremin\agent\Agent.class : $(OBJ) java\jremin\agent\Agent.java
329+ $(JAVAC) -Xlint:none -source 1.5 -target 1.5 -sourcepath java -d $(OBJ) java\jremin\agent\Agent.java
--- exewrap/trunk/exewrap/src/jvm.c (revision 21)
+++ exewrap/trunk/exewrap/src/jvm.c (revision 22)
@@ -7,9 +7,9 @@
77
88 #include "include/jvm.h"
99
10-void InitializePath(char* relative_classpath, char* relative_extdirs, BOOL useServerVM);
10+void InitializePath(char* relative_classpath, char* relative_extdirs, BOOL useServerVM, BOOL useSideBySideJRE);
1111 int GetProcessArchitecture();
12-JNIEnv* CreateJavaVM(LPTSTR vm_args_opt, BOOL useServerVM, int* err);
12+JNIEnv* CreateJavaVM(LPTSTR vm_args_opt, BOOL useServerVM, BOOL useSideBySideJRE, int* err);
1313 void DestroyJavaVM();
1414 JNIEnv* AttachJavaVM();
1515 void DetachJavaVM();
@@ -34,16 +34,16 @@
3434
3535 JavaVM* jvm = NULL;
3636 JNIEnv* env = NULL;
37-DWORD javaRuntimeVersion = 0xFFFFFFFF;
37+DWORD javaRuntimeVersion = 0xFFFFFFFF;
3838
39-TCHAR opt_app_path[MAX_PATH + 32];
40-TCHAR opt_app_name[MAX_PATH + 32];
41-TCHAR opt_app_version[64];
42-TCHAR opt_policy_path[MAX_PATH + 32];
39+char opt_app_path[MAX_PATH + 32];
40+char opt_app_name[MAX_PATH + 32];
41+char opt_app_version[64];
42+char opt_policy_path[MAX_PATH + 32];
4343 BOOL path_initialized = FALSE;
44-TCHAR binpath[MAX_PATH];
45-TCHAR jvmpath[MAX_PATH];
46-TCHAR extpath[MAX_PATH];
44+char binpath[MAX_PATH];
45+char jvmpath[MAX_PATH];
46+char extpath[MAX_PATH];
4747 char* classpath = NULL;
4848 char* extdirs = NULL;
4949 char* libpath = NULL;
@@ -57,24 +57,24 @@
5757 return sizeof(int*) * 8;
5858 }
5959
60-JNIEnv* CreateJavaVM(LPTSTR vm_args_opt, BOOL useServerVM, int* err)
60+JNIEnv* CreateJavaVM(LPTSTR vm_args_opt, BOOL useServerVM, BOOL useSideBySideJRE, int* err)
6161 {
6262 JNIGetDefaultJavaVMInitArgs getDefaultJavaVMInitArgs;
6363 JNICreateJavaVM createJavaVM;
6464 JavaVMOption options[64];
6565 JavaVMInitArgs vm_args;
66- char** argv;
66+ char** argv = NULL;
6767 int argc;
6868 int i;
6969 int result;
7070
71- if(!path_initialized)
71+ if (!path_initialized)
7272 {
73- InitializePath(NULL, "lib", useServerVM);
73+ InitializePath(NULL, "lib", useServerVM, useSideBySideJRE);
7474 }
7575
7676 jvmdll = LoadLibrary("jvm.dll");
77- if(jvmdll == NULL)
77+ if (jvmdll == NULL)
7878 {
7979 if(err != NULL)
8080 {
@@ -119,11 +119,14 @@
119119 }
120120
121121 EXIT:
122- for (i = 0; i < argc; i++)
122+ if (argv != NULL)
123123 {
124- HeapFree(GetProcessHeap(), 0, argv[i]);
124+ for (i = 0; i < argc; i++)
125+ {
126+ HeapFree(GetProcessHeap(), 0, argv[i]);
127+ }
128+ HeapFree(GetProcessHeap(), 0, argv);
125129 }
126- HeapFree(GetProcessHeap(), 0, argv);
127130
128131 return env;
129132 }
@@ -274,7 +277,7 @@
274277 return ret;
275278 }
276279
277-void InitializePath(char* relative_classpath, char* relative_extdirs, BOOL useServerVM) {
280+void InitializePath(char* relative_classpath, char* relative_extdirs, BOOL useServerVM, BOOL useSideBySideJRE) {
278281 char modulePath[_MAX_PATH];
279282 char* buffer;
280283 char* token;
@@ -332,7 +335,7 @@
332335 }
333336
334337 // Find local JRE
335- if (jvmpath[0] == 0)
338+ if (useSideBySideJRE && jvmpath[0] == 0)
336339 {
337340 GetModulePath(jre1, MAX_PATH);
338341 lstrcpy(search, jre1);
@@ -366,7 +369,7 @@
366369 }
367370 }
368371
369- if (jvmpath[0] == 0)
372+ if (useSideBySideJRE && jvmpath[0] == 0)
370373 {
371374 GetModulePath(jre2, MAX_PATH);
372375 lstrcpy(search, jre2);
--- exewrap/trunk/exewrap/src/java/URLStreamHandler.java (revision 21)
+++ exewrap/trunk/exewrap/src/java/URLStreamHandler.java (revision 22)
@@ -1,9 +0,0 @@
1-import java.io.IOException;
2-import java.net.URL;
3-
4-public class URLStreamHandler extends java.net.URLStreamHandler {
5-
6- protected java.net.URLConnection openConnection(URL url) throws IOException {
7- return new URLConnection(url);
8- }
9-}
--- exewrap/trunk/exewrap/src/java/UncaughtHandler.java (revision 21)
+++ exewrap/trunk/exewrap/src/java/UncaughtHandler.java (revision 22)
@@ -1,27 +0,0 @@
1-import java.lang.Thread.UncaughtExceptionHandler;
2-import java.io.PrintWriter;
3-import java.io.StringWriter;
4-
5-public class UncaughtHandler implements UncaughtExceptionHandler {
6-
7- public static void initialize() {
8- Thread.setDefaultUncaughtExceptionHandler(new UncaughtHandler());
9- }
10-
11- public void uncaughtException(Thread t, Throwable e) {
12- System.err.print("Exception in thread \"" + t.getName() + "\" ");
13- e.printStackTrace();
14- UncaughtException(e.toString(), getStackTrace(e));
15- }
16-
17- private static String getStackTrace(Throwable t) {
18- StringWriter s = new StringWriter();
19- PrintWriter w = new PrintWriter(s);
20- t.printStackTrace(w);
21- w.flush();
22- s.flush();
23- return s.toString();
24- }
25-
26- public static native void UncaughtException(String message, String trace);
27-}
--- exewrap/trunk/exewrap/src/java/FileLogStream.java (revision 21)
+++ exewrap/trunk/exewrap/src/java/FileLogStream.java (revision 22)
@@ -1,61 +0,0 @@
1-import java.io.File;
2-import java.io.FileNotFoundException;
3-import java.io.FileOutputStream;
4-import java.io.IOException;
5-import java.io.OutputStream;
6-import java.io.PrintStream;
7-
8-public class FileLogStream extends OutputStream {
9- static private String filename = null;
10- static private FileOutputStream out = null;
11-
12- public static void initialize(String moduleName) throws FileNotFoundException {
13- File path = new File(moduleName);
14- String name = path.getName().substring(0, path.getName().length() - 4) + ".log";
15- if(!path.getParent().endsWith(":\\") && new File(path.getParentFile().getParent() + "\\log").exists()) {
16- filename = path.getParentFile().getParent() + "\\log\\" + name;
17- }
18- if(filename == null && new File(path.getParent() + "\\log").exists()) {
19- filename = path.getParent() + "\\log\\" + name;
20- }
21- if(filename == null) {
22- filename = path.getParent() + "\\" + name;
23- }
24- FileLogStream stream = new FileLogStream();
25- System.setOut(new PrintStream(stream));
26- System.setErr(new PrintStream(stream));
27- }
28-
29- private void open() {
30- try {
31- out = new FileOutputStream(filename);
32- } catch(FileNotFoundException e) {}
33- }
34-
35- public void close() throws IOException {
36- if(out != null) {
37- out.close();
38- }
39- }
40-
41- public void flush() throws IOException {
42- }
43-
44- public void write(byte[] b, int off, int len) throws IOException {
45- if(out == null) open();
46- out.write(b, off, len);
47- out.flush();
48- }
49-
50- public void write(byte[] b) throws IOException {
51- if(out == null) open();
52- out.write(b);
53- out.flush();
54- }
55-
56- public void write(int b) throws IOException {
57- if(out == null) open();
58- out.write(b);
59- out.flush();
60- }
61-}
--- exewrap/trunk/exewrap/src/java/EventLogStream.java (revision 21)
+++ exewrap/trunk/exewrap/src/java/EventLogStream.java (revision 22)
@@ -1,72 +0,0 @@
1-import java.io.ByteArrayOutputStream;
2-import java.io.IOException;
3-import java.io.PrintStream;
4-import java.io.PrintWriter;
5-import java.io.StringWriter;
6-
7-public class EventLogStream extends PrintStream {
8- public static final int INFORMATION = 0;
9- public static final int WARNING = 1;
10- public static final int ERROR = 2;
11- private static ByteArrayOutputStream info = new ByteArrayOutputStream();
12- private static ByteArrayOutputStream warning = new ByteArrayOutputStream();
13- private static ByteArrayOutputStream error = new ByteArrayOutputStream();
14-
15- public static void initialize() {
16- System.setOut(new EventLogStream(INFORMATION));
17- System.setErr(new EventLogStream(WARNING));
18- }
19-
20- private int type;
21- ByteArrayOutputStream buffer;
22-
23- public EventLogStream(int type) {
24- super(type==INFORMATION?info:(type==WARNING?warning:error));
25- this.type = type;
26- switch(type) {
27- case INFORMATION: buffer = info; break;
28- case WARNING: buffer = warning; break;
29- case ERROR: buffer = error; break;
30- }
31- }
32-
33- public void close() {
34- flush();
35- }
36-
37- public void flush() {
38- WriteEventLog(type, new String(buffer.toByteArray()));
39- buffer.reset();
40- }
41-
42- public void write(byte[] b, int off, int len) {
43- buffer.write(b, off, len);
44- }
45-
46- public void write(byte[] b) throws IOException {
47- buffer.write(b);
48- }
49-
50- public void write(int b) {
51- buffer.write(b);
52- }
53-
54- public void print(String s) {
55- if("".equals(s)) {
56- buffer.reset();
57- } else {
58- super.print(s);
59- }
60- }
61-
62- public static String getStackTrace(Throwable t) {
63- StringWriter s = new StringWriter();
64- PrintWriter w = new PrintWriter(s);
65- t.printStackTrace(w);
66- w.flush();
67- s.flush();
68- return s.toString();
69- }
70-
71- public static native void WriteEventLog(int type, String message);
72-}
--- exewrap/trunk/exewrap/src/java/JarOptimizer.java (revision 21)
+++ exewrap/trunk/exewrap/src/java/JarOptimizer.java (revision 22)
@@ -1,141 +0,0 @@
1-import java.io.ByteArrayInputStream;
2-import java.io.ByteArrayOutputStream;
3-import java.io.FileInputStream;
4-import java.util.Arrays;
5-import java.util.jar.JarEntry;
6-import java.util.jar.JarInputStream;
7-import java.util.jar.JarOutputStream;
8-import java.util.jar.Manifest;
9-import java.util.jar.Pack200;
10-import java.util.jar.Pack200.Packer;
11-import java.util.zip.CRC32;
12-import java.util.zip.GZIPOutputStream;
13-
14-public class JarOptimizer extends ClassLoader {
15-
16- private String relative_classpath = null;
17- private ByteArrayOutputStream resource_gz = new ByteArrayOutputStream();
18- private ByteArrayOutputStream classes_pack_gz = new ByteArrayOutputStream();
19- private String splash_path = null;
20- private byte[] splash_image = null;
21-
22- public JarOptimizer(String filename) throws Exception {
23- int resourceCount = 0;
24- int classCount = 0;
25- ByteArrayOutputStream resources = new ByteArrayOutputStream();
26- ByteArrayOutputStream classes = new ByteArrayOutputStream();
27-
28- JarInputStream in = new JarInputStream(new FileInputStream(filename));
29- Manifest manifest = in.getManifest();
30- relative_classpath = manifest.getMainAttributes().getValue("Class-Path");
31- splash_path = manifest.getMainAttributes().getValue("SplashScreen-Image");
32- JarOutputStream classJar = new JarOutputStream(classes, manifest);
33- JarOutputStream resourceJar = new JarOutputStream(resources);
34-
35- JarEntry inEntry;
36- byte[] buf = new byte[65536];
37- int size;
38- while((inEntry = in.getNextJarEntry()) != null) {
39- ByteArrayOutputStream baos = new ByteArrayOutputStream();
40- while(in.available() > 0) {
41- size = in.read(buf);
42- if(size > 0) {
43- baos.write(buf, 0, size);
44- }
45- }
46- byte[] data = baos.toByteArray();
47- if(inEntry.getName().equals(this.splash_path)) {
48- this.splash_image = data;
49- } else if(inEntry.getName().toLowerCase().endsWith(".class")) {
50- CRC32 crc = new CRC32();
51- crc.update(data);
52-
53- JarEntry outEntry = new JarEntry(inEntry.getName());
54- outEntry.setMethod(JarEntry.STORED);
55- outEntry.setSize(data.length);
56- outEntry.setCrc(crc.getValue());
57-
58- classJar.putNextEntry(outEntry);
59- classJar.write(data);
60- classJar.closeEntry();
61- classCount++;
62- } else {
63- /*
64- String resourceEntryName;
65- if(inEntry.getName().length() > 1 && inEntry.getName().charAt(0) == '/' && inEntry.getName().charAt(1) != '/') {
66- resourceEntryName = inEntry.getName().substring(1);
67- } else {
68- resourceEntryName = inEntry.getName();
69- }
70- */
71- CRC32 crc = new CRC32();
72- crc.update(data);
73-
74- //JarEntry outEntry = new JarEntry(resourceEntryName);
75- JarEntry outEntry = new JarEntry(inEntry.getName());
76- outEntry.setMethod(JarEntry.STORED);
77- outEntry.setSize(data.length);
78- outEntry.setCrc(crc.getValue());
79-
80- resourceJar.putNextEntry(outEntry);
81- resourceJar.write(data);
82- resourceJar.closeEntry();
83- resourceCount++;
84- }
85- in.closeEntry();
86- }
87- in.close();
88- if(resourceCount > 0) {
89- resourceJar.close();
90- GZIPOutputStream gzout = new GZIPOutputStream(resource_gz);
91- gzout.write(resources.toByteArray());
92- gzout.flush();
93- gzout.finish();
94- gzout.close();
95- }
96- if(classCount > 0) {
97- classJar.close();
98- Packer packer = Pack200.newPacker();
99- GZIPOutputStream gzout = new GZIPOutputStream(classes_pack_gz);
100- in = new JarInputStream(new ByteArrayInputStream(classes.toByteArray()));
101- packer.pack(in, gzout);
102- gzout.flush();
103- gzout.finish();
104- gzout.close();
105- in.close();
106- }
107- }
108-
109- public byte[] getRelativeClassPath() {
110- if(this.relative_classpath != null) {
111- byte[] buf = this.relative_classpath.replaceAll("/", "\\\\").getBytes();
112- return Arrays.copyOf(buf, buf.length + 2);
113- }
114- return null;
115- }
116-
117- public byte[] getClassesPackGz() {
118- if(this.classes_pack_gz.size() > 0) {
119- return this.classes_pack_gz.toByteArray();
120- }
121- return null;
122- }
123-
124- public byte[] getResourcesGz() {
125- if(this.resource_gz.size() > 0) {
126- return this.resource_gz.toByteArray();
127- }
128- return null;
129- }
130-
131- public byte[] getSplashPath() {
132- if(this.splash_path != null) {
133- return this.splash_path.getBytes();
134- }
135- return null;
136- }
137-
138- public byte[] getSplashImage() {
139- return this.splash_image;
140- }
141-}
--- exewrap/trunk/exewrap/src/java/EventLogHandler.java (revision 21)
+++ exewrap/trunk/exewrap/src/java/EventLogHandler.java (revision 22)
@@ -1,36 +0,0 @@
1-import java.util.logging.Handler;
2-import java.util.logging.Level;
3-import java.util.logging.LogRecord;
4-import java.util.logging.Logger;
5-
6-public class EventLogHandler extends Handler {
7- public static final int INFORMATION = 0;
8- public static final int WARNING = 1;
9- public static final int ERROR = 2;
10- private static final Logger eventlog = Logger.getLogger("eventlog");
11-
12- public static void initialize() {
13- EventLogHandler.eventlog.setUseParentHandlers(false);
14- EventLogHandler.eventlog.addHandler(new EventLogHandler());
15- }
16-
17- public void publish(LogRecord record) {
18- int level = record.getLevel().intValue();
19-
20- if(level >= Level.SEVERE.intValue()) {
21- WriteEventLog(ERROR, record.getMessage() + "");
22- } else if(level >= Level.WARNING.intValue()) {
23- WriteEventLog(WARNING, record.getMessage() + "");
24- } else if(level >= Level.INFO.intValue()) {
25- WriteEventLog(INFORMATION, record.getMessage() + "");
26- }
27- }
28-
29- public void flush() {
30- }
31-
32- public void close() throws SecurityException {
33- }
34-
35- public static native void WriteEventLog(int type, String message);
36-}
--- exewrap/trunk/exewrap/src/java/URLConnection.java (revision 21)
+++ exewrap/trunk/exewrap/src/java/URLConnection.java (revision 22)
@@ -1,26 +0,0 @@
1-import java.io.ByteArrayInputStream;
2-import java.io.IOException;
3-import java.io.InputStream;
4-import java.net.URL;
5-import java.util.HashMap;
6-import java.util.Map;
7-
8-public class URLConnection extends java.net.URLConnection {
9- /* package private */ static final Map resources = new HashMap();
10-
11- protected URLConnection(URL url) {
12- super(url);
13- }
14-
15- public void connect() throws IOException {
16- }
17-
18- public InputStream getInputStream() throws IOException {
19- String name = getURL().getFile();
20- byte[] buffer = (byte[])resources.get(name);
21- if(buffer != null) {
22- return new ByteArrayInputStream(buffer);
23- }
24- return null;
25- }
26-}
--- exewrap/trunk/exewrap/src/java/PackLoader.java (revision 21)
+++ exewrap/trunk/exewrap/src/java/PackLoader.java (revision 22)
@@ -1,107 +0,0 @@
1-import java.io.ByteArrayInputStream;
2-import java.io.ByteArrayOutputStream;
3-import java.io.IOException;
4-import java.io.InputStream;
5-import java.net.MalformedURLException;
6-import java.net.URL;
7-import java.util.HashMap;
8-import java.util.Map;
9-import java.util.jar.JarEntry;
10-import java.util.jar.JarInputStream;
11-import java.util.jar.JarOutputStream;
12-import java.util.jar.Manifest;
13-import java.util.jar.Pack200;
14-import java.util.jar.Pack200.Unpacker;
15-import java.util.zip.GZIPInputStream;
16-
17-public class PackLoader extends ClassLoader {
18-
19- private Map classes = new HashMap();
20-
21- public Class initialize(byte[] classesPackGz, byte[] resourcesGz, byte[] splashPath, byte[] splashImage) throws IOException, ClassNotFoundException {
22- ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
23- JarEntry entry;
24- byte[] buf = new byte[65536];
25- int size;
26-
27- //initialize resources.
28- if(resourcesGz != null) {
29- JarInputStream resourcesJarInputStream = new JarInputStream(new GZIPInputStream(new ByteArrayInputStream(resourcesGz)));
30- while((entry = resourcesJarInputStream.getNextJarEntry()) != null) {
31- byteArray.reset();
32- while(resourcesJarInputStream.available() > 0) {
33- size = resourcesJarInputStream.read(buf);
34- if(size > 0) {
35- byteArray.write(buf, 0, size);
36- }
37- }
38- URLConnection.resources.put(entry.getName(), byteArray.toByteArray());
39- resourcesJarInputStream.closeEntry();
40- }
41- resourcesJarInputStream.close();
42- }
43-
44- //add splash image.
45- if(splashPath != null && splashImage != null) {
46- URLConnection.resources.put(new String(splashPath), splashImage);
47- }
48-
49- //initialize classes.
50- InputStream classesPackGzInputStream = new GZIPInputStream(new ByteArrayInputStream(classesPackGz));
51- ByteArrayOutputStream classesJar = new ByteArrayOutputStream();
52- JarOutputStream classesJarOutputStream = new JarOutputStream(classesJar);
53- Unpacker unpacker = Pack200.newUnpacker();
54- unpacker.unpack(classesPackGzInputStream, classesJarOutputStream);
55- classesPackGzInputStream.close();
56- classesJarOutputStream.close();
57- classesJar.close();
58- JarInputStream classesJarInputStream = new JarInputStream(new ByteArrayInputStream(classesJar.toByteArray()));
59- while((entry = classesJarInputStream.getNextJarEntry()) != null) {
60- String className = entry.getName().substring(0, entry.getName().length() - 6).replace('/', '.');
61- byteArray.reset();
62- while(classesJarInputStream.available() > 0) {
63- size = classesJarInputStream.read(buf);
64- if(size > 0) {
65- byteArray.write(buf, 0, size);
66- }
67- }
68- this.classes.put(className, byteArray.toByteArray());
69- classesJarInputStream.closeEntry();
70- }
71-
72- //find main class.
73- Manifest manifest = classesJarInputStream.getManifest();
74- classesJarInputStream.close();
75- if(manifest != null) {
76- String mainClassName = classesJarInputStream.getManifest().getMainAttributes().getValue("Main-Class");
77- if(mainClassName != null) {
78- Thread.currentThread().setContextClassLoader(this);
79- return Class.forName(mainClassName, true, this);
80- }
81- }
82- return null;
83- }
84-
85- protected Class findClass(String name) throws ClassNotFoundException {
86- byte[] buffer = (byte[])this.classes.get(name);
87- if(buffer != null) {
88- if(name.indexOf('.') >= 0) {
89- String packageName = name.substring(0, name.lastIndexOf('.'));
90- if(getPackage(packageName) == null) {
91- definePackage(packageName, null, null, null, null, null, null, null);
92- }
93- }
94- return defineClass(name, buffer, 0, buffer.length);
95- }
96- throw new ClassNotFoundException(name);
97- }
98-
99- public URL getResource(String name) {
100- try {
101- if(URLConnection.resources.containsKey(name)) {
102- return new URL("exewrap", "", -1, name, new URLStreamHandler());
103- }
104- } catch (MalformedURLException e) {}
105- return super.getResource(name);
106- }
107-}
--- exewrap/trunk/exewrap/src/java/ClassicLoader.java (revision 21)
+++ exewrap/trunk/exewrap/src/java/ClassicLoader.java (revision 22)
@@ -1,92 +0,0 @@
1-import java.io.ByteArrayInputStream;
2-import java.io.ByteArrayOutputStream;
3-import java.io.IOException;
4-import java.net.MalformedURLException;
5-import java.net.URL;
6-import java.util.HashMap;
7-import java.util.Map;
8-import java.util.jar.JarEntry;
9-import java.util.jar.JarInputStream;
10-import java.util.jar.Manifest;
11-
12-public class ClassicLoader extends ClassLoader {
13-
14- private Map classes = new HashMap();
15-
16- public Class initialize(byte[] jar) throws IOException, ClassNotFoundException {
17- JarInputStream jarInputStream;
18- ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
19- JarEntry entry;
20- byte[] buf = new byte[65536];
21- int size;
22-
23- //initialize resources.
24- jarInputStream = new JarInputStream(new ByteArrayInputStream(jar));
25- while((entry = jarInputStream.getNextJarEntry()) != null) {
26- if(!entry.getName().toLowerCase().endsWith(".class")) {
27- byteArray.reset();
28- while(jarInputStream.available() > 0) {
29- size = jarInputStream.read(buf);
30- if(size > 0) {
31- byteArray.write(buf, 0, size);
32- }
33- }
34- URLConnection.resources.put(entry.getName(), byteArray.toByteArray());
35- }
36- jarInputStream.closeEntry();
37- }
38- jarInputStream.close();
39-
40- //initialize classes.
41- jarInputStream = new JarInputStream(new ByteArrayInputStream(jar));
42- while((entry = jarInputStream.getNextJarEntry()) != null) {
43- if(entry.getName().toLowerCase().endsWith(".class")) {
44- String className = entry.getName().substring(0, entry.getName().length() - 6).replace('/', '.');
45- byteArray.reset();
46- while(jarInputStream.available() > 0) {
47- size = jarInputStream.read(buf);
48- if(size > 0) {
49- byteArray.write(buf, 0, size);
50- }
51- }
52- this.classes.put(className, byteArray.toByteArray());
53- }
54- jarInputStream.closeEntry();
55- }
56-
57- //find main class.
58- Manifest manifest = jarInputStream.getManifest();
59- jarInputStream.close();
60- if(manifest != null) {
61- String mainClassName = manifest.getMainAttributes().getValue("Main-Class");
62- if(mainClassName != null) {
63- Thread.currentThread().setContextClassLoader(this);
64- return Class.forName(mainClassName, true, this);
65- }
66- }
67- return null;
68- }
69-
70- protected Class findClass(String name) throws ClassNotFoundException {
71- byte[] buffer = (byte[])this.classes.get(name);
72- if(buffer != null) {
73- if(name.indexOf('.') >= 0) {
74- String packageName = name.substring(0, name.lastIndexOf('.'));
75- if(getPackage(packageName) == null) {
76- definePackage(packageName, null, null, null, null, null, null, null);
77- }
78- }
79- return defineClass(name, buffer, 0, buffer.length);
80- }
81- throw new ClassNotFoundException(name);
82- }
83-
84- public URL getResource(String name) {
85- try {
86- if(URLConnection.resources.containsKey(name)) {
87- return new URL("exewrap", "127.0.0.1", -1, name, new URLStreamHandler());
88- }
89- } catch (MalformedURLException e) {}
90- return super.getResource(name);
91- }
92-}
--- exewrap/trunk/exewrap/src/java/exewrap/util/UncaughtExceptionHandler.java (revision 21)
+++ exewrap/trunk/exewrap/src/java/exewrap/util/UncaughtExceptionHandler.java (revision 22)
@@ -12,6 +12,7 @@
1212 }
1313
1414 public void uncaughtException(Thread t, Throwable e) {
15+ e.printStackTrace();
1516 ExewrapClassLoader.UncaughtException(t.getName(), e.toString(), getStackTrace(e));
1617 }
1718
--- exewrap/trunk/exewrap/src/java/exewrap/core/ExewrapClassLoader.java (revision 21)
+++ exewrap/trunk/exewrap/src/java/exewrap/core/ExewrapClassLoader.java (revision 22)
@@ -68,6 +68,9 @@
6868 if(utilities.contains("EventLogHandler;")) {
6969 Class.forName("exewrap.util.EventLogHandler", true, this);
7070 }
71+ if(utilities.contains("ConsoleOutputStream;")) {
72+ Class.forName("exewrap.util.ConsoleOutputStream", true, this);
73+ }
7174 }
7275
7376 public Class<?> getMainClass(String mainClassName) throws ClassNotFoundException {
@@ -166,6 +169,7 @@
166169 return buf.toByteArray();
167170 }
168171
172+ public static native void WriteConsole(byte[] b, int off, int len);
169173 public static native void WriteEventLog(int type, String message);
170174 public static native void UncaughtException(String thread, String message, String trace);
171175 }
--- exewrap/trunk/exewrap/src/Make.bat (revision 21)
+++ exewrap/trunk/exewrap/src/Make.bat (revision 22)
@@ -4,6 +4,7 @@
44 SET VCDIR=C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC
55
66 IF "%1" == "clean" (
7+call "%VCDIR%\vcvarsall.bat"
78 nmake /nologo clean
89 IF ERRORLEVEL 1 GOTO ERR
910 goto SUCCESS
@@ -19,10 +20,12 @@
1920
2021 call "%VCDIR%\vcvarsall.bat" x86
2122 nmake /nologo EXEWRAP_X86
23+nmake /nologo JREMIN_X86
2224 IF ERRORLEVEL 1 GOTO ERR
2325
2426 call "%VCDIR%\vcvarsall.bat" x64
2527 nmake /nologo EXEWRAP_X64
28+nmake /nologo JREMIN_X64
2629 IF ERRORLEVEL 1 GOTO ERR
2730
2831 :SUCCESS
--- exewrap/trunk/exewrap/src/include/message.h (revision 21)
+++ exewrap/trunk/exewrap/src/include/message.h (revision 22)
@@ -7,7 +7,7 @@
77 #define MSG_LANG_ID_EN 0
88 #define MSG_LANG_ID_JA 1
99
10-#define MSG_ID_COUNT 31
10+#define MSG_ID_COUNT 32
1111 #define MSG_ID_ERR_CREATE_JVM_UNKNOWN 1
1212 #define MSG_ID_ERR_CREATE_JVM_EDETACHED 2
1313 #define MSG_ID_ERR_CREATE_JVM_EVERSION 3
@@ -25,20 +25,21 @@
2525 #define MSG_ID_ERR_FIND_CLASSLOADER 15
2626 #define MSG_ID_ERR_REGISTER_NATIVE 16
2727 #define MSG_ID_ERR_LOAD_MAIN_CLASS 17
28-#define MSG_ID_ERR_FIND_MAIN_METHOD 18
29-#define MSG_ID_ERR_FIND_METHOD_SERVICE_START 19
30-#define MSG_ID_ERR_FIND_METHOD_SERVICE_STOP 20
31-#define MSG_ID_ERR_SERVICE_ABORT 21
32-#define MSG_ID_ERR_SERVICE_NOT_STOPPED 22
33-#define MSG_ID_SUCCESS_SERVICE_INSTALL 23
34-#define MSG_ID_SUCCESS_SERVICE_REMOVE 24
35-#define MSG_ID_SERVICE_STARTING 25
36-#define MSG_ID_SERVICE_STOPING 26
37-#define MSG_ID_SUCCESS_SERVICE_START 27
38-#define MSG_ID_SUCCESS_SERVICE_STOP 28
39-#define MSG_ID_CTRL_SERVICE_STOP 29
40-#define MSG_ID_CTRL_SERVICE_TERMINATE 30
41-#define MSG_ID_CTRL_BREAK 31
28+#define MSG_ID_ERR_FIND_MAIN_CLASS 18
29+#define MSG_ID_ERR_FIND_MAIN_METHOD 19
30+#define MSG_ID_ERR_FIND_METHOD_SERVICE_START 20
31+#define MSG_ID_ERR_FIND_METHOD_SERVICE_STOP 21
32+#define MSG_ID_ERR_SERVICE_ABORT 22
33+#define MSG_ID_ERR_SERVICE_NOT_STOPPED 23
34+#define MSG_ID_SUCCESS_SERVICE_INSTALL 24
35+#define MSG_ID_SUCCESS_SERVICE_REMOVE 25
36+#define MSG_ID_SERVICE_STARTING 26
37+#define MSG_ID_SERVICE_STOPING 27
38+#define MSG_ID_SUCCESS_SERVICE_START 28
39+#define MSG_ID_SUCCESS_SERVICE_STOP 29
40+#define MSG_ID_CTRL_SERVICE_STOP 30
41+#define MSG_ID_CTRL_SERVICE_TERMINATE 31
42+#define MSG_ID_CTRL_BREAK 32
4243
4344 extern const char* get_message(int msg_id);
4445
--- exewrap/trunk/exewrap/src/include/loader.h (revision 21)
+++ exewrap/trunk/exewrap/src/include/loader.h (revision 22)
@@ -8,6 +8,7 @@
88 #define UTIL_FILE_LOG_STREAM "FileLogStream;"
99 #define UTIL_EVENT_LOG_STREAM "EventLogStream;"
1010 #define UTIL_EVENT_LOG_HANDLER "EventLogHandler;"
11+#define UTIL_CONSOLE_OUTPUT_STREAM "ConsoleOutputStream;"
1112
1213 typedef struct _RESOURCE {
1314 BYTE* buf;
--- exewrap/trunk/exewrap/src/include/jvm.h (revision 21)
+++ exewrap/trunk/exewrap/src/include/jvm.h (revision 22)
@@ -4,8 +4,8 @@
44 #define JVM_ELOADLIB (+1)
55
66 extern int GetProcessArchitecture();
7-extern void InitializePath(LPTSTR relative_classpath, LPTSTR relative_extdirs, BOOL useServerVM);
8-extern JNIEnv* CreateJavaVM(LPTSTR vm_args_opt, BOOL useServerVM, int* err);
7+extern void InitializePath(LPTSTR relative_classpath, LPTSTR relative_extdirs, BOOL useServerVM, BOOL useSideBySideJRE);
8+extern JNIEnv* CreateJavaVM(LPTSTR vm_args_opt, BOOL useServerVM, BOOL useSideBySideJRE, int* err);
99 extern void DestroyJavaVM();
1010 extern JNIEnv* AttachJavaVM();
1111 extern void DetachJavaVM();
--- exewrap/trunk/exewrap/src/image_service.c (revision 21)
+++ exewrap/trunk/exewrap/src/image_service.c (revision 22)
@@ -20,7 +20,7 @@
2020 #define SERVICE_START_BY_SCM 32
2121 #define SHOW_HELP_MESSAGE 64
2222
23-
23+void OutputConsole(BYTE* buf, DWORD len);
2424 void OutputMessage(const char* text);
2525 UINT UncaughtException(const char* thread, const char* message, const char* trace);
2626
@@ -49,6 +49,7 @@
4949 static char** ARG_VALUE;
5050 static jclass MainClass;
5151 static jmethodID MainClass_stop;
52+static HANDLE hConOut = NULL;
5253
5354
5455 static int service_main(int argc, char* argv[])
@@ -59,6 +60,7 @@
5960 char* relative_classpath;
6061 char* relative_extdirs;
6162 BOOL use_server_vm;
63+ BOOL use_side_by_side_jre;
6264 char* ext_flags;
6365 char* vm_args_opt;
6466 char utilities[128];
@@ -68,6 +70,12 @@
6870 jobjectArray MainClass_start_args;
6971 int i;
7072
73+ utilities[0] = '\0';
74+ #ifdef TRACE
75+ StartTrace(TRUE);
76+ strcat(utilities, UTIL_CONSOLE_OUTPUT_STREAM);
77+ #endif
78+
7179 service_name = get_service_name(NULL);
7280 is_service = (flags & SERVICE_START_BY_SCM);
7381
@@ -77,10 +85,11 @@
7785 relative_extdirs = (char*)GetResource("EXTDIRS", NULL);
7886 ext_flags = (char*)GetResource("EXTFLAGS", NULL);
7987 use_server_vm = (ext_flags != NULL && strstr(ext_flags, "SERVER") != NULL);
80- InitializePath(relative_classpath, relative_extdirs, use_server_vm);
88+ use_side_by_side_jre = (ext_flags == NULL) || (strstr(ext_flags, "NOSIDEBYSIDE") == NULL);
89+ InitializePath(relative_classpath, relative_extdirs, use_server_vm, use_side_by_side_jre);
8190
8291 vm_args_opt = (char*)GetResource("VMARGS", NULL);
83- CreateJavaVM(vm_args_opt, use_server_vm, &err);
92+ CreateJavaVM(vm_args_opt, use_server_vm, use_side_by_side_jre, &err);
8493 if (err != JNI_OK)
8594 {
8695 OutputMessage(GetWinErrorMessage(err, &result.msg_id, result.msg));
@@ -226,10 +235,19 @@
226235 }
227236 }
228237
238+ #ifdef TRACE
239+ StopTrace();
240+ #endif
241+
229242 return result.msg_id;
230243 }
231244
232245
246+void OutputConsole(BYTE* buf, DWORD len)
247+{
248+}
249+
250+
233251 void OutputMessage(const char* text)
234252 {
235253 DWORD written;
@@ -246,17 +264,16 @@
246264
247265 UINT UncaughtException(const char* thread, const char* message, const char* trace)
248266 {
249- if (thread != NULL)
267+ BOOL is_service = (flags & SERVICE_START_BY_SCM);
268+
269+ if (is_service)
250270 {
251- char* buf = malloc(32 + strlen(thread));
252- sprintf(buf, "Exception in thread \"%s\"", thread);
253- OutputMessage(buf);
271+ char* buf = (char*)malloc(strlen(thread) + strlen(message) + strlen(trace) + 64);
272+
273+ sprintf(buf, "Exception in thread \"%s\" %s", thread, trace);
274+ WriteEventLog(EVENTLOG_ERROR_TYPE, buf);
254275 free(buf);
255276 }
256- if (trace != NULL)
257- {
258- OutputMessage(trace);
259- }
260277 return MSG_ID_ERR_UNCAUGHT_EXCEPTION;
261278 }
262279
--- exewrap/trunk/exewrap/src/image_console.c (revision 21)
+++ exewrap/trunk/exewrap/src/image_console.c (revision 22)
@@ -10,10 +10,15 @@
1010 #include "include/loader.h"
1111 #include "include/notify.h"
1212 #include "include/message.h"
13+#include "include/trace.h"
1314
15+void OutputConsole(BYTE* buf, DWORD len);
1416 void OutputMessage(const char* text);
1517 UINT UncaughtException(const char* thread, const char* message, const char* trace);
1618
19+static HANDLE hConOut = NULL;
20+
21+
1722 int main(int argc, char* argv[])
1823 {
1924 int err;
@@ -20,6 +25,7 @@
2025 char* relative_classpath;
2126 char* relative_extdirs;
2227 BOOL use_server_vm;
28+ BOOL use_side_by_side_jre;
2329 HANDLE synchronize_mutex_handle = NULL;
2430 char* ext_flags;
2531 char* vm_args_opt;
@@ -27,6 +33,12 @@
2733 RESOURCE res;
2834 LOAD_RESULT result;
2935
36+ utilities[0] = '\0';
37+ #ifdef TRACE
38+ StartTrace(TRUE);
39+ strcat(utilities, UTIL_CONSOLE_OUTPUT_STREAM);
40+ #endif
41+
3042 result.msg = malloc(2048);
3143
3244 relative_classpath = (char*)GetResource("CLASS_PATH", NULL);
@@ -33,7 +45,8 @@
3345 relative_extdirs = (char*)GetResource("EXTDIRS", NULL);
3446 ext_flags = (char*)GetResource("EXTFLAGS", NULL);
3547 use_server_vm = (ext_flags != NULL && strstr(ext_flags, "SERVER") != NULL);
36- InitializePath(relative_classpath, relative_extdirs, use_server_vm);
48+ use_side_by_side_jre = (ext_flags == NULL) || (strstr(ext_flags, "NOSIDEBYSIDE") == NULL);
49+ InitializePath(relative_classpath, relative_extdirs, use_server_vm, use_side_by_side_jre);
3750
3851 if (ext_flags != NULL && strstr(ext_flags, "SHARE") != NULL)
3952 {
@@ -54,7 +67,7 @@
5467 }
5568
5669 vm_args_opt = (char*)GetResource("VMARGS", NULL);
57- CreateJavaVM(vm_args_opt, use_server_vm, &err);
70+ CreateJavaVM(vm_args_opt, use_server_vm, use_side_by_side_jre, &err);
5871 if (err != JNI_OK)
5972 {
6073 OutputMessage(GetJniErrorMessage(err, &result.msg_id, result.msg));
@@ -75,7 +88,6 @@
7588 }
7689 }
7790
78- utilities[0] = '\0';
7991 if (ext_flags == NULL || strstr(ext_flags, "IGNORE_UNCAUGHT_EXCEPTION") == NULL)
8092 {
8193 strcat(utilities, UTIL_UNCAUGHT_EXCEPTION_HANDLER);
@@ -117,9 +129,32 @@
117129
118130 NotifyClose();
119131
132+ #ifdef TRACE
133+ StopTrace();
134+ #endif
135+
120136 return result.msg_id;
121137 }
122138
139+void OutputConsole(BYTE* buf, DWORD len)
140+{
141+ DWORD written;
142+
143+ if (hConOut == INVALID_HANDLE_VALUE)
144+ {
145+ return;
146+ }
147+ if (hConOut == NULL)
148+ {
149+ hConOut = CreateFile("CONOUT$", GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
150+ if (hConOut == INVALID_HANDLE_VALUE)
151+ {
152+ return;
153+ }
154+ }
155+ WriteConsole(hConOut, buf, len, &written, NULL);
156+}
157+
123158 void OutputMessage(const char* text)
124159 {
125160 DWORD written;
--- exewrap/trunk/exewrap/src/loader.c (revision 21)
+++ exewrap/trunk/exewrap/src/loader.c (revision 22)
@@ -19,6 +19,7 @@
1919 BYTE* GetResource(LPCTSTR name, RESOURCE* resource);
2020 char* GetWinErrorMessage(DWORD err, int* exit_code, char* buf);
2121 char* GetJniErrorMessage(int err, int* exit_code, char* buf);
22+void JNICALL JNI_WriteConsole(JNIEnv *env, jobject clazz, jbyteArray b, jint off, jint len);
2223 void JNICALL JNI_WriteEventLog(JNIEnv *env, jobject clazz, jint logType, jstring message);
2324 void JNICALL JNI_UncaughtException(JNIEnv *env, jobject clazz, jstring thread, jstring message, jstring trace);
2425
@@ -26,13 +27,14 @@
2627 static void print_stack_trace(const char* text);
2728 static char** split_args(char* buffer, int* p_argc);
2829
30+extern void OutputConsole(BYTE* buf, DWORD len);
2931 extern void OutputMessage(const char* text);
3032 extern UINT UncaughtException(const char* thread, const char* message, const char* trace);
3133
32-jclass ExewrapClassLoader = NULL;
33-jobject exewrapClassLoader = NULL;
34-jclass MainClass = NULL;
35-jmethodID MainClass_main = NULL;
34+static jclass ExewrapClassLoader = NULL;
35+static jobject exewrapClassLoader = NULL;
36+static jclass MainClass = NULL;
37+static jmethodID MainClass_main = NULL;
3638
3739 BOOL LoadMainClass(int argc, char* argv[], char* utilities, LOAD_RESULT* result)
3840 {
@@ -328,6 +330,12 @@
328330 goto EXIT;
329331 }
330332 // register native methods
333+ if (register_native(env, ExewrapClassLoader, "WriteConsole", "([BII)V", JNI_WriteConsole) != 0)
334+ {
335+ result->msg_id = MSG_ID_ERR_REGISTER_NATIVE;
336+ sprintf(result->msg, _(MSG_ID_ERR_REGISTER_NATIVE), "WriteConsole");
337+ goto EXIT;
338+ }
331339 if (register_native(env, ExewrapClassLoader, "WriteEventLog", "(ILjava/lang/String;)V", JNI_WriteEventLog) != 0)
332340 {
333341 result->msg_id = MSG_ID_ERR_REGISTER_NATIVE;
@@ -417,6 +425,11 @@
417425 return TRUE;
418426
419427 EXIT:
428+ if ((*env)->ExceptionCheck(env) == JNI_TRUE)
429+ {
430+ (*env)->ExceptionDescribe(env);
431+ (*env)->ExceptionClear(env);
432+ }
420433
421434 return FALSE;
422435 }
@@ -680,6 +693,17 @@
680693 }
681694
682695
696+void JNICALL JNI_WriteConsole(JNIEnv *env, jobject clazz, jbyteArray b, jint off, jint len)
697+{
698+ jboolean isCopy;
699+ BYTE* buf;
700+
701+ buf = (*env)->GetByteArrayElements(env, b, &isCopy);
702+ OutputConsole(buf, len);
703+ (*env)->ReleaseByteArrayElements(env, b, buf, 0);
704+}
705+
706+
683707 void JNICALL JNI_WriteEventLog(JNIEnv *env, jobject clazz, jint logType, jstring message)
684708 {
685709 WORD nType;
--- exewrap/trunk/exewrap/src/exewrap.c (revision 21)
+++ exewrap/trunk/exewrap/src/exewrap.c (revision 22)
@@ -16,6 +16,7 @@
1616 #define DEFAULT_VERSION "0.0"
1717 #define DEFAULT_PRODUCT_VERSION "0.0"
1818
19+void OutputConsole(BYTE* buf, DWORD len);
1920 void OutputMessage(const char* text);
2021 UINT UncaughtException(const char* thread, const char* message, const char* trace);
2122
@@ -49,6 +50,8 @@
4950 BOOL enable_java = FALSE;
5051 BYTE* jar_buf;
5152 DWORD jar_len;
53+ char* ext_flags = NULL;
54+ char* vmargs = NULL;
5255 char* version_number;
5356 char* file_description;
5457 char* copyright;
@@ -69,7 +72,16 @@
6972 {
7073 int bits = GetProcessArchitecture();
7174
72- printf("exewrap 1.0.4 for %s (%d-bit)\r\n"
75+ if (strrchr(argv[0], '\\') > 0)
76+ {
77+ exe_file = strrchr(argv[0], '\\') + 1;
78+ }
79+ else
80+ {
81+ exe_file = argv[0];
82+ }
83+
84+ printf("exewrap 1.1.0 for %s (%d-bit)\r\n"
7385 "Native executable java application wrapper.\r\n"
7486 "Copyright (C) 2005-2015 HIRUKAWA Ryo. All rights reserved.\r\n"
7587 "\r\n"
@@ -80,6 +92,8 @@
8092 " -A <architecture> \t select exe-file architecture. (default %s)\r\n"
8193 " -t <version> \t set target java runtime version. (default 1.5)\r\n"
8294 " -2 \t disable Pack200.\r\n"
95+ " -T \t enable trace for to shrink JRE.\r\n"
96+ " -M <main-class> \t set main-class.\r\n"
8397 " -L <ext-dirs> \t set ext-dirs.\r\n"
8498 " -e <ext-flags> \t set extended flags.\r\n"
8599 " -a <vm-args> \t set Java VM arguments.\r\n"
@@ -92,7 +106,7 @@
92106 " -V <product-version>\t set product version.\r\n"
93107 " -j <jar-file> \t input jar-file.\r\n"
94108 " -o <exe-file> \t output exe-file.\r\n"
95- , (bits == 64 ? "x64" : "x86"), bits, argv[0], (bits == 64 ? "x64" : "x86"));
109+ , (bits == 64 ? "x64" : "x86"), bits, exe_file, (bits == 64 ? "x64" : "x86"));
96110
97111 return 0;
98112 }
@@ -131,12 +145,24 @@
131145 strcat(exe_file, ".exe");
132146 }
133147
134- if(GetFullPathName(exe_file, _MAX_PATH, buf, &ptr) == 0)
148+ if (GetFullPathName(exe_file, _MAX_PATH, buf, &ptr) == 0)
135149 {
136150 printf("Invalid path: %s\n", exe_file);
151+ return 2;
137152 }
138153 strcpy(exe_file, buf);
139154
155+ if (strrchr(strrchr(exe_file, '\\') + 1, '.') == NULL)
156+ {
157+ *strrchr(strrchr(exe_file, '\\' + 1), '.') = '\0';
158+ strcat(exe_file, ".exe");
159+ }
160+ if (opt['T'])
161+ {
162+ *strrchr(exe_file, '.') = '\0';
163+ strcat(exe_file, ".TRACE.exe");
164+ }
165+
140166 if(opt['A'])
141167 {
142168 if(strstr(opt['A'], "86") != NULL)
@@ -156,15 +182,15 @@
156182
157183 if(opt['g'])
158184 {
159- sprintf(image_name, "IMAGE_GUI_%d", architecture_bits);
185+ sprintf(image_name, "IMAGE%s_GUI_%d", (opt['T'] ? "_TRACE" : ""), architecture_bits);
160186 }
161187 else if(opt['s'])
162188 {
163- sprintf(image_name, "IMAGE_SERVICE_%d", architecture_bits);
189+ sprintf(image_name, "IMAGE%s_SERVICE_%d", (opt['T'] ? "_TRACE" : ""), architecture_bits);
164190 }
165191 else
166192 {
167- sprintf(image_name, "IMAGE_CONSOLE_%d", architecture_bits);
193+ sprintf(image_name, "IMAGE%s_CONSOLE_%d", (opt['T'] ? "_TRACE" : ""), architecture_bits);
168194 }
169195
170196 GetResource(image_name, &res);
@@ -202,7 +228,7 @@
202228 set_resource(exe_file, "EXTDIRS", RT_RCDATA, opt['L'], (DWORD)strlen(opt['L']) + 1);
203229 }
204230
205- enable_java = CreateJavaVM(NULL, FALSE, NULL) != NULL;
231+ enable_java = CreateJavaVM(NULL, FALSE, FALSE, NULL) != NULL;
206232 if (enable_java)
207233 {
208234 LOAD_RESULT result;
@@ -221,8 +247,11 @@
221247 BYTE* splash_screen_image;
222248 BYTE* bytes;
223249
250+ result.msg = (char*)malloc(2048);
251+
224252 if (LoadMainClass(argc, argv, NULL, &result) == FALSE)
225253 {
254+ printf("ERROR: LoadMainClass: tool.jar exewrap.tool.JarProcessor\n");
226255 goto EXIT;
227256 }
228257 JarProcessor = result.MainClass;
@@ -289,10 +318,19 @@
289318 goto EXIT;
290319 }
291320
292- main_class = GetShiftJIS(env, (*env)->CallObjectMethod(env, jarProcessor, jarProcessor_getMainClass));
321+ if (opt['M'])
322+ {
323+ main_class = opt['M'];
324+ }
325+ else
326+ {
327+ main_class = GetShiftJIS(env, (*env)->CallObjectMethod(env, jarProcessor, jarProcessor_getMainClass));
328+ }
293329 if (main_class == NULL)
294330 {
295-
331+ result.msg_id = MSG_ID_ERR_LOAD_MAIN_CLASS;
332+ printf(_(MSG_ID_ERR_LOAD_MAIN_CLASS));
333+ goto EXIT;
296334 }
297335 set_resource(exe_file, "MAIN_CLASS", RT_RCDATA, main_class, (DWORD)strlen(main_class) + 1);
298336
@@ -338,51 +376,52 @@
338376 }
339377 printf("Pack200: disable / JavaVM (%d-bit) not found.\r\n", GetProcessArchitecture());
340378 }
341- /*
342- if(target_version >= 0x01050000 && enable_java && !disable_pack200)
379+
380+ ext_flags = (char*)malloc(1024);
381+ ext_flags[0] = '\0';
382+ if (opt['T'])
343383 {
344- jar_buf = get_jar_buf(jar_file, &jar_len);
345- if (jar_buf == NULL)
384+ strcat(ext_flags, "NOSIDEBYSIDE;");
385+ }
386+ if (opt['e'] && *opt['e'] != '-' && *opt['e'] != '\0')
387+ {
388+ strcat(ext_flags, opt['e']);
389+ }
390+ set_resource(exe_file, "EXTFLAGS", RT_RCDATA, ext_flags, (DWORD)strlen(ext_flags) + 1);
391+ free(ext_flags);
392+
393+ if (opt['T'])
394+ {
395+ if (vmargs == NULL)
346396 {
347- goto EXIT;
397+ vmargs = (char*)malloc(2048);
398+ vmargs[0] = '\0';
348399 }
349- UsePack200(exe_file, jar_file);
350- classBuffer = GetResource("PACK_LOADER", RT_RCDATA, &classSize);
351- SetResource(exefile, "PACK_LOADER", RT_RCDATA, classBuffer, classSize);
352- printf("Pack200: enable\r\n");
400+ else
401+ {
402+ strcat(vmargs, " ");
403+ }
404+ strcat(vmargs, "-XX:+TraceClassLoading");
353405 }
354- if(classBuffer == NULL)
406+ if(opt['a'] && *opt['a'] != '\0')
355407 {
356- jarBuffer = GetFileData(jarfile, &jarSize);
357- SetResource(exefile, "JAR", RT_RCDATA, jarBuffer, jarSize);
358- HeapFree(GetProcessHeap(), 0, jarBuffer);
359- classBuffer = GetResource("CLASSIC_LOADER", RT_RCDATA, &classSize);
360- SetResource(exefile, "CLASSIC_LOADER", RT_RCDATA, classBuffer, classSize);
361- if(!enableJava)
408+ if (vmargs == NULL)
362409 {
363- printf("Pack200: disable / JavaVM (%d-bit) not found.\r\n", GetProcessArchitecture());
410+ vmargs = (char*)malloc(2048);
411+ vmargs[0] = '\0';
364412 }
365- else if(targetVersion < 0x01050000)
366- {
367- printf("Pack200: disable / Target version is lower than 1.5\r\n");
368- }
369413 else
370414 {
371- printf("Pack200: disable\r\n");
415+ strcat(vmargs, " ");
372416 }
417+ strcat(vmargs, opt['a']);
373418 }
374- */
375-
376- if(opt['e'] && *opt['e'] != '-' && *opt['e'] != '\0')
419+ if (vmargs != NULL)
377420 {
378- set_resource(exe_file, "EXTFLAGS", RT_RCDATA, opt['e'], (DWORD)strlen(opt['e']) + 1);
421+ set_resource(exe_file, "VMARGS", RT_RCDATA, vmargs, (DWORD)strlen(vmargs) + 1);
422+ free(vmargs);
379423 }
380-
381- if(opt['a'] && *opt['a'] != '\0')
382- {
383- set_resource(exe_file, "VMARGS", RT_RCDATA, opt['a'], (DWORD)strlen(opt['a']) + 1);
384- }
385-
424+
386425 if(opt['i'] && *opt['i'] != '-' && *opt['i'] != '\0')
387426 {
388427 set_application_icon(exe_file, opt['i']);
@@ -583,7 +622,7 @@
583622 }
584623 while (*++argv)
585624 {
586- if (*argv[0] == '-')
625+ if (*argv[0] == '-' && *(argv[0] + 1) != '\0' && *(argv[0] + 2) == '\0')
587626 {
588627 if (argv[1] == NULL)
589628 {
@@ -656,6 +695,7 @@
656695
657696 static BOOL create_exe_file(const char* filename, BYTE* image_buf, DWORD image_len, BOOL is_reverse)
658697 {
698+ BOOL ret = FALSE;
659699 HANDLE hFile;
660700 BYTE* buf = NULL;
661701 DWORD write_size;
@@ -667,7 +707,7 @@
667707 if (hFile == INVALID_HANDLE_VALUE)
668708 {
669709 printf("Failed to create file: %s\n", filename);
670- return FALSE;
710+ goto EXIT;
671711 }
672712 }
673713
@@ -691,7 +731,7 @@
691731 if (WriteFile(hFile, image_buf, image_len, &write_size, NULL) == 0)
692732 {
693733 printf("Failed to write: %s\n", filename);
694- return FALSE;
734+ goto EXIT;
695735 }
696736 image_buf += write_size;
697737 image_len -= write_size;
@@ -698,6 +738,8 @@
698738 }
699739 CloseHandle(hFile);
700740
741+ ret = TRUE;
742+
701743 EXIT:
702744 if (is_reverse)
703745 {
@@ -707,7 +749,7 @@
707749 }
708750 }
709751
710- return TRUE;
752+ return ret;
711753 }
712754
713755
@@ -1141,10 +1183,17 @@
11411183 return new_version;
11421184 }
11431185
1186+
1187+void OutputConsole(BYTE* buf, DWORD len)
1188+{
1189+}
1190+
1191+
11441192 void OutputMessage(const char* text)
11451193 {
11461194 }
11471195
1196+
11481197 UINT UncaughtException(const char* thread, const char* message, const char* trace)
11491198 {
11501199 return 0;
--- exewrap/trunk/exewrap/src/minhook/LICENSE.txt (revision 0)
+++ exewrap/trunk/exewrap/src/minhook/LICENSE.txt (revision 22)
@@ -0,0 +1,81 @@
1+MinHook - The Minimalistic API Hooking Library for x64/x86
2+Copyright (C) 2009-2015 Tsuda Kageyu.
3+All rights reserved.
4+
5+Redistribution and use in source and binary forms, with or without
6+modification, are permitted provided that the following conditions
7+are met:
8+
9+ 1. Redistributions of source code must retain the above copyright
10+ notice, this list of conditions and the following disclaimer.
11+ 2. Redistributions in binary form must reproduce the above copyright
12+ notice, this list of conditions and the following disclaimer in the
13+ documentation and/or other materials provided with the distribution.
14+
15+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
17+TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
18+PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
19+OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
22+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
23+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
27+================================================================================
28+Portions of this software are Copyright (c) 2008-2009, Vyacheslav Patkov.
29+================================================================================
30+Hacker Disassembler Engine 32 C
31+Copyright (c) 2008-2009, Vyacheslav Patkov.
32+All rights reserved.
33+
34+Redistribution and use in source and binary forms, with or without
35+modification, are permitted provided that the following conditions
36+are met:
37+
38+ 1. Redistributions of source code must retain the above copyright
39+ notice, this list of conditions and the following disclaimer.
40+ 2. Redistributions in binary form must reproduce the above copyright
41+ notice, this list of conditions and the following disclaimer in the
42+ documentation and/or other materials provided with the distribution.
43+
44+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
45+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
46+TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
47+PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
48+CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
49+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
50+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
51+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
52+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
53+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
54+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
55+
56+-------------------------------------------------------------------------------
57+Hacker Disassembler Engine 64 C
58+Copyright (c) 2008-2009, Vyacheslav Patkov.
59+All rights reserved.
60+
61+Redistribution and use in source and binary forms, with or without
62+modification, are permitted provided that the following conditions
63+are met:
64+
65+ 1. Redistributions of source code must retain the above copyright
66+ notice, this list of conditions and the following disclaimer.
67+ 2. Redistributions in binary form must reproduce the above copyright
68+ notice, this list of conditions and the following disclaimer in the
69+ documentation and/or other materials provided with the distribution.
70+
71+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
72+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
73+TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
74+PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
75+CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
76+EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
77+PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
78+PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
79+LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
80+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
81+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
--- exewrap/trunk/exewrap/src/minhook/AUTHORS.txt (revision 0)
+++ exewrap/trunk/exewrap/src/minhook/AUTHORS.txt (revision 22)
@@ -0,0 +1,8 @@
1+Tsuda Kageyu <tsuda.kageyu@gmail.com>
2+ Creator, maintainer
3+
4+Michael Maltsev <leahcimmar@gmail.com>
5+ Added "Queue" functions. A lot of bug fixes.
6+
7+Andrey Unis <uniskz@gmail.com>
8+ Rewrote the hook engine in plain C.
--- exewrap/trunk/exewrap/src/minhook/include/MinHook.h (revision 0)
+++ exewrap/trunk/exewrap/src/minhook/include/MinHook.h (revision 22)
@@ -0,0 +1,169 @@
1+/*
2+ * MinHook - The Minimalistic API Hooking Library for x64/x86
3+ * Copyright (C) 2009-2015 Tsuda Kageyu.
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions
8+ * are met:
9+ *
10+ * 1. Redistributions of source code must retain the above copyright
11+ * notice, this list of conditions and the following disclaimer.
12+ * 2. Redistributions in binary form must reproduce the above copyright
13+ * notice, this list of conditions and the following disclaimer in the
14+ * documentation and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
19+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
20+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27+ */
28+
29+#pragma once
30+
31+#if !(defined _M_IX86) && !(defined _M_X64)
32+ #error MinHook supports only x86 and x64 systems.
33+#endif
34+
35+#include <windows.h>
36+
37+// MinHook Error Codes.
38+typedef enum MH_STATUS
39+{
40+ // Unknown error. Should not be returned.
41+ MH_UNKNOWN = -1,
42+
43+ // Successful.
44+ MH_OK = 0,
45+
46+ // MinHook is already initialized.
47+ MH_ERROR_ALREADY_INITIALIZED,
48+
49+ // MinHook is not initialized yet, or already uninitialized.
50+ MH_ERROR_NOT_INITIALIZED,
51+
52+ // The hook for the specified target function is already created.
53+ MH_ERROR_ALREADY_CREATED,
54+
55+ // The hook for the specified target function is not created yet.
56+ MH_ERROR_NOT_CREATED,
57+
58+ // The hook for the specified target function is already enabled.
59+ MH_ERROR_ENABLED,
60+
61+ // The hook for the specified target function is not enabled yet, or already
62+ // disabled.
63+ MH_ERROR_DISABLED,
64+
65+ // The specified pointer is invalid. It points the address of non-allocated
66+ // and/or non-executable region.
67+ MH_ERROR_NOT_EXECUTABLE,
68+
69+ // The specified target function cannot be hooked.
70+ MH_ERROR_UNSUPPORTED_FUNCTION,
71+
72+ // Failed to allocate memory.
73+ MH_ERROR_MEMORY_ALLOC,
74+
75+ // Failed to change the memory protection.
76+ MH_ERROR_MEMORY_PROTECT,
77+
78+ // The specified module is not loaded.
79+ MH_ERROR_MODULE_NOT_FOUND,
80+
81+ // The specified function is not found.
82+ MH_ERROR_FUNCTION_NOT_FOUND
83+}
84+MH_STATUS;
85+
86+// Can be passed as a parameter to MH_EnableHook, MH_DisableHook,
87+// MH_QueueEnableHook or MH_QueueDisableHook.
88+#define MH_ALL_HOOKS NULL
89+
90+#ifdef __cplusplus
91+extern "C" {
92+#endif
93+
94+ // Initialize the MinHook library. You must call this function EXACTLY ONCE
95+ // at the beginning of your program.
96+ MH_STATUS WINAPI MH_Initialize(VOID);
97+
98+ // Uninitialize the MinHook library. You must call this function EXACTLY
99+ // ONCE at the end of your program.
100+ MH_STATUS WINAPI MH_Uninitialize(VOID);
101+
102+ // Creates a Hook for the specified target function, in disabled state.
103+ // Parameters:
104+ // pTarget [in] A pointer to the target function, which will be
105+ // overridden by the detour function.
106+ // pDetour [in] A pointer to the detour function, which will override
107+ // the target function.
108+ // ppOriginal [out] A pointer to the trampoline function, which will be
109+ // used to call the original target function.
110+ // This parameter can be NULL.
111+ MH_STATUS WINAPI MH_CreateHook(LPVOID pTarget, LPVOID pDetour, LPVOID *ppOriginal);
112+
113+ // Creates a Hook for the specified API function, in disabled state.
114+ // Parameters:
115+ // pszModule [in] A pointer to the loaded module name which contains the
116+ // target function.
117+ // pszTarget [in] A pointer to the target function name, which will be
118+ // overridden by the detour function.
119+ // pDetour [in] A pointer to the detour function, which will override
120+ // the target function.
121+ // ppOriginal [out] A pointer to the trampoline function, which will be
122+ // used to call the original target function.
123+ // This parameter can be NULL.
124+ MH_STATUS WINAPI MH_CreateHookApi(
125+ LPCWSTR pszModule, LPCSTR pszProcName, LPVOID pDetour, LPVOID *ppOriginal);
126+
127+ // Removes an already created hook.
128+ // Parameters:
129+ // pTarget [in] A pointer to the target function.
130+ MH_STATUS WINAPI MH_RemoveHook(LPVOID pTarget);
131+
132+ // Enables an already created hook.
133+ // Parameters:
134+ // pTarget [in] A pointer to the target function.
135+ // If this parameter is MH_ALL_HOOKS, all created hooks are
136+ // enabled in one go.
137+ MH_STATUS WINAPI MH_EnableHook(LPVOID pTarget);
138+
139+ // Disables an already created hook.
140+ // Parameters:
141+ // pTarget [in] A pointer to the target function.
142+ // If this parameter is MH_ALL_HOOKS, all created hooks are
143+ // disabled in one go.
144+ MH_STATUS WINAPI MH_DisableHook(LPVOID pTarget);
145+
146+ // Queues to enable an already created hook.
147+ // Parameters:
148+ // pTarget [in] A pointer to the target function.
149+ // If this parameter is MH_ALL_HOOKS, all created hooks are
150+ // queued to be enabled.
151+ MH_STATUS WINAPI MH_QueueEnableHook(LPVOID pTarget);
152+
153+ // Queues to disable an already created hook.
154+ // Parameters:
155+ // pTarget [in] A pointer to the target function.
156+ // If this parameter is MH_ALL_HOOKS, all created hooks are
157+ // queued to be disabled.
158+ MH_STATUS WINAPI MH_QueueDisableHook(LPVOID pTarget);
159+
160+ // Applies all queued changes in one go.
161+ MH_STATUS WINAPI MH_ApplyQueued(VOID);
162+
163+ // Translates the MH_STATUS to its name as a string.
164+ const char * WINAPI MH_StatusToString(MH_STATUS status);
165+
166+#ifdef __cplusplus
167+}
168+#endif
169+
--- exewrap/trunk/exewrap/src/minhook/src/trampoline.c (revision 0)
+++ exewrap/trunk/exewrap/src/minhook/src/trampoline.c (revision 22)
@@ -0,0 +1,316 @@
1+/*
2+ * MinHook - The Minimalistic API Hooking Library for x64/x86
3+ * Copyright (C) 2009-2015 Tsuda Kageyu.
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions
8+ * are met:
9+ *
10+ * 1. Redistributions of source code must retain the above copyright
11+ * notice, this list of conditions and the following disclaimer.
12+ * 2. Redistributions in binary form must reproduce the above copyright
13+ * notice, this list of conditions and the following disclaimer in the
14+ * documentation and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
19+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
20+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27+ */
28+
29+#include <windows.h>
30+
31+#ifndef ARRAYSIZE
32+ #define ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0]))
33+#endif
34+
35+#ifdef _M_X64
36+ #include "./hde/hde64.h"
37+ typedef hde64s HDE;
38+ #define HDE_DISASM(code, hs) hde64_disasm(code, hs)
39+#else
40+ #include "./hde/hde32.h"
41+ typedef hde32s HDE;
42+ #define HDE_DISASM(code, hs) hde32_disasm(code, hs)
43+#endif
44+
45+#include "trampoline.h"
46+#include "buffer.h"
47+
48+// Maximum size of a trampoline function.
49+#ifdef _M_X64
50+ #define TRAMPOLINE_MAX_SIZE (MEMORY_SLOT_SIZE - sizeof(JMP_ABS))
51+#else
52+ #define TRAMPOLINE_MAX_SIZE MEMORY_SLOT_SIZE
53+#endif
54+
55+//-------------------------------------------------------------------------
56+static BOOL IsCodePadding(LPBYTE pInst, UINT size)
57+{
58+ UINT i;
59+
60+ if (pInst[0] != 0x00 && pInst[0] != 0x90 && pInst[0] != 0xCC)
61+ return FALSE;
62+
63+ for (i = 1; i < size; ++i)
64+ {
65+ if (pInst[i] != pInst[0])
66+ return FALSE;
67+ }
68+ return TRUE;
69+}
70+
71+//-------------------------------------------------------------------------
72+BOOL CreateTrampolineFunction(PTRAMPOLINE ct)
73+{
74+#ifdef _M_X64
75+ CALL_ABS call = {
76+ 0xFF, 0x15, 0x00000002, // FF15 00000002: CALL [RIP+8]
77+ 0xEB, 0x08, // EB 08: JMP +10
78+ 0x0000000000000000ULL // Absolute destination address
79+ };
80+ JMP_ABS jmp = {
81+ 0xFF, 0x25, 0x00000000, // FF25 00000000: JMP [RIP+6]
82+ 0x0000000000000000ULL // Absolute destination address
83+ };
84+ JCC_ABS jcc = {
85+ 0x70, 0x0E, // 7* 0E: J** +16
86+ 0xFF, 0x25, 0x00000000, // FF25 00000000: JMP [RIP+6]
87+ 0x0000000000000000ULL // Absolute destination address
88+ };
89+#else
90+ CALL_REL call = {
91+ 0xE8, // E8 xxxxxxxx: CALL +5+xxxxxxxx
92+ 0x00000000 // Relative destination address
93+ };
94+ JMP_REL jmp = {
95+ 0xE9, // E9 xxxxxxxx: JMP +5+xxxxxxxx
96+ 0x00000000 // Relative destination address
97+ };
98+ JCC_REL jcc = {
99+ 0x0F, 0x80, // 0F8* xxxxxxxx: J** +6+xxxxxxxx
100+ 0x00000000 // Relative destination address
101+ };
102+#endif
103+
104+ UINT8 oldPos = 0;
105+ UINT8 newPos = 0;
106+ ULONG_PTR jmpDest = 0; // Destination address of an internal jump.
107+ BOOL finished = FALSE; // Is the function completed?
108+#ifdef _M_X64
109+ UINT8 instBuf[16];
110+#endif
111+
112+ ct->patchAbove = FALSE;
113+ ct->nIP = 0;
114+
115+ do
116+ {
117+ HDE hs;
118+ UINT copySize;
119+ LPVOID pCopySrc;
120+ ULONG_PTR pOldInst = (ULONG_PTR)ct->pTarget + oldPos;
121+ ULONG_PTR pNewInst = (ULONG_PTR)ct->pTrampoline + newPos;
122+
123+ copySize = HDE_DISASM((LPVOID)pOldInst, &hs);
124+ if (hs.flags & F_ERROR)
125+ return FALSE;
126+
127+ pCopySrc = (LPVOID)pOldInst;
128+ if (oldPos >= sizeof(JMP_REL))
129+ {
130+ // The trampoline function is long enough.
131+ // Complete the function with the jump to the target function.
132+#ifdef _M_X64
133+ jmp.address = pOldInst;
134+#else
135+ jmp.operand = (UINT32)(pOldInst - (pNewInst + sizeof(jmp)));
136+#endif
137+ pCopySrc = &jmp;
138+ copySize = sizeof(jmp);
139+
140+ finished = TRUE;
141+ }
142+#ifdef _M_X64
143+ else if ((hs.modrm & 0xC7) == 0x05)
144+ {
145+ // Instructions using RIP relative addressing. (ModR/M = 00???101B)
146+
147+ // Modify the RIP relative address.
148+ PUINT32 pRelAddr;
149+
150+ // Avoid using memcpy to reduce the footprint.
151+#ifndef _MSC_VER
152+ memcpy(instBuf, (LPBYTE)pOldInst, copySize);
153+#else
154+ __movsb(instBuf, (LPBYTE)pOldInst, copySize);
155+#endif
156+ pCopySrc = instBuf;
157+
158+ // Relative address is stored at (instruction length - immediate value length - 4).
159+ pRelAddr = (PUINT32)(instBuf + hs.len - ((hs.flags & 0x3C) >> 2) - 4);
160+ *pRelAddr
161+ = (UINT32)((pOldInst + hs.len + (INT32)hs.disp.disp32) - (pNewInst + hs.len));
162+
163+ // Complete the function if JMP (FF /4).
164+ if (hs.opcode == 0xFF && hs.modrm_reg == 4)
165+ finished = TRUE;
166+ }
167+#endif
168+ else if (hs.opcode == 0xE8)
169+ {
170+ // Direct relative CALL
171+ ULONG_PTR dest = pOldInst + hs.len + (INT32)hs.imm.imm32;
172+#ifdef _M_X64
173+ call.address = dest;
174+#else
175+ call.operand = (UINT32)(dest - (pNewInst + sizeof(call)));
176+#endif
177+ pCopySrc = &call;
178+ copySize = sizeof(call);
179+ }
180+ else if ((hs.opcode & 0xFD) == 0xE9)
181+ {
182+ // Direct relative JMP (EB or E9)
183+ ULONG_PTR dest = pOldInst + hs.len;
184+
185+ if (hs.opcode == 0xEB) // isShort jmp
186+ dest += (INT8)hs.imm.imm8;
187+ else
188+ dest += (INT32)hs.imm.imm32;
189+
190+ // Simply copy an internal jump.
191+ if ((ULONG_PTR)ct->pTarget <= dest
192+ && dest < ((ULONG_PTR)ct->pTarget + sizeof(JMP_REL)))
193+ {
194+ if (jmpDest < dest)
195+ jmpDest = dest;
196+ }
197+ else
198+ {
199+#ifdef _M_X64
200+ jmp.address = dest;
201+#else
202+ jmp.operand = (UINT32)(dest - (pNewInst + sizeof(jmp)));
203+#endif
204+ pCopySrc = &jmp;
205+ copySize = sizeof(jmp);
206+
207+ // Exit the function If it is not in the branch
208+ finished = (pOldInst >= jmpDest);
209+ }
210+ }
211+ else if ((hs.opcode & 0xF0) == 0x70
212+ || (hs.opcode & 0xFC) == 0xE0
213+ || (hs.opcode2 & 0xF0) == 0x80)
214+ {
215+ // Direct relative Jcc
216+ ULONG_PTR dest = pOldInst + hs.len;
217+
218+ if ((hs.opcode & 0xF0) == 0x70 // Jcc
219+ || (hs.opcode & 0xFC) == 0xE0) // LOOPNZ/LOOPZ/LOOP/JECXZ
220+ dest += (INT8)hs.imm.imm8;
221+ else
222+ dest += (INT32)hs.imm.imm32;
223+
224+ // Simply copy an internal jump.
225+ if ((ULONG_PTR)ct->pTarget <= dest
226+ && dest < ((ULONG_PTR)ct->pTarget + sizeof(JMP_REL)))
227+ {
228+ if (jmpDest < dest)
229+ jmpDest = dest;
230+ }
231+ else if ((hs.opcode & 0xFC) == 0xE0)
232+ {
233+ // LOOPNZ/LOOPZ/LOOP/JCXZ/JECXZ to the outside are not supported.
234+ return FALSE;
235+ }
236+ else
237+ {
238+ UINT8 cond = ((hs.opcode != 0x0F ? hs.opcode : hs.opcode2) & 0x0F);
239+#ifdef _M_X64
240+ // Invert the condition in x64 mode to simplify the conditional jump logic.
241+ jcc.opcode = 0x71 ^ cond;
242+ jcc.address = dest;
243+#else
244+ jcc.opcode1 = 0x80 | cond;
245+ jcc.operand = (UINT32)(dest - (pNewInst + sizeof(jcc)));
246+#endif
247+ pCopySrc = &jcc;
248+ copySize = sizeof(jcc);
249+ }
250+ }
251+ else if ((hs.opcode & 0xFE) == 0xC2)
252+ {
253+ // RET (C2 or C3)
254+
255+ // Complete the function if not in a branch.
256+ finished = (pOldInst >= jmpDest);
257+ }
258+
259+ // Can't alter the instruction length in a branch.
260+ if (pOldInst < jmpDest && copySize != hs.len)
261+ return FALSE;
262+
263+ // Trampoline function is too large.
264+ if ((newPos + copySize) > TRAMPOLINE_MAX_SIZE)
265+ return FALSE;
266+
267+ // Trampoline function has too many instructions.
268+ if (ct->nIP >= ARRAYSIZE(ct->oldIPs))
269+ return FALSE;
270+
271+ ct->oldIPs[ct->nIP] = oldPos;
272+ ct->newIPs[ct->nIP] = newPos;
273+ ct->nIP++;
274+
275+ // Avoid using memcpy to reduce the footprint.
276+#ifndef _MSC_VER
277+ memcpy((LPBYTE)ct->pTrampoline + newPos, pCopySrc, copySize);
278+#else
279+ __movsb((LPBYTE)ct->pTrampoline + newPos, pCopySrc, copySize);
280+#endif
281+ newPos += copySize;
282+ oldPos += hs.len;
283+ }
284+ while (!finished);
285+
286+ // Is there enough place for a long jump?
287+ if (oldPos < sizeof(JMP_REL)
288+ && !IsCodePadding((LPBYTE)ct->pTarget + oldPos, sizeof(JMP_REL) - oldPos))
289+ {
290+ // Is there enough place for a short jump?
291+ if (oldPos < sizeof(JMP_REL_SHORT)
292+ && !IsCodePadding((LPBYTE)ct->pTarget + oldPos, sizeof(JMP_REL_SHORT) - oldPos))
293+ {
294+ return FALSE;
295+ }
296+
297+ // Can we place the long jump above the function?
298+ if (!IsExecutableAddress((LPBYTE)ct->pTarget - sizeof(JMP_REL)))
299+ return FALSE;
300+
301+ if (!IsCodePadding((LPBYTE)ct->pTarget - sizeof(JMP_REL), sizeof(JMP_REL)))
302+ return FALSE;
303+
304+ ct->patchAbove = TRUE;
305+ }
306+
307+#ifdef _M_X64
308+ // Create a relay function.
309+ jmp.address = (ULONG_PTR)ct->pDetour;
310+
311+ ct->pRelay = (LPBYTE)ct->pTrampoline + newPos;
312+ memcpy(ct->pRelay, &jmp, sizeof(jmp));
313+#endif
314+
315+ return TRUE;
316+}
--- exewrap/trunk/exewrap/src/minhook/src/buffer.h (revision 0)
+++ exewrap/trunk/exewrap/src/minhook/src/buffer.h (revision 22)
@@ -0,0 +1,42 @@
1+/*
2+ * MinHook - The Minimalistic API Hooking Library for x64/x86
3+ * Copyright (C) 2009-2015 Tsuda Kageyu.
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions
8+ * are met:
9+ *
10+ * 1. Redistributions of source code must retain the above copyright
11+ * notice, this list of conditions and the following disclaimer.
12+ * 2. Redistributions in binary form must reproduce the above copyright
13+ * notice, this list of conditions and the following disclaimer in the
14+ * documentation and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
19+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
20+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27+ */
28+
29+#pragma once
30+
31+// Size of each memory slot.
32+#ifdef _M_X64
33+ #define MEMORY_SLOT_SIZE 64
34+#else
35+ #define MEMORY_SLOT_SIZE 32
36+#endif
37+
38+VOID InitializeBuffer(VOID);
39+VOID UninitializeBuffer(VOID);
40+LPVOID AllocateBuffer(LPVOID pOrigin);
41+VOID FreeBuffer(LPVOID pBuffer);
42+BOOL IsExecutableAddress(LPVOID pAddress);
--- exewrap/trunk/exewrap/src/minhook/src/HDE/hde32.c (revision 0)
+++ exewrap/trunk/exewrap/src/minhook/src/HDE/hde32.c (revision 22)
@@ -0,0 +1,322 @@
1+/*
2+ * Hacker Disassembler Engine 32 C
3+ * Copyright (c) 2008-2009, Vyacheslav Patkov.
4+ * All rights reserved.
5+ *
6+ */
7+
8+#include "hde32.h"
9+#include "table32.h"
10+
11+unsigned int hde32_disasm(const void *code, hde32s *hs)
12+{
13+ uint8_t x, c, *p = (uint8_t *)code, cflags, opcode, pref = 0;
14+ uint8_t *ht = hde32_table, m_mod, m_reg, m_rm, disp_size = 0;
15+
16+ // Avoid using memset to reduce the footprint.
17+#ifndef _MSC_VER
18+ memset((LPBYTE)hs, 0, sizeof(hde32s));
19+#else
20+ __stosb((LPBYTE)hs, 0, sizeof(hde32s));
21+#endif
22+
23+ for (x = 16; x; x--)
24+ switch (c = *p++) {
25+ case 0xf3:
26+ hs->p_rep = c;
27+ pref |= PRE_F3;
28+ break;
29+ case 0xf2:
30+ hs->p_rep = c;
31+ pref |= PRE_F2;
32+ break;
33+ case 0xf0:
34+ hs->p_lock = c;
35+ pref |= PRE_LOCK;
36+ break;
37+ case 0x26: case 0x2e: case 0x36:
38+ case 0x3e: case 0x64: case 0x65:
39+ hs->p_seg = c;
40+ pref |= PRE_SEG;
41+ break;
42+ case 0x66:
43+ hs->p_66 = c;
44+ pref |= PRE_66;
45+ break;
46+ case 0x67:
47+ hs->p_67 = c;
48+ pref |= PRE_67;
49+ break;
50+ default:
51+ goto pref_done;
52+ }
53+ pref_done:
54+
55+ hs->flags = (uint32_t)pref << 23;
56+
57+ if (!pref)
58+ pref |= PRE_NONE;
59+
60+ if ((hs->opcode = c) == 0x0f) {
61+ hs->opcode2 = c = *p++;
62+ ht += DELTA_OPCODES;
63+ } else if (c >= 0xa0 && c <= 0xa3) {
64+ if (pref & PRE_67)
65+ pref |= PRE_66;
66+ else
67+ pref &= ~PRE_66;
68+ }
69+
70+ opcode = c;
71+ cflags = ht[ht[opcode / 4] + (opcode % 4)];
72+
73+ if (cflags == C_ERROR) {
74+ hs->flags |= F_ERROR | F_ERROR_OPCODE;
75+ cflags = 0;
76+ if ((opcode & -3) == 0x24)
77+ cflags++;
78+ }
79+
80+ x = 0;
81+ if (cflags & C_GROUP) {
82+ uint16_t t;
83+ t = *(uint16_t *)(ht + (cflags & 0x7f));
84+ cflags = (uint8_t)t;
85+ x = (uint8_t)(t >> 8);
86+ }
87+
88+ if (hs->opcode2) {
89+ ht = hde32_table + DELTA_PREFIXES;
90+ if (ht[ht[opcode / 4] + (opcode % 4)] & pref)
91+ hs->flags |= F_ERROR | F_ERROR_OPCODE;
92+ }
93+
94+ if (cflags & C_MODRM) {
95+ hs->flags |= F_MODRM;
96+ hs->modrm = c = *p++;
97+ hs->modrm_mod = m_mod = c >> 6;
98+ hs->modrm_rm = m_rm = c & 7;
99+ hs->modrm_reg = m_reg = (c & 0x3f) >> 3;
100+
101+ if (x && ((x << m_reg) & 0x80))
102+ hs->flags |= F_ERROR | F_ERROR_OPCODE;
103+
104+ if (!hs->opcode2 && opcode >= 0xd9 && opcode <= 0xdf) {
105+ uint8_t t = opcode - 0xd9;
106+ if (m_mod == 3) {
107+ ht = hde32_table + DELTA_FPU_MODRM + t*8;
108+ t = ht[m_reg] << m_rm;
109+ } else {
110+ ht = hde32_table + DELTA_FPU_REG;
111+ t = ht[t] << m_reg;
112+ }
113+ if (t & 0x80)
114+ hs->flags |= F_ERROR | F_ERROR_OPCODE;
115+ }
116+
117+ if (pref & PRE_LOCK) {
118+ if (m_mod == 3) {
119+ hs->flags |= F_ERROR | F_ERROR_LOCK;
120+ } else {
121+ uint8_t *table_end, op = opcode;
122+ if (hs->opcode2) {
123+ ht = hde32_table + DELTA_OP2_LOCK_OK;
124+ table_end = ht + DELTA_OP_ONLY_MEM - DELTA_OP2_LOCK_OK;
125+ } else {
126+ ht = hde32_table + DELTA_OP_LOCK_OK;
127+ table_end = ht + DELTA_OP2_LOCK_OK - DELTA_OP_LOCK_OK;
128+ op &= -2;
129+ }
130+ for (; ht != table_end; ht++)
131+ if (*ht++ == op) {
132+ if (!((*ht << m_reg) & 0x80))
133+ goto no_lock_error;
134+ else
135+ break;
136+ }
137+ hs->flags |= F_ERROR | F_ERROR_LOCK;
138+ no_lock_error:
139+ ;
140+ }
141+ }
142+
143+ if (hs->opcode2) {
144+ switch (opcode) {
145+ case 0x20: case 0x22:
146+ m_mod = 3;
147+ if (m_reg > 4 || m_reg == 1)
148+ goto error_operand;
149+ else
150+ goto no_error_operand;
151+ case 0x21: case 0x23:
152+ m_mod = 3;
153+ if (m_reg == 4 || m_reg == 5)
154+ goto error_operand;
155+ else
156+ goto no_error_operand;
157+ }
158+ } else {
159+ switch (opcode) {
160+ case 0x8c:
161+ if (m_reg > 5)
162+ goto error_operand;
163+ else
164+ goto no_error_operand;
165+ case 0x8e:
166+ if (m_reg == 1 || m_reg > 5)
167+ goto error_operand;
168+ else
169+ goto no_error_operand;
170+ }
171+ }
172+
173+ if (m_mod == 3) {
174+ uint8_t *table_end;
175+ if (hs->opcode2) {
176+ ht = hde32_table + DELTA_OP2_ONLY_MEM;
177+ table_end = ht + sizeof(hde32_table) - DELTA_OP2_ONLY_MEM;
178+ } else {
179+ ht = hde32_table + DELTA_OP_ONLY_MEM;
180+ table_end = ht + DELTA_OP2_ONLY_MEM - DELTA_OP_ONLY_MEM;
181+ }
182+ for (; ht != table_end; ht += 2)
183+ if (*ht++ == opcode) {
184+ if (*ht++ & pref && !((*ht << m_reg) & 0x80))
185+ goto error_operand;
186+ else
187+ break;
188+ }
189+ goto no_error_operand;
190+ } else if (hs->opcode2) {
191+ switch (opcode) {
192+ case 0x50: case 0xd7: case 0xf7:
193+ if (pref & (PRE_NONE | PRE_66))
194+ goto error_operand;
195+ break;
196+ case 0xd6:
197+ if (pref & (PRE_F2 | PRE_F3))
198+ goto error_operand;
199+ break;
200+ case 0xc5:
201+ goto error_operand;
202+ }
203+ goto no_error_operand;
204+ } else
205+ goto no_error_operand;
206+
207+ error_operand:
208+ hs->flags |= F_ERROR | F_ERROR_OPERAND;
209+ no_error_operand:
210+
211+ c = *p++;
212+ if (m_reg <= 1) {
213+ if (opcode == 0xf6)
214+ cflags |= C_IMM8;
215+ else if (opcode == 0xf7)
216+ cflags |= C_IMM_P66;
217+ }
218+
219+ switch (m_mod) {
220+ case 0:
221+ if (pref & PRE_67) {
222+ if (m_rm == 6)
223+ disp_size = 2;
224+ } else
225+ if (m_rm == 5)
226+ disp_size = 4;
227+ break;
228+ case 1:
229+ disp_size = 1;
230+ break;
231+ case 2:
232+ disp_size = 2;
233+ if (!(pref & PRE_67))
234+ disp_size <<= 1;
235+ }
236+
237+ if (m_mod != 3 && m_rm == 4 && !(pref & PRE_67)) {
238+ hs->flags |= F_SIB;
239+ p++;
240+ hs->sib = c;
241+ hs->sib_scale = c >> 6;
242+ hs->sib_index = (c & 0x3f) >> 3;
243+ if ((hs->sib_base = c & 7) == 5 && !(m_mod & 1))
244+ disp_size = 4;
245+ }
246+
247+ p--;
248+ switch (disp_size) {
249+ case 1:
250+ hs->flags |= F_DISP8;
251+ hs->disp.disp8 = *p;
252+ break;
253+ case 2:
254+ hs->flags |= F_DISP16;
255+ hs->disp.disp16 = *(uint16_t *)p;
256+ break;
257+ case 4:
258+ hs->flags |= F_DISP32;
259+ hs->disp.disp32 = *(uint32_t *)p;
260+ }
261+ p += disp_size;
262+ } else if (pref & PRE_LOCK)
263+ hs->flags |= F_ERROR | F_ERROR_LOCK;
264+
265+ if (cflags & C_IMM_P66) {
266+ if (cflags & C_REL32) {
267+ if (pref & PRE_66) {
268+ hs->flags |= F_IMM16 | F_RELATIVE;
269+ hs->imm.imm16 = *(uint16_t *)p;
270+ p += 2;
271+ goto disasm_done;
272+ }
273+ goto rel32_ok;
274+ }
275+ if (pref & PRE_66) {
276+ hs->flags |= F_IMM16;
277+ hs->imm.imm16 = *(uint16_t *)p;
278+ p += 2;
279+ } else {
280+ hs->flags |= F_IMM32;
281+ hs->imm.imm32 = *(uint32_t *)p;
282+ p += 4;
283+ }
284+ }
285+
286+ if (cflags & C_IMM16) {
287+ if (hs->flags & F_IMM32) {
288+ hs->flags |= F_IMM16;
289+ hs->disp.disp16 = *(uint16_t *)p;
290+ } else if (hs->flags & F_IMM16) {
291+ hs->flags |= F_2IMM16;
292+ hs->disp.disp16 = *(uint16_t *)p;
293+ } else {
294+ hs->flags |= F_IMM16;
295+ hs->imm.imm16 = *(uint16_t *)p;
296+ }
297+ p += 2;
298+ }
299+ if (cflags & C_IMM8) {
300+ hs->flags |= F_IMM8;
301+ hs->imm.imm8 = *p++;
302+ }
303+
304+ if (cflags & C_REL32) {
305+ rel32_ok:
306+ hs->flags |= F_IMM32 | F_RELATIVE;
307+ hs->imm.imm32 = *(uint32_t *)p;
308+ p += 4;
309+ } else if (cflags & C_REL8) {
310+ hs->flags |= F_IMM8 | F_RELATIVE;
311+ hs->imm.imm8 = *p++;
312+ }
313+
314+ disasm_done:
315+
316+ if ((hs->len = (uint8_t)(p-(uint8_t *)code)) > 15) {
317+ hs->flags |= F_ERROR | F_ERROR_LENGTH;
318+ hs->len = 15;
319+ }
320+
321+ return (unsigned int)hs->len;
322+}
--- exewrap/trunk/exewrap/src/minhook/src/HDE/table64.h (revision 0)
+++ exewrap/trunk/exewrap/src/minhook/src/HDE/table64.h (revision 22)
@@ -0,0 +1,74 @@
1+/*
2+ * Hacker Disassembler Engine 64 C
3+ * Copyright (c) 2008-2009, Vyacheslav Patkov.
4+ * All rights reserved.
5+ *
6+ */
7+
8+#define C_NONE 0x00
9+#define C_MODRM 0x01
10+#define C_IMM8 0x02
11+#define C_IMM16 0x04
12+#define C_IMM_P66 0x10
13+#define C_REL8 0x20
14+#define C_REL32 0x40
15+#define C_GROUP 0x80
16+#define C_ERROR 0xff
17+
18+#define PRE_ANY 0x00
19+#define PRE_NONE 0x01
20+#define PRE_F2 0x02
21+#define PRE_F3 0x04
22+#define PRE_66 0x08
23+#define PRE_67 0x10
24+#define PRE_LOCK 0x20
25+#define PRE_SEG 0x40
26+#define PRE_ALL 0xff
27+
28+#define DELTA_OPCODES 0x4a
29+#define DELTA_FPU_REG 0xfd
30+#define DELTA_FPU_MODRM 0x104
31+#define DELTA_PREFIXES 0x13c
32+#define DELTA_OP_LOCK_OK 0x1ae
33+#define DELTA_OP2_LOCK_OK 0x1c6
34+#define DELTA_OP_ONLY_MEM 0x1d8
35+#define DELTA_OP2_ONLY_MEM 0x1e7
36+
37+unsigned char hde64_table[] = {
38+ 0xa5,0xaa,0xa5,0xb8,0xa5,0xaa,0xa5,0xaa,0xa5,0xb8,0xa5,0xb8,0xa5,0xb8,0xa5,
39+ 0xb8,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xac,0xc0,0xcc,0xc0,0xa1,0xa1,
40+ 0xa1,0xa1,0xb1,0xa5,0xa5,0xa6,0xc0,0xc0,0xd7,0xda,0xe0,0xc0,0xe4,0xc0,0xea,
41+ 0xea,0xe0,0xe0,0x98,0xc8,0xee,0xf1,0xa5,0xd3,0xa5,0xa5,0xa1,0xea,0x9e,0xc0,
42+ 0xc0,0xc2,0xc0,0xe6,0x03,0x7f,0x11,0x7f,0x01,0x7f,0x01,0x3f,0x01,0x01,0xab,
43+ 0x8b,0x90,0x64,0x5b,0x5b,0x5b,0x5b,0x5b,0x92,0x5b,0x5b,0x76,0x90,0x92,0x92,
44+ 0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x6a,0x73,0x90,
45+ 0x5b,0x52,0x52,0x52,0x52,0x5b,0x5b,0x5b,0x5b,0x77,0x7c,0x77,0x85,0x5b,0x5b,
46+ 0x70,0x5b,0x7a,0xaf,0x76,0x76,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,
47+ 0x5b,0x5b,0x86,0x01,0x03,0x01,0x04,0x03,0xd5,0x03,0xd5,0x03,0xcc,0x01,0xbc,
48+ 0x03,0xf0,0x03,0x03,0x04,0x00,0x50,0x50,0x50,0x50,0xff,0x20,0x20,0x20,0x20,
49+ 0x01,0x01,0x01,0x01,0xc4,0x02,0x10,0xff,0xff,0xff,0x01,0x00,0x03,0x11,0xff,
50+ 0x03,0xc4,0xc6,0xc8,0x02,0x10,0x00,0xff,0xcc,0x01,0x01,0x01,0x00,0x00,0x00,
51+ 0x00,0x01,0x01,0x03,0x01,0xff,0xff,0xc0,0xc2,0x10,0x11,0x02,0x03,0x01,0x01,
52+ 0x01,0xff,0xff,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x10,
53+ 0x10,0x10,0x10,0x02,0x10,0x00,0x00,0xc6,0xc8,0x02,0x02,0x02,0x02,0x06,0x00,
54+ 0x04,0x00,0x02,0xff,0x00,0xc0,0xc2,0x01,0x01,0x03,0x03,0x03,0xca,0x40,0x00,
55+ 0x0a,0x00,0x04,0x00,0x00,0x00,0x00,0x7f,0x00,0x33,0x01,0x00,0x00,0x00,0x00,
56+ 0x00,0x00,0xff,0xbf,0xff,0xff,0x00,0x00,0x00,0x00,0x07,0x00,0x00,0xff,0x00,
57+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,
58+ 0x00,0x00,0x00,0xbf,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7f,0x00,0x00,
59+ 0xff,0x40,0x40,0x40,0x40,0x41,0x49,0x40,0x40,0x40,0x40,0x4c,0x42,0x40,0x40,
60+ 0x40,0x40,0x40,0x40,0x40,0x40,0x4f,0x44,0x53,0x40,0x40,0x40,0x44,0x57,0x43,
61+ 0x5c,0x40,0x60,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,
62+ 0x40,0x40,0x64,0x66,0x6e,0x6b,0x40,0x40,0x6a,0x46,0x40,0x40,0x44,0x46,0x40,
63+ 0x40,0x5b,0x44,0x40,0x40,0x00,0x00,0x00,0x00,0x06,0x06,0x06,0x06,0x01,0x06,
64+ 0x06,0x02,0x06,0x06,0x00,0x06,0x00,0x0a,0x0a,0x00,0x00,0x00,0x02,0x07,0x07,
65+ 0x06,0x02,0x0d,0x06,0x06,0x06,0x0e,0x05,0x05,0x02,0x02,0x00,0x00,0x04,0x04,
66+ 0x04,0x04,0x05,0x06,0x06,0x06,0x00,0x00,0x00,0x0e,0x00,0x00,0x08,0x00,0x10,
67+ 0x00,0x18,0x00,0x20,0x00,0x28,0x00,0x30,0x00,0x80,0x01,0x82,0x01,0x86,0x00,
68+ 0xf6,0xcf,0xfe,0x3f,0xab,0x00,0xb0,0x00,0xb1,0x00,0xb3,0x00,0xba,0xf8,0xbb,
69+ 0x00,0xc0,0x00,0xc1,0x00,0xc7,0xbf,0x62,0xff,0x00,0x8d,0xff,0x00,0xc4,0xff,
70+ 0x00,0xc5,0xff,0x00,0xff,0xff,0xeb,0x01,0xff,0x0e,0x12,0x08,0x00,0x13,0x09,
71+ 0x00,0x16,0x08,0x00,0x17,0x09,0x00,0x2b,0x09,0x00,0xae,0xff,0x07,0xb2,0xff,
72+ 0x00,0xb4,0xff,0x00,0xb5,0xff,0x00,0xc3,0x01,0x00,0xc7,0xff,0xbf,0xe7,0x08,
73+ 0x00,0xf0,0x02,0x00
74+};
--- exewrap/trunk/exewrap/src/minhook/src/HDE/hde32.h (revision 0)
+++ exewrap/trunk/exewrap/src/minhook/src/HDE/hde32.h (revision 22)
@@ -0,0 +1,105 @@
1+/*
2+ * Hacker Disassembler Engine 32
3+ * Copyright (c) 2006-2009, Vyacheslav Patkov.
4+ * All rights reserved.
5+ *
6+ * hde32.h: C/C++ header file
7+ *
8+ */
9+
10+#ifndef _HDE32_H_
11+#define _HDE32_H_
12+
13+/* stdint.h - C99 standard header
14+ * http://en.wikipedia.org/wiki/stdint.h
15+ *
16+ * if your compiler doesn't contain "stdint.h" header (for
17+ * example, Microsoft Visual C++), you can download file:
18+ * http://www.azillionmonkeys.com/qed/pstdint.h
19+ * and change next line to:
20+ * #include "pstdint.h"
21+ */
22+#include "pstdint.h"
23+
24+#define F_MODRM 0x00000001
25+#define F_SIB 0x00000002
26+#define F_IMM8 0x00000004
27+#define F_IMM16 0x00000008
28+#define F_IMM32 0x00000010
29+#define F_DISP8 0x00000020
30+#define F_DISP16 0x00000040
31+#define F_DISP32 0x00000080
32+#define F_RELATIVE 0x00000100
33+#define F_2IMM16 0x00000800
34+#define F_ERROR 0x00001000
35+#define F_ERROR_OPCODE 0x00002000
36+#define F_ERROR_LENGTH 0x00004000
37+#define F_ERROR_LOCK 0x00008000
38+#define F_ERROR_OPERAND 0x00010000
39+#define F_PREFIX_REPNZ 0x01000000
40+#define F_PREFIX_REPX 0x02000000
41+#define F_PREFIX_REP 0x03000000
42+#define F_PREFIX_66 0x04000000
43+#define F_PREFIX_67 0x08000000
44+#define F_PREFIX_LOCK 0x10000000
45+#define F_PREFIX_SEG 0x20000000
46+#define F_PREFIX_ANY 0x3f000000
47+
48+#define PREFIX_SEGMENT_CS 0x2e
49+#define PREFIX_SEGMENT_SS 0x36
50+#define PREFIX_SEGMENT_DS 0x3e
51+#define PREFIX_SEGMENT_ES 0x26
52+#define PREFIX_SEGMENT_FS 0x64
53+#define PREFIX_SEGMENT_GS 0x65
54+#define PREFIX_LOCK 0xf0
55+#define PREFIX_REPNZ 0xf2
56+#define PREFIX_REPX 0xf3
57+#define PREFIX_OPERAND_SIZE 0x66
58+#define PREFIX_ADDRESS_SIZE 0x67
59+
60+#pragma pack(push,1)
61+
62+typedef struct {
63+ uint8_t len;
64+ uint8_t p_rep;
65+ uint8_t p_lock;
66+ uint8_t p_seg;
67+ uint8_t p_66;
68+ uint8_t p_67;
69+ uint8_t opcode;
70+ uint8_t opcode2;
71+ uint8_t modrm;
72+ uint8_t modrm_mod;
73+ uint8_t modrm_reg;
74+ uint8_t modrm_rm;
75+ uint8_t sib;
76+ uint8_t sib_scale;
77+ uint8_t sib_index;
78+ uint8_t sib_base;
79+ union {
80+ uint8_t imm8;
81+ uint16_t imm16;
82+ uint32_t imm32;
83+ } imm;
84+ union {
85+ uint8_t disp8;
86+ uint16_t disp16;
87+ uint32_t disp32;
88+ } disp;
89+ uint32_t flags;
90+} hde32s;
91+
92+#pragma pack(pop)
93+
94+#ifdef __cplusplus
95+extern "C" {
96+#endif
97+
98+/* __cdecl */
99+unsigned int hde32_disasm(const void *code, hde32s *hs);
100+
101+#ifdef __cplusplus
102+}
103+#endif
104+
105+#endif /* _HDE32_H_ */
--- exewrap/trunk/exewrap/src/minhook/src/HDE/hde64.c (revision 0)
+++ exewrap/trunk/exewrap/src/minhook/src/HDE/hde64.c (revision 22)
@@ -0,0 +1,333 @@
1+/*
2+ * Hacker Disassembler Engine 64 C
3+ * Copyright (c) 2008-2009, Vyacheslav Patkov.
4+ * All rights reserved.
5+ *
6+ */
7+
8+#include "hde64.h"
9+#include "table64.h"
10+
11+unsigned int hde64_disasm(const void *code, hde64s *hs)
12+{
13+ uint8_t x, c, *p = (uint8_t *)code, cflags, opcode, pref = 0;
14+ uint8_t *ht = hde64_table, m_mod, m_reg, m_rm, disp_size = 0;
15+ uint8_t op64 = 0;
16+
17+ // Avoid using memset to reduce the footprint.
18+#ifndef _MSC_VER
19+ memset((LPBYTE)hs, 0, sizeof(hde64s));
20+#else
21+ __stosb((LPBYTE)hs, 0, sizeof(hde64s));
22+#endif
23+
24+ for (x = 16; x; x--)
25+ switch (c = *p++) {
26+ case 0xf3:
27+ hs->p_rep = c;
28+ pref |= PRE_F3;
29+ break;
30+ case 0xf2:
31+ hs->p_rep = c;
32+ pref |= PRE_F2;
33+ break;
34+ case 0xf0:
35+ hs->p_lock = c;
36+ pref |= PRE_LOCK;
37+ break;
38+ case 0x26: case 0x2e: case 0x36:
39+ case 0x3e: case 0x64: case 0x65:
40+ hs->p_seg = c;
41+ pref |= PRE_SEG;
42+ break;
43+ case 0x66:
44+ hs->p_66 = c;
45+ pref |= PRE_66;
46+ break;
47+ case 0x67:
48+ hs->p_67 = c;
49+ pref |= PRE_67;
50+ break;
51+ default:
52+ goto pref_done;
53+ }
54+ pref_done:
55+
56+ hs->flags = (uint32_t)pref << 23;
57+
58+ if (!pref)
59+ pref |= PRE_NONE;
60+
61+ if ((c & 0xf0) == 0x40) {
62+ hs->flags |= F_PREFIX_REX;
63+ if ((hs->rex_w = (c & 0xf) >> 3) && (*p & 0xf8) == 0xb8)
64+ op64++;
65+ hs->rex_r = (c & 7) >> 2;
66+ hs->rex_x = (c & 3) >> 1;
67+ hs->rex_b = c & 1;
68+ if (((c = *p++) & 0xf0) == 0x40) {
69+ opcode = c;
70+ goto error_opcode;
71+ }
72+ }
73+
74+ if ((hs->opcode = c) == 0x0f) {
75+ hs->opcode2 = c = *p++;
76+ ht += DELTA_OPCODES;
77+ } else if (c >= 0xa0 && c <= 0xa3) {
78+ op64++;
79+ if (pref & PRE_67)
80+ pref |= PRE_66;
81+ else
82+ pref &= ~PRE_66;
83+ }
84+
85+ opcode = c;
86+ cflags = ht[ht[opcode / 4] + (opcode % 4)];
87+
88+ if (cflags == C_ERROR) {
89+ error_opcode:
90+ hs->flags |= F_ERROR | F_ERROR_OPCODE;
91+ cflags = 0;
92+ if ((opcode & -3) == 0x24)
93+ cflags++;
94+ }
95+
96+ x = 0;
97+ if (cflags & C_GROUP) {
98+ uint16_t t;
99+ t = *(uint16_t *)(ht + (cflags & 0x7f));
100+ cflags = (uint8_t)t;
101+ x = (uint8_t)(t >> 8);
102+ }
103+
104+ if (hs->opcode2) {
105+ ht = hde64_table + DELTA_PREFIXES;
106+ if (ht[ht[opcode / 4] + (opcode % 4)] & pref)
107+ hs->flags |= F_ERROR | F_ERROR_OPCODE;
108+ }
109+
110+ if (cflags & C_MODRM) {
111+ hs->flags |= F_MODRM;
112+ hs->modrm = c = *p++;
113+ hs->modrm_mod = m_mod = c >> 6;
114+ hs->modrm_rm = m_rm = c & 7;
115+ hs->modrm_reg = m_reg = (c & 0x3f) >> 3;
116+
117+ if (x && ((x << m_reg) & 0x80))
118+ hs->flags |= F_ERROR | F_ERROR_OPCODE;
119+
120+ if (!hs->opcode2 && opcode >= 0xd9 && opcode <= 0xdf) {
121+ uint8_t t = opcode - 0xd9;
122+ if (m_mod == 3) {
123+ ht = hde64_table + DELTA_FPU_MODRM + t*8;
124+ t = ht[m_reg] << m_rm;
125+ } else {
126+ ht = hde64_table + DELTA_FPU_REG;
127+ t = ht[t] << m_reg;
128+ }
129+ if (t & 0x80)
130+ hs->flags |= F_ERROR | F_ERROR_OPCODE;
131+ }
132+
133+ if (pref & PRE_LOCK) {
134+ if (m_mod == 3) {
135+ hs->flags |= F_ERROR | F_ERROR_LOCK;
136+ } else {
137+ uint8_t *table_end, op = opcode;
138+ if (hs->opcode2) {
139+ ht = hde64_table + DELTA_OP2_LOCK_OK;
140+ table_end = ht + DELTA_OP_ONLY_MEM - DELTA_OP2_LOCK_OK;
141+ } else {
142+ ht = hde64_table + DELTA_OP_LOCK_OK;
143+ table_end = ht + DELTA_OP2_LOCK_OK - DELTA_OP_LOCK_OK;
144+ op &= -2;
145+ }
146+ for (; ht != table_end; ht++)
147+ if (*ht++ == op) {
148+ if (!((*ht << m_reg) & 0x80))
149+ goto no_lock_error;
150+ else
151+ break;
152+ }
153+ hs->flags |= F_ERROR | F_ERROR_LOCK;
154+ no_lock_error:
155+ ;
156+ }
157+ }
158+
159+ if (hs->opcode2) {
160+ switch (opcode) {
161+ case 0x20: case 0x22:
162+ m_mod = 3;
163+ if (m_reg > 4 || m_reg == 1)
164+ goto error_operand;
165+ else
166+ goto no_error_operand;
167+ case 0x21: case 0x23:
168+ m_mod = 3;
169+ if (m_reg == 4 || m_reg == 5)
170+ goto error_operand;
171+ else
172+ goto no_error_operand;
173+ }
174+ } else {
175+ switch (opcode) {
176+ case 0x8c:
177+ if (m_reg > 5)
178+ goto error_operand;
179+ else
180+ goto no_error_operand;
181+ case 0x8e:
182+ if (m_reg == 1 || m_reg > 5)
183+ goto error_operand;
184+ else
185+ goto no_error_operand;
186+ }
187+ }
188+
189+ if (m_mod == 3) {
190+ uint8_t *table_end;
191+ if (hs->opcode2) {
192+ ht = hde64_table + DELTA_OP2_ONLY_MEM;
193+ table_end = ht + sizeof(hde64_table) - DELTA_OP2_ONLY_MEM;
194+ } else {
195+ ht = hde64_table + DELTA_OP_ONLY_MEM;
196+ table_end = ht + DELTA_OP2_ONLY_MEM - DELTA_OP_ONLY_MEM;
197+ }
198+ for (; ht != table_end; ht += 2)
199+ if (*ht++ == opcode) {
200+ if (*ht++ & pref && !((*ht << m_reg) & 0x80))
201+ goto error_operand;
202+ else
203+ break;
204+ }
205+ goto no_error_operand;
206+ } else if (hs->opcode2) {
207+ switch (opcode) {
208+ case 0x50: case 0xd7: case 0xf7:
209+ if (pref & (PRE_NONE | PRE_66))
210+ goto error_operand;
211+ break;
212+ case 0xd6:
213+ if (pref & (PRE_F2 | PRE_F3))
214+ goto error_operand;
215+ break;
216+ case 0xc5:
217+ goto error_operand;
218+ }
219+ goto no_error_operand;
220+ } else
221+ goto no_error_operand;
222+
223+ error_operand:
224+ hs->flags |= F_ERROR | F_ERROR_OPERAND;
225+ no_error_operand:
226+
227+ c = *p++;
228+ if (m_reg <= 1) {
229+ if (opcode == 0xf6)
230+ cflags |= C_IMM8;
231+ else if (opcode == 0xf7)
232+ cflags |= C_IMM_P66;
233+ }
234+
235+ switch (m_mod) {
236+ case 0:
237+ if (pref & PRE_67) {
238+ if (m_rm == 6)
239+ disp_size = 2;
240+ } else
241+ if (m_rm == 5)
242+ disp_size = 4;
243+ break;
244+ case 1:
245+ disp_size = 1;
246+ break;
247+ case 2:
248+ disp_size = 2;
249+ if (!(pref & PRE_67))
250+ disp_size <<= 1;
251+ }
252+
253+ if (m_mod != 3 && m_rm == 4) {
254+ hs->flags |= F_SIB;
255+ p++;
256+ hs->sib = c;
257+ hs->sib_scale = c >> 6;
258+ hs->sib_index = (c & 0x3f) >> 3;
259+ if ((hs->sib_base = c & 7) == 5 && !(m_mod & 1))
260+ disp_size = 4;
261+ }
262+
263+ p--;
264+ switch (disp_size) {
265+ case 1:
266+ hs->flags |= F_DISP8;
267+ hs->disp.disp8 = *p;
268+ break;
269+ case 2:
270+ hs->flags |= F_DISP16;
271+ hs->disp.disp16 = *(uint16_t *)p;
272+ break;
273+ case 4:
274+ hs->flags |= F_DISP32;
275+ hs->disp.disp32 = *(uint32_t *)p;
276+ }
277+ p += disp_size;
278+ } else if (pref & PRE_LOCK)
279+ hs->flags |= F_ERROR | F_ERROR_LOCK;
280+
281+ if (cflags & C_IMM_P66) {
282+ if (cflags & C_REL32) {
283+ if (pref & PRE_66) {
284+ hs->flags |= F_IMM16 | F_RELATIVE;
285+ hs->imm.imm16 = *(uint16_t *)p;
286+ p += 2;
287+ goto disasm_done;
288+ }
289+ goto rel32_ok;
290+ }
291+ if (op64) {
292+ hs->flags |= F_IMM64;
293+ hs->imm.imm64 = *(uint64_t *)p;
294+ p += 8;
295+ } else if (!(pref & PRE_66)) {
296+ hs->flags |= F_IMM32;
297+ hs->imm.imm32 = *(uint32_t *)p;
298+ p += 4;
299+ } else
300+ goto imm16_ok;
301+ }
302+
303+
304+ if (cflags & C_IMM16) {
305+ imm16_ok:
306+ hs->flags |= F_IMM16;
307+ hs->imm.imm16 = *(uint16_t *)p;
308+ p += 2;
309+ }
310+ if (cflags & C_IMM8) {
311+ hs->flags |= F_IMM8;
312+ hs->imm.imm8 = *p++;
313+ }
314+
315+ if (cflags & C_REL32) {
316+ rel32_ok:
317+ hs->flags |= F_IMM32 | F_RELATIVE;
318+ hs->imm.imm32 = *(uint32_t *)p;
319+ p += 4;
320+ } else if (cflags & C_REL8) {
321+ hs->flags |= F_IMM8 | F_RELATIVE;
322+ hs->imm.imm8 = *p++;
323+ }
324+
325+ disasm_done:
326+
327+ if ((hs->len = (uint8_t)(p-(uint8_t *)code)) > 15) {
328+ hs->flags |= F_ERROR | F_ERROR_LENGTH;
329+ hs->len = 15;
330+ }
331+
332+ return (unsigned int)hs->len;
333+}
--- exewrap/trunk/exewrap/src/minhook/src/HDE/pstdint.h (revision 0)
+++ exewrap/trunk/exewrap/src/minhook/src/HDE/pstdint.h (revision 22)
@@ -0,0 +1,39 @@
1+/*
2+ * MinHook - The Minimalistic API Hooking Library for x64/x86
3+ * Copyright (C) 2009-2015 Tsuda Kageyu. All rights reserved.
4+ *
5+ * Redistribution and use in source and binary forms, with or without
6+ * modification, are permitted provided that the following conditions
7+ * are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright
10+ * notice, this list of conditions and the following disclaimer.
11+ * 2. Redistributions in binary form must reproduce the above copyright
12+ * notice, this list of conditions and the following disclaimer in the
13+ * documentation and/or other materials provided with the distribution.
14+ *
15+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR
16+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25+ */
26+
27+#pragma once
28+
29+#include <windows.h>
30+
31+// Integer types for HDE.
32+typedef INT8 int8_t;
33+typedef INT16 int16_t;
34+typedef INT32 int32_t;
35+typedef INT64 int64_t;
36+typedef UINT8 uint8_t;
37+typedef UINT16 uint16_t;
38+typedef UINT32 uint32_t;
39+typedef UINT64 uint64_t;
--- exewrap/trunk/exewrap/src/minhook/src/HDE/hde64.h (revision 0)
+++ exewrap/trunk/exewrap/src/minhook/src/HDE/hde64.h (revision 22)
@@ -0,0 +1,112 @@
1+/*
2+ * Hacker Disassembler Engine 64
3+ * Copyright (c) 2008-2009, Vyacheslav Patkov.
4+ * All rights reserved.
5+ *
6+ * hde64.h: C/C++ header file
7+ *
8+ */
9+
10+#ifndef _HDE64_H_
11+#define _HDE64_H_
12+
13+/* stdint.h - C99 standard header
14+ * http://en.wikipedia.org/wiki/stdint.h
15+ *
16+ * if your compiler doesn't contain "stdint.h" header (for
17+ * example, Microsoft Visual C++), you can download file:
18+ * http://www.azillionmonkeys.com/qed/pstdint.h
19+ * and change next line to:
20+ * #include "pstdint.h"
21+ */
22+#include "pstdint.h"
23+
24+#define F_MODRM 0x00000001
25+#define F_SIB 0x00000002
26+#define F_IMM8 0x00000004
27+#define F_IMM16 0x00000008
28+#define F_IMM32 0x00000010
29+#define F_IMM64 0x00000020
30+#define F_DISP8 0x00000040
31+#define F_DISP16 0x00000080
32+#define F_DISP32 0x00000100
33+#define F_RELATIVE 0x00000200
34+#define F_ERROR 0x00001000
35+#define F_ERROR_OPCODE 0x00002000
36+#define F_ERROR_LENGTH 0x00004000
37+#define F_ERROR_LOCK 0x00008000
38+#define F_ERROR_OPERAND 0x00010000
39+#define F_PREFIX_REPNZ 0x01000000
40+#define F_PREFIX_REPX 0x02000000
41+#define F_PREFIX_REP 0x03000000
42+#define F_PREFIX_66 0x04000000
43+#define F_PREFIX_67 0x08000000
44+#define F_PREFIX_LOCK 0x10000000
45+#define F_PREFIX_SEG 0x20000000
46+#define F_PREFIX_REX 0x40000000
47+#define F_PREFIX_ANY 0x7f000000
48+
49+#define PREFIX_SEGMENT_CS 0x2e
50+#define PREFIX_SEGMENT_SS 0x36
51+#define PREFIX_SEGMENT_DS 0x3e
52+#define PREFIX_SEGMENT_ES 0x26
53+#define PREFIX_SEGMENT_FS 0x64
54+#define PREFIX_SEGMENT_GS 0x65
55+#define PREFIX_LOCK 0xf0
56+#define PREFIX_REPNZ 0xf2
57+#define PREFIX_REPX 0xf3
58+#define PREFIX_OPERAND_SIZE 0x66
59+#define PREFIX_ADDRESS_SIZE 0x67
60+
61+#pragma pack(push,1)
62+
63+typedef struct {
64+ uint8_t len;
65+ uint8_t p_rep;
66+ uint8_t p_lock;
67+ uint8_t p_seg;
68+ uint8_t p_66;
69+ uint8_t p_67;
70+ uint8_t rex;
71+ uint8_t rex_w;
72+ uint8_t rex_r;
73+ uint8_t rex_x;
74+ uint8_t rex_b;
75+ uint8_t opcode;
76+ uint8_t opcode2;
77+ uint8_t modrm;
78+ uint8_t modrm_mod;
79+ uint8_t modrm_reg;
80+ uint8_t modrm_rm;
81+ uint8_t sib;
82+ uint8_t sib_scale;
83+ uint8_t sib_index;
84+ uint8_t sib_base;
85+ union {
86+ uint8_t imm8;
87+ uint16_t imm16;
88+ uint32_t imm32;
89+ uint64_t imm64;
90+ } imm;
91+ union {
92+ uint8_t disp8;
93+ uint16_t disp16;
94+ uint32_t disp32;
95+ } disp;
96+ uint32_t flags;
97+} hde64s;
98+
99+#pragma pack(pop)
100+
101+#ifdef __cplusplus
102+extern "C" {
103+#endif
104+
105+/* __cdecl */
106+unsigned int hde64_disasm(const void *code, hde64s *hs);
107+
108+#ifdef __cplusplus
109+}
110+#endif
111+
112+#endif /* _HDE64_H_ */
--- exewrap/trunk/exewrap/src/minhook/src/HDE/table32.h (revision 0)
+++ exewrap/trunk/exewrap/src/minhook/src/HDE/table32.h (revision 22)
@@ -0,0 +1,73 @@
1+/*
2+ * Hacker Disassembler Engine 32 C
3+ * Copyright (c) 2008-2009, Vyacheslav Patkov.
4+ * All rights reserved.
5+ *
6+ */
7+
8+#define C_NONE 0x00
9+#define C_MODRM 0x01
10+#define C_IMM8 0x02
11+#define C_IMM16 0x04
12+#define C_IMM_P66 0x10
13+#define C_REL8 0x20
14+#define C_REL32 0x40
15+#define C_GROUP 0x80
16+#define C_ERROR 0xff
17+
18+#define PRE_ANY 0x00
19+#define PRE_NONE 0x01
20+#define PRE_F2 0x02
21+#define PRE_F3 0x04
22+#define PRE_66 0x08
23+#define PRE_67 0x10
24+#define PRE_LOCK 0x20
25+#define PRE_SEG 0x40
26+#define PRE_ALL 0xff
27+
28+#define DELTA_OPCODES 0x4a
29+#define DELTA_FPU_REG 0xf1
30+#define DELTA_FPU_MODRM 0xf8
31+#define DELTA_PREFIXES 0x130
32+#define DELTA_OP_LOCK_OK 0x1a1
33+#define DELTA_OP2_LOCK_OK 0x1b9
34+#define DELTA_OP_ONLY_MEM 0x1cb
35+#define DELTA_OP2_ONLY_MEM 0x1da
36+
37+unsigned char hde32_table[] = {
38+ 0xa3,0xa8,0xa3,0xa8,0xa3,0xa8,0xa3,0xa8,0xa3,0xa8,0xa3,0xa8,0xa3,0xa8,0xa3,
39+ 0xa8,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xac,0xaa,0xb2,0xaa,0x9f,0x9f,
40+ 0x9f,0x9f,0xb5,0xa3,0xa3,0xa4,0xaa,0xaa,0xba,0xaa,0x96,0xaa,0xa8,0xaa,0xc3,
41+ 0xc3,0x96,0x96,0xb7,0xae,0xd6,0xbd,0xa3,0xc5,0xa3,0xa3,0x9f,0xc3,0x9c,0xaa,
42+ 0xaa,0xac,0xaa,0xbf,0x03,0x7f,0x11,0x7f,0x01,0x7f,0x01,0x3f,0x01,0x01,0x90,
43+ 0x82,0x7d,0x97,0x59,0x59,0x59,0x59,0x59,0x7f,0x59,0x59,0x60,0x7d,0x7f,0x7f,
44+ 0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x9a,0x88,0x7d,
45+ 0x59,0x50,0x50,0x50,0x50,0x59,0x59,0x59,0x59,0x61,0x94,0x61,0x9e,0x59,0x59,
46+ 0x85,0x59,0x92,0xa3,0x60,0x60,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,
47+ 0x59,0x59,0x9f,0x01,0x03,0x01,0x04,0x03,0xd5,0x03,0xcc,0x01,0xbc,0x03,0xf0,
48+ 0x10,0x10,0x10,0x10,0x50,0x50,0x50,0x50,0x14,0x20,0x20,0x20,0x20,0x01,0x01,
49+ 0x01,0x01,0xc4,0x02,0x10,0x00,0x00,0x00,0x00,0x01,0x01,0xc0,0xc2,0x10,0x11,
50+ 0x02,0x03,0x11,0x03,0x03,0x04,0x00,0x00,0x14,0x00,0x02,0x00,0x00,0xc6,0xc8,
51+ 0x02,0x02,0x02,0x02,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0xff,0xca,
52+ 0x01,0x01,0x01,0x00,0x06,0x00,0x04,0x00,0xc0,0xc2,0x01,0x01,0x03,0x01,0xff,
53+ 0xff,0x01,0x00,0x03,0xc4,0xc4,0xc6,0x03,0x01,0x01,0x01,0xff,0x03,0x03,0x03,
54+ 0xc8,0x40,0x00,0x0a,0x00,0x04,0x00,0x00,0x00,0x00,0x7f,0x00,0x33,0x01,0x00,
55+ 0x00,0x00,0x00,0x00,0x00,0xff,0xbf,0xff,0xff,0x00,0x00,0x00,0x00,0x07,0x00,
56+ 0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
57+ 0x00,0xff,0xff,0x00,0x00,0x00,0xbf,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
58+ 0x7f,0x00,0x00,0xff,0x4a,0x4a,0x4a,0x4a,0x4b,0x52,0x4a,0x4a,0x4a,0x4a,0x4f,
59+ 0x4c,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x55,0x45,0x40,0x4a,0x4a,0x4a,
60+ 0x45,0x59,0x4d,0x46,0x4a,0x5d,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,
61+ 0x4a,0x4a,0x4a,0x4a,0x4a,0x61,0x63,0x67,0x4e,0x4a,0x4a,0x6b,0x6d,0x4a,0x4a,
62+ 0x45,0x6d,0x4a,0x4a,0x44,0x45,0x4a,0x4a,0x00,0x00,0x00,0x02,0x0d,0x06,0x06,
63+ 0x06,0x06,0x0e,0x00,0x00,0x00,0x00,0x06,0x06,0x06,0x00,0x06,0x06,0x02,0x06,
64+ 0x00,0x0a,0x0a,0x07,0x07,0x06,0x02,0x05,0x05,0x02,0x02,0x00,0x00,0x04,0x04,
65+ 0x04,0x04,0x00,0x00,0x00,0x0e,0x05,0x06,0x06,0x06,0x01,0x06,0x00,0x00,0x08,
66+ 0x00,0x10,0x00,0x18,0x00,0x20,0x00,0x28,0x00,0x30,0x00,0x80,0x01,0x82,0x01,
67+ 0x86,0x00,0xf6,0xcf,0xfe,0x3f,0xab,0x00,0xb0,0x00,0xb1,0x00,0xb3,0x00,0xba,
68+ 0xf8,0xbb,0x00,0xc0,0x00,0xc1,0x00,0xc7,0xbf,0x62,0xff,0x00,0x8d,0xff,0x00,
69+ 0xc4,0xff,0x00,0xc5,0xff,0x00,0xff,0xff,0xeb,0x01,0xff,0x0e,0x12,0x08,0x00,
70+ 0x13,0x09,0x00,0x16,0x08,0x00,0x17,0x09,0x00,0x2b,0x09,0x00,0xae,0xff,0x07,
71+ 0xb2,0xff,0x00,0xb4,0xff,0x00,0xb5,0xff,0x00,0xc3,0x01,0x00,0xc7,0xff,0xbf,
72+ 0xe7,0x08,0x00,0xf0,0x02,0x00
73+};
--- exewrap/trunk/exewrap/src/minhook/src/trampoline.h (revision 0)
+++ exewrap/trunk/exewrap/src/minhook/src/trampoline.h (revision 22)
@@ -0,0 +1,105 @@
1+/*
2+ * MinHook - The Minimalistic API Hooking Library for x64/x86
3+ * Copyright (C) 2009-2015 Tsuda Kageyu.
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions
8+ * are met:
9+ *
10+ * 1. Redistributions of source code must retain the above copyright
11+ * notice, this list of conditions and the following disclaimer.
12+ * 2. Redistributions in binary form must reproduce the above copyright
13+ * notice, this list of conditions and the following disclaimer in the
14+ * documentation and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
19+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
20+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27+ */
28+
29+#pragma once
30+
31+#pragma pack(push, 1)
32+
33+// Structs for writing x86/x64 instructions.
34+
35+// 8-bit relative jump.
36+typedef struct _JMP_REL_SHORT
37+{
38+ UINT8 opcode; // EB xx: JMP +2+xx
39+ UINT8 operand;
40+} JMP_REL_SHORT, *PJMP_REL_SHORT;
41+
42+// 32-bit direct relative jump/call.
43+typedef struct _JMP_REL
44+{
45+ UINT8 opcode; // E9/E8 xxxxxxxx: JMP/CALL +5+xxxxxxxx
46+ UINT32 operand; // Relative destination address
47+} JMP_REL, *PJMP_REL, CALL_REL;
48+
49+// 64-bit indirect absolute jump.
50+typedef struct _JMP_ABS
51+{
52+ UINT8 opcode0; // FF25 00000000: JMP [+6]
53+ UINT8 opcode1;
54+ UINT32 dummy;
55+ UINT64 address; // Absolute destination address
56+} JMP_ABS, *PJMP_ABS;
57+
58+// 64-bit indirect absolute call.
59+typedef struct _CALL_ABS
60+{
61+ UINT8 opcode0; // FF15 00000002: CALL [+6]
62+ UINT8 opcode1;
63+ UINT32 dummy0;
64+ UINT8 dummy1; // EB 08: JMP +10
65+ UINT8 dummy2;
66+ UINT64 address; // Absolute destination address
67+} CALL_ABS;
68+
69+// 32-bit direct relative conditional jumps.
70+typedef struct _JCC_REL
71+{
72+ UINT8 opcode0; // 0F8* xxxxxxxx: J** +6+xxxxxxxx
73+ UINT8 opcode1;
74+ UINT32 operand; // Relative destination address
75+} JCC_REL;
76+
77+// 64bit indirect absolute conditional jumps that x64 lacks.
78+typedef struct _JCC_ABS
79+{
80+ UINT8 opcode; // 7* 0E: J** +16
81+ UINT8 dummy0;
82+ UINT8 dummy1; // FF25 00000000: JMP [+6]
83+ UINT8 dummy2;
84+ UINT32 dummy3;
85+ UINT64 address; // Absolute destination address
86+} JCC_ABS;
87+
88+#pragma pack(pop)
89+
90+typedef struct _TRAMPOLINE
91+{
92+ LPVOID pTarget; // [In] Address of the target function.
93+ LPVOID pDetour; // [In] Address of the detour function.
94+ LPVOID pTrampoline; // [In] Buffer address for the trampoline and relay function.
95+
96+#ifdef _M_X64
97+ LPVOID pRelay; // [Out] Address of the relay function.
98+#endif
99+ BOOL patchAbove; // [Out] Should use the hot patch area?
100+ UINT nIP; // [Out] Number of the instruction boundaries.
101+ UINT8 oldIPs[8]; // [Out] Instruction boundaries of the target function.
102+ UINT8 newIPs[8]; // [Out] Instruction boundaries of the trampoline function.
103+} TRAMPOLINE, *PTRAMPOLINE;
104+
105+BOOL CreateTrampolineFunction(PTRAMPOLINE ct);
--- exewrap/trunk/exewrap/src/minhook/src/hook.c (revision 0)
+++ exewrap/trunk/exewrap/src/minhook/src/hook.c (revision 22)
@@ -0,0 +1,874 @@
1+/*
2+ * MinHook - The Minimalistic API Hooking Library for x64/x86
3+ * Copyright (C) 2009-2015 Tsuda Kageyu.
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions
8+ * are met:
9+ *
10+ * 1. Redistributions of source code must retain the above copyright
11+ * notice, this list of conditions and the following disclaimer.
12+ * 2. Redistributions in binary form must reproduce the above copyright
13+ * notice, this list of conditions and the following disclaimer in the
14+ * documentation and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
19+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
20+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27+ */
28+
29+#define STRICT
30+#define _WIN32_WINNT 0x0501
31+#include <windows.h>
32+#include <tlhelp32.h>
33+#include <limits.h>
34+
35+#include "../include/MinHook.h"
36+#include "buffer.h"
37+#include "trampoline.h"
38+
39+#ifndef ARRAYSIZE
40+ #define ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0]))
41+#endif
42+
43+// Initial capacity of the HOOK_ENTRY buffer.
44+#define INITIAL_HOOK_CAPACITY 32
45+
46+// Initial capacity of the thread IDs buffer.
47+#define INITIAL_THREAD_CAPACITY 128
48+
49+// Special hook position values.
50+#define INVALID_HOOK_POS UINT_MAX
51+#define ALL_HOOKS_POS UINT_MAX
52+
53+// Freeze() action argument defines.
54+#define ACTION_DISABLE 0
55+#define ACTION_ENABLE 1
56+#define ACTION_APPLY_QUEUED 2
57+
58+// Thread access rights for suspending/resuming threads.
59+#define THREAD_ACCESS \
60+ (THREAD_SUSPEND_RESUME | THREAD_GET_CONTEXT | THREAD_QUERY_INFORMATION | THREAD_SET_CONTEXT)
61+
62+// Hook information.
63+typedef struct _HOOK_ENTRY
64+{
65+ LPVOID pTarget; // Address of the target function.
66+ LPVOID pDetour; // Address of the detour or relay function.
67+ LPVOID pTrampoline; // Address of the trampoline function.
68+ UINT8 backup[8]; // Original prologue of the target function.
69+
70+ BOOL patchAbove : 1; // Uses the hot patch area.
71+ BOOL isEnabled : 1; // Enabled.
72+ BOOL queueEnable : 1; // Queued for enabling/disabling when != isEnabled.
73+
74+ UINT nIP : 3; // Count of the instruction boundaries.
75+ UINT8 oldIPs[8]; // Instruction boundaries of the target function.
76+ UINT8 newIPs[8]; // Instruction boundaries of the trampoline function.
77+} HOOK_ENTRY, *PHOOK_ENTRY;
78+
79+// Suspended threads for Freeze()/Unfreeze().
80+typedef struct _FROZEN_THREADS
81+{
82+ LPDWORD pItems; // Data heap
83+ UINT capacity; // Size of allocated data heap, items
84+ UINT size; // Actual number of data items
85+} FROZEN_THREADS, *PFROZEN_THREADS;
86+
87+//-------------------------------------------------------------------------
88+// Global Variables:
89+//-------------------------------------------------------------------------
90+
91+// Spin lock flag for EnterSpinLock()/LeaveSpinLock().
92+volatile LONG g_isLocked = FALSE;
93+
94+// Private heap handle. If not NULL, this library is initialized.
95+HANDLE g_hHeap = NULL;
96+
97+// Hook entries.
98+struct
99+{
100+ PHOOK_ENTRY pItems; // Data heap
101+ UINT capacity; // Size of allocated data heap, items
102+ UINT size; // Actual number of data items
103+} g_hooks;
104+
105+//-------------------------------------------------------------------------
106+// Returns INVALID_HOOK_POS if not found.
107+static UINT FindHookEntry(LPVOID pTarget)
108+{
109+ UINT i;
110+ for (i = 0; i < g_hooks.size; ++i)
111+ {
112+ if ((ULONG_PTR)pTarget == (ULONG_PTR)g_hooks.pItems[i].pTarget)
113+ return i;
114+ }
115+
116+ return INVALID_HOOK_POS;
117+}
118+
119+//-------------------------------------------------------------------------
120+static PHOOK_ENTRY AddHookEntry()
121+{
122+ if (g_hooks.pItems == NULL)
123+ {
124+ g_hooks.capacity = INITIAL_HOOK_CAPACITY;
125+ g_hooks.pItems = (PHOOK_ENTRY)HeapAlloc(
126+ g_hHeap, 0, g_hooks.capacity * sizeof(HOOK_ENTRY));
127+ if (g_hooks.pItems == NULL)
128+ return NULL;
129+ }
130+ else if (g_hooks.size >= g_hooks.capacity)
131+ {
132+ PHOOK_ENTRY p = (PHOOK_ENTRY)HeapReAlloc(
133+ g_hHeap, 0, g_hooks.pItems, (g_hooks.capacity * 2) * sizeof(HOOK_ENTRY));
134+ if (p == NULL)
135+ return NULL;
136+
137+ g_hooks.capacity *= 2;
138+ g_hooks.pItems = p;
139+ }
140+
141+ return &g_hooks.pItems[g_hooks.size++];
142+}
143+
144+//-------------------------------------------------------------------------
145+static void DeleteHookEntry(UINT pos)
146+{
147+ if (pos < g_hooks.size - 1)
148+ g_hooks.pItems[pos] = g_hooks.pItems[g_hooks.size - 1];
149+
150+ g_hooks.size--;
151+
152+ if (g_hooks.capacity / 2 >= INITIAL_HOOK_CAPACITY && g_hooks.capacity / 2 >= g_hooks.size)
153+ {
154+ PHOOK_ENTRY p = (PHOOK_ENTRY)HeapReAlloc(
155+ g_hHeap, 0, g_hooks.pItems, (g_hooks.capacity / 2) * sizeof(HOOK_ENTRY));
156+ if (p == NULL)
157+ return;
158+
159+ g_hooks.capacity /= 2;
160+ g_hooks.pItems = p;
161+ }
162+}
163+
164+//-------------------------------------------------------------------------
165+static DWORD_PTR FindOldIP(PHOOK_ENTRY pHook, DWORD_PTR ip)
166+{
167+ UINT i;
168+
169+ if (pHook->patchAbove && ip == ((DWORD_PTR)pHook->pTarget - sizeof(JMP_REL)))
170+ return (DWORD_PTR)pHook->pTarget;
171+
172+ for (i = 0; i < pHook->nIP; ++i)
173+ {
174+ if (ip == ((DWORD_PTR)pHook->pTrampoline + pHook->newIPs[i]))
175+ return (DWORD_PTR)pHook->pTarget + pHook->oldIPs[i];
176+ }
177+
178+#ifdef _M_X64
179+ // Check relay function.
180+ if (ip == (DWORD_PTR)pHook->pDetour)
181+ return (DWORD_PTR)pHook->pTarget;
182+#endif
183+
184+ return 0;
185+}
186+
187+//-------------------------------------------------------------------------
188+static DWORD_PTR FindNewIP(PHOOK_ENTRY pHook, DWORD_PTR ip)
189+{
190+ UINT i;
191+ for (i = 0; i < pHook->nIP; ++i)
192+ {
193+ if (ip == ((DWORD_PTR)pHook->pTarget + pHook->oldIPs[i]))
194+ return (DWORD_PTR)pHook->pTrampoline + pHook->newIPs[i];
195+ }
196+
197+ return 0;
198+}
199+
200+//-------------------------------------------------------------------------
201+static void ProcessThreadIPs(HANDLE hThread, UINT pos, UINT action)
202+{
203+ // If the thread suspended in the overwritten area,
204+ // move IP to the proper address.
205+
206+ CONTEXT c;
207+#ifdef _M_X64
208+ DWORD64 *pIP = &c.Rip;
209+#else
210+ DWORD *pIP = &c.Eip;
211+#endif
212+ UINT count;
213+
214+ c.ContextFlags = CONTEXT_CONTROL;
215+ if (!GetThreadContext(hThread, &c))
216+ return;
217+
218+ if (pos == ALL_HOOKS_POS)
219+ {
220+ pos = 0;
221+ count = g_hooks.size;
222+ }
223+ else
224+ {
225+ count = pos + 1;
226+ }
227+
228+ for (; pos < count; ++pos)
229+ {
230+ PHOOK_ENTRY pHook = &g_hooks.pItems[pos];
231+ BOOL enable;
232+ DWORD_PTR ip;
233+
234+ switch (action)
235+ {
236+ case ACTION_DISABLE:
237+ enable = FALSE;
238+ break;
239+
240+ case ACTION_ENABLE:
241+ enable = TRUE;
242+ break;
243+
244+ case ACTION_APPLY_QUEUED:
245+ enable = pHook->queueEnable;
246+ break;
247+ }
248+ if (pHook->isEnabled == enable)
249+ continue;
250+
251+ if (enable)
252+ ip = FindNewIP(pHook, *pIP);
253+ else
254+ ip = FindOldIP(pHook, *pIP);
255+
256+ if (ip != 0)
257+ {
258+ *pIP = ip;
259+ SetThreadContext(hThread, &c);
260+ }
261+ }
262+}
263+
264+//-------------------------------------------------------------------------
265+static VOID EnumerateThreads(PFROZEN_THREADS pThreads)
266+{
267+ HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0);
268+ if (hSnapshot != INVALID_HANDLE_VALUE)
269+ {
270+ THREADENTRY32 te;
271+ te.dwSize = sizeof(THREADENTRY32);
272+ if (Thread32First(hSnapshot, &te))
273+ {
274+ do
275+ {
276+ if (te.dwSize >= (FIELD_OFFSET(THREADENTRY32, th32OwnerProcessID) + sizeof(DWORD))
277+ && te.th32OwnerProcessID == GetCurrentProcessId()
278+ && te.th32ThreadID != GetCurrentThreadId())
279+ {
280+ if (pThreads->pItems == NULL)
281+ {
282+ pThreads->capacity = INITIAL_THREAD_CAPACITY;
283+ pThreads->pItems
284+ = (LPDWORD)HeapAlloc(g_hHeap, 0, pThreads->capacity * sizeof(DWORD));
285+ if (pThreads->pItems == NULL)
286+ break;
287+ }
288+ else if (pThreads->size >= pThreads->capacity)
289+ {
290+ LPDWORD p = (LPDWORD)HeapReAlloc(
291+ g_hHeap, 0, pThreads->pItems, (pThreads->capacity * 2) * sizeof(DWORD));
292+ if (p == NULL)
293+ break;
294+
295+ pThreads->capacity *= 2;
296+ pThreads->pItems = p;
297+ }
298+ pThreads->pItems[pThreads->size++] = te.th32ThreadID;
299+ }
300+
301+ te.dwSize = sizeof(THREADENTRY32);
302+ } while (Thread32Next(hSnapshot, &te));
303+ }
304+ CloseHandle(hSnapshot);
305+ }
306+}
307+
308+//-------------------------------------------------------------------------
309+static VOID Freeze(PFROZEN_THREADS pThreads, UINT pos, UINT action)
310+{
311+ pThreads->pItems = NULL;
312+ pThreads->capacity = 0;
313+ pThreads->size = 0;
314+ EnumerateThreads(pThreads);
315+
316+ if (pThreads->pItems != NULL)
317+ {
318+ UINT i;
319+ for (i = 0; i < pThreads->size; ++i)
320+ {
321+ HANDLE hThread = OpenThread(THREAD_ACCESS, FALSE, pThreads->pItems[i]);
322+ if (hThread != NULL)
323+ {
324+ SuspendThread(hThread);
325+ ProcessThreadIPs(hThread, pos, action);
326+ CloseHandle(hThread);
327+ }
328+ }
329+ }
330+}
331+
332+//-------------------------------------------------------------------------
333+static VOID Unfreeze(PFROZEN_THREADS pThreads)
334+{
335+ if (pThreads->pItems != NULL)
336+ {
337+ UINT i;
338+ for (i = 0; i < pThreads->size; ++i)
339+ {
340+ HANDLE hThread = OpenThread(THREAD_ACCESS, FALSE, pThreads->pItems[i]);
341+ if (hThread != NULL)
342+ {
343+ ResumeThread(hThread);
344+ CloseHandle(hThread);
345+ }
346+ }
347+
348+ HeapFree(g_hHeap, 0, pThreads->pItems);
349+ }
350+}
351+
352+//-------------------------------------------------------------------------
353+static MH_STATUS EnableHookLL(UINT pos, BOOL enable)
354+{
355+ PHOOK_ENTRY pHook = &g_hooks.pItems[pos];
356+ DWORD oldProtect;
357+ SIZE_T patchSize = sizeof(JMP_REL);
358+ LPBYTE pPatchTarget = (LPBYTE)pHook->pTarget;
359+
360+ if (pHook->patchAbove)
361+ {
362+ pPatchTarget -= sizeof(JMP_REL);
363+ patchSize += sizeof(JMP_REL_SHORT);
364+ }
365+
366+ if (!VirtualProtect(pPatchTarget, patchSize, PAGE_EXECUTE_READWRITE, &oldProtect))
367+ return MH_ERROR_MEMORY_PROTECT;
368+
369+ if (enable)
370+ {
371+ PJMP_REL pJmp = (PJMP_REL)pPatchTarget;
372+ pJmp->opcode = 0xE9;
373+ pJmp->operand = (UINT32)((LPBYTE)pHook->pDetour - (pPatchTarget + sizeof(JMP_REL)));
374+
375+ if (pHook->patchAbove)
376+ {
377+ PJMP_REL_SHORT pShortJmp = (PJMP_REL_SHORT)pHook->pTarget;
378+ pShortJmp->opcode = 0xEB;
379+ pShortJmp->operand = (UINT8)(0 - (sizeof(JMP_REL_SHORT) + sizeof(JMP_REL)));
380+ }
381+ }
382+ else
383+ {
384+ if (pHook->patchAbove)
385+ memcpy(pPatchTarget, pHook->backup, sizeof(JMP_REL) + sizeof(JMP_REL_SHORT));
386+ else
387+ memcpy(pPatchTarget, pHook->backup, sizeof(JMP_REL));
388+ }
389+
390+ VirtualProtect(pPatchTarget, patchSize, oldProtect, &oldProtect);
391+
392+ // Just-in-case measure.
393+ FlushInstructionCache(GetCurrentProcess(), pPatchTarget, patchSize);
394+
395+ pHook->isEnabled = enable;
396+ pHook->queueEnable = enable;
397+
398+ return MH_OK;
399+}
400+
401+//-------------------------------------------------------------------------
402+static MH_STATUS EnableAllHooksLL(BOOL enable)
403+{
404+ MH_STATUS status = MH_OK;
405+ UINT i, first = INVALID_HOOK_POS;
406+
407+ for (i = 0; i < g_hooks.size; ++i)
408+ {
409+ if (g_hooks.pItems[i].isEnabled != enable)
410+ {
411+ first = i;
412+ break;
413+ }
414+ }
415+
416+ if (first != INVALID_HOOK_POS)
417+ {
418+ FROZEN_THREADS threads;
419+ Freeze(&threads, ALL_HOOKS_POS, enable ? ACTION_ENABLE : ACTION_DISABLE);
420+
421+ for (i = first; i < g_hooks.size; ++i)
422+ {
423+ if (g_hooks.pItems[i].isEnabled != enable)
424+ {
425+ status = EnableHookLL(i, enable);
426+ if (status != MH_OK)
427+ break;
428+ }
429+ }
430+
431+ Unfreeze(&threads);
432+ }
433+
434+ return status;
435+}
436+
437+//-------------------------------------------------------------------------
438+static VOID EnterSpinLock(VOID)
439+{
440+ SIZE_T spinCount = 0;
441+
442+ // Wait until the flag is FALSE.
443+ while (InterlockedCompareExchange(&g_isLocked, TRUE, FALSE) != FALSE)
444+ {
445+ // Prevent the loop from being too busy.
446+ if (spinCount < 32)
447+ Sleep(0);
448+ else
449+ Sleep(1);
450+
451+ spinCount++;
452+ }
453+}
454+
455+//-------------------------------------------------------------------------
456+static VOID LeaveSpinLock(VOID)
457+{
458+ InterlockedExchange(&g_isLocked, FALSE);
459+}
460+
461+//-------------------------------------------------------------------------
462+MH_STATUS WINAPI MH_Initialize(VOID)
463+{
464+ MH_STATUS status = MH_OK;
465+
466+ EnterSpinLock();
467+
468+ if (g_hHeap == NULL)
469+ {
470+ g_hHeap = HeapCreate(0, 0, 0);
471+ if (g_hHeap != NULL)
472+ {
473+ // Initialize the internal function buffer.
474+ InitializeBuffer();
475+ }
476+ else
477+ {
478+ status = MH_ERROR_MEMORY_ALLOC;
479+ }
480+ }
481+ else
482+ {
483+ status = MH_ERROR_ALREADY_INITIALIZED;
484+ }
485+
486+ LeaveSpinLock();
487+
488+ return status;
489+}
490+
491+//-------------------------------------------------------------------------
492+MH_STATUS WINAPI MH_Uninitialize(VOID)
493+{
494+ MH_STATUS status = MH_OK;
495+
496+ EnterSpinLock();
497+
498+ if (g_hHeap != NULL)
499+ {
500+ status = EnableAllHooksLL(FALSE);
501+ if (status == MH_OK)
502+ {
503+ // Free the internal function buffer.
504+
505+ // HeapFree is actually not required, but some tools detect a false
506+ // memory leak without HeapFree.
507+
508+ UninitializeBuffer();
509+
510+ HeapFree(g_hHeap, 0, g_hooks.pItems);
511+ HeapDestroy(g_hHeap);
512+
513+ g_hHeap = NULL;
514+
515+ g_hooks.pItems = NULL;
516+ g_hooks.capacity = 0;
517+ g_hooks.size = 0;
518+ }
519+ }
520+ else
521+ {
522+ status = MH_ERROR_NOT_INITIALIZED;
523+ }
524+
525+ LeaveSpinLock();
526+
527+ return status;
528+}
529+
530+//-------------------------------------------------------------------------
531+MH_STATUS WINAPI MH_CreateHook(LPVOID pTarget, LPVOID pDetour, LPVOID *ppOriginal)
532+{
533+ MH_STATUS status = MH_OK;
534+
535+ EnterSpinLock();
536+
537+ if (g_hHeap != NULL)
538+ {
539+ if (IsExecutableAddress(pTarget) && IsExecutableAddress(pDetour))
540+ {
541+ UINT pos = FindHookEntry(pTarget);
542+ if (pos == INVALID_HOOK_POS)
543+ {
544+ LPVOID pBuffer = AllocateBuffer(pTarget);
545+ if (pBuffer != NULL)
546+ {
547+ TRAMPOLINE ct;
548+
549+ ct.pTarget = pTarget;
550+ ct.pDetour = pDetour;
551+ ct.pTrampoline = pBuffer;
552+ if (CreateTrampolineFunction(&ct))
553+ {
554+ PHOOK_ENTRY pHook = AddHookEntry();
555+ if (pHook != NULL)
556+ {
557+ pHook->pTarget = ct.pTarget;
558+#ifdef _M_X64
559+ pHook->pDetour = ct.pRelay;
560+#else
561+ pHook->pDetour = ct.pDetour;
562+#endif
563+ pHook->pTrampoline = ct.pTrampoline;
564+ pHook->patchAbove = ct.patchAbove;
565+ pHook->isEnabled = FALSE;
566+ pHook->queueEnable = FALSE;
567+ pHook->nIP = ct.nIP;
568+ memcpy(pHook->oldIPs, ct.oldIPs, ARRAYSIZE(ct.oldIPs));
569+ memcpy(pHook->newIPs, ct.newIPs, ARRAYSIZE(ct.newIPs));
570+
571+ // Back up the target function.
572+
573+ if (ct.patchAbove)
574+ {
575+ memcpy(
576+ pHook->backup,
577+ (LPBYTE)pTarget - sizeof(JMP_REL),
578+ sizeof(JMP_REL) + sizeof(JMP_REL_SHORT));
579+ }
580+ else
581+ {
582+ memcpy(pHook->backup, pTarget, sizeof(JMP_REL));
583+ }
584+
585+ if (ppOriginal != NULL)
586+ *ppOriginal = pHook->pTrampoline;
587+ }
588+ else
589+ {
590+ status = MH_ERROR_MEMORY_ALLOC;
591+ }
592+ }
593+ else
594+ {
595+ status = MH_ERROR_UNSUPPORTED_FUNCTION;
596+ }
597+
598+ if (status != MH_OK)
599+ {
600+ FreeBuffer(pBuffer);
601+ }
602+ }
603+ else
604+ {
605+ status = MH_ERROR_MEMORY_ALLOC;
606+ }
607+ }
608+ else
609+ {
610+ status = MH_ERROR_ALREADY_CREATED;
611+ }
612+ }
613+ else
614+ {
615+ status = MH_ERROR_NOT_EXECUTABLE;
616+ }
617+ }
618+ else
619+ {
620+ status = MH_ERROR_NOT_INITIALIZED;
621+ }
622+
623+ LeaveSpinLock();
624+
625+ return status;
626+}
627+
628+//-------------------------------------------------------------------------
629+MH_STATUS WINAPI MH_RemoveHook(LPVOID pTarget)
630+{
631+ MH_STATUS status = MH_OK;
632+
633+ EnterSpinLock();
634+
635+ if (g_hHeap != NULL)
636+ {
637+ UINT pos = FindHookEntry(pTarget);
638+ if (pos != INVALID_HOOK_POS)
639+ {
640+ if (g_hooks.pItems[pos].isEnabled)
641+ {
642+ FROZEN_THREADS threads;
643+ Freeze(&threads, pos, ACTION_DISABLE);
644+
645+ status = EnableHookLL(pos, FALSE);
646+
647+ Unfreeze(&threads);
648+ }
649+
650+ if (status == MH_OK)
651+ {
652+ FreeBuffer(g_hooks.pItems[pos].pTrampoline);
653+ DeleteHookEntry(pos);
654+ }
655+ }
656+ else
657+ {
658+ status = MH_ERROR_NOT_CREATED;
659+ }
660+ }
661+ else
662+ {
663+ status = MH_ERROR_NOT_INITIALIZED;
664+ }
665+
666+ LeaveSpinLock();
667+
668+ return status;
669+}
670+
671+//-------------------------------------------------------------------------
672+static MH_STATUS EnableHook(LPVOID pTarget, BOOL enable)
673+{
674+ MH_STATUS status = MH_OK;
675+
676+ EnterSpinLock();
677+
678+ if (g_hHeap != NULL)
679+ {
680+ if (pTarget == MH_ALL_HOOKS)
681+ {
682+ status = EnableAllHooksLL(enable);
683+ }
684+ else
685+ {
686+ FROZEN_THREADS threads;
687+ UINT pos = FindHookEntry(pTarget);
688+ if (pos != INVALID_HOOK_POS)
689+ {
690+ if (g_hooks.pItems[pos].isEnabled != enable)
691+ {
692+ Freeze(&threads, pos, ACTION_ENABLE);
693+
694+ status = EnableHookLL(pos, enable);
695+
696+ Unfreeze(&threads);
697+ }
698+ else
699+ {
700+ status = enable ? MH_ERROR_ENABLED : MH_ERROR_DISABLED;
701+ }
702+ }
703+ else
704+ {
705+ status = MH_ERROR_NOT_CREATED;
706+ }
707+ }
708+ }
709+ else
710+ {
711+ status = MH_ERROR_NOT_INITIALIZED;
712+ }
713+
714+ LeaveSpinLock();
715+
716+ return status;
717+}
718+
719+//-------------------------------------------------------------------------
720+MH_STATUS WINAPI MH_EnableHook(LPVOID pTarget)
721+{
722+ return EnableHook(pTarget, TRUE);
723+}
724+
725+//-------------------------------------------------------------------------
726+MH_STATUS WINAPI MH_DisableHook(LPVOID pTarget)
727+{
728+ return EnableHook(pTarget, FALSE);
729+}
730+
731+//-------------------------------------------------------------------------
732+static MH_STATUS QueueHook(LPVOID pTarget, BOOL queueEnable)
733+{
734+ MH_STATUS status = MH_OK;
735+
736+ EnterSpinLock();
737+
738+ if (g_hHeap != NULL)
739+ {
740+ if (pTarget == MH_ALL_HOOKS)
741+ {
742+ UINT i;
743+ for (i = 0; i < g_hooks.size; ++i)
744+ g_hooks.pItems[i].queueEnable = queueEnable;
745+ }
746+ else
747+ {
748+ UINT pos = FindHookEntry(pTarget);
749+ if (pos != INVALID_HOOK_POS)
750+ {
751+ g_hooks.pItems[pos].queueEnable = queueEnable;
752+ }
753+ else
754+ {
755+ status = MH_ERROR_NOT_CREATED;
756+ }
757+ }
758+ }
759+ else
760+ {
761+ status = MH_ERROR_NOT_INITIALIZED;
762+ }
763+
764+ LeaveSpinLock();
765+
766+ return status;
767+}
768+
769+//-------------------------------------------------------------------------
770+MH_STATUS WINAPI MH_QueueEnableHook(LPVOID pTarget)
771+{
772+ return QueueHook(pTarget, TRUE);
773+}
774+
775+//-------------------------------------------------------------------------
776+MH_STATUS WINAPI MH_QueueDisableHook(LPVOID pTarget)
777+{
778+ return QueueHook(pTarget, FALSE);
779+}
780+
781+//-------------------------------------------------------------------------
782+MH_STATUS WINAPI MH_ApplyQueued(VOID)
783+{
784+ MH_STATUS status = MH_OK;
785+ UINT i, first = INVALID_HOOK_POS;
786+
787+ EnterSpinLock();
788+
789+ if (g_hHeap != NULL)
790+ {
791+ for (i = 0; i < g_hooks.size; ++i)
792+ {
793+ if (g_hooks.pItems[i].isEnabled != g_hooks.pItems[i].queueEnable)
794+ {
795+ first = i;
796+ break;
797+ }
798+ }
799+
800+ if (first != INVALID_HOOK_POS)
801+ {
802+ FROZEN_THREADS threads;
803+ Freeze(&threads, ALL_HOOKS_POS, ACTION_APPLY_QUEUED);
804+
805+ for (i = first; i < g_hooks.size; ++i)
806+ {
807+ PHOOK_ENTRY pHook = &g_hooks.pItems[i];
808+ if (pHook->isEnabled != pHook->queueEnable)
809+ {
810+ status = EnableHookLL(i, pHook->queueEnable);
811+ if (status != MH_OK)
812+ break;
813+ }
814+ }
815+
816+ Unfreeze(&threads);
817+ }
818+ }
819+ else
820+ {
821+ status = MH_ERROR_NOT_INITIALIZED;
822+ }
823+
824+ LeaveSpinLock();
825+
826+ return status;
827+}
828+
829+//-------------------------------------------------------------------------
830+MH_STATUS WINAPI MH_CreateHookApi(
831+ LPCWSTR pszModule, LPCSTR pszProcName, LPVOID pDetour, LPVOID *ppOriginal)
832+{
833+ HMODULE hModule;
834+ LPVOID pTarget;
835+
836+ hModule = GetModuleHandleW(pszModule);
837+ if (hModule == NULL)
838+ return MH_ERROR_MODULE_NOT_FOUND;
839+
840+ pTarget = (LPVOID)GetProcAddress(hModule, pszProcName);
841+ if (pTarget == NULL)
842+ return MH_ERROR_FUNCTION_NOT_FOUND;
843+
844+ return MH_CreateHook(pTarget, pDetour, ppOriginal);
845+}
846+
847+//-------------------------------------------------------------------------
848+const char * WINAPI MH_StatusToString(MH_STATUS status)
849+{
850+#define MH_ST2STR(x) \
851+ case x: \
852+ return #x;
853+
854+ switch (status) {
855+ MH_ST2STR(MH_UNKNOWN)
856+ MH_ST2STR(MH_OK)
857+ MH_ST2STR(MH_ERROR_ALREADY_INITIALIZED)
858+ MH_ST2STR(MH_ERROR_NOT_INITIALIZED)
859+ MH_ST2STR(MH_ERROR_ALREADY_CREATED)
860+ MH_ST2STR(MH_ERROR_NOT_CREATED)
861+ MH_ST2STR(MH_ERROR_ENABLED)
862+ MH_ST2STR(MH_ERROR_DISABLED)
863+ MH_ST2STR(MH_ERROR_NOT_EXECUTABLE)
864+ MH_ST2STR(MH_ERROR_UNSUPPORTED_FUNCTION)
865+ MH_ST2STR(MH_ERROR_MEMORY_ALLOC)
866+ MH_ST2STR(MH_ERROR_MEMORY_PROTECT)
867+ MH_ST2STR(MH_ERROR_MODULE_NOT_FOUND)
868+ MH_ST2STR(MH_ERROR_FUNCTION_NOT_FOUND)
869+ }
870+
871+#undef MH_ST2STR
872+
873+ return "(unknown)";
874+}
--- exewrap/trunk/exewrap/src/minhook/src/buffer.c (revision 0)
+++ exewrap/trunk/exewrap/src/minhook/src/buffer.c (revision 22)
@@ -0,0 +1,315 @@
1+/*
2+ * MinHook - The Minimalistic API Hooking Library for x64/x86
3+ * Copyright (C) 2009-2015 Tsuda Kageyu.
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions
8+ * are met:
9+ *
10+ * 1. Redistributions of source code must retain the above copyright
11+ * notice, this list of conditions and the following disclaimer.
12+ * 2. Redistributions in binary form must reproduce the above copyright
13+ * notice, this list of conditions and the following disclaimer in the
14+ * documentation and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
19+ * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
20+ * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
24+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
25+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27+ */
28+
29+#define STRICT
30+#define NOMINMAX
31+#define _WIN32_WINNT 0x0501
32+#include <windows.h>
33+#include "buffer.h"
34+
35+// Size of each memory block. (= page size of VirtualAlloc)
36+#define MEMORY_BLOCK_SIZE 0x1000
37+
38+// Max range for seeking a memory block. (= 1024MB)
39+#define MAX_MEMORY_RANGE 0x40000000
40+
41+// Memory protection flags to check the executable address.
42+#define PAGE_EXECUTE_FLAGS \
43+ (PAGE_EXECUTE | PAGE_EXECUTE_READ | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY)
44+
45+// Memory slot.
46+typedef struct _MEMORY_SLOT
47+{
48+ union
49+ {
50+ struct _MEMORY_SLOT *pNext;
51+ UINT8 buffer[MEMORY_SLOT_SIZE];
52+ };
53+} MEMORY_SLOT, *PMEMORY_SLOT;
54+
55+// Memory block info. Placed at the head of each block.
56+typedef struct _MEMORY_BLOCK
57+{
58+ struct _MEMORY_BLOCK *pNext;
59+ PMEMORY_SLOT pFree; // First element of the free slot list.
60+ UINT usedCount;
61+} MEMORY_BLOCK, *PMEMORY_BLOCK;
62+
63+//-------------------------------------------------------------------------
64+// Global Variables:
65+//-------------------------------------------------------------------------
66+
67+// First element of the memory block list.
68+PMEMORY_BLOCK g_pMemoryBlocks;
69+
70+//-------------------------------------------------------------------------
71+VOID InitializeBuffer(VOID)
72+{
73+ // Nothing to do for now.
74+}
75+
76+//-------------------------------------------------------------------------
77+VOID UninitializeBuffer(VOID)
78+{
79+ PMEMORY_BLOCK pBlock = g_pMemoryBlocks;
80+ g_pMemoryBlocks = NULL;
81+
82+ while (pBlock)
83+ {
84+ PMEMORY_BLOCK pNext = pBlock->pNext;
85+ VirtualFree(pBlock, 0, MEM_RELEASE);
86+ pBlock = pNext;
87+ }
88+}
89+
90+//-------------------------------------------------------------------------
91+#ifdef _M_X64
92+static LPVOID FindPrevFreeRegion(LPVOID pAddress, LPVOID pMinAddr, DWORD dwAllocationGranularity)
93+{
94+ ULONG_PTR tryAddr = (ULONG_PTR)pAddress;
95+
96+ // Round down to the next allocation granularity.
97+ tryAddr -= tryAddr % dwAllocationGranularity;
98+
99+ // Start from the previous allocation granularity multiply.
100+ tryAddr -= dwAllocationGranularity;
101+
102+ while (tryAddr >= (ULONG_PTR)pMinAddr)
103+ {
104+ MEMORY_BASIC_INFORMATION mbi;
105+ if (VirtualQuery((LPVOID)tryAddr, &mbi, sizeof(MEMORY_BASIC_INFORMATION)) == 0)
106+ break;
107+
108+ if (mbi.State == MEM_FREE)
109+ return (LPVOID)tryAddr;
110+
111+ if ((ULONG_PTR)mbi.AllocationBase < dwAllocationGranularity)
112+ break;
113+
114+ tryAddr = (ULONG_PTR)mbi.AllocationBase - dwAllocationGranularity;
115+ }
116+
117+ return NULL;
118+}
119+#endif
120+
121+//-------------------------------------------------------------------------
122+#ifdef _M_X64
123+static LPVOID FindNextFreeRegion(LPVOID pAddress, LPVOID pMaxAddr, DWORD dwAllocationGranularity)
124+{
125+ ULONG_PTR tryAddr = (ULONG_PTR)pAddress;
126+
127+ // Round down to the next allocation granularity.
128+ tryAddr -= tryAddr % dwAllocationGranularity;
129+
130+ // Start from the next allocation granularity multiply.
131+ tryAddr += dwAllocationGranularity;
132+
133+ while (tryAddr <= (ULONG_PTR)pMaxAddr)
134+ {
135+ MEMORY_BASIC_INFORMATION mbi;
136+ if (VirtualQuery((LPVOID)tryAddr, &mbi, sizeof(MEMORY_BASIC_INFORMATION)) == 0)
137+ break;
138+
139+ if (mbi.State == MEM_FREE)
140+ return (LPVOID)tryAddr;
141+
142+ tryAddr = (ULONG_PTR)mbi.BaseAddress + mbi.RegionSize;
143+
144+ // Round up to the next allocation granularity.
145+ tryAddr += dwAllocationGranularity - 1;
146+ tryAddr -= tryAddr % dwAllocationGranularity;
147+ }
148+
149+ return NULL;
150+}
151+#endif
152+
153+//-------------------------------------------------------------------------
154+static PMEMORY_BLOCK GetMemoryBlock(LPVOID pOrigin)
155+{
156+ PMEMORY_BLOCK pBlock;
157+#ifdef _M_X64
158+ ULONG_PTR minAddr;
159+ ULONG_PTR maxAddr;
160+
161+ SYSTEM_INFO si;
162+ GetSystemInfo(&si);
163+ minAddr = (ULONG_PTR)si.lpMinimumApplicationAddress;
164+ maxAddr = (ULONG_PTR)si.lpMaximumApplicationAddress;
165+
166+ // pOrigin ± 512MB
167+ if ((ULONG_PTR)pOrigin > MAX_MEMORY_RANGE && minAddr < (ULONG_PTR)pOrigin - MAX_MEMORY_RANGE)
168+ minAddr = (ULONG_PTR)pOrigin - MAX_MEMORY_RANGE;
169+
170+ if (maxAddr > (ULONG_PTR)pOrigin + MAX_MEMORY_RANGE)
171+ maxAddr = (ULONG_PTR)pOrigin + MAX_MEMORY_RANGE;
172+
173+ // Make room for MEMORY_BLOCK_SIZE bytes.
174+ maxAddr -= MEMORY_BLOCK_SIZE - 1;
175+#endif
176+
177+ // Look the registered blocks for a reachable one.
178+ for (pBlock = g_pMemoryBlocks; pBlock != NULL; pBlock = pBlock->pNext)
179+ {
180+#ifdef _M_X64
181+ // Ignore the blocks too far.
182+ if ((ULONG_PTR)pBlock < minAddr || (ULONG_PTR)pBlock >= maxAddr)
183+ continue;
184+#endif
185+ // The block has at least one unused slot.
186+ if (pBlock->pFree != NULL)
187+ return pBlock;
188+ }
189+
190+#ifdef _M_X64
191+ // Alloc a new block above if not found.
192+ {
193+ LPVOID pAlloc = pOrigin;
194+ while ((ULONG_PTR)pAlloc >= minAddr)
195+ {
196+ pAlloc = FindPrevFreeRegion(pAlloc, (LPVOID)minAddr, si.dwAllocationGranularity);
197+ if (pAlloc == NULL)
198+ break;
199+
200+ pBlock = (PMEMORY_BLOCK)VirtualAlloc(
201+ pAlloc, MEMORY_BLOCK_SIZE, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
202+ if (pBlock != NULL)
203+ break;
204+ }
205+ }
206+
207+ // Alloc a new block below if not found.
208+ if (pBlock == NULL)
209+ {
210+ LPVOID pAlloc = pOrigin;
211+ while ((ULONG_PTR)pAlloc <= maxAddr)
212+ {
213+ pAlloc = FindNextFreeRegion(pAlloc, (LPVOID)maxAddr, si.dwAllocationGranularity);
214+ if (pAlloc == NULL)
215+ break;
216+
217+ pBlock = (PMEMORY_BLOCK)VirtualAlloc(
218+ pAlloc, MEMORY_BLOCK_SIZE, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
219+ if (pBlock != NULL)
220+ break;
221+ }
222+ }
223+#else
224+ // In x86 mode, a memory block can be placed anywhere.
225+ pBlock = (PMEMORY_BLOCK)VirtualAlloc(
226+ NULL, MEMORY_BLOCK_SIZE, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
227+#endif
228+
229+ if (pBlock != NULL)
230+ {
231+ // Build a linked list of all the slots.
232+ PMEMORY_SLOT pSlot = (PMEMORY_SLOT)pBlock + 1;
233+ pBlock->pFree = NULL;
234+ pBlock->usedCount = 0;
235+ do
236+ {
237+ pSlot->pNext = pBlock->pFree;
238+ pBlock->pFree = pSlot;
239+ pSlot++;
240+ } while ((ULONG_PTR)pSlot - (ULONG_PTR)pBlock <= MEMORY_BLOCK_SIZE - MEMORY_SLOT_SIZE);
241+
242+ pBlock->pNext = g_pMemoryBlocks;
243+ g_pMemoryBlocks = pBlock;
244+ }
245+
246+ return pBlock;
247+}
248+
249+//-------------------------------------------------------------------------
250+LPVOID AllocateBuffer(LPVOID pOrigin)
251+{
252+ PMEMORY_SLOT pSlot;
253+ PMEMORY_BLOCK pBlock = GetMemoryBlock(pOrigin);
254+ if (pBlock == NULL)
255+ return NULL;
256+
257+ // Remove an unused slot from the list.
258+ pSlot = pBlock->pFree;
259+ pBlock->pFree = pSlot->pNext;
260+ pBlock->usedCount++;
261+#ifdef _DEBUG
262+ // Fill the slot with INT3 for debugging.
263+ memset(pSlot, 0xCC, sizeof(MEMORY_SLOT));
264+#endif
265+ return pSlot;
266+}
267+
268+//-------------------------------------------------------------------------
269+VOID FreeBuffer(LPVOID pBuffer)
270+{
271+ PMEMORY_BLOCK pBlock = g_pMemoryBlocks;
272+ PMEMORY_BLOCK pPrev = NULL;
273+ ULONG_PTR pTargetBlock = ((ULONG_PTR)pBuffer / MEMORY_BLOCK_SIZE) * MEMORY_BLOCK_SIZE;
274+
275+ while (pBlock != NULL)
276+ {
277+ if ((ULONG_PTR)pBlock == pTargetBlock)
278+ {
279+ PMEMORY_SLOT pSlot = (PMEMORY_SLOT)pBuffer;
280+#ifdef _DEBUG
281+ // Clear the released slot for debugging.
282+ memset(pSlot, 0x00, sizeof(MEMORY_SLOT));
283+#endif
284+ // Restore the released slot to the list.
285+ pSlot->pNext = pBlock->pFree;
286+ pBlock->pFree = pSlot;
287+ pBlock->usedCount--;
288+
289+ // Free if unused.
290+ if (pBlock->usedCount == 0)
291+ {
292+ if (pPrev)
293+ pPrev->pNext = pBlock->pNext;
294+ else
295+ g_pMemoryBlocks = pBlock->pNext;
296+
297+ VirtualFree(pBlock, 0, MEM_RELEASE);
298+ }
299+
300+ break;
301+ }
302+
303+ pPrev = pBlock;
304+ pBlock = pBlock->pNext;
305+ }
306+}
307+
308+//-------------------------------------------------------------------------
309+BOOL IsExecutableAddress(LPVOID pAddress)
310+{
311+ MEMORY_BASIC_INFORMATION mi;
312+ VirtualQuery(pAddress, &mi, sizeof(MEMORY_BASIC_INFORMATION));
313+
314+ return (mi.State == MEM_COMMIT && (mi.Protect & PAGE_EXECUTE_FLAGS));
315+}
--- exewrap/trunk/exewrap/src/minhook/README.md (revision 0)
+++ exewrap/trunk/exewrap/src/minhook/README.md (revision 22)
@@ -0,0 +1,72 @@
1+# MinHook
2+
3+The Minimalistic x86/x64 API Hooking Library for Windows
4+
5+http://www.codeproject.com/KB/winsdk/LibMinHook.aspx
6+
7+### Donation please
8+
9+Need some funds to continue developing this library. All contributions gratefully accepted.
10+
11+<a href='https://pledgie.com/campaigns/27314'><img alt='Click here to lend your support to: MinHook - Help me continue to develop this library and make a donation at pledgie.com !' src='https://pledgie.com/campaigns/27314.png?skin_name=chrome' border='0' ></a>
12+
13+### Version history
14+
15+- ####v1.3.2-beta3
16+ * Support MinGW. (Experimental)
17+
18+- ####v1.3.2-beta2 - 18 May 2015
19+ * Fixed some subtle bugs. (Thanks to RaMMicHaeL)
20+ * Added a helper function ```MH_StatusToString```. (Thanks to Jan Klass)
21+
22+- ####v1.3.2-beta - 12 May 2015
23+ * Fixed a possible thread deadlock in x64 mode. (Thanks to Aleh Kazakevich)
24+ * Reduced the footprint a little more.
25+ * Support Visual Studio 2015 RC. (Experimental)
26+
27+- ####v1.3.1 - 19 Mar 2015
28+ * No major changes from v1.3.1-beta.
29+
30+- ####v1.3.1-beta - 11 Mar 2015
31+ * Added a helper function ```MH_CreateHookApi```. (Thanks to uniskz).
32+ * Fixed a false memory leak reported by some tools.
33+ * Fixed a degradated compatibility issue.
34+
35+- ####v1.3 - 13 Sep 2014
36+ * No major changes from v1.3-beta3.
37+
38+- ####v1.3-beta3 - 31 Jul 2014
39+
40+ * Fixed some small bugs.
41+ * Improved the memory management.
42+
43+- ####v1.3-beta2 - 21 Jul 2014
44+
45+ * Changed the parameters to Windows-friendly types. (void* to LPVOID)
46+ * Fixed some small bugs.
47+ * Reorganized the source files.
48+ * Reduced the footprint a little more.
49+
50+- ####v1.3-beta - 17 Jul 2014
51+
52+ * Rewrote in plain C to reduce the footprint and memory usage. (suggested by Andrey Unis)
53+ * Simplified the overall code base to make it more readable and maintainable.
54+ * Changed the license from 3-clause to 2-clause BSD License.
55+
56+- ####v1.2 - 28 Sep 2013
57+
58+ * Removed boost dependency ([jarredholman](https://github.com/jarredholman/minhook)).
59+ * Fixed a small bug in the GetRelativeBranchDestination function ([pillbug99](http://www.codeproject.com/Messages/4058892/Small-Bug-Found.aspx)).
60+ * Added the ```MH_RemoveHook``` function, which removes a hook created with the ```MH_CreateHook``` function.
61+ * Added the following functions to enable or disable multiple hooks in one go: ```MH_QueueEnableHook```, ```MH_QueueDisableHook```, ```MH_ApplyQueued```. This is the preferred way of handling multiple hooks as every call to `MH_EnableHook` or `MH_DisableHook` suspends and resumes all threads.
62+ * Made the functions ```MH_EnableHook``` and ```MH_DisableHook``` enable/disable all created hooks when the ```MH_ALL_HOOKS``` parameter is passed. This, too, is an efficient way of handling multiple hooks.
63+ * If the target function is too small to be patched with a jump, MinHook tries to place the jump above the function. If that fails as well, the ```MH_CreateHook``` function returns ```MH_ERROR_UNSUPPORTED_FUNCTION```. This fixes an issue of hooking the LoadLibraryExW function on Windows 7 x64 ([reported by Obble](http://www.codeproject.com/Messages/4578613/Re-Bug-LoadLibraryExW-hook-fails-on-windows-2008-r.aspx)).
64+
65+- ####v1.1 - 26 Nov 2009
66+
67+ * Changed the interface to create a hook and a trampoline function in one go to prevent the detour function from being called before the trampoline function is created. ([reported by xliqz](http://www.codeproject.com/Messages/3280374/Unsafe.aspx))
68+ * Shortened the function names from ```MinHook_*``` to ```MH_*``` to make them handier.
69+
70+- ####v1.0 - 22 Nov 2009
71+
72+ * Initial release.
--- exewrap/trunk/exewrap/src/message.c (revision 21)
+++ exewrap/trunk/exewrap/src/message.c (revision 22)
@@ -103,6 +103,9 @@
103103 msg[MSG_ID_COUNT * MSG_LANG_ID_EN + MSG_ID_ERR_LOAD_MAIN_CLASS] =
104104 "Failed to load the Main Class.";
105105
106+ msg[MSG_ID_COUNT * MSG_LANG_ID_EN + MSG_ID_ERR_FIND_MAIN_CLASS] =
107+ "Main class not found.";
108+
106109 msg[MSG_ID_COUNT * MSG_LANG_ID_EN + MSG_ID_ERR_FIND_MAIN_METHOD] =
107110 "Main method is not implemented.";
108111
@@ -200,6 +203,9 @@
200203 msg[MSG_ID_COUNT * MSG_LANG_ID_JA + MSG_ID_ERR_LOAD_MAIN_CLASS] =
201204 "メインクラスのロードに失敗しました。";
202205
206+ msg[MSG_ID_COUNT * MSG_LANG_ID_JA + MSG_ID_ERR_FIND_MAIN_CLASS] =
207+ "メインクラスが見つかりません。";
208+
203209 msg[MSG_ID_COUNT * MSG_LANG_ID_JA + MSG_ID_ERR_FIND_MAIN_METHOD] =
204210 "mainメソッドが実装されていません。";
205211
Show on old repository browser