• R/O
  • SSH
  • HTTPS

exewrap: Commit


Commit MetaInfo

Revision39 (tree)
Time2017-10-14 18:42:08
Authorhirukawa_ryo

Log Message

* exewrap 1.2.0
リフレクションを使わずにExewrapClassLoaderをシステムクラスローダーに設定できるようにしました。

Exewrap関連クラスを保持するJARファイルを生成ファイルの末尾に連結するようにしました。
これにより生成ファイルはEXEとしてだけでなくJARとしても扱えるようになりました。
classpathに自身のEXEを指定することで既定のシステムクラスローダーでExewrap関連クラスをロードできるようになったことで
-Djava.system.class.loader でExewrapClassLoaderを指定可能となりました。

トレース、JREMIN関連コードを削除しました。

Change Summary

Incremental Difference

--- exewrap/trunk/exewrap/src/trace.c (revision 38)
+++ exewrap/trunk/exewrap/src/trace.c (revision 39)
@@ -1,423 +0,0 @@
1-#define _CRT_SECURE_NO_WARNINGS
2-
3-#include <Windows.h>
4-#include <stdio.h>
5-#include <string.h>
6-#include "minhook\include\MinHook.h"
7-
8-#define BUFFER_SIZE 1024
9-
10-const char* StartTrace();
11-void StopTrace();
12-
13-static char* _w2a(LPCWSTR s);
14-
15-static char* filename1 = NULL;
16-static char* filename2 = NULL;
17-static HANDLE hStdOut = NULL;
18-static FILE* fpStdOut = NULL;
19-static FILE* fp = NULL;
20-
21-typedef HANDLE(WINAPI *CREATEFILEA)(LPCSTR, DWORD, DWORD, LPSECURITY_ATTRIBUTES, DWORD, DWORD, HANDLE);
22-typedef HANDLE(WINAPI *CREATEFILEW)(LPCWSTR, DWORD, DWORD, LPSECURITY_ATTRIBUTES, DWORD, DWORD, HANDLE);
23-typedef HMODULE(WINAPI *LOADLIBRARYA)(LPCSTR);
24-typedef HMODULE(WINAPI *LOADLIBRARYW)(LPCWSTR);
25-typedef HMODULE(WINAPI *LOADLIBRARYEXA)(LPCSTR, HANDLE, DWORD);
26-typedef HMODULE(WINAPI *LOADLIBRARYEXW)(LPCWSTR, HANDLE, DWORD);
27-
28-CREATEFILEA fpCreateFileA = NULL;
29-CREATEFILEW fpCreateFileW = NULL;
30-LOADLIBRARYA fpLoadLibraryA = NULL;
31-LOADLIBRARYW fpLoadLibraryW = NULL;
32-LOADLIBRARYEXA fpLoadLibraryExA = NULL;
33-LOADLIBRARYEXW fpLoadLibraryExW = NULL;
34-
35-HANDLE WINAPI DetourCreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile);
36-HANDLE WINAPI DetourCreateFileW(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile);
37-HMODULE WINAPI DetourLoadLibraryA(LPCSTR lpLibFileName);
38-HMODULE WINAPI DetourLoadLibraryW(LPCWSTR lpLibFileName);
39-HMODULE WINAPI DetourLoadLibraryExA(LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags);
40-HMODULE WINAPI DetourLoadLibraryExW(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags);
41-
42-static void print(LPCSTR type, LPCSTR full_path_name);
43-static LPSTR is_file_in_JRE(LPCSTR lpFileName);
44-
45-const char* StartTrace(BOOL replace_stdout)
46-{
47- BOOL succeeded = FALSE;
48-
49- filename1 = (char*)malloc(1024);
50- GetModuleFileName(NULL, filename1, 1024);
51- *strrchr(filename1, '.') = '\0';
52- strcat(filename1, ".log");
53-
54- if (replace_stdout)
55- {
56- hStdOut = CreateFile(filename1, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
57- if (hStdOut == INVALID_HANDLE_VALUE)
58- {
59- goto EXIT;
60- }
61-
62- fpStdOut = freopen(filename1, "wb", stdout);
63- if (fpStdOut == NULL)
64- {
65- goto EXIT;
66- }
67- }
68- else
69- {
70- filename2 = (char*)malloc(1024);
71- strcpy(filename2, filename1);
72- *strrchr(filename2, '.') = '\0';
73- strcat(filename2, "2.log");
74- fp = fopen(filename2, "wb");
75- }
76-
77- if (MH_Initialize() != MH_OK)
78- {
79- goto EXIT;
80- }
81-
82- if (MH_CreateHook(&CreateFileA, &DetourCreateFileA, (LPVOID*)(&fpCreateFileA)) != MH_OK)
83- {
84- goto EXIT;
85- }
86- if (MH_EnableHook(&CreateFileA) != MH_OK)
87- {
88- goto EXIT;
89- }
90-
91- if (MH_CreateHook(&CreateFileW, &DetourCreateFileW, (LPVOID*)(&fpCreateFileW)) != MH_OK)
92- {
93- goto EXIT;
94- }
95- if (MH_EnableHook(&CreateFileW) != MH_OK)
96- {
97- goto EXIT;
98- }
99-
100- if (MH_CreateHook(&LoadLibraryA, &DetourLoadLibraryA, (LPVOID*)(&fpLoadLibraryA)) != MH_OK)
101- {
102- goto EXIT;
103- }
104- if (MH_EnableHook(&LoadLibraryA) != MH_OK)
105- {
106- goto EXIT;
107- }
108-
109- if (MH_CreateHook(&LoadLibraryW, &DetourLoadLibraryW, (LPVOID*)(&fpLoadLibraryW)) != MH_OK)
110- {
111- goto EXIT;
112- }
113- if (MH_EnableHook(&LoadLibraryW) != MH_OK)
114- {
115- goto EXIT;
116- }
117-
118- if (MH_CreateHook(&LoadLibraryExA, &DetourLoadLibraryExA, (LPVOID*)(&fpLoadLibraryExA)) != MH_OK)
119- {
120- goto EXIT;
121- }
122- if (MH_EnableHook(&LoadLibraryExA) != MH_OK)
123- {
124- goto EXIT;
125- }
126-
127- if (MH_CreateHook(&LoadLibraryExW, &DetourLoadLibraryExW, (LPVOID*)(&fpLoadLibraryExW)) != MH_OK)
128- {
129- goto EXIT;
130- }
131- if (MH_EnableHook(&LoadLibraryExW) != MH_OK)
132- {
133- goto EXIT;
134- }
135-
136- succeeded = TRUE;
137-
138-EXIT:
139- if (!succeeded)
140- {
141- free(filename1);
142- filename1 = NULL;
143- }
144- return filename1;
145-}
146-
147-
148-void StopTrace()
149-{
150- if (MH_DisableHook(&LoadLibraryW) != MH_OK)
151- {
152- }
153-
154- if (MH_DisableHook(&CreateFileW) != MH_OK)
155- {
156- }
157-
158- if (MH_Uninitialize() != MH_OK)
159- {
160- }
161-
162- if (hStdOut != NULL && hStdOut != INVALID_HANDLE_VALUE)
163- {
164- FlushFileBuffers(hStdOut);
165- CloseHandle(hStdOut);
166- }
167- hStdOut = NULL;
168-
169- if (fpStdOut != NULL)
170- {
171- fflush(fpStdOut);
172- fclose(fpStdOut);
173- }
174- fpStdOut = NULL;
175-
176- if (fp != NULL)
177- {
178- fclose(fp);
179- }
180- fp = NULL;
181-
182- if (filename2 != NULL)
183- {
184- free(filename2);
185- }
186-
187- if (filename1 != NULL)
188- {
189- free(filename1);
190- }
191-}
192-
193-
194-static void print(LPCSTR type, LPCSTR full_path_name)
195-{
196- if (fpStdOut != NULL)
197- {
198- printf("[%s %s]\n", type, full_path_name);
199- fflush(stdout);
200- }
201- else if (fp != NULL)
202- {
203- fprintf(fp, "[%s %s]\n", type, full_path_name);
204- fflush(fp);
205- }
206-}
207-
208-
209-static LPSTR is_file_in_JRE(LPCSTR lpFileName)
210-{
211- BOOL b = FALSE;
212- LPSTR buf = NULL;
213- LPSTR java_home = NULL;
214- LPSTR full_path_name = NULL;
215- DWORD size1;
216- DWORD size2;
217- LPSTR ptr;
218-
219- buf = (LPSTR)malloc(BUFFER_SIZE);
220- size1 = GetEnvironmentVariableA("JAVA_HOME", buf, BUFFER_SIZE);
221- if (size1 > 0)
222- {
223- java_home = (LPSTR)malloc(BUFFER_SIZE);
224- size1 = GetFullPathNameA(buf, BUFFER_SIZE, java_home, &ptr);
225- if (size1 > 0)
226- {
227- full_path_name = (LPSTR)malloc(BUFFER_SIZE);
228- size2 = GetFullPathNameA(lpFileName, BUFFER_SIZE, full_path_name, &ptr);
229- if (size2 > 0)
230- {
231- if (_memicmp(java_home, full_path_name, size1) == 0)
232- {
233- b = TRUE;
234- }
235- }
236- }
237- }
238-
239- if (buf != NULL)
240- {
241- free(buf);
242- }
243- if (java_home != NULL)
244- {
245- free(java_home);
246- }
247- if (!b && full_path_name != NULL)
248- {
249- free(full_path_name);
250- full_path_name = NULL;
251- }
252- return full_path_name;
253-}
254-
255-
256-HANDLE WINAPI DetourCreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
257-{
258- LPSTR full_path_name;
259-
260- full_path_name = is_file_in_JRE(lpFileName);
261- if (full_path_name != NULL)
262- {
263- print("CreateFile", full_path_name);
264- free(full_path_name);
265- }
266-
267- return fpCreateFileA(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
268-}
269-
270-
271-HANDLE WINAPI DetourCreateFileW(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
272-{
273- LPSTR lpFileNameA = _w2a(lpFileName);
274- LPSTR full_path_name;
275-
276- full_path_name = is_file_in_JRE(lpFileNameA);
277- if (full_path_name != NULL)
278- {
279- print("CreateFile", full_path_name);
280- free(full_path_name);
281- }
282- free(lpFileNameA);
283-
284- return fpCreateFileW(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
285-}
286-
287-
288-HMODULE WINAPI DetourLoadLibraryA(LPCSTR lpLibFileName)
289-{
290- HMODULE hModule;
291- LPSTR buf = (LPSTR)malloc(BUFFER_SIZE);
292- LPSTR full_path_name = NULL;
293-
294- hModule = fpLoadLibraryA(lpLibFileName);
295- if (hModule != NULL)
296- {
297- if (GetModuleFileNameA(hModule, buf, BUFFER_SIZE) > 0)
298- {
299- full_path_name = is_file_in_JRE(buf);
300- if (full_path_name != NULL)
301- {
302- print("LoadLibrary", full_path_name);
303- }
304- }
305- }
306-
307- if (full_path_name != NULL)
308- {
309- free(full_path_name);
310- }
311- free(buf);
312-
313- return hModule;
314-}
315-
316-
317-HMODULE WINAPI DetourLoadLibraryW(LPCWSTR lpLibFileName)
318-{
319- HMODULE hModule;
320- LPSTR buf = (LPSTR)malloc(BUFFER_SIZE);
321- LPSTR full_path_name = NULL;
322-
323- hModule = fpLoadLibraryW(lpLibFileName);
324- if (hModule != NULL)
325- {
326- if (GetModuleFileName(hModule, buf, BUFFER_SIZE) > 0)
327- {
328- full_path_name = is_file_in_JRE(buf);
329- if (full_path_name != NULL)
330- {
331- print("LoadLibrary", full_path_name);
332- }
333- }
334- }
335-
336- if (full_path_name != NULL)
337- {
338- free(full_path_name);
339- }
340- free(buf);
341-
342- return hModule;
343-}
344-
345-
346-HMODULE WINAPI DetourLoadLibraryExA(LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
347-{
348- HMODULE hModule;
349- LPSTR buf = (LPSTR)malloc(BUFFER_SIZE);
350- LPSTR full_path_name = NULL;
351-
352- hModule = fpLoadLibraryExA(lpLibFileName, hFile, dwFlags);
353- if (hModule != NULL)
354- {
355- if (GetModuleFileNameA(hModule, buf, BUFFER_SIZE) > 0)
356- {
357- full_path_name = is_file_in_JRE(buf);
358- if (full_path_name != NULL)
359- {
360- print("LoadLibrary", full_path_name);
361- }
362- }
363- }
364-
365- if (full_path_name != NULL)
366- {
367- free(full_path_name);
368- }
369- free(buf);
370-
371- return hModule;
372-}
373-
374-
375-HMODULE WINAPI DetourLoadLibraryExW(LPCWSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
376-{
377- HMODULE hModule;
378- LPSTR buf = (LPSTR)malloc(BUFFER_SIZE);
379- LPSTR full_path_name = NULL;
380-
381- hModule = fpLoadLibraryExW(lpLibFileName, hFile, dwFlags);
382- if (hModule != NULL)
383- {
384- if (GetModuleFileNameA(hModule, buf, BUFFER_SIZE) > 0)
385- {
386- full_path_name = is_file_in_JRE(buf);
387- if (full_path_name != NULL)
388- {
389- print("LoadLibrary", full_path_name);
390- }
391- }
392- }
393-
394- if (full_path_name != NULL)
395- {
396- free(full_path_name);
397- }
398- free(buf);
399-
400- return hModule;
401-}
402-
403-static char* _w2a(LPCWSTR s)
404-{
405- char* buf;
406- int ret;
407-
408- ret = WideCharToMultiByte(CP_ACP, 0, s, -1, NULL, 0, NULL, NULL);
409- if (ret <= 0)
410- {
411- return NULL;
412- }
413- buf = (LPSTR)malloc(ret + 1);
414- ret = WideCharToMultiByte(CP_ACP, 0, s, -1, buf, (ret + 1), NULL, NULL);
415- if (ret == 0)
416- {
417- free(buf);
418- return NULL;
419- }
420- buf[ret] = '\0';
421-
422- return buf;
423-}
--- exewrap/trunk/exewrap/src/minhook/README.md (revision 38)
+++ exewrap/trunk/exewrap/src/minhook/README.md (revision 39)
@@ -1,72 +0,0 @@
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/minhook/WindowsSDK/include/winapifamily.h (revision 38)
+++ exewrap/trunk/exewrap/src/minhook/WindowsSDK/include/winapifamily.h (revision 39)
@@ -1,240 +0,0 @@
1-/*
2-
3-Copyright (c) Microsoft Corporation. All rights reserved.
4-
5-Module Name:
6-
7- winapifamily.h
8-
9-Abstract:
10-
11- Master include file for API family partitioning.
12-
13-*/
14-
15-#ifndef _INC_WINAPIFAMILY
16-#define _INC_WINAPIFAMILY
17-
18-#if defined(_MSC_VER) && !defined(MOFCOMP_PASS)
19-#if _MSC_VER >= 1200
20-#pragma warning(push)
21-#pragma warning(disable:4001) /* nonstandard extension 'single line comment' was used */
22-#endif
23-#pragma once
24-#endif // defined(_MSC_VER) && !defined(MOFCOMP_PASS)
25-
26-#include <winpackagefamily.h>
27-
28-/*
29- * When compiling C and C++ code using SDK header files, the development
30- * environment can specify a target platform by #define-ing the
31- * pre-processor symbol WINAPI_FAMILY to one of the following values.
32- * Each FAMILY value denotes an application family for which a different
33- * subset of the total set of header-file-defined APIs are available.
34- * Setting the WINAPI_FAMILY value will effectively hide from the
35- * editing and compilation environments the existence of APIs that
36- * are not applicable to the family of applications targeting a
37- * specific platform.
38- */
39-
40-/* In Windows 10, WINAPI_PARTITIONs will be used to add additional
41- * device specific APIs to a particular WINAPI_FAMILY.
42- * For example, when writing Windows Universal apps, specifying
43- * WINAPI_FAMILY_APP will hide phone APIs from compilation.
44- * However, specifying WINAPI_PARTITION_PHONE_APP=1 additionally, will
45- * unhide any API hidden behind the partition, to the compiler.
46-
47- * The following partitions are currently defined:
48- * WINAPI_PARTITION_DESKTOP // usable for Desktop Win32 apps (but not store apps)
49- * WINAPI_PARTITION_APP // usable for Windows Universal store apps
50- * WINAPI_PARTITION_PC_APP // specific to Desktop-only store apps
51- * WINAPI_PARTITION_PHONE_APP // specific to Phone-only store apps
52- * WINAPI_PARTITION_SYSTEM // specific to System applications
53-
54- * The following partitions are indirect partitions and defined in
55- * winpackagefamily.h. These partitions are related to package based
56- * partitions. For example, specifying WINAPI_PARTITION_SERVER=1 will light up
57- * any API hidden behind the package based partitions that are bound to
58- * WINAPI_PARTITION_SERVER, to the compiler.
59- * WINAPI_PARTITION_SERVER // specific to Server applications
60-*/
61-
62-/*
63- * The WINAPI_FAMILY values of 0 and 1 are reserved to ensure that
64- * an error will occur if WINAPI_FAMILY is set to any
65- * WINAPI_PARTITION value (which must be 0 or 1, see below).
66- */
67-#define WINAPI_FAMILY_PC_APP 2 /* Windows Store Applications */
68-#define WINAPI_FAMILY_PHONE_APP 3 /* Windows Phone Applications */
69-#define WINAPI_FAMILY_SYSTEM 4 /* Windows Drivers and Tools */
70-#define WINAPI_FAMILY_SERVER 5 /* Windows Server Applications */
71-#define WINAPI_FAMILY_DESKTOP_APP 100 /* Windows Desktop Applications */
72-/* The value of WINAPI_FAMILY_DESKTOP_APP may change in future SDKs. */
73-/* Additional WINAPI_FAMILY values may be defined in future SDKs. */
74-
75-/*
76- * For compatibility with Windows 8 header files, the following
77- * synonym for WINAPI_FAMILY_PC_APP is temporarily #define'd.
78- * Use of this symbol should be considered deprecated.
79- */
80-#define WINAPI_FAMILY_APP WINAPI_FAMILY_PC_APP
81-
82-/*
83- * If no WINAPI_FAMILY value is specified, then all APIs available to
84- * Windows desktop applications are exposed.
85- */
86-#ifndef WINAPI_FAMILY
87-#define WINAPI_FAMILY WINAPI_FAMILY_DESKTOP_APP
88-#endif
89-
90-/*
91- * API PARTITONs are part of an indirection mechanism for mapping between
92- * individual APIs and the FAMILYs to which they apply.
93- * Each PARTITION is a category or subset of named APIs. PARTITIONs
94- * are permitted to have overlapping membership -- some single API
95- * might be part of more than one PARTITION. PARTITIONS are each #define-ed
96- * to be either 1 or 0 or depending on the platform at which the app is targeted.
97- */
98-
99-/*
100- * The mapping between families and partitions is summarized here.
101- * An X indicates that the given partition is active for the given
102- * platform/family.
103- *
104- * +-------------------+---+
105- * | *Partition* | |
106- * +---+---+---+---+---+---+
107- * | | | | | | |
108- * | | | | | | |
109- * | | | | P | | |
110- * | | | | H | | |
111- * | D | | | O | | |
112- * | E | | P | N | S | S |
113- * | S | | C | E | Y | E |
114- * | K | | _ | _ | S | R |
115- * | T | A | A | A | T | V |
116- * +-------------------------+----+ O | P | P | P | E | E |
117- * | *Platform/Family* \| P | P | P | P | M | R |
118- * +------------------------------+---+---+---+---+---+---+
119- * | WINAPI_FAMILY_DESKTOP_APP | X | X | X | | | |
120- * +------------------------------+---+---+---+---+---+---+
121- * | WINAPI_FAMILY_PC_APP | | X | X | | | |
122- * +------------------------------+---+---+---+---+---+---+
123- * | WINAPI_FAMILY_PHONE_APP | | X | | X | | |
124- * +----------------------------- +---+---+---+---+---+---+
125- * | WINAPI_FAMILY_SYSTEM | | | | | X | |
126- * +----------------------------- +---+---+---+---+---+---+
127- * | WINAPI_FAMILY_SERVER | | | | | X | X |
128- * +------------------------------+---+---+---+---+---+---+
129- *
130- * The table above is encoded in the following expressions,
131- * each of which evaluates to 1 or 0.
132- *
133- * Whenever a new family is added, all of these expressions
134- * need to be reconsidered.
135- */
136-#if WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_APP && \
137- WINAPI_FAMILY != WINAPI_FAMILY_PC_APP && \
138- WINAPI_FAMILY != WINAPI_FAMILY_PHONE_APP && \
139- WINAPI_FAMILY != WINAPI_FAMILY_SYSTEM && \
140- WINAPI_FAMILY != WINAPI_FAMILY_SERVER
141-#error Unknown WINAPI_FAMILY value. Was it defined in terms of a WINAPI_PARTITION_* value?
142-#endif
143-
144-#ifndef WINAPI_PARTITION_DESKTOP
145-#define WINAPI_PARTITION_DESKTOP (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP)
146-#endif
147-
148-#ifndef WINAPI_PARTITION_APP
149-#define WINAPI_PARTITION_APP \
150- (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP || \
151- WINAPI_FAMILY == WINAPI_FAMILY_PC_APP || \
152- WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
153-#endif
154-
155-#ifndef WINAPI_PARTITION_PC_APP
156-#define WINAPI_PARTITION_PC_APP \
157- (WINAPI_FAMILY == WINAPI_FAMILY_DESKTOP_APP || \
158- WINAPI_FAMILY == WINAPI_FAMILY_PC_APP)
159-#endif
160-
161-#ifndef WINAPI_PARTITION_PHONE_APP
162-#define WINAPI_PARTITION_PHONE_APP (WINAPI_FAMILY == WINAPI_FAMILY_PHONE_APP)
163-#endif
164-
165-/*
166- * SYSTEM is the only partition defined here.
167- * All other System based editions are defined as packages
168- * on top of the System partition.
169- * See winpackagefamily.h for packages level partitions
170- */
171-#ifndef WINAPI_PARTITION_SYSTEM
172-#define WINAPI_PARTITION_SYSTEM \
173- (WINAPI_FAMILY == WINAPI_FAMILY_SYSTEM || \
174- WINAPI_FAMILY == WINAPI_FAMILY_SERVER)
175-#endif
176-
177-/*
178- * For compatibility with Windows Phone 8 header files, the following
179- * synonym for WINAPI_PARTITION_PHONE_APP is temporarily #define'd.
180- * Use of this symbol should be regarded as deprecated.
181- */
182-#define WINAPI_PARTITION_PHONE WINAPI_PARTITION_PHONE_APP
183-
184-/*
185- * Header files use the WINAPI_FAMILY_PARTITION macro to assign one or
186- * more declarations to some group of partitions. The macro chooses
187- * whether the preprocessor will emit or omit a sequence of declarations
188- * bracketed by an #if/#endif pair. All header file references to the
189- * WINAPI_PARTITION_* values should be in the form of occurrences of
190- * WINAPI_FAMILY_PARTITION(...).
191- *
192- * For example, the following usage of WINAPI_FAMILY_PARTITION identifies
193- * a sequence of declarations that are part of both the Windows Desktop
194- * Partition and the Windows-Phone-Specific Store Partition:
195- *
196- * #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_PHONE_APP)
197- * ...
198- * #endif // WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_PHONE_APP)
199- *
200- * The comment on the closing #endif allow tools as well as people to find the
201- * matching #ifdef properly.
202- *
203- * Usages of WINAPI_FAMILY_PARTITION may be combined, when the partitition definitions are
204- * related. In particular one might use declarations like
205- *
206- * #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
207- *
208- * or
209- *
210- * #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP)
211- *
212- * Direct references to WINAPI_PARTITION_ values (eg #if !WINAPI_FAMILY_PARTITION_...)
213- * should not be used.
214- */
215-#define WINAPI_FAMILY_PARTITION(Partitions) (Partitions)
216-
217-/*
218- * Macro used to #define or typedef a symbol used for selective deprecation
219- * of individual methods of a COM interfaces that are otherwise available
220- * for a given set of partitions.
221- */
222-#define _WINAPI_DEPRECATED_DECLARATION __declspec(deprecated("This API cannot be used in the context of the caller's application type."))
223-
224-/*
225- * For compatibility with Windows 8 header files, the following
226- * symbol is temporarily conditionally #define'd. Additional symbols
227- * like this should be not defined in winapifamily.h, but rather should be
228- * introduced locally to the header files of the component that needs them.
229- */
230-#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
231-# define APP_DEPRECATED_HRESULT HRESULT _WINAPI_DEPRECATED_DECLARATION
232-#endif // WINAPIFAMILY_PARTITION(WINAPI_PARTITION_APP) && !WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
233-
234-#if defined(_MSC_VER) && !defined(MOFCOMP_PASS)
235-#if _MSC_VER >= 1200
236-#pragma warning(pop)
237-#endif
238-#endif
239-
240-#endif /* !_INC_WINAPIFAMILY */
--- exewrap/trunk/exewrap/src/minhook/WindowsSDK/include/winpackagefamily.h (revision 38)
+++ exewrap/trunk/exewrap/src/minhook/WindowsSDK/include/winpackagefamily.h (revision 39)
@@ -1,91 +0,0 @@
1-/*
2-
3-Copyright (c) Microsoft Corporation. All rights reserved.
4-
5-Module Name:
6-
7- winpackagefamily.h
8-
9-Abstract:
10-
11- API family partitioning based on packages.
12-
13-*/
14-
15-#ifndef _INC_WINPACKAGEFAMILY
16-#define _INC_WINPACKAGEFAMILY
17-
18-#if defined(_MSC_VER) && !defined(MOFCOMP_PASS)
19-#if _MSC_VER >= 1200
20-#pragma warning(push)
21-#pragma warning(disable:4001) /* nonstandard extension 'single line comment' was used */
22-#endif
23-#pragma once
24-#endif // defined(_MSC_VER) && !defined(MOFCOMP_PASS)
25-
26-#ifndef WINAPI_PARTITION_SERVER
27-#define WINAPI_PARTITION_SERVER (WINAPI_FAMILY == WINAPI_FAMILY_SERVER)
28-#endif
29-
30-/*
31- * PARTITIONS based on packages are each #undef'ed below, and then will be #define-ed
32- * to be either 1 or 0 or depending on the active WINAPI_FAMILY.
33- */
34-#undef WINAPI_PARTITION_PKG_WINTRUST
35-#undef WINAPI_PARTITION_PKG_WEBSERVICES
36-#undef WINAPI_PARTITION_PKG_EVENTLOGSERVICE
37-#undef WINAPI_PARTITION_PKG_VHD
38-#undef WINAPI_PARTITION_PKG_PERFCOUNTER
39-#undef WINAPI_PARTITION_PKG_SECURESTARTUP
40-#undef WINAPI_PARTITION_PKG_REMOTEFS
41-#undef WINAPI_PARTITION_PKG_BOOTABLESKU
42-#undef WINAPI_PARTITION_PKG_CMDTOOLS
43-#undef WINAPI_PARTITION_PKG_DISM
44-#undef WINAPI_PARTITION_PKG_CORESETUP
45-#undef WINAPI_PARTITION_PKG_APPRUNTIME
46-#undef WINAPI_PARTITION_PKG_ESENT
47-#undef WINAPI_PARTITION_PKG_WINMGMT
48-#undef WINAPI_PARTITION_PKG_WNV
49-#undef WINAPI_PARTITION_PKG_CLUSTER
50-#undef WINAPI_PARTITION_PKG_VSS
51-#undef WINAPI_PARTITION_PKG_TRAFFIC
52-#undef WINAPI_PARTITION_PKG_ISCSI
53-#undef WINAPI_PARTITION_PKG_STORAGE
54-#undef WINAPI_PARTITION_PKG_MPSSVC
55-#undef WINAPI_PARTITION_PKG_APPXDEPLOYMENT
56-#undef WINAPI_PARTITION_PKG_WER
57-
58-/*
59- * PARTITIONS for feature packages. Each package might be active for one or more editions
60- */
61-#define WINAPI_PARTITION_PKG_WINTRUST (WINAPI_PARTITION_SERVER == 1)
62-#define WINAPI_PARTITION_PKG_WEBSERVICES (WINAPI_PARTITION_SERVER == 1)
63-#define WINAPI_PARTITION_PKG_EVENTLOGSERVICE (WINAPI_PARTITION_SERVER == 1)
64-#define WINAPI_PARTITION_PKG_VHD (WINAPI_PARTITION_SERVER == 1)
65-#define WINAPI_PARTITION_PKG_PERFCOUNTER (WINAPI_PARTITION_SERVER == 1)
66-#define WINAPI_PARTITION_PKG_SECURESTARTUP (WINAPI_PARTITION_SERVER == 1)
67-#define WINAPI_PARTITION_PKG_REMOTEFS (WINAPI_PARTITION_SERVER == 1)
68-#define WINAPI_PARTITION_PKG_BOOTABLESKU (WINAPI_PARTITION_SERVER == 1)
69-#define WINAPI_PARTITION_PKG_CMDTOOLS (WINAPI_PARTITION_SERVER == 1)
70-#define WINAPI_PARTITION_PKG_DISM (WINAPI_PARTITION_SERVER == 1)
71-#define WINAPI_PARTITION_PKG_CORESETUP (WINAPI_PARTITION_SERVER == 1)
72-#define WINAPI_PARTITION_PKG_APPRUNTIME (WINAPI_PARTITION_SERVER == 1)
73-#define WINAPI_PARTITION_PKG_ESENT (WINAPI_PARTITION_SERVER == 1)
74-#define WINAPI_PARTITION_PKG_WINMGMT (WINAPI_PARTITION_SERVER == 1)
75-#define WINAPI_PARTITION_PKG_WNV (WINAPI_PARTITION_SERVER == 1)
76-#define WINAPI_PARTITION_PKG_CLUSTER (WINAPI_PARTITION_SERVER == 1)
77-#define WINAPI_PARTITION_PKG_VSS (WINAPI_PARTITION_SERVER == 1)
78-#define WINAPI_PARTITION_PKG_TRAFFIC (WINAPI_PARTITION_SERVER == 1)
79-#define WINAPI_PARTITION_PKG_ISCSI (WINAPI_PARTITION_SERVER == 1)
80-#define WINAPI_PARTITION_PKG_STORAGE (WINAPI_PARTITION_SERVER == 1)
81-#define WINAPI_PARTITION_PKG_MPSSVC (WINAPI_PARTITION_SERVER == 1)
82-#define WINAPI_PARTITION_PKG_APPXDEPLOYMENT (WINAPI_PARTITION_SERVER == 1)
83-#define WINAPI_PARTITION_PKG_WER (WINAPI_PARTITION_SERVER == 1)
84-
85-#if defined(_MSC_VER) && !defined(MOFCOMP_PASS)
86-#if _MSC_VER >= 1200
87-#pragma warning(pop)
88-#endif
89-#endif
90-
91-#endif /* !_INC_WINPACKAGEFAMILY */
--- exewrap/trunk/exewrap/src/minhook/WindowsSDK/include/TlHelp32.h (revision 38)
+++ exewrap/trunk/exewrap/src/minhook/WindowsSDK/include/TlHelp32.h (revision 39)
@@ -1,325 +0,0 @@
1-/*****************************************************************************\
2-* *
3-* tlhelp32.h - WIN32 tool help functions, types, and definitions *
4-* *
5-* Version 1.0 *
6-* *
7-* NOTE: windows.h/winbase.h must be #included first *
8-* *
9-* Copyright (c) Microsoft Corp. All rights reserved. *
10-* *
11-\*****************************************************************************/
12-
13-#ifndef _INC_TOOLHELP32
14-#define _INC_TOOLHELP32
15-
16-#if _MSC_VER > 1000
17-#pragma once
18-#endif
19-#include <winapifamily.h>
20-
21-#pragma region Desktop Family
22-#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
23-
24-
25-#ifdef __cplusplus
26-extern "C" { /* Assume C declarations for C++ */
27-#endif /* __cplusplus */
28-
29-#define MAX_MODULE_NAME32 255
30-
31-/****** Shapshot function **********************************************/
32-
33-HANDLE
34-WINAPI
35-CreateToolhelp32Snapshot(
36- DWORD dwFlags,
37- DWORD th32ProcessID
38- );
39-
40-//
41-// The th32ProcessID argument is only used if TH32CS_SNAPHEAPLIST or
42-// TH32CS_SNAPMODULE is specified. th32ProcessID == 0 means the current
43-// process.
44-//
45-// NOTE that all of the snapshots are global except for the heap and module
46-// lists which are process specific. To enumerate the heap or module
47-// state for all WIN32 processes call with TH32CS_SNAPALL and the
48-// current process. Then for each process in the TH32CS_SNAPPROCESS
49-// list that isn't the current process, do a call with just
50-// TH32CS_SNAPHEAPLIST and/or TH32CS_SNAPMODULE.
51-//
52-// dwFlags
53-//
54-#define TH32CS_SNAPHEAPLIST 0x00000001
55-#define TH32CS_SNAPPROCESS 0x00000002
56-#define TH32CS_SNAPTHREAD 0x00000004
57-#define TH32CS_SNAPMODULE 0x00000008
58-#define TH32CS_SNAPMODULE32 0x00000010
59-#define TH32CS_SNAPALL (TH32CS_SNAPHEAPLIST | TH32CS_SNAPPROCESS | TH32CS_SNAPTHREAD | TH32CS_SNAPMODULE)
60-#define TH32CS_INHERIT 0x80000000
61-//
62-// Use CloseHandle to destroy the snapshot
63-//
64-
65-/****** heap walking ***************************************************/
66-
67-typedef struct tagHEAPLIST32
68-{
69- SIZE_T dwSize;
70- DWORD th32ProcessID; // owning process
71- ULONG_PTR th32HeapID; // heap (in owning process's context!)
72- DWORD dwFlags;
73-} HEAPLIST32;
74-typedef HEAPLIST32 * PHEAPLIST32;
75-typedef HEAPLIST32 * LPHEAPLIST32;
76-//
77-// dwFlags
78-//
79-#define HF32_DEFAULT 1 // process's default heap
80-#define HF32_SHARED 2 // is shared heap
81-
82-BOOL
83-WINAPI
84-Heap32ListFirst(
85- HANDLE hSnapshot,
86- LPHEAPLIST32 lphl
87- );
88-
89-BOOL
90-WINAPI
91-Heap32ListNext(
92- HANDLE hSnapshot,
93- LPHEAPLIST32 lphl
94- );
95-
96-typedef struct tagHEAPENTRY32
97-{
98- SIZE_T dwSize;
99- HANDLE hHandle; // Handle of this heap block
100- ULONG_PTR dwAddress; // Linear address of start of block
101- SIZE_T dwBlockSize; // Size of block in bytes
102- DWORD dwFlags;
103- DWORD dwLockCount;
104- DWORD dwResvd;
105- DWORD th32ProcessID; // owning process
106- ULONG_PTR th32HeapID; // heap block is in
107-} HEAPENTRY32;
108-typedef HEAPENTRY32 * PHEAPENTRY32;
109-typedef HEAPENTRY32 * LPHEAPENTRY32;
110-//
111-// dwFlags
112-//
113-#define LF32_FIXED 0x00000001
114-#define LF32_FREE 0x00000002
115-#define LF32_MOVEABLE 0x00000004
116-
117-BOOL
118-WINAPI
119-Heap32First(
120- LPHEAPENTRY32 lphe,
121- DWORD th32ProcessID,
122- ULONG_PTR th32HeapID
123- );
124-
125-BOOL
126-WINAPI
127-Heap32Next(
128- LPHEAPENTRY32 lphe
129- );
130-
131-BOOL
132-WINAPI
133-Toolhelp32ReadProcessMemory(
134- DWORD th32ProcessID,
135- LPCVOID lpBaseAddress,
136- LPVOID lpBuffer,
137- SIZE_T cbRead,
138- SIZE_T *lpNumberOfBytesRead
139- );
140-
141-/***** Process walking *************************************************/
142-
143-typedef struct tagPROCESSENTRY32W
144-{
145- DWORD dwSize;
146- DWORD cntUsage;
147- DWORD th32ProcessID; // this process
148- ULONG_PTR th32DefaultHeapID;
149- DWORD th32ModuleID; // associated exe
150- DWORD cntThreads;
151- DWORD th32ParentProcessID; // this process's parent process
152- LONG pcPriClassBase; // Base priority of process's threads
153- DWORD dwFlags;
154- WCHAR szExeFile[MAX_PATH]; // Path
155-} PROCESSENTRY32W;
156-typedef PROCESSENTRY32W * PPROCESSENTRY32W;
157-typedef PROCESSENTRY32W * LPPROCESSENTRY32W;
158-
159-BOOL
160-WINAPI
161-Process32FirstW(
162- HANDLE hSnapshot,
163- LPPROCESSENTRY32W lppe
164- );
165-
166-BOOL
167-WINAPI
168-Process32NextW(
169- HANDLE hSnapshot,
170- LPPROCESSENTRY32W lppe
171- );
172-
173-typedef struct tagPROCESSENTRY32
174-{
175- DWORD dwSize;
176- DWORD cntUsage;
177- DWORD th32ProcessID; // this process
178- ULONG_PTR th32DefaultHeapID;
179- DWORD th32ModuleID; // associated exe
180- DWORD cntThreads;
181- DWORD th32ParentProcessID; // this process's parent process
182- LONG pcPriClassBase; // Base priority of process's threads
183- DWORD dwFlags;
184- CHAR szExeFile[MAX_PATH]; // Path
185-} PROCESSENTRY32;
186-typedef PROCESSENTRY32 * PPROCESSENTRY32;
187-typedef PROCESSENTRY32 * LPPROCESSENTRY32;
188-
189-BOOL
190-WINAPI
191-Process32First(
192- HANDLE hSnapshot,
193- LPPROCESSENTRY32 lppe
194- );
195-
196-BOOL
197-WINAPI
198-Process32Next(
199- HANDLE hSnapshot,
200- LPPROCESSENTRY32 lppe
201- );
202-
203-#ifdef UNICODE
204-#define Process32First Process32FirstW
205-#define Process32Next Process32NextW
206-#define PROCESSENTRY32 PROCESSENTRY32W
207-#define PPROCESSENTRY32 PPROCESSENTRY32W
208-#define LPPROCESSENTRY32 LPPROCESSENTRY32W
209-#endif // !UNICODE
210-
211-/***** Thread walking **************************************************/
212-
213-typedef struct tagTHREADENTRY32
214-{
215- DWORD dwSize;
216- DWORD cntUsage;
217- DWORD th32ThreadID; // this thread
218- DWORD th32OwnerProcessID; // Process this thread is associated with
219- LONG tpBasePri;
220- LONG tpDeltaPri;
221- DWORD dwFlags;
222-} THREADENTRY32;
223-typedef THREADENTRY32 * PTHREADENTRY32;
224-typedef THREADENTRY32 * LPTHREADENTRY32;
225-
226-BOOL
227-WINAPI
228-Thread32First(
229- HANDLE hSnapshot,
230- LPTHREADENTRY32 lpte
231- );
232-
233-BOOL
234-WINAPI
235-Thread32Next(
236- HANDLE hSnapshot,
237- LPTHREADENTRY32 lpte
238- );
239-
240-/***** Module walking *************************************************/
241-
242-typedef struct tagMODULEENTRY32W
243-{
244- DWORD dwSize;
245- DWORD th32ModuleID; // This module
246- DWORD th32ProcessID; // owning process
247- DWORD GlblcntUsage; // Global usage count on the module
248- DWORD ProccntUsage; // Module usage count in th32ProcessID's context
249- BYTE * modBaseAddr; // Base address of module in th32ProcessID's context
250- DWORD modBaseSize; // Size in bytes of module starting at modBaseAddr
251- HMODULE hModule; // The hModule of this module in th32ProcessID's context
252- WCHAR szModule[MAX_MODULE_NAME32 + 1];
253- WCHAR szExePath[MAX_PATH];
254-} MODULEENTRY32W;
255-typedef MODULEENTRY32W * PMODULEENTRY32W;
256-typedef MODULEENTRY32W * LPMODULEENTRY32W;
257-
258-BOOL
259-WINAPI
260-Module32FirstW(
261- HANDLE hSnapshot,
262- LPMODULEENTRY32W lpme
263- );
264-
265-BOOL
266-WINAPI
267-Module32NextW(
268- HANDLE hSnapshot,
269- LPMODULEENTRY32W lpme
270- );
271-
272-
273-typedef struct tagMODULEENTRY32
274-{
275- DWORD dwSize;
276- DWORD th32ModuleID; // This module
277- DWORD th32ProcessID; // owning process
278- DWORD GlblcntUsage; // Global usage count on the module
279- DWORD ProccntUsage; // Module usage count in th32ProcessID's context
280- BYTE * modBaseAddr; // Base address of module in th32ProcessID's context
281- DWORD modBaseSize; // Size in bytes of module starting at modBaseAddr
282- HMODULE hModule; // The hModule of this module in th32ProcessID's context
283- char szModule[MAX_MODULE_NAME32 + 1];
284- char szExePath[MAX_PATH];
285-} MODULEENTRY32;
286-typedef MODULEENTRY32 * PMODULEENTRY32;
287-typedef MODULEENTRY32 * LPMODULEENTRY32;
288-
289-//
290-// NOTE CAREFULLY that the modBaseAddr and hModule fields are valid ONLY
291-// in th32ProcessID's process context.
292-//
293-
294-BOOL
295-WINAPI
296-Module32First(
297- HANDLE hSnapshot,
298- LPMODULEENTRY32 lpme
299- );
300-
301-BOOL
302-WINAPI
303-Module32Next(
304- HANDLE hSnapshot,
305- LPMODULEENTRY32 lpme
306- );
307-
308-#ifdef UNICODE
309-#define Module32First Module32FirstW
310-#define Module32Next Module32NextW
311-#define MODULEENTRY32 MODULEENTRY32W
312-#define PMODULEENTRY32 PMODULEENTRY32W
313-#define LPMODULEENTRY32 LPMODULEENTRY32W
314-#endif // !UNICODE
315-
316-
317-#ifdef __cplusplus
318-}
319-#endif
320-
321-
322-#endif /* WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) */
323-#pragma endregion
324-
325-#endif // _INC_TOOLHELP32
--- exewrap/trunk/exewrap/src/minhook/LICENSE.txt (revision 38)
+++ exewrap/trunk/exewrap/src/minhook/LICENSE.txt (revision 39)
@@ -1,81 +0,0 @@
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 38)
+++ exewrap/trunk/exewrap/src/minhook/AUTHORS.txt (revision 39)
@@ -1,8 +0,0 @@
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 38)
+++ exewrap/trunk/exewrap/src/minhook/include/MinHook.h (revision 39)
@@ -1,169 +0,0 @@
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/buffer.c (revision 38)
+++ exewrap/trunk/exewrap/src/minhook/src/buffer.c (revision 39)
@@ -1,315 +0,0 @@
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/src/trampoline.c (revision 38)
+++ exewrap/trunk/exewrap/src/minhook/src/trampoline.c (revision 39)
@@ -1,316 +0,0 @@
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 38)
+++ exewrap/trunk/exewrap/src/minhook/src/buffer.h (revision 39)
@@ -1,42 +0,0 @@
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/hde64.h (revision 38)
+++ exewrap/trunk/exewrap/src/minhook/src/HDE/hde64.h (revision 39)
@@ -1,112 +0,0 @@
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 38)
+++ exewrap/trunk/exewrap/src/minhook/src/HDE/table32.h (revision 39)
@@ -1,73 +0,0 @@
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/HDE/hde32.c (revision 38)
+++ exewrap/trunk/exewrap/src/minhook/src/HDE/hde32.c (revision 39)
@@ -1,322 +0,0 @@
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 38)
+++ exewrap/trunk/exewrap/src/minhook/src/HDE/table64.h (revision 39)
@@ -1,74 +0,0 @@
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 38)
+++ exewrap/trunk/exewrap/src/minhook/src/HDE/hde32.h (revision 39)
@@ -1,105 +0,0 @@
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 38)
+++ exewrap/trunk/exewrap/src/minhook/src/HDE/hde64.c (revision 39)
@@ -1,333 +0,0 @@
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 38)
+++ exewrap/trunk/exewrap/src/minhook/src/HDE/pstdint.h (revision 39)
@@ -1,39 +0,0 @@
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/trampoline.h (revision 38)
+++ exewrap/trunk/exewrap/src/minhook/src/trampoline.h (revision 39)
@@ -1,105 +0,0 @@
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 38)
+++ exewrap/trunk/exewrap/src/minhook/src/hook.c (revision 39)
@@ -1,874 +0,0 @@
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/image_service.c (revision 38)
+++ exewrap/trunk/exewrap/src/image_service.c (revision 39)
@@ -94,7 +94,7 @@
9494 if(vm_args_opt == NULL) {
9595 vm_args_opt = (char*)GetResource("VMARGS", NULL);
9696 }
97- CreateJavaVM(vm_args_opt, use_server_vm, use_side_by_side_jre, &err);
97+ CreateJavaVM(vm_args_opt, "exewrap.core.ExewrapClassLoader", use_server_vm, use_side_by_side_jre, &err);
9898 if (err != JNI_OK)
9999 {
100100 OutputMessage(GetWinErrorMessage(err, &result.msg_id, result.msg));
--- exewrap/trunk/exewrap/src/include/message.h (revision 38)
+++ exewrap/trunk/exewrap/src/include/message.h (revision 39)
@@ -18,7 +18,7 @@
1818 #define MSG_ID_ERR_UNCAUGHT_EXCEPTION 8
1919 #define MSG_ID_ERR_RESOURCE_NOT_FOUND 9
2020 #define MSG_ID_ERR_TARGET_VERSION 10
21-#define MSG_ID_ERR_DEFINE_CLASS 11
21+#define MSG_ID_ERR_FIND_CLASS 11
2222 #define MSG_ID_ERR_GET_METHOD 12
2323 #define MSG_ID_ERR_GET_CONSTRUCTOR 13
2424 #define MSG_ID_ERR_NEW_OBJECT 14
--- exewrap/trunk/exewrap/src/include/jvm.h (revision 38)
+++ exewrap/trunk/exewrap/src/include/jvm.h (revision 39)
@@ -5,7 +5,7 @@
55
66 extern int GetProcessArchitecture();
77 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);
8+extern JNIEnv* CreateJavaVM(LPTSTR vm_args_opt, LPTSTR systemClassLoader, BOOL useServerVM, BOOL useSideBySideJRE, int* err);
99 extern void DestroyJavaVM();
1010 extern JNIEnv* AttachJavaVM();
1111 extern void DetachJavaVM();
--- exewrap/trunk/exewrap/src/image_console.c (revision 38)
+++ exewrap/trunk/exewrap/src/image_console.c (revision 39)
@@ -67,7 +67,7 @@
6767 }
6868
6969 vm_args_opt = (char*)GetResource("VMARGS", NULL);
70- CreateJavaVM(vm_args_opt, use_server_vm, use_side_by_side_jre, &err);
70+ CreateJavaVM(vm_args_opt, "exewrap.core.ExewrapClassLoader", use_server_vm, use_side_by_side_jre, &err);
7171 if (err != JNI_OK)
7272 {
7373 OutputMessage(GetJniErrorMessage(err, &result.msg_id, result.msg));
--- exewrap/trunk/exewrap/src/loader.c (revision 38)
+++ exewrap/trunk/exewrap/src/loader.c (revision 39)
@@ -33,7 +33,6 @@
3333 extern UINT UncaughtException(const char* thread, const char* message, const char* trace);
3434
3535 static jclass ExewrapClassLoader = NULL;
36-static jobject exewrapClassLoader = NULL;
3736 static jclass MainClass = NULL;
3837 static jmethodID MainClass_main = NULL;
3938
@@ -40,63 +39,21 @@
4039 BOOL LoadMainClass(int argc, char* argv[], char* utilities, LOAD_RESULT* result)
4140 {
4241 RESOURCE res;
43- jclass ClassLoader;
44- jmethodID ClassLoader_getSystemClassLoader;
45- jmethodID ClassLoader_definePackage;
46- jobject systemClassLoader;
4742 jclass JarInputStream;
4843 jmethodID JarInputStream_init;
4944 jclass ByteBufferInputStream;
5045 jmethodID ByteBufferInputStream_init;
5146 jobjectArray jars;
52- jclass URLConnection;
53- jclass URLStreamHandler;
54- jclass URLStreamHandlerFactory;
55- jmethodID ExewrapClassLoader_init;
56- jmethodID exewrapClassLoader_register;
57- jmethodID exewrapClassLoader_loadUtilities;
58- jmethodID exewrapClassLoader_getMainClass;
47+ jmethodID ExewrapClassLoader_setInputs;
48+ jmethodID ExewrapClassLoader_loadUtilities;
49+ jmethodID ExewrapClassLoader_getMainClass;
5950
60- // ClassLoader
61- ClassLoader = (*env)->FindClass(env, "java/lang/ClassLoader");
62- if (ClassLoader == NULL)
63- {
64- result->msg_id = MSG_ID_ERR_DEFINE_CLASS;
65- sprintf(result->msg, _(MSG_ID_ERR_DEFINE_CLASS), "java.lang.ClassLoader");
66- goto EXIT;
67- }
68- ClassLoader_definePackage = (*env)->GetMethodID(env, ClassLoader, "definePackage", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/net/URL;)Ljava/lang/Package;");
69- if (ClassLoader_definePackage == NULL)
70- {
71- result->msg_id = MSG_ID_ERR_GET_METHOD;
72- sprintf(result->msg, _(MSG_ID_ERR_GET_METHOD), "java.lang.ClassLoader.definePackage(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.net.URL)");
73- goto EXIT;
74- }
75- ClassLoader_getSystemClassLoader = (*env)->GetStaticMethodID(env, ClassLoader, "getSystemClassLoader", "()Ljava/lang/ClassLoader;");
76- if (ClassLoader_getSystemClassLoader == NULL)
77- {
78- result->msg_id = MSG_ID_ERR_GET_METHOD;
79- sprintf(result->msg, _(MSG_ID_ERR_GET_METHOD), "java.lang.ClassLoader.getSystemClassLoader()");
80- goto EXIT;
81- }
82- systemClassLoader = (*env)->CallStaticObjectMethod(env, ClassLoader, ClassLoader_getSystemClassLoader);
83- if (systemClassLoader == NULL)
84- {
85- //ignore
86- }
87- else
88- {
89- // Define package "exewrap.core"
90- jstring packageName = GetJString(env, "exewrap.core");
91- (*env)->CallObjectMethod(env, systemClassLoader, ClassLoader_definePackage, packageName, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
92- }
93-
9451 // JarInputStream
9552 JarInputStream = (*env)->FindClass(env, "java/util/jar/JarInputStream");
9653 if (JarInputStream == NULL)
9754 {
98- result->msg_id = MSG_ID_ERR_DEFINE_CLASS;
99- sprintf(result->msg, _(MSG_ID_ERR_DEFINE_CLASS), "java.util.jar.JarInputStream");
55+ result->msg_id = MSG_ID_ERR_FIND_CLASS;
56+ sprintf(result->msg, _(MSG_ID_ERR_FIND_CLASS), "java.util.jar.JarInputStream");
10057 goto EXIT;
10158 }
10259 JarInputStream_init = (*env)->GetMethodID(env, JarInputStream, "<init>", "(Ljava/io/InputStream;)V");
@@ -108,17 +65,11 @@
10865 }
10966
11067 // ByteBufferInputStream
111- if (GetResource("BYTE_BUFFER_INPUT_STREAM", &res) == NULL)
112- {
113- result->msg_id = MSG_ID_ERR_RESOURCE_NOT_FOUND;
114- sprintf(result->msg, _(MSG_ID_ERR_RESOURCE_NOT_FOUND), "RT_RCDATA: BYTE_BUFFER_INPUT_STREAM");
115- goto EXIT;
116- }
117- ByteBufferInputStream = (*env)->DefineClass(env, "exewrap/core/ByteBufferInputStream", systemClassLoader, res.buf, res.len);
68+ ByteBufferInputStream = (*env)->FindClass(env, "exewrap/core/ByteBufferInputStream");
11869 if (ByteBufferInputStream == NULL)
11970 {
120- result->msg_id = MSG_ID_ERR_DEFINE_CLASS;
121- sprintf(result->msg, _(MSG_ID_ERR_DEFINE_CLASS), "exewrap.core.ByteBufferInputStream");
71+ result->msg_id = MSG_ID_ERR_FIND_CLASS;
72+ sprintf(result->msg, _(MSG_ID_ERR_FIND_CLASS), "exewrap.core.ByteBufferInputStream");
12273 goto EXIT;
12374 }
12475 ByteBufferInputStream_init = (*env)->GetMethodID(env, ByteBufferInputStream, "<init>", "(Ljava/nio/ByteBuffer;)V");
@@ -129,8 +80,8 @@
12980 goto EXIT;
13081 }
13182
132- // JarInputStream[] jars = new JarInputStream[2];
133- jars = (*env)->NewObjectArray(env, 2, JarInputStream, NULL);
83+ // JarInputStream[] jars = new JarInputStream[1];
84+ jars = (*env)->NewObjectArray(env, 1, JarInputStream, NULL);
13485 if (jars == NULL)
13586 {
13687 result->msg_id = MSG_ID_ERR_NEW_OBJECT;
@@ -138,42 +89,6 @@
13889 goto EXIT;
13990 }
14091
141- //util.jar
142- {
143- jobject byteBuffer;
144- jobject byteBufferInputStream = NULL;
145- jobject jarInputStream = NULL;
146-
147- if (GetResource("UTIL_JAR", &res) == NULL)
148- {
149- result->msg_id = MSG_ID_ERR_RESOURCE_NOT_FOUND;
150- sprintf(result->msg, _(MSG_ID_ERR_RESOURCE_NOT_FOUND), "RT_RCDATA: UTIL_JAR");
151- goto EXIT;
152- }
153- byteBuffer = (*env)->NewDirectByteBuffer(env, res.buf, res.len);
154- if (byteBuffer == NULL)
155- {
156- result->msg_id = MSG_ID_ERR_NEW_OBJECT;
157- sprintf(result->msg, _(MSG_ID_ERR_NEW_OBJECT), "NewDirectByteBuffer(JNIEnv* env, void* address, jlong capacity)");
158- goto EXIT;
159- }
160- byteBufferInputStream = (*env)->NewObject(env, ByteBufferInputStream, ByteBufferInputStream_init, byteBuffer);
161- if (byteBufferInputStream == NULL)
162- {
163- result->msg_id = MSG_ID_ERR_NEW_OBJECT;
164- sprintf(result->msg, _(MSG_ID_ERR_NEW_OBJECT), "exewrap.core.ByteBufferInputStream(java.nio.ByteBuffer)");
165- goto EXIT;
166- }
167- jarInputStream = (*env)->NewObject(env, JarInputStream, JarInputStream_init, byteBufferInputStream);
168- if (jarInputStream == NULL)
169- {
170- result->msg_id = MSG_ID_ERR_NEW_OBJECT;
171- sprintf(result->msg, _(MSG_ID_ERR_NEW_OBJECT), "java.util.jar.JarInputStream(exewrap.core.ByteBufferInputStream)");
172- goto EXIT;
173- }
174- (*env)->SetObjectArrayElement(env, jars, 0, jarInputStream);
175- }
176-
17792 // user.jar or user.pack.gz
17893 {
17994 BOOL isPackGz = TRUE;
@@ -218,8 +133,8 @@
218133 GZIPInputStream = (*env)->FindClass(env, "java/util/zip/GZIPInputStream");
219134 if (GZIPInputStream == NULL)
220135 {
221- result->msg_id = MSG_ID_ERR_DEFINE_CLASS;
222- sprintf(result->msg, _(MSG_ID_ERR_DEFINE_CLASS), "java.util.zip.GZIPInputStream");
136+ result->msg_id = MSG_ID_ERR_FIND_CLASS;
137+ sprintf(result->msg, _(MSG_ID_ERR_FIND_CLASS), "java.util.zip.GZIPInputStream");
223138 goto EXIT;
224139 }
225140 GZIPInputStream_init = (*env)->GetMethodID(env, GZIPInputStream, "<init>", "(Ljava/io/InputStream;)V");
@@ -238,17 +153,11 @@
238153 }
239154
240155 // PackInputStream
241- if (GetResource("PACK_INPUT_STREAM", &res) == NULL)
242- {
243- result->msg_id = MSG_ID_ERR_RESOURCE_NOT_FOUND;
244- sprintf(result->msg, _(MSG_ID_ERR_RESOURCE_NOT_FOUND), "RT_RCDATA: PACK_INPUT_STREAM");
245- goto EXIT;
246- }
247- PackInputStream = (*env)->DefineClass(env, "exewrap/core/PackInputStream", systemClassLoader, res.buf, res.len);
156+ PackInputStream = (*env)->FindClass(env, "exewrap/core/PackInputStream");
248157 if (PackInputStream == NULL)
249158 {
250- result->msg_id = MSG_ID_ERR_DEFINE_CLASS;
251- sprintf(result->msg, _(MSG_ID_ERR_DEFINE_CLASS), "exewrap.core.PackInputStream");
159+ result->msg_id = MSG_ID_ERR_FIND_CLASS;
160+ sprintf(result->msg, _(MSG_ID_ERR_FIND_CLASS), "exewrap.core.PackInputStream");
252161 goto EXIT;
253162 }
254163 PackInputStream_init = (*env)->GetMethodID(env, PackInputStream, "<init>", "(Ljava/io/InputStream;)V");
@@ -286,65 +195,18 @@
286195 goto EXIT;
287196 }
288197 }
289- (*env)->SetObjectArrayElement(env, jars, 1, jarInputStream);
198+ (*env)->SetObjectArrayElement(env, jars, 0, jarInputStream);
290199 }
291-
292- // URLConnection
293- if (GetResource("URL_CONNECTION", &res) == NULL)
294- {
295- result->msg_id = MSG_ID_ERR_RESOURCE_NOT_FOUND;
296- sprintf(result->msg, _(MSG_ID_ERR_RESOURCE_NOT_FOUND), "RT_RCDATA: URL_CONNECTION");
297- goto EXIT;
298- }
299- URLConnection = (*env)->DefineClass(env, "exewrap/core/URLConnection", systemClassLoader, res.buf, res.len);
300- if (URLConnection == NULL)
301- {
302- result->msg_id = MSG_ID_ERR_DEFINE_CLASS;
303- sprintf(result->msg, _(MSG_ID_ERR_DEFINE_CLASS), "exewrap.core.URLConnection");
304- goto EXIT;
305- }
306- // URLStreamHandler
307- if (GetResource("URL_STREAM_HANDLER", &res) == NULL)
308- {
309- result->msg_id = MSG_ID_ERR_RESOURCE_NOT_FOUND;
310- sprintf(result->msg, _(MSG_ID_ERR_RESOURCE_NOT_FOUND), "RT_RCDATA: URL_STREAM_HANDLER");
311- goto EXIT;
312- }
313- URLStreamHandler = (*env)->DefineClass(env, "exewrap/core/URLStreamHandler", systemClassLoader, res.buf, res.len);
314- if (URLStreamHandler == NULL)
315- {
316- result->msg_id = MSG_ID_ERR_DEFINE_CLASS;
317- sprintf(result->msg, _(MSG_ID_ERR_DEFINE_CLASS), "exewrap.core.URLStreamHandler");
318- goto EXIT;
319- }
320- // URLStreamHandlerFactory
321- if (GetResource("URL_STREAM_HANDLER_FACTORY", &res) == NULL)
322- {
323- result->msg_id = MSG_ID_ERR_RESOURCE_NOT_FOUND;
324- sprintf(result->msg, _(MSG_ID_ERR_RESOURCE_NOT_FOUND), "RT_RCDATA: URL_STREAM_HANDLER_FACTORY");
325- goto EXIT;
326- }
327- URLStreamHandlerFactory = (*env)->DefineClass(env, "exewrap/core/URLStreamHandlerFactory", systemClassLoader, res.buf, res.len);
328- if (URLStreamHandlerFactory == NULL)
329- {
330- result->msg_id = MSG_ID_ERR_DEFINE_CLASS;
331- sprintf(result->msg, _(MSG_ID_ERR_DEFINE_CLASS), "exewrap.core.URLStreamHandlerFactory");
332- goto EXIT;
333- }
200+
334201 // ExewrapClassLoader
335- if (GetResource("EXEWRAP_CLASS_LOADER", &res) == NULL)
336- {
337- result->msg_id = MSG_ID_ERR_RESOURCE_NOT_FOUND;
338- sprintf(result->msg, _(MSG_ID_ERR_RESOURCE_NOT_FOUND), "RT_RCDATA: EXEWRAP_CLASS_LOADER");
339- goto EXIT;
340- }
341- ExewrapClassLoader = (*env)->DefineClass(env, "exewrap/core/ExewrapClassLoader", systemClassLoader, res.buf, res.len);
202+ ExewrapClassLoader = (*env)->FindClass(env, "exewrap/core/ExewrapClassLoader");
342203 if (ExewrapClassLoader == NULL)
343204 {
344- result->msg_id = MSG_ID_ERR_DEFINE_CLASS;
345- sprintf(result->msg, _(MSG_ID_ERR_DEFINE_CLASS), "exewrap.core.ExewrapClassLoader");
205+ result->msg_id = MSG_ID_ERR_FIND_CLASS;
206+ sprintf(result->msg, _(MSG_ID_ERR_FIND_CLASS), "exewrap.core.ExewrapClassLoader");
346207 goto EXIT;
347208 }
209+
348210 // register native methods
349211 if (register_native(env, ExewrapClassLoader, "WriteConsole", "([BII)V", JNI_WriteConsole) != 0)
350212 {
@@ -370,55 +232,39 @@
370232 sprintf(result->msg, _(MSG_ID_ERR_REGISTER_NATIVE), "SetEnvironment");
371233 goto EXIT;
372234 }
373- // Create ExewrapClassLoader instance
374- ExewrapClassLoader_init = (*env)->GetMethodID(env, ExewrapClassLoader, "<init>", "(Ljava/lang/ClassLoader;[Ljava/util/jar/JarInputStream;)V");
375- if (ExewrapClassLoader_init == NULL)
235+
236+ ExewrapClassLoader_setInputs = (*env)->GetStaticMethodID(env, ExewrapClassLoader, "setInputs", "([Ljava/util/jar/JarInputStream;)V");
237+ if (ExewrapClassLoader_setInputs == NULL)
376238 {
377- result->msg_id = MSG_ID_ERR_GET_CONSTRUCTOR;
378- sprintf(result->msg, _(MSG_ID_ERR_GET_CONSTRUCTOR), "exewrap.core.ExewrapClassLoader(java.lang.ClassLoader, java.util.jar.JarInputStream[])");
379- goto EXIT;
380- }
381- // ExewrapClassLoader exewrarpClassLoader = new ExewrapClassLoader(ClassLoader.getSystemClasssLoader());
382- exewrapClassLoader = (*env)->NewObject(env, ExewrapClassLoader, ExewrapClassLoader_init, systemClassLoader, jars);
383- if (exewrapClassLoader == NULL)
384- {
385- result->msg_id = MSG_ID_ERR_NEW_OBJECT;
386- sprintf(result->msg, _(MSG_ID_ERR_NEW_OBJECT), "exewrap.core.ExewrapClassLoader(java.lang.ClassLoader, java.util.jar.JarInputStream[])");
387- goto EXIT;
388- }
389- exewrapClassLoader_register = (*env)->GetMethodID(env, ExewrapClassLoader, "register", "()V");
390- if (exewrapClassLoader_register == NULL)
391- {
392239 result->msg_id = MSG_ID_ERR_GET_METHOD;
393- sprintf(result->msg, _(MSG_ID_ERR_GET_METHOD), "exewrap.core.ExewrapClassLoader.register()");
240+ sprintf(result->msg, _(MSG_ID_ERR_GET_METHOD), "exewrap.core.ExewrapClassLoader.setInputs(java.util.jar.JarInputStream[])");
394241 goto EXIT;
395242 }
396- exewrapClassLoader_loadUtilities = (*env)->GetMethodID(env, ExewrapClassLoader, "loadUtilities", "(Ljava/lang/String;)V");
397- if (exewrapClassLoader_loadUtilities == NULL)
243+ (*env)->CallStaticObjectMethod(env, ExewrapClassLoader, ExewrapClassLoader_setInputs, jars);
244+
245+
246+ ExewrapClassLoader_loadUtilities = (*env)->GetStaticMethodID(env, ExewrapClassLoader, "loadUtilities", "(Ljava/lang/String;)V");
247+ if (ExewrapClassLoader_loadUtilities == NULL)
398248 {
399249 result->msg_id = MSG_ID_ERR_GET_METHOD;
400250 sprintf(result->msg, _(MSG_ID_ERR_GET_METHOD), "exewrap.core.ExewrapClassLoader.loadUtilities(java.lang.String)");
401251 goto EXIT;
402252 }
403-
404- // exewrapClassLoader.register();
405- (*env)->CallObjectMethod(env, exewrapClassLoader, exewrapClassLoader_register);
406-
407253 // exewrapClassLoader.loadUtilities();
408254 {
409255 jstring s = GetJString(env, utilities);
410- (*env)->CallObjectMethod(env, exewrapClassLoader, exewrapClassLoader_loadUtilities, s);
256+ (*env)->CallStaticObjectMethod(env, ExewrapClassLoader, ExewrapClassLoader_loadUtilities, s);
411257 }
412258
413259 // MainClass
414- exewrapClassLoader_getMainClass = (*env)->GetMethodID(env, ExewrapClassLoader, "getMainClass", "(Ljava/lang/String;)Ljava/lang/Class;");
415- if (exewrapClassLoader_getMainClass == NULL)
260+ ExewrapClassLoader_getMainClass = (*env)->GetStaticMethodID(env, ExewrapClassLoader, "getMainClass", "(Ljava/lang/String;)Ljava/lang/Class;");
261+ if (ExewrapClassLoader_getMainClass == NULL)
416262 {
417263 result->msg_id = MSG_ID_ERR_GET_METHOD;
418264 sprintf(result->msg, _(MSG_ID_ERR_GET_METHOD), "exewrap.core.ExewrapClassLoader.getMainClass(java.lang.String)");
419265 goto EXIT;
420266 }
421- MainClass = (*env)->CallObjectMethod(env, exewrapClassLoader, exewrapClassLoader_getMainClass, GetJString(env, GetResource("MAIN_CLASS", NULL)));
267+ MainClass = (*env)->CallStaticObjectMethod(env, ExewrapClassLoader, ExewrapClassLoader_getMainClass, GetJString(env, GetResource("MAIN_CLASS", NULL)));
422268 if (MainClass == NULL)
423269 {
424270 result->msg_id = MSG_ID_ERR_LOAD_MAIN_CLASS;
@@ -462,7 +308,7 @@
462308 BOOL ret = FALSE;
463309 jstring name;
464310 jbyteArray image;
465- jmethodID exewrapClassLoader_setSplashScreenResource;
311+ jmethodID ExewrapClassLoader_setSplashScreenResource;
466312
467313 name = GetJString(env, splash_screen_name);
468314 if (name == NULL)
@@ -477,13 +323,13 @@
477323 }
478324 (*env)->SetByteArrayRegion(env, image, 0, splash_screen_image_len, splash_screen_image_buf);
479325
480- exewrapClassLoader_setSplashScreenResource = (*env)->GetMethodID(env, ExewrapClassLoader, "setSplashScreenResource", "(Ljava/lang/String;[B)V");
481- if (exewrapClassLoader_setSplashScreenResource == NULL)
326+ ExewrapClassLoader_setSplashScreenResource = (*env)->GetStaticMethodID(env, ExewrapClassLoader, "setSplashScreenResource", "(Ljava/lang/String;[B)V");
327+ if (ExewrapClassLoader_setSplashScreenResource == NULL)
482328 {
483329 goto EXIT;
484330 }
485331
486- (*env)->CallVoidMethod(env, exewrapClassLoader, exewrapClassLoader_setSplashScreenResource, name, image);
332+ (*env)->CallStaticVoidMethod(env, ExewrapClassLoader, ExewrapClassLoader_setSplashScreenResource, name, image);
487333
488334 ret = TRUE;
489335
--- exewrap/trunk/exewrap/src/exewrap.c (revision 38)
+++ exewrap/trunk/exewrap/src/exewrap.c (revision 39)
@@ -25,6 +25,7 @@
2525 static char** parse_opt(int argc, char* argv[]);
2626 static DWORD get_version_revision(char* filename);
2727 static BOOL create_exe_file(const char* filename, BYTE* image_buf, DWORD image_len, BOOL is_reverse);
28+static BOOL append_exe_file(const char* filename, BYTE* image_buf, DWORD image_len);
2829 static DWORD get_target_java_runtime_version(char* version);
2930 static char* get_target_java_runtime_version_string(DWORD version, char* buf);
3031 static void set_resource(const char* filename, const char* rsc_name, const char* rsc_type, BYTE* rsc_data, DWORD rsc_size);
@@ -60,7 +61,6 @@
6061 char* product_version;
6162 char* original_filename;
6263 char* new_version;
63- BOOL is_trace_version = FALSE;
6464 BOOL contains_visualvm_display_name = FALSE;
6565
6666 char* buf = NULL;
@@ -83,9 +83,7 @@
8383 exe_file = argv[0];
8484 }
8585
86- is_trace_version = strstr(exe_file, "trace") != NULL;
87-
88- printf("exewrap 1.1.9 for %s (%d-bit) %s\r\n"
86+ printf("exewrap 1.2.0 for %s (%d-bit) \r\n"
8987 "Native executable java application wrapper.\r\n"
9088 "Copyright (C) 2005-2017 HIRUKAWA Ryo. All rights reserved.\r\n"
9189 "\r\n"
@@ -110,7 +108,7 @@
110108 " -V <product-version>\t Set product version.\r\n"
111109 " -j <jar-file> \t Input jar-file.\r\n"
112110 " -o <exe-file> \t Output exe-file.\r\n"
113- , (bits == 64 ? "x64" : "x86"), bits, (is_trace_version ? "[ TRACE VERSION ]" : ""), exe_file, (bits == 64 ? "x64" : "x86"));
111+ , (bits == 64 ? "x64" : "x86"), bits, exe_file, (bits == 64 ? "x64" : "x86"));
114112
115113 return 0;
116114 }
@@ -156,12 +154,6 @@
156154 }
157155 strcpy(exe_file, buf);
158156
159- if (is_trace_version)
160- {
161- *strrchr(exe_file, '.') = '\0';
162- strcat(exe_file, ".TRACE.exe");
163- }
164-
165157 if(opt['A'])
166158 {
167159 if(strstr(opt['A'], "86") != NULL)
@@ -181,15 +173,15 @@
181173
182174 if(opt['g'])
183175 {
184- sprintf(image_name, "IMAGE%s_GUI_%d", (is_trace_version ? "_TRACE" : ""), architecture_bits);
176+ sprintf(image_name, "IMAGE_GUI_%d", architecture_bits);
185177 }
186178 else if(opt['s'])
187179 {
188- sprintf(image_name, "IMAGE%s_SERVICE_%d", (is_trace_version ? "_TRACE" : ""), architecture_bits);
180+ sprintf(image_name, "IMAGE_SERVICE_%d", architecture_bits);
189181 }
190182 else
191183 {
192- sprintf(image_name, "IMAGE%s_CONSOLE_%d", (is_trace_version ? "_TRACE" : ""), architecture_bits);
184+ sprintf(image_name, "IMAGE_CONSOLE_%d", architecture_bits);
193185 }
194186
195187 GetResource(image_name, &res);
@@ -231,7 +223,7 @@
231223 set_resource(exe_file, "EXTDIRS", RT_RCDATA, "lib", 4);
232224 }
233225
234- enable_java = CreateJavaVM(NULL, FALSE, TRUE, NULL) != NULL;
226+ enable_java = CreateJavaVM(NULL, "exewrap.core.ExewrapClassLoader", FALSE, TRUE, NULL) != NULL;
235227 if (enable_java)
236228 {
237229 LOAD_RESULT result;
@@ -313,7 +305,7 @@
313305 printf(_(MSG_ID_ERR_GET_METHOD), "exewrap.tool.JarProcessor.getSplashScreenImage()");
314306 goto EXIT;
315307 }
316- jarProcessor_getBytes = (*env)->GetMethodID(env, JarProcessor, "getBytes", "()[B");
308+ jarProcessor_getBytes = (*env)->GetMethodID(env, JarProcessor, "getBytes", "()[B");
317309 if (jarProcessor_getBytes == NULL)
318310 {
319311 result.msg_id = MSG_ID_ERR_GET_METHOD;
@@ -382,10 +374,6 @@
382374
383375 ext_flags = (char*)malloc(1024);
384376 ext_flags[0] = '\0';
385- if (is_trace_version)
386- {
387- strcat(ext_flags, "NOSIDEBYSIDE;");
388- }
389377 if (opt['e'] && *opt['e'] != '-' && *opt['e'] != '\0')
390378 {
391379 strcat(ext_flags, opt['e']);
@@ -393,19 +381,6 @@
393381 set_resource(exe_file, "EXTFLAGS", RT_RCDATA, ext_flags, (DWORD)strlen(ext_flags) + 1);
394382 free(ext_flags);
395383
396- if (is_trace_version)
397- {
398- if (vmargs == NULL)
399- {
400- vmargs = (char*)malloc(2048);
401- vmargs[0] = '\0';
402- }
403- else
404- {
405- strcat(vmargs, " ");
406- }
407- strcat(vmargs, "-XX:+TraceClassLoading");
408- }
409384 if(opt['a'] && *opt['a'] != '\0')
410385 {
411386 if (vmargs == NULL)
@@ -533,6 +508,20 @@
533508
534509 original_filename = strrchr(exe_file, '\\') + 1;
535510 new_version = set_version_info(exe_file, version_number, previous_revision, file_description, copyright, company_name, product_name, product_version, original_filename, jar_file);
511+
512+ if(GetResource("CORE_JAR", &res) == NULL)
513+ {
514+ printf("ERROR: GetResource: CORE_JAR\n");
515+ goto EXIT;
516+ }
517+ else
518+ {
519+ if(append_exe_file(exe_file, res.buf, res.len) == FALSE)
520+ {
521+ goto EXIT;
522+ }
523+ }
524+
536525 printf("%s (%d-bit) version %s\r\n", strrchr(exe_file, '\\') + 1, architecture_bits, new_version);
537526
538527 EXIT:
@@ -588,10 +577,11 @@
588577
589578 static DWORD get_version_revision(char* filename)
590579 {
591- /* GetFileVersionInfoSize, GetFileVersionInfo ?ス?ス?スg?ス?ス?スニ難ソス?ス?ス?ス?ス LoadLibrary ?ス?ス?スg?スp?ス?ス?ス?ス?ス轤オ?ス?ス
592- * ?ス?ス?スフ鯉ソスフ?ソス?ス\?ス[?スX?ス?ス?ス?ス?ス?ス?スンゑソス?ス?ス?スワゑソス?ス?ス?ス?ス?スネゑソス?スネゑソス謔、?スナゑソス?スB?スネので、?ス?ス?スヘゑソス EXE?スt?ス@?スC?ス?ス?ス?ス?ス?ス
593- * ?ス?ス?スr?スW?ス?ス?ス?ス?スi?ス?ス?スo?ス[?ス?ス?ス?ス?スo?ス?ス?ス謔、?スノ変更?ス?ス?スワゑソス?ス?ス?スB
594- */
580+ /* GetFileVersionInfoSize, GetFileVersionInfo を使うと内部で LoadLibrary が使用されるらしく
581+ * その後のリソース書き込みがうまくいかなくなるようです。なので、自力で EXEファイルから
582+ * リビジョンナンバーを取り出すように変更しました。
583+ */
584+ int SCAN_SIZE = 8192 * 3;
595585 DWORD revision = 0;
596586 HANDLE hFile;
597587 char HEADER[] = "VS_VERSION_INFO";
@@ -601,7 +591,7 @@
601591 unsigned int i;
602592 size_t j;
603593
604- buf = (BYTE*)malloc(8192);
594+ buf = (BYTE*)malloc(SCAN_SIZE);
605595
606596 hFile = CreateFile(filename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
607597 if (hFile == INVALID_HANDLE_VALUE)
@@ -609,8 +599,8 @@
609599 goto EXIT;
610600 }
611601
612- SetFilePointer(hFile, -1 * 8192, 0, FILE_END);
613- ReadFile(hFile, buf, 8192, &size, NULL);
602+ SetFilePointer(hFile, -1 * SCAN_SIZE, 0, FILE_END);
603+ ReadFile(hFile, buf, SCAN_SIZE, &size, NULL);
614604 CloseHandle(hFile);
615605
616606 len = strlen(HEADER);
@@ -679,10 +669,6 @@
679669 }
680670 image_buf = buf;
681671 }
682- else
683- {
684- buf = image_buf;
685- }
686672
687673 while (image_len > 0)
688674 {
@@ -711,6 +697,41 @@
711697 }
712698
713699
700+static BOOL append_exe_file(const char* filename, BYTE* image_buf, DWORD image_len)
701+{
702+ BOOL ret = FALSE;
703+ HANDLE hFile;
704+ BYTE* buf = NULL;
705+ DWORD write_size;
706+ char* dir;
707+ char* ptr;
708+
709+ hFile = CreateFile(filename, FILE_APPEND_DATA, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
710+ if (hFile == INVALID_HANDLE_VALUE)
711+ {
712+ printf("Failed to open file: %s\n", filename);
713+ goto EXIT;
714+ }
715+
716+ while (image_len > 0)
717+ {
718+ if (WriteFile(hFile, image_buf, image_len, &write_size, NULL) == 0)
719+ {
720+ printf("Failed to write: %s\n", filename);
721+ goto EXIT;
722+ }
723+ image_buf += write_size;
724+ image_len -= write_size;
725+ }
726+ CloseHandle(hFile);
727+
728+ ret = TRUE;
729+
730+EXIT:
731+ return ret;
732+}
733+
734+
714735 /*
715736 * major(7bit) 31-25
716737 * minor(7bit) 24-18
@@ -760,7 +781,7 @@
760781
761782 *(DWORD*)buf = version;
762783
763- //1.7?ス`
784+ //1.7-
764785 if (major == 1 && minor >= 7 && build == 0)
765786 {
766787 if(revision == 0)
@@ -1056,7 +1077,7 @@
10561077 product_version_build = atoi(strtok(NULL, "."));
10571078 product_version_revision = atoi(strtok(NULL, "."));
10581079
1059- // revison ?ス?ス?ス?ス?ス?ス?スI?スノ指?ス閧ウ?ス?ストゑソス?スネゑソス?ス?ス?ス?ス?ス鼾?ソスA?ス?ス?ス?ス?スt?ス@?スC?ス?ス?ス?ス?ス?ス謫セ?ス?ス?ス?ス?スl?ス?ス 1?ス@?ス?ス?ス?ス?スZ?ス?ス?ス?ス revision ?スニゑソス?ス?スB
1080+ // revison が明示的に指定されていなかった場合、既存ファイルから取得した値に 1 を加算して revision とする。
10601081 strcpy(buffer, version_number);
10611082 if (strtok(buffer, ".") != NULL)
10621083 {
@@ -1073,7 +1094,7 @@
10731094 }
10741095
10751096 file_version_revision = (short)previous_revision + 1;
1076- // build ?ス?ス?スZ?ス?ス?ス閧ア?ス?ス?スワで。
1097+ // build 加算判定ここまで。
10771098 sprintf(file_version, "%d.%d.%d.%d", file_version_major, file_version_minor, file_version_build, file_version_revision);
10781099
10791100 GetResource("VERSION_INFO", &res);
--- exewrap/trunk/exewrap/src/message.c (revision 38)
+++ exewrap/trunk/exewrap/src/message.c (revision 39)
@@ -82,7 +82,7 @@
8282 msg[MSG_ID_COUNT * MSG_LANG_ID_EN + MSG_ID_ERR_TARGET_VERSION] =
8383 "%s or higher is required to run this program.";
8484
85- msg[MSG_ID_COUNT * MSG_LANG_ID_EN + MSG_ID_ERR_DEFINE_CLASS] =
85+ msg[MSG_ID_COUNT * MSG_LANG_ID_EN + MSG_ID_ERR_FIND_CLASS] =
8686 "Class not found: %s";
8787
8888 msg[MSG_ID_COUNT * MSG_LANG_ID_EN + MSG_ID_ERR_GET_CONSTRUCTOR] =
@@ -182,7 +182,7 @@
182182 msg[MSG_ID_COUNT * MSG_LANG_ID_JA + MSG_ID_ERR_TARGET_VERSION] =
183183 "このプログラムの実行には%s以上が必要です。";
184184
185- msg[MSG_ID_COUNT * MSG_LANG_ID_JA + MSG_ID_ERR_DEFINE_CLASS] =
185+ msg[MSG_ID_COUNT * MSG_LANG_ID_JA + MSG_ID_ERR_FIND_CLASS] =
186186 "クラスが見つかりません: %s";
187187
188188 msg[MSG_ID_COUNT * MSG_LANG_ID_JA + MSG_ID_ERR_GET_CONSTRUCTOR] =
--- exewrap/trunk/exewrap/src/image_gui.c (revision 38)
+++ exewrap/trunk/exewrap/src/image_gui.c (revision 39)
@@ -119,7 +119,7 @@
119119 {
120120 vm_args_opt = (char*)GetResource("VMARGS", NULL);
121121 }
122- CreateJavaVM(vm_args_opt, use_server_vm, use_side_by_side_jre, &err);
122+ CreateJavaVM(vm_args_opt, "exewrap.core.ExewrapClassLoader", use_server_vm, use_side_by_side_jre, &err);
123123 if (err != JNI_OK)
124124 {
125125 OutputMessage(GetJniErrorMessage(err, &result.msg_id, result.msg));
--- exewrap/trunk/exewrap/src/Makefile (revision 38)
+++ exewrap/trunk/exewrap/src/Makefile (revision 39)
@@ -47,15 +47,6 @@
4747 IMAGE_X86 : $(OBJ)\image_console.exe $(OBJ)\image_gui.exe $(OBJ)\image_service.exe
4848 IMAGE_X64 : $(OBJ)\image_console.exe $(OBJ)\image_gui.exe $(OBJ)\image_service.exe
4949
50-TRACE_EXEWRAP_X86 : $(BIN)\exewrap-trace.exe
51-TRACE_EXEWRAP_X64 : $(BIN)\exewrap-trace.exe
52-
53-TRACE_IMAGE_X86 : $(OBJ)\image_console_trace.exe $(OBJ)\image_gui_trace.exe $(OBJ)\image_service_trace.exe
54-TRACE_IMAGE_X64 : $(OBJ)\image_console_trace.exe $(OBJ)\image_gui_trace.exe $(OBJ)\image_service_trace.exe
55-
56-JREMIN_X86 : $(BIN)\jremin.exe
57-JREMIN_X64 : $(BIN)\jremin.exe
58-
5950 CLEAN :
6051 @if exist $(OBJ)\..\x86 RMDIR /S /Q $(OBJ)\..\x86
6152 @if exist $(OBJ)\..\x64 RMDIR /S /Q $(OBJ)\..\x64
@@ -65,53 +56,28 @@
6556
6657 $(OBJ) :
6758 @if not exist $(OBJ)/$(NULL) mkdir $(OBJ)
59+
60+$(OBJ)\exewrap-tool :
61+ @if not exist $(OBJ)\exewrap-tool/$(NULL) mkdir $(OBJ)\exewrap-tool
6862
6963 $(BIN)\exewrap.exe : $(BIN) $(OBJ) $(OBJ)\exewrap.res $(OBJ)\exewrap.obj \
7064 $(OBJ)\jvm.obj $(OBJ)\loader.obj $(OBJ)\message.obj $(OBJ)\eventlog.obj \
7165 $(OBJ)\image_console.exe $(OBJ)\image_gui.exe $(OBJ)\image_service.exe \
72- $(OBJ)\bindres.exe $(OBJ)\exewrap\core\ByteBufferInputStream.class $(OBJ)\exewrap\core\ExewrapClassLoader.class $(OBJ)\tool.jar
73- $(LINK) $(LDFLAGS) /SUBSYSTEM:CONSOLE$(TARGET_VER) /MANIFEST /MANIFESTFILE:$(OBJ)\exewrap\exewrap.exe.manifest /OUT:$(BIN)\exewrap.exe $(OBJ)\exewrap.res $(OBJ)\exewrap.obj \
66+ $(OBJ)\bindres.exe $(OBJ)\core.jar $(OBJ)\tool.jar
67+ $(LINK) $(LDFLAGS) /SUBSYSTEM:CONSOLE$(TARGET_VER) /MANIFEST /MANIFESTFILE:$(OBJ)\exewrap.exe.manifest /OUT:$(OBJ)\exewrap.exe $(OBJ)\exewrap.res $(OBJ)\exewrap.obj \
7468 $(OBJ)\jvm.obj $(OBJ)\loader.obj $(OBJ)\message.obj $(OBJ)\eventlog.obj $(LIBS) $(MSVCRT_PATCH)
75- $(MT) -manifest $(OBJ)\exewrap\exewrap.exe.manifest -outputresource:$(BIN)\exewrap.exe;1
76- $(OBJ)\bindres.exe $(BIN)\exewrap.exe VERSION_INFO resources\versioninfo.bin
77- $(OBJ)\bindres.exe -r $(BIN)\exewrap.exe IMAGE_CONSOLE_32 $(OBJ)\..\x86\image_console.exe
78- $(OBJ)\bindres.exe -r $(BIN)\exewrap.exe IMAGE_CONSOLE_64 $(OBJ)\..\x64\image_console.exe
79- $(OBJ)\bindres.exe -r $(BIN)\exewrap.exe IMAGE_GUI_32 $(OBJ)\..\x86\image_gui.exe
80- $(OBJ)\bindres.exe -r $(BIN)\exewrap.exe IMAGE_GUI_64 $(OBJ)\..\x64\image_gui.exe
81- $(OBJ)\bindres.exe -r $(BIN)\exewrap.exe IMAGE_SERVICE_32 $(OBJ)\..\x86\image_service.exe
82- $(OBJ)\bindres.exe -r $(BIN)\exewrap.exe IMAGE_SERVICE_64 $(OBJ)\..\x64\image_service.exe
83- $(OBJ)\bindres.exe $(BIN)\exewrap.exe BYTE_BUFFER_INPUT_STREAM $(OBJ)\exewrap\core\ByteBufferInputStream.class
84- $(OBJ)\bindres.exe $(BIN)\exewrap.exe PACK_INPUT_STREAM $(OBJ)\exewrap\core\PackInputStream.class
85- $(OBJ)\bindres.exe $(BIN)\exewrap.exe URL_CONNECTION $(OBJ)\exewrap\core\URLConnection.class
86- $(OBJ)\bindres.exe $(BIN)\exewrap.exe URL_STREAM_HANDLER $(OBJ)\exewrap\core\URLStreamHandler.class
87- $(OBJ)\bindres.exe $(BIN)\exewrap.exe URL_STREAM_HANDLER_FACTORY $(OBJ)\exewrap\core\URLStreamHandlerFactory.class
88- $(OBJ)\bindres.exe $(BIN)\exewrap.exe EXEWRAP_CLASS_LOADER $(OBJ)\exewrap\core\ExewrapClassLoader.class
89- $(OBJ)\bindres.exe $(BIN)\exewrap.exe UTIL_JAR $(OBJ)\util.jar
90- $(OBJ)\bindres.exe $(BIN)\exewrap.exe JAR $(OBJ)\tool.jar
69+ $(MT) -manifest $(OBJ)\exewrap.exe.manifest -outputresource:$(BIN)\exewrap.exe;1
70+ $(OBJ)\bindres.exe $(OBJ)\exewrap.exe VERSION_INFO resources\versioninfo.bin
71+ $(OBJ)\bindres.exe -r $(OBJ)\exewrap.exe IMAGE_CONSOLE_32 $(OBJ)\..\x86\image_console.exe
72+ $(OBJ)\bindres.exe -r $(OBJ)\exewrap.exe IMAGE_CONSOLE_64 $(OBJ)\..\x64\image_console.exe
73+ $(OBJ)\bindres.exe -r $(OBJ)\exewrap.exe IMAGE_GUI_32 $(OBJ)\..\x86\image_gui.exe
74+ $(OBJ)\bindres.exe -r $(OBJ)\exewrap.exe IMAGE_GUI_64 $(OBJ)\..\x64\image_gui.exe
75+ $(OBJ)\bindres.exe -r $(OBJ)\exewrap.exe IMAGE_SERVICE_32 $(OBJ)\..\x86\image_service.exe
76+ $(OBJ)\bindres.exe -r $(OBJ)\exewrap.exe IMAGE_SERVICE_64 $(OBJ)\..\x64\image_service.exe
77+ $(OBJ)\bindres.exe $(OBJ)\exewrap.exe JAR $(OBJ)\tool.jar
78+ $(OBJ)\bindres.exe $(OBJ)\exewrap.exe CORE_JAR $(OBJ)\core.jar
79+ copy /V /Y /B $(OBJ)\exewrap.exe + $(OBJ)\core.jar $(BIN)\exewrap.exe
9180
92-$(BIN)\exewrap-trace.exe : $(BIN) $(OBJ) $(OBJ)\exewrap.res $(OBJ)\exewrap.obj \
93- $(OBJ)\jvm.obj $(OBJ)\loader.obj $(OBJ)\message.obj $(OBJ)\eventlog.obj \
94- $(OBJ)\image_console_trace.exe $(OBJ)\image_gui_trace.exe $(OBJ)\image_service_trace.exe \
95- $(OBJ)\bindres.exe $(OBJ)\exewrap\core\ByteBufferInputStream.class $(OBJ)\exewrap\core\ExewrapClassLoader.class $(OBJ)\tool.jar
96- $(LINK) $(LDFLAGS) /SUBSYSTEM:CONSOLE$(TARGET_VER) /MANIFEST /MANIFESTFILE:$(OBJ)\exewrap\exewrap-trace.exe.manifest /OUT:$(BIN)\exewrap-trace.exe $(OBJ)\exewrap.res $(OBJ)\exewrap.obj \
97- $(OBJ)\jvm.obj $(OBJ)\loader.obj $(OBJ)\message.obj $(OBJ)\eventlog.obj $(LIBS) $(MSVCRT_PATCH)
98- $(MT) -manifest $(OBJ)\exewrap\exewrap-trace.exe.manifest -outputresource:$(BIN)\exewrap-trace.exe;1
99- $(OBJ)\bindres.exe $(BIN)\exewrap-trace.exe VERSION_INFO resources\versioninfo.bin
100- $(OBJ)\bindres.exe -r $(BIN)\exewrap-trace.exe IMAGE_TRACE_CONSOLE_32 $(OBJ)\..\x86\image_console_trace.exe
101- $(OBJ)\bindres.exe -r $(BIN)\exewrap-trace.exe IMAGE_TRACE_CONSOLE_64 $(OBJ)\..\x64\image_console_trace.exe
102- $(OBJ)\bindres.exe -r $(BIN)\exewrap-trace.exe IMAGE_TRACE_GUI_32 $(OBJ)\..\x86\image_gui_trace.exe
103- $(OBJ)\bindres.exe -r $(BIN)\exewrap-trace.exe IMAGE_TRACE_GUI_64 $(OBJ)\..\x64\image_gui_trace.exe
104- $(OBJ)\bindres.exe -r $(BIN)\exewrap-trace.exe IMAGE_TRACE_SERVICE_32 $(OBJ)\..\x86\image_service_trace.exe
105- $(OBJ)\bindres.exe -r $(BIN)\exewrap-trace.exe IMAGE_TRACE_SERVICE_64 $(OBJ)\..\x64\image_service_trace.exe
106- $(OBJ)\bindres.exe $(BIN)\exewrap-trace.exe BYTE_BUFFER_INPUT_STREAM $(OBJ)\exewrap\core\ByteBufferInputStream.class
107- $(OBJ)\bindres.exe $(BIN)\exewrap-trace.exe PACK_INPUT_STREAM $(OBJ)\exewrap\core\PackInputStream.class
108- $(OBJ)\bindres.exe $(BIN)\exewrap-trace.exe URL_CONNECTION $(OBJ)\exewrap\core\URLConnection.class
109- $(OBJ)\bindres.exe $(BIN)\exewrap-trace.exe URL_STREAM_HANDLER $(OBJ)\exewrap\core\URLStreamHandler.class
110- $(OBJ)\bindres.exe $(BIN)\exewrap-trace.exe URL_STREAM_HANDLER_FACTORY $(OBJ)\exewrap\core\URLStreamHandlerFactory.class
111- $(OBJ)\bindres.exe $(BIN)\exewrap-trace.exe EXEWRAP_CLASS_LOADER $(OBJ)\exewrap\core\ExewrapClassLoader.class
112- $(OBJ)\bindres.exe $(BIN)\exewrap-trace.exe UTIL_JAR $(OBJ)\util.jar
113- $(OBJ)\bindres.exe $(BIN)\exewrap-trace.exe JAR $(OBJ)\tool.jar
114-
11581 $(OBJ)\exewrap.obj : $(OBJ) exewrap.c
11682 $(CC) $(CFLAGS) $(INC) /Fo$(OBJ)\exewrap.obj exewrap.c
11783
@@ -120,34 +86,11 @@
12086
12187 $(OBJ)\image_console.exe : $(OBJ) $(OBJ)\image_console.res $(OBJ)\image_console.obj \
12288 $(OBJ)\jvm.obj $(OBJ)\loader.obj $(OBJ)\message.obj $(OBJ)\notify.obj $(OBJ)\eventlog.obj \
123- $(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)\exewrap\core\URLStreamHandlerFactory.class $(OBJ)\util.jar
89+ $(OBJ)\bindres.exe $(OBJ)\core.jar
12490 $(LINK) $(LDFLAGS) /SUBSYSTEM:CONSOLE$(TARGET_VER) /MANIFEST /OUT:$(OBJ)\image_console.exe $(OBJ)\image_console.obj \
12591 $(OBJ)\jvm.obj $(OBJ)\loader.obj $(OBJ)\message.obj $(OBJ)\notify.obj $(OBJ)\eventlog.obj $(LIBS) $(MSVCRT_PATCH)
12692 $(MT) -manifest $(OBJ)\image_console.exe.manifest -outputresource:$(OBJ)\image_console.exe;1
127- $(OBJ)\bindres.exe $(OBJ)\image_console.exe BYTE_BUFFER_INPUT_STREAM $(OBJ)\exewrap\core\ByteBufferInputStream.class
128- $(OBJ)\bindres.exe $(OBJ)\image_console.exe PACK_INPUT_STREAM $(OBJ)\exewrap\core\PackInputStream.class
129- $(OBJ)\bindres.exe $(OBJ)\image_console.exe URL_CONNECTION $(OBJ)\exewrap\core\URLConnection.class
130- $(OBJ)\bindres.exe $(OBJ)\image_console.exe URL_STREAM_HANDLER $(OBJ)\exewrap\core\URLStreamHandler.class
131- $(OBJ)\bindres.exe $(OBJ)\image_console.exe URL_STREAM_HANDLER_FACTORY $(OBJ)\exewrap\core\URLStreamHandlerFactory.class
132- $(OBJ)\bindres.exe $(OBJ)\image_console.exe EXEWRAP_CLASS_LOADER $(OBJ)\exewrap\core\ExewrapClassLoader.class
133- $(OBJ)\bindres.exe $(OBJ)\image_console.exe UTIL_JAR $(OBJ)\util.jar
13493
135-$(OBJ)\image_console_trace.exe : $(OBJ) $(OBJ)\image_console.res $(OBJ)\image_console_trace.obj $(OBJ)\trace.obj \
136- $(OBJ)\buffer.obj $(OBJ)\hde$(BITS).obj $(OBJ)\hook.obj $(OBJ)\trampoline.obj \
137- $(OBJ)\jvm.obj $(OBJ)\loader.obj $(OBJ)\message.obj $(OBJ)\notify.obj $(OBJ)\eventlog.obj \
138- $(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)\exewrap\core\URLStreamHandlerFactory.class $(OBJ)\util.jar
139- $(LINK) $(LDFLAGS) /SUBSYSTEM:CONSOLE$(TARGET_VER) /MANIFEST /OUT:$(OBJ)\image_console_trace.exe $(OBJ)\image_console_trace.obj $(OBJ)\trace.obj \
140- $(OBJ)\buffer.obj $(OBJ)\hde$(BITS).obj $(OBJ)\hook.obj $(OBJ)\trampoline.obj \
141- $(OBJ)\jvm.obj $(OBJ)\loader.obj $(OBJ)\message.obj $(OBJ)\notify.obj $(OBJ)\eventlog.obj $(LIBS) $(MSVCRT_PATCH)
142- $(MT) -manifest $(OBJ)\image_console_trace.exe.manifest -outputresource:$(OBJ)\image_console_trace.exe;1
143- $(OBJ)\bindres.exe $(OBJ)\image_console_trace.exe BYTE_BUFFER_INPUT_STREAM $(OBJ)\exewrap\core\ByteBufferInputStream.class
144- $(OBJ)\bindres.exe $(OBJ)\image_console_trace.exe PACK_INPUT_STREAM $(OBJ)\exewrap\core\PackInputStream.class
145- $(OBJ)\bindres.exe $(OBJ)\image_console_trace.exe URL_CONNECTION $(OBJ)\exewrap\core\URLConnection.class
146- $(OBJ)\bindres.exe $(OBJ)\image_console_trace.exe URL_STREAM_HANDLER $(OBJ)\exewrap\core\URLStreamHandler.class
147- $(OBJ)\bindres.exe $(OBJ)\image_console_trace.exe URL_STREAM_HANDLER_FACTORY $(OBJ)\exewrap\core\URLStreamHandlerFactory.class
148- $(OBJ)\bindres.exe $(OBJ)\image_console_trace.exe EXEWRAP_CLASS_LOADER $(OBJ)\exewrap\core\ExewrapClassLoader.class
149- $(OBJ)\bindres.exe $(OBJ)\image_console_trace.exe UTIL_JAR $(OBJ)\util.jar
150-
15194 $(OBJ)\image_console.res : $(OBJ) resources\image_console.rc resources\eventlog.bin
15295 $(RC) /fo$(OBJ)\image_console.res resources\image_console.rc
15396
@@ -154,39 +97,13 @@
15497 $(OBJ)\image_console.obj : $(OBJ) image_console.c
15598 $(CC) $(CFLAGS) $(INC) /Fo$(OBJ)\image_console.obj image_console.c
15699
157-$(OBJ)\image_console_trace.obj : $(OBJ) image_console.c
158- $(CC) $(CFLAGS) $(INC) /DTRACE /Fo$(OBJ)\image_console_trace.obj image_console.c
159-
160100 $(OBJ)\image_gui.exe : $(OBJ) $(OBJ)\image_gui.res $(OBJ)\image_gui.obj \
161101 $(OBJ)\jvm.obj $(OBJ)\loader.obj $(OBJ)\message.obj $(OBJ)\notify.obj $(OBJ)\eventlog.obj \
162- $(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)\exewrap\core\URLStreamHandlerFactory.class $(OBJ)\util.jar
102+ $(OBJ)\bindres.exe $(OBJ)\core.jar
163103 $(LINK) $(LDFLAGS) /SUBSYSTEM:WINDOWS$(TARGET_VER) /MANIFEST /OUT:$(OBJ)\image_gui.exe $(OBJ)\image_gui.res $(OBJ)\image_gui.obj \
164104 $(OBJ)\jvm.obj $(OBJ)\loader.obj $(OBJ)\message.obj $(OBJ)\notify.obj $(OBJ)\eventlog.obj $(LIBS) $(MSVCRT_PATCH)
165105 $(MT) -manifest $(OBJ)\image_gui.exe.manifest -outputresource:$(OBJ)\image_gui.exe;1
166- $(OBJ)\bindres.exe $(OBJ)\image_gui.exe BYTE_BUFFER_INPUT_STREAM $(OBJ)\exewrap\core\ByteBufferInputStream.class
167- $(OBJ)\bindres.exe $(OBJ)\image_gui.exe PACK_INPUT_STREAM $(OBJ)\exewrap\core\PackInputStream.class
168- $(OBJ)\bindres.exe $(OBJ)\image_gui.exe URL_CONNECTION $(OBJ)\exewrap\core\URLConnection.class
169- $(OBJ)\bindres.exe $(OBJ)\image_gui.exe URL_STREAM_HANDLER $(OBJ)\exewrap\core\URLStreamHandler.class
170- $(OBJ)\bindres.exe $(OBJ)\image_gui.exe URL_STREAM_HANDLER_FACTORY $(OBJ)\exewrap\core\URLStreamHandlerFactory.class
171- $(OBJ)\bindres.exe $(OBJ)\image_gui.exe EXEWRAP_CLASS_LOADER $(OBJ)\exewrap\core\ExewrapClassLoader.class
172- $(OBJ)\bindres.exe $(OBJ)\image_gui.exe UTIL_JAR $(OBJ)\util.jar
173106
174-$(OBJ)\image_gui_trace.exe : $(OBJ) $(OBJ)\image_gui.res $(OBJ)\image_gui_trace.obj $(OBJ)\trace.obj \
175- $(OBJ)\buffer.obj $(OBJ)\hde$(BITS).obj $(OBJ)\hook.obj $(OBJ)\trampoline.obj \
176- $(OBJ)\jvm.obj $(OBJ)\loader.obj $(OBJ)\message.obj $(OBJ)\notify.obj $(OBJ)\eventlog.obj \
177- $(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)\exewrap\core\URLStreamHandlerFactory.class $(OBJ)\util.jar
178- $(LINK) $(LDFLAGS) /SUBSYSTEM:WINDOWS$(TARGET_VER) /MANIFEST /OUT:$(OBJ)\image_gui_trace.exe $(OBJ)\image_gui.res $(OBJ)\image_gui_trace.obj $(OBJ)\trace.obj \
179- $(OBJ)\buffer.obj $(OBJ)\hde$(BITS).obj $(OBJ)\hook.obj $(OBJ)\trampoline.obj \
180- $(OBJ)\jvm.obj $(OBJ)\loader.obj $(OBJ)\message.obj $(OBJ)\notify.obj $(OBJ)\eventlog.obj $(LIBS) $(MSVCRT_PATCH)
181- $(MT) -manifest $(OBJ)\image_gui_trace.exe.manifest -outputresource:$(OBJ)\image_gui_trace.exe;1
182- $(OBJ)\bindres.exe $(OBJ)\image_gui_trace.exe BYTE_BUFFER_INPUT_STREAM $(OBJ)\exewrap\core\ByteBufferInputStream.class
183- $(OBJ)\bindres.exe $(OBJ)\image_gui_trace.exe PACK_INPUT_STREAM $(OBJ)\exewrap\core\PackInputStream.class
184- $(OBJ)\bindres.exe $(OBJ)\image_gui_trace.exe URL_CONNECTION $(OBJ)\exewrap\core\URLConnection.class
185- $(OBJ)\bindres.exe $(OBJ)\image_gui_trace.exe URL_STREAM_HANDLER $(OBJ)\exewrap\core\URLStreamHandler.class
186- $(OBJ)\bindres.exe $(OBJ)\image_gui_trace.exe URL_STREAM_HANDLER_FACTORY $(OBJ)\exewrap\core\URLStreamHandlerFactory.class
187- $(OBJ)\bindres.exe $(OBJ)\image_gui_trace.exe EXEWRAP_CLASS_LOADER $(OBJ)\exewrap\core\ExewrapClassLoader.class
188- $(OBJ)\bindres.exe $(OBJ)\image_gui_trace.exe UTIL_JAR $(OBJ)\util.jar
189-
190107 $(OBJ)\image_gui.res : $(OBJ) resources\image_gui.rc resources\eventlog.bin
191108 $(RC) /fo$(OBJ)\image_gui.res resources\image_gui.rc
192109
@@ -193,39 +110,13 @@
193110 $(OBJ)\image_gui.obj : $(OBJ) image_gui.c
194111 $(CC) $(CFLAGS) $(INC) /Fo$(OBJ)\image_gui.obj image_gui.c
195112
196-$(OBJ)\image_gui_trace.obj : $(OBJ) image_gui.c
197- $(CC) $(CFLAGS) $(INC) /DTRACE /Fo$(OBJ)\image_gui_trace.obj image_gui.c
198-
199113 $(OBJ)\image_service.exe : $(OBJ) $(OBJ)\image_service.res $(OBJ)\image_service.obj \
200114 $(OBJ)\jvm.obj $(OBJ)\loader.obj $(OBJ)\message.obj $(OBJ)\eventlog.obj \
201- $(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)\exewrap\core\URLStreamHandlerFactory.class $(OBJ)\util.jar
115+ $(OBJ)\bindres.exe $(OBJ)\core.jar
202116 $(LINK) $(LDFLAGS) /SUBSYSTEM:CONSOLE$(TARGET_VER) /MANIFEST /OUT:$(OBJ)\image_service.exe $(OBJ)\image_service.res $(OBJ)\image_service.obj \
203117 $(OBJ)\jvm.obj $(OBJ)\loader.obj $(OBJ)\message.obj $(OBJ)\eventlog.obj $(LIBS) $(MSVCRT_PATCH)
204118 $(MT) -manifest $(OBJ)\image_service.exe.manifest -outputresource:$(OBJ)\image_service.exe;1
205- $(OBJ)\bindres.exe $(OBJ)\image_service.exe BYTE_BUFFER_INPUT_STREAM $(OBJ)\exewrap\core\ByteBufferInputStream.class
206- $(OBJ)\bindres.exe $(OBJ)\image_service.exe PACK_INPUT_STREAM $(OBJ)\exewrap\core\PackInputStream.class
207- $(OBJ)\bindres.exe $(OBJ)\image_service.exe URL_CONNECTION $(OBJ)\exewrap\core\URLConnection.class
208- $(OBJ)\bindres.exe $(OBJ)\image_service.exe URL_STREAM_HANDLER $(OBJ)\exewrap\core\URLStreamHandler.class
209- $(OBJ)\bindres.exe $(OBJ)\image_service.exe URL_STREAM_HANDLER_FACTORY $(OBJ)\exewrap\core\URLStreamHandlerFactory.class
210- $(OBJ)\bindres.exe $(OBJ)\image_service.exe EXEWRAP_CLASS_LOADER $(OBJ)\exewrap\core\ExewrapClassLoader.class
211- $(OBJ)\bindres.exe $(OBJ)\image_service.exe UTIL_JAR $(OBJ)\util.jar
212119
213-$(OBJ)\image_service_trace.exe : $(OBJ) $(OBJ)\image_service.res $(OBJ)\image_service_trace.obj $(OBJ)\trace.obj \
214- $(OBJ)\buffer.obj $(OBJ)\hde$(BITS).obj $(OBJ)\hook.obj $(OBJ)\trampoline.obj \
215- $(OBJ)\jvm.obj $(OBJ)\loader.obj $(OBJ)\message.obj $(OBJ)\eventlog.obj \
216- $(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)\exewrap\core\URLStreamHandlerFactory.class $(OBJ)\util.jar
217- $(LINK) $(LDFLAGS) /SUBSYSTEM:CONSOLE$(TARGET_VER) /MANIFEST /OUT:$(OBJ)\image_service_trace.exe $(OBJ)\image_service.res $(OBJ)\image_service_trace.obj $(OBJ)\trace.obj \
218- $(OBJ)\buffer.obj $(OBJ)\hde$(BITS).obj $(OBJ)\hook.obj $(OBJ)\trampoline.obj \
219- $(OBJ)\jvm.obj $(OBJ)\loader.obj $(OBJ)\message.obj $(OBJ)\eventlog.obj $(LIBS) $(MSVCRT_PATCH)
220- $(MT) -manifest $(OBJ)\image_service_trace.exe.manifest -outputresource:$(OBJ)\image_service_trace.exe;1
221- $(OBJ)\bindres.exe $(OBJ)\image_service_trace.exe BYTE_BUFFER_INPUT_STREAM $(OBJ)\exewrap\core\ByteBufferInputStream.class
222- $(OBJ)\bindres.exe $(OBJ)\image_service_trace.exe PACK_INPUT_STREAM $(OBJ)\exewrap\core\PackInputStream.class
223- $(OBJ)\bindres.exe $(OBJ)\image_service_trace.exe URL_CONNECTION $(OBJ)\exewrap\core\URLConnection.class
224- $(OBJ)\bindres.exe $(OBJ)\image_service_trace.exe URL_STREAM_HANDLER $(OBJ)\exewrap\core\URLStreamHandler.class
225- $(OBJ)\bindres.exe $(OBJ)\image_service_trace.exe URL_STREAM_HANDLER_FACTORY $(OBJ)\exewrap\core\URLStreamHandlerFactory.class
226- $(OBJ)\bindres.exe $(OBJ)\image_service_trace.exe EXEWRAP_CLASS_LOADER $(OBJ)\exewrap\core\ExewrapClassLoader.class
227- $(OBJ)\bindres.exe $(OBJ)\image_service_trace.exe UTIL_JAR $(OBJ)\util.jar
228-
229120 $(OBJ)\image_service.res : $(OBJ) resources\image_service.rc resources\eventlog.bin
230121 $(RC) /fo$(OBJ)\image_service.res resources\image_service.rc
231122
@@ -232,9 +123,6 @@
232123 $(OBJ)\image_service.obj : $(OBJ) image_service.c
233124 $(CC) $(CFLAGS) $(INC) /Fo$(OBJ)\image_service.obj image_service.c
234125
235-$(OBJ)\image_service_trace.obj : $(OBJ) image_service.c
236- $(CC) $(CFLAGS) $(INC) /Fo$(OBJ)\image_service_trace.obj image_service.c
237-
238126 $(OBJ)\eventlog.obj : $(OBJ) eventlog.c
239127 $(CC) $(CFLAGS) $(INC) /Fo$(OBJ)\eventlog.obj eventlog.c
240128
@@ -250,9 +138,6 @@
250138 $(OBJ)\jvm.obj : $(OBJ) jvm.c
251139 $(CC) $(CFLAGS) $(INC) /Fo$(OBJ)\jvm.obj jvm.c
252140
253-$(OBJ)\trace.obj : $(OBJ) trace.c
254- $(CC) $(CFLAGS) $(INC) /Fo$(OBJ)\trace.obj trace.c
255-
256141 $(OBJ)\bindres.exe : $(OBJ) $(OBJ)\bindres.obj
257142 $(LINK) $(LDFLAGS) /SUBSYSTEM:CONSOLE$(TARGET_VER) /OUT:$(OBJ)\bindres.exe $(OBJ)\bindres.obj $(LIBS) $(MSVCRT_PATCH)
258143
@@ -261,28 +146,14 @@
261146
262147
263148 ###
264-### MinHook
149+### Java
265150 ###
266151
267-$(OBJ)\buffer.obj : minhook\src\buffer.c
268- $(CC) $(CFLAGS) $(INC) /Fo$(OBJ)\buffer.obj minhook\src\buffer.c
269-
270-$(OBJ)\hook.obj : minhook\src\hook.c
271- $(CC) $(CFLAGS) $(INC) /I minhook\WindowsSDK\include /Fo$(OBJ)\hook.obj minhook\src\hook.c
272-
273-$(OBJ)\trampoline.obj : minhook\src\trampoline.c
274- $(CC) $(CFLAGS) $(INC) /Fo$(OBJ)\trampoline.obj minhook\src\trampoline.c
152+### exewrap.core (including exewrap.util)
275153
276-$(OBJ)\hde$(BITS).obj : minhook\src\HDE\hde$(BITS).c
277- $(CC) $(CFLAGS) $(INC) /Fo$(OBJ)\hde$(BITS).obj minhook\src\HDE\hde$(BITS).c
154+$(OBJ)\core.jar : $(OBJ) $(OBJ)\exewrap\core\ExewrapClassLoader.class $(OBJ)\exewrap\core\PackInputStream.class $(OBJ)\exewrap\core\ByteBufferInputStream.class $(OBJ)\exewrap\core\URLConnection.class $(OBJ)\exewrap\core\URLStreamHandler.class $(OBJ)\exewrap\core\URLStreamHandler.class $(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 $(OBJ)\exewrap\util\Environment.class
155+ $(JAR) cvf $(OBJ)\core.jar -C $(OBJ) exewrap
278156
279-
280-###
281-### Java
282-###
283-
284-### exewrap.core
285-
286157 $(OBJ)\exewrap\core\ExewrapClassLoader.class : $(OBJ) java\exewrap\core\ExewrapClassLoader.java
287158 $(JAVAC) -Xlint:none -source 1.5 -target 1.5 -sourcepath java -d $(OBJ) java\exewrap\core\ExewrapClassLoader.java
288159
@@ -326,42 +197,12 @@
326197
327198 ### exewrap.tool
328199
329-$(OBJ)\tool.jar : $(OBJ) $(OBJ)\exewrap\tool\JarProcessor.class $(OBJ)\exewrap\tool\PackOutputStream.class
330- $(JAR) cvfe $(OBJ)\tool.jar exewrap.tool.JarProcessor -C $(OBJ) exewrap\tool
200+$(OBJ)\tool.jar : $(OBJ) $(OBJ)\exewrap-tool $(OBJ)\exewrap\tool\JarProcessor.class $(OBJ)\exewrap\tool\PackOutputStream.class
201+ $(JAR) cvfe $(OBJ)\tool.jar exewrap.tool.JarProcessor -C $(OBJ)\exewrap-tool exewrap\tool
331202
332203 $(OBJ)\exewrap\tool\PackOutputStream.class : $(OBJ) java\exewrap\tool\PackOutputStream.java
333- $(JAVAC) -Xlint:none -source 1.5 -target 1.5 -sourcepath java -d $(OBJ) java\exewrap\tool\PackOutputStream.java
204+ $(JAVAC) -Xlint:none -source 1.5 -target 1.5 -sourcepath java -d $(OBJ)\exewrap-tool java\exewrap\tool\PackOutputStream.java
334205
335206 $(OBJ)\exewrap\tool\JarProcessor.class : $(OBJ) java\exewrap\tool\JarProcessor.java
336- $(JAVAC) -Xlint:none -source 1.5 -target 1.5 -sourcepath java -d $(OBJ) java\exewrap\tool\JarProcessor.java
207+ $(JAVAC) -Xlint:none -source 1.5 -target 1.5 -sourcepath java -d $(OBJ)\exewrap-tool java\exewrap\tool\JarProcessor.java
337208
338-### jeremin
339-
340-$(BIN)\jremin.exe : $(OBJ)\jremin.jar $(BIN)\exewrap.exe
341- $(BIN)\exewrap.exe -o $(BIN)\jremin.exe -j $(OBJ)\jremin.jar -a "-Xmx1024m" -e "NOSIDEBYSIDE" \
342- -p jremin \
343- -V 1.1.0 \
344- -v 1.1.0.0 \
345- -d "Java Runtime Environment (JRE) Minimizer" \
346- -c "Copyright (C) 2015 HIRUKAWA Ryo. All rights reserved."
347-
348-$(OBJ)\jremin.jar : $(OBJ) $(OBJ)\jremin\Jremin.class $(OBJ)\jremin\Trace.class $(OBJ)\jremin\classes.txt
349- $(JAR) cvfe $(OBJ)\jremin.jar jremin.JreMin -C $(OBJ) jremin
350-
351-$(OBJ)\jremin\JreMin.class : $(OBJ) java\jremin\JreMin.java
352- $(JAVAC) -Xlint:none -source 1.5 -target 1.5 -sourcepath java -d $(OBJ) java\jremin\JreMin.java
353-
354-$(OBJ)\jremin\Trace.class : $(OBJ) java\jremin\Trace.java
355- $(JAVAC) -Xlint:none -source 1.5 -target 1.5 -sourcepath java -d $(OBJ) java\jremin\Trace.java
356-
357-$(OBJ)\jremin\classes.txt : $(OBJ) $(OBJ)\agent.exe
358- $(OBJ)\agent.exe > $(OBJ)\jremin\classes.txt
359-
360-$(OBJ)\agent.exe : $(OBJ) $(OBJ)\agent.jar
361- $(BIN)\exewrap.exe -o $(OBJ)\agent.exe -j $(OBJ)\agent.jar -e "NOSIDEBYSIDE" -a "-javaagent:$(OBJ)\agent.jar"
362-
363-$(OBJ)\agent.jar : $(OBJ) $(OBJ)\jremin\agent\Agent.class java\jremin\agent\manifest.txt
364- $(JAR) cvfm $(OBJ)\agent.jar java\jremin\agent\manifest.txt -C $(OBJ) jremin
365-
366-$(OBJ)\jremin\agent\Agent.class : $(OBJ) java\jremin\agent\Agent.java
367- $(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 38)
+++ exewrap/trunk/exewrap/src/jvm.c (revision 39)
@@ -9,7 +9,7 @@
99
1010 void InitializePath(char* relative_classpath, char* relative_extdirs, BOOL useServerVM, BOOL useSideBySideJRE);
1111 int GetProcessArchitecture();
12-JNIEnv* CreateJavaVM(LPTSTR vm_args_opt, BOOL useServerVM, BOOL useSideBySideJRE, int* err);
12+JNIEnv* CreateJavaVM(LPTSTR vm_args_opt, LPTSTR systemClassLoader, BOOL useServerVM, BOOL useSideBySideJRE, int* err);
1313 void DestroyJavaVM();
1414 JNIEnv* AttachJavaVM();
1515 void DetachJavaVM();
@@ -39,6 +39,7 @@
3939 JNIEnv* env = NULL;
4040 DWORD javaRuntimeVersion = 0xFFFFFFFF;
4141
42+char opt_system_class_loader[512];
4243 char opt_app_path[MAX_PATH + 32];
4344 char opt_app_name[MAX_PATH + 32];
4445 char opt_app_version[64];
@@ -58,7 +59,7 @@
5859 return sizeof(int*) * 8;
5960 }
6061
61-JNIEnv* CreateJavaVM(LPTSTR vm_args_opt, BOOL useServerVM, BOOL useSideBySideJRE, int* err)
62+JNIEnv* CreateJavaVM(LPTSTR vm_args_opt, LPTSTR systemClassLoader, BOOL useServerVM, BOOL useSideBySideJRE, int* err)
6263 {
6364 JNIGetDefaultJavaVMInitArgs getDefaultJavaVMInitArgs;
6465 JNICreateJavaVM createJavaVM;
@@ -98,6 +99,13 @@
9899 vm_args.options = options;
99100 vm_args.nOptions = 5;
100101 vm_args.ignoreUnrecognized = 1;
102+
103+ if(systemClassLoader != NULL)
104+ {
105+ lstrcpy(opt_system_class_loader, "-Djava.system.class.loader=");
106+ lstrcat(opt_system_class_loader, systemClassLoader);
107+ options[vm_args.nOptions++].optionString = opt_system_class_loader;
108+ }
101109
102110 if(opt_policy_path[0] != 0x00)
103111 {
@@ -111,6 +119,13 @@
111119 options[vm_args.nOptions++].optionString = argv[i];
112120 }
113121
122+ /*
123+ for(i = 0; i < vm_args.nOptions; i++)
124+ {
125+ printf("[%d] %s\n\n", i, options[i].optionString);
126+ }
127+ */
128+
114129 getDefaultJavaVMInitArgs(&vm_args);
115130 result = createJavaVM(&jvm, (void**)&env, &vm_args);
116131 if(err != NULL)
@@ -317,6 +332,7 @@
317332
318333 void InitializePath(char* relative_classpath, char* relative_extdirs, BOOL useServerVM, BOOL useSideBySideJRE) {
319334 char modulePath[_MAX_PATH];
335+ char moduleFileFullPath[_MAX_PATH];
320336 char* buffer;
321337 char* token;
322338 DWORD size = MAX_PATH;
@@ -354,9 +370,9 @@
354370 lstrcpy(opt_policy_path, "-Djava.security.policy=");
355371 lstrcat(opt_policy_path, modulePath);
356372
357- GetModuleFileName(NULL, buffer, size);
373+ GetModuleFileName(NULL, moduleFileFullPath, MAX_PATH);
358374 lstrcpy(opt_app_name, "-Djava.application.name=");
359- lstrcat(opt_app_name, strrchr(buffer, '\\') + 1);
375+ lstrcat(opt_app_name, strrchr(moduleFileFullPath, '\\') + 1);
360376
361377 lstrcat(opt_policy_path, "\\");
362378 *(strrchr(buffer, '.')) = 0;
@@ -504,6 +520,8 @@
504520 }
505521
506522 lstrcpy(classpath, "-Djava.class.path=");
523+ lstrcat(classpath, moduleFileFullPath);
524+ lstrcat(classpath, ";");
507525 lstrcpy(libpath, "-Djava.library.path=.;");
508526
509527 if(relative_classpath != NULL)
--- exewrap/trunk/exewrap/src/java/jremin/Trace.java (revision 38)
+++ exewrap/trunk/exewrap/src/java/jremin/Trace.java (revision 39)
@@ -1,163 +0,0 @@
1-package jremin;
2-
3-import java.io.BufferedReader;
4-import java.io.File;
5-import java.io.FileInputStream;
6-import java.io.FilenameFilter;
7-import java.io.IOException;
8-import java.io.InputStreamReader;
9-import java.nio.charset.Charset;
10-import java.util.ArrayList;
11-import java.util.HashSet;
12-import java.util.List;
13-import java.util.Set;
14-import java.util.jar.JarEntry;
15-import java.util.jar.JarInputStream;
16-import java.util.regex.Matcher;
17-import java.util.regex.Pattern;
18-
19-public class Trace {
20-
21- private static Pattern LOADED_CLASS = Pattern.compile("Loaded (\\S+)", Pattern.CASE_INSENSITIVE);
22- private static Pattern LOAD_LIBRARY = Pattern.compile("\\[LoadLibrary (.+)\\]", Pattern.CASE_INSENSITIVE);
23- private static Pattern CREATE_FILE = Pattern.compile("\\[CreateFile (.+)\\]", Pattern.CASE_INSENSITIVE);
24-
25- private File jre = null;
26- private Set<String> jars = null;
27- private Set<String> files = new HashSet<String>();
28- private Set<String> packages = new HashSet<String>();
29- private Set<String> requiredClassEntryNames = new HashSet<String>();
30- private boolean useAwt;
31- private boolean useSwing;
32-
33- public Trace(File file) throws IOException {
34- file = file.getCanonicalFile();
35- String s = file.getName();
36- int i = s.toUpperCase().indexOf(".TRACE");
37- if(i >= 0) {
38- s = s.substring(0, i);
39- }
40- final String basename = s;
41- File dir = file.getParentFile();
42- File[] files = dir.listFiles(new FilenameFilter() {
43- @Override
44- public boolean accept(File dir, String name) {
45- return name.startsWith(basename) && name.toUpperCase().contains(".TRACE") && name.toLowerCase().endsWith(".log");
46- }
47- });
48- for(File f : files) {
49- BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(f), Charset.forName("MS932")));
50- String line;
51- while((line = r.readLine()) != null) {
52- Matcher m;
53- m = LOADED_CLASS.matcher(line);
54- if(m.find()) {
55- String cls = m.group(1);
56- if(!this.useAwt && (cls.startsWith("com.sun.awt.") || cls.startsWith("java.awt."))) {
57- this.useAwt = true;
58- }
59- if(!this.useSwing && (cls.startsWith("com.sun.swing.") || cls.startsWith("javax.swing."))) {
60- this.useSwing = true;
61- }
62- if(cls.startsWith("exewrap.")) {
63- continue;
64- }
65- this.requiredClassEntryNames.add(cls.replace('.', '/') + ".class");
66- continue;
67- }
68- m = LOAD_LIBRARY.matcher(line);
69- if(m.find()) {
70- this.files.add(m.group(1));
71- continue;
72- }
73- m = CREATE_FILE.matcher(line);
74- if(m.find()) {
75- this.files.add(m.group(1));
76- continue;
77- }
78- }
79- r.close();
80- }
81- for(String cls : this.requiredClassEntryNames) {
82- int j = cls.lastIndexOf('/');
83- if(j >= 0) {
84- this.packages.add(cls.substring(0, j));
85- }
86- }
87- }
88-
89- public File getJRE() {
90- if(jre == null) {
91- for(String s : files) {
92- File f = new File(s);
93- if(f.exists() && (f.getName().equalsIgnoreCase("jvm.dll") || f.getName().equalsIgnoreCase("rt.jar"))) {
94- File dir = f.getParentFile();
95- while(dir != null) {
96- if(dir.getName().equalsIgnoreCase("bin") || dir.getName().equalsIgnoreCase("lib")) {
97- jre = dir.getParentFile();
98- return jre;
99- }
100- dir = dir.getParentFile();
101- }
102- }
103- }
104- }
105- return jre;
106- }
107-
108- public Set<String> getUsedJars() throws IOException {
109- if(jars == null) {
110- jars = new HashSet<String>();
111- List<File> list = new ArrayList<File>();
112- traverseJars(list, getJRE());
113- for(File jar : list) {
114- boolean used = false;
115- JarInputStream jarIn = new JarInputStream(new FileInputStream(jar));
116- JarEntry entry;
117- while((entry = jarIn.getNextJarEntry()) != null) {
118- if(requiredClassEntryNames.contains(entry.getName())) {
119- used = true;
120- break;
121- }
122- }
123- jarIn.close();
124- if(used) {
125- jars.add(jar.getCanonicalPath());
126- }
127- }
128- }
129- return jars;
130- }
131-
132- private void traverseJars(List<File> list, File dir) throws IOException {
133- for(File file : dir.listFiles()) {
134- if(file.isDirectory()) {
135- traverseJars(list, file);
136- } else {
137- if(file.getName().toLowerCase().endsWith(".jar")) {
138- list.add(file);
139- };
140- }
141- }
142- }
143-
144- public Set<String> getRequiredClassEntryNames() {
145- return this.requiredClassEntryNames;
146- }
147-
148- public Set<String> getPackages() {
149- return this.packages;
150- }
151-
152- public Set<String> getFiles() {
153- return this.files;
154- }
155-
156- public boolean useAwt() {
157- return this.useAwt;
158- }
159-
160- public boolean useSwing() {
161- return this.useSwing;
162- }
163-}
\ No newline at end of file
--- exewrap/trunk/exewrap/src/java/jremin/agent/manifest.txt (revision 38)
+++ exewrap/trunk/exewrap/src/java/jremin/agent/manifest.txt (revision 39)
@@ -1,2 +0,0 @@
1-Premain-Class: jremin.agent.Agent
2-Main-Class: jremin.agent.Agent
--- exewrap/trunk/exewrap/src/java/jremin/agent/Agent.java (revision 38)
+++ exewrap/trunk/exewrap/src/java/jremin/agent/Agent.java (revision 39)
@@ -1,18 +0,0 @@
1-package jremin.agent;
2-
3-import java.lang.instrument.Instrumentation;
4-
5-public class Agent {
6- public static void premain(String agentArgs, Instrumentation instrumentation) {
7- Class<?>[] classes = instrumentation.getAllLoadedClasses();
8- for (Class<?> cls : classes) {
9- String name = cls.getName();
10- if(name.length() >= 1 && name.charAt(0) != '[' && !name.startsWith("jremin.")) {
11- System.out.println(name);
12- }
13- }
14- }
15-
16- public static void main(String[] args) {
17- }
18-}
--- exewrap/trunk/exewrap/src/java/jremin/JreMin.java (revision 38)
+++ exewrap/trunk/exewrap/src/java/jremin/JreMin.java (revision 39)
@@ -1,345 +0,0 @@
1-package jremin;
2-
3-import java.io.BufferedReader;
4-import java.io.BufferedWriter;
5-import java.io.ByteArrayOutputStream;
6-import java.io.File;
7-import java.io.FileInputStream;
8-import java.io.FileNotFoundException;
9-import java.io.FileOutputStream;
10-import java.io.IOException;
11-import java.io.InputStream;
12-import java.io.InputStreamReader;
13-import java.io.OutputStreamWriter;
14-import java.io.Writer;
15-import java.nio.channels.FileChannel;
16-import java.nio.charset.Charset;
17-import java.util.ArrayList;
18-import java.util.Arrays;
19-import java.util.Collections;
20-import java.util.HashMap;
21-import java.util.HashSet;
22-import java.util.List;
23-import java.util.Map;
24-import java.util.Set;
25-import java.util.jar.JarEntry;
26-import java.util.jar.JarInputStream;
27-import java.util.jar.JarOutputStream;
28-
29-public class JreMin {
30-
31- private static Set<String> excluded = new HashSet<String>(Arrays.asList(new String[] {
32- "classes.jsa",
33- "meta-index"
34- }));
35-
36- private static Set<String> requiredFiles = new HashSet<String>(Arrays.asList(new String[] {
37- "copyright",
38- "license",
39- "readme.txt",
40- "thirdpartylicensereadme.txt",
41- "thirdpartylicensereadme-javafx.txt",
42- "welcome.html"
43- }));
44-
45- private static Set<String> fonts = new HashSet<String>(Arrays.asList(new String[] {
46- "lucidabrightdemibold.ttf",
47- "lucidabrightdemiitalic.ttf",
48- "lucidabrightitalic.ttf",
49- "lucidabrightregular.ttf",
50- "lucidasansdemibold.ttf",
51- "lucidasansregular.ttf",
52- "lucidatypewriterbold.ttf",
53- "lucidatypewriterregular.ttf"
54- }));
55-
56- private static Map<String, Set<String>> map = new HashMap<String, Set<String>>();
57-
58- private static Set<String> requiredPackages = new HashSet<String>(Arrays.asList(new String[] {
59- "java/lang/*"
60- }));
61-
62- public static void main(String[] args) throws Exception {
63- if(args.length == 0) {
64- showUsage();
65- return;
66- }
67-
68- map.put("awt", new HashSet<String>(Arrays.asList(new String[] {
69- "com/sun/awt/*",
70- "java/text/*",
71- "java/awt/*",
72- "sun/awt/*",
73- "sun/dc/*",
74- "sun/font/*",
75- "sun/util/locale/*",
76- //--------
77- "java/util",
78- "sun/util",
79- "sun/util/calendar"
80- })));
81-
82- map.put("swing", new HashSet<String>(Arrays.asList(new String[] {
83- "com/sun/beans/util/*",
84- "com/sun/java/swing/*",
85- "com/sun/media/*",
86- "com/sun/swing/*",
87- "java/applet/*",
88- "java/awt/*",
89- "java/beans/*",
90- "java/io/*",
91- "java/math/*",
92- "java/net/*",
93- "java/nio/*",
94- "java/security/*",
95- "java/text/*",
96- "java/util/*",
97- "javax/accessibility/*",
98- "javax/print/*",
99- "javax/sound/*",
100- "javax/swing/*",
101- "jdk/internal/org/objectweb/asm/*",
102- "sun/awt/*",
103- "sun/dc/*",
104- "sun/font/*",
105- "sun/invoke/*",
106- "sun/io/*",
107- "sun/java2d/*",
108- "sun/misc/*",
109- "sun/net/*",
110- "sun/nio/*",
111- "sun/print/*",
112- "sun/reflect/*",
113- "sun/security/*",
114- "sun/swing/*",
115- "sun/text/*",
116- "sun/util/*"
117- })));
118-
119- String filename = args[0];
120-
121- boolean debug = false;
122- if(args.length >= 2 && args[0].equals("-d")) {
123- debug = true;
124- filename = args[1];
125- }
126-
127- if(!new File(filename).exists()) {
128- System.out.println();
129- }
130-
131- Trace trace = new Trace(new File(filename));
132- if(debug) {
133- debugOut(trace);
134- }
135-
136- File jre = trace.getJRE();
137- if(jre == null) {
138- System.out.println("JRE not found.");
139- return;
140- }
141- File target = new File(jre.getName() + "_min");
142-
143- Set<String> appends = new HashSet<String>();
144-
145- if(trace.useAwt()) {
146- for(String pkg : map.get("awt")) {
147- requiredPackages.add(pkg);
148- }
149- appends.addAll(fonts);
150- }
151- if(trace.useSwing()) {
152- for(String pkg : map.get("swing")) {
153- requiredPackages.add(pkg);
154- }
155- appends.addAll(fonts);
156- }
157-
158- Set<File> files = new HashSet<File>();
159- for(File file : getRequiredFiles(jre, appends)) {
160- files.add(file);
161- }
162- for(String s : trace.getFiles()) {
163- File file = new File(s).getCanonicalFile();
164- files.add(file);
165- }
166- for(String s : trace.getUsedJars()) {
167- File file = new File(s).getCanonicalFile();
168- files.add(file);
169- }
170-
171- Set<String> requiredClassEntryNames = getRequiredClassEntryNames();
172- for(String name : trace.getRequiredClassEntryNames()) {
173- requiredClassEntryNames.add(name);
174- }
175-
176- for(File file : files) {
177- if(!file.exists()) {
178- continue;
179- }
180- if(!file.getPath().toLowerCase().startsWith(jre.getPath().toLowerCase())) {
181- continue;
182- }
183- if(excluded.contains(file.getName().toLowerCase())) {
184- continue;
185- }
186- File dst = new File(target, file.getPath().substring(jre.getPath().length()));
187- File dir = dst.getParentFile();
188- if(!dir.exists()) {
189- dir.mkdirs();
190- }
191- System.out.println(dst.getPath());
192- if(file.getPath().toLowerCase().endsWith(".jar")) {
193- copyJAR(file, dst, requiredClassEntryNames, requiredPackages);
194- } else {
195- copy(file, dst);
196- }
197- }
198- }
199-
200- public static void showUsage() {
201- System.out.println(
202- "jremin 1.1.0\r\n" +
203- "Java Runtime Environment (JRE) minimizer.\r\n" +
204- "Copyright (C) 2015 HIRUKAWA Ryo. All rights reserved.\r\n" +
205- "\r\n" +
206- "Usage: jremin.exe <trace-file>\r\n"
207- );
208- }
209-
210- public static void copy(File src, File dst) throws IOException {
211- FileChannel sc = null;
212- FileChannel dc = null;
213- try {
214- sc = new FileInputStream(src).getChannel();
215- dc = new FileOutputStream(dst).getChannel();
216- dc.transferFrom(sc, 0, sc.size());
217- } finally {
218- if (dc != null) try { dc.close(); } catch (Exception e) {}
219- if (sc != null) try { sc.close(); } catch (Exception e) {}
220- }
221- }
222-
223- public static void copyJAR(File src, File dst, Set<String> requiredClassEntryNames, Set<String> requirePackages) throws FileNotFoundException, IOException {
224- JarInputStream jarIn = new JarInputStream(new FileInputStream(src));
225- JarOutputStream jarOut = new JarOutputStream(new FileOutputStream(dst), jarIn.getManifest());
226- JarEntry entryIn;
227- while((entryIn = jarIn.getNextJarEntry()) != null) {
228- String name = entryIn.getName();
229- String pkg = null;
230- boolean required = false;;
231- int i = name.lastIndexOf('/');
232- if(i > 0) {
233- pkg = name.substring(0, i);
234- for(String p : requirePackages) {
235- if(p.endsWith("/*")) {
236- p = p.substring(0, p.length() - 2);
237- if(pkg.startsWith(p)) {
238- required = true;
239- break;
240- }
241- } else if(p.equals(pkg)) {
242- required = true;
243- break;
244- }
245- }
246- }
247-
248- if(!required && name.endsWith(".class") && !requiredClassEntryNames.contains(name)) {
249- continue;
250- }
251- JarEntry entryOut = new JarEntry(name);
252- entryOut.setMethod(JarEntry.DEFLATED);
253- jarOut.putNextEntry(entryOut);
254- byte[] data = getBytes(jarIn);
255- jarIn.closeEntry();
256- jarOut.write(data);
257- jarOut.flush();
258- jarOut.closeEntry();
259- }
260- jarIn.close();
261- jarOut.flush();
262- jarOut.finish();
263- jarOut.close();
264- }
265-
266- private static byte[] getBytes(InputStream in) throws IOException {
267- ByteArrayOutputStream out = new ByteArrayOutputStream();
268- byte[] buf = new byte[65536];
269- int size;
270- while((size = in.read(buf)) != -1) {
271- out.write(buf, 0, size);
272- }
273- return out.toByteArray();
274- }
275-
276- public static List<File> getRequiredFiles(File jre, Set<String> appends) {
277- List<File> list = new ArrayList<File>();
278- traverseRequiredFiles(list, jre, appends);
279- return list;
280- }
281-
282- private static void traverseRequiredFiles(List<File> list, File dir, Set<String> appends) {
283- for(File file : dir.listFiles()) {
284- if(file.isDirectory()) {
285- traverseRequiredFiles(list, file, appends);
286- } else {
287- if(appends != null && appends.contains(file.getName().toLowerCase())) {
288- list.add(file);
289- continue;
290- }
291- if(requiredFiles.contains(file.getName().toLowerCase())) {
292- list.add(file);
293- continue;
294- }
295- }
296- }
297- }
298-
299- public static Set<String> getRequiredClassEntryNames() throws IOException {
300- Set<String> set = new HashSet<String>();
301- InputStream in = JreMin.class.getResourceAsStream("classes.txt");
302- if(in != null) {
303- BufferedReader r = new BufferedReader(new InputStreamReader(in, Charset.forName("UTF-8")));
304- String line;
305- while((line = r.readLine()) != null) {
306- String name = line.replace('.', '/') + ".class";
307- set.add(name);
308- }
309- r.close();
310- }
311- in.close();
312- return set;
313- }
314-
315- public static void debugOut(Trace trace) throws Exception {
316- Writer w;
317- List<String> list;
318-
319- w = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("classes.txt"), Charset.forName("UTF-8")));
320- list = new ArrayList<String>();
321- for(String s : trace.getRequiredClassEntryNames()) {
322- if(s.endsWith(".class")) {
323- list.add(s.substring(0, s.length() - 6).replace('/', '.'));
324- }
325- };
326- Collections.sort(list);
327- for(String line : list) {
328- w.write(line);
329- w.write("\r\n");
330- }
331- w.close();
332-
333- w = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("packages.txt"), Charset.forName("UTF-8")));
334- list = new ArrayList<String>();
335- for(String s : trace.getPackages()) {
336- list.add(s.replace('/', '.'));
337- };
338- Collections.sort(list);
339- for(String line : list) {
340- w.write(line);
341- w.write("\r\n");
342- }
343- w.close();
344- }
345-}
--- exewrap/trunk/exewrap/src/java/exewrap/core/ExewrapClassLoader.java (revision 38)
+++ exewrap/trunk/exewrap/src/java/exewrap/core/ExewrapClassLoader.java (revision 39)
@@ -21,36 +21,38 @@
2121
2222 public class ExewrapClassLoader extends ClassLoader {
2323
24- private Map<String, byte[]> classes = new HashMap<String, byte[]>();
25- private Map<String, byte[]> resources = new HashMap<String, byte[]>();
26- private Queue<JarInputStream> inputs = new LinkedList<JarInputStream>();
27- private JarInputStream in;
28- private String mainClassName;
29- private String specTitle;
30- private String specVersion;
31- private String specVendor;
32- private String implTitle;
33- private String implVersion;
34- private String implVendor;
35- private URL context;
36- private ProtectionDomain protectionDomain;
37-
38- public ExewrapClassLoader(ClassLoader parent, JarInputStream[] inputs) throws MalformedURLException {
39- super(parent);
40- for(JarInputStream in : inputs) {
41- Manifest manifest = in.getManifest();
24+ private static Map<String, byte[]> classes = new HashMap<String, byte[]>();
25+ private static Map<String, byte[]> resources = new HashMap<String, byte[]>();
26+ private static Queue<JarInputStream> inputs = new LinkedList<JarInputStream>();
27+ private static JarInputStream in;
28+ private static String mainClassName;
29+ private static String specTitle;
30+ private static String specVersion;
31+ private static String specVendor;
32+ private static String implTitle;
33+ private static String implVersion;
34+ private static String implVendor;
35+ private static URL context;
36+ private static ProtectionDomain protectionDomain;
37+
38+ public static void setInputs(JarInputStream[] jars) throws MalformedURLException {
39+ for(JarInputStream jar : jars) {
40+ if(jar == null) {
41+ continue;
42+ }
43+ Manifest manifest = jar.getManifest();
4244 if(manifest != null) {
43- this.mainClassName = manifest.getMainAttributes().getValue(Name.MAIN_CLASS);
44- this.specTitle = manifest.getMainAttributes().getValue(Name.SPECIFICATION_TITLE);
45- this.specVersion = manifest.getMainAttributes().getValue(Name.SPECIFICATION_VERSION);
46- this.specVendor = manifest.getMainAttributes().getValue(Name.SPECIFICATION_VENDOR);
47- this.implTitle = manifest.getMainAttributes().getValue(Name.IMPLEMENTATION_TITLE);
48- this.implVersion = manifest.getMainAttributes().getValue(Name.IMPLEMENTATION_VERSION);
49- this.implVendor = manifest.getMainAttributes().getValue(Name.IMPLEMENTATION_VENDOR);
45+ mainClassName = manifest.getMainAttributes().getValue(Name.MAIN_CLASS);
46+ specTitle = manifest.getMainAttributes().getValue(Name.SPECIFICATION_TITLE);
47+ specVersion = manifest.getMainAttributes().getValue(Name.SPECIFICATION_VERSION);
48+ specVendor = manifest.getMainAttributes().getValue(Name.SPECIFICATION_VENDOR);
49+ implTitle = manifest.getMainAttributes().getValue(Name.IMPLEMENTATION_TITLE);
50+ implVersion = manifest.getMainAttributes().getValue(Name.IMPLEMENTATION_VERSION);
51+ implVendor = manifest.getMainAttributes().getValue(Name.IMPLEMENTATION_VENDOR);
5052 }
51- this.inputs.offer(in);
53+ inputs.offer(jar);
5254 }
53- this.in = this.inputs.poll();
55+ in = inputs.poll();
5456
5557 String path = System.getProperty("java.application.path");
5658 if(path == null) {
@@ -61,54 +63,63 @@
6163 name = "";
6264 }
6365
64- URL.setURLStreamHandlerFactory(new URLStreamHandlerFactory(this));
65- this.context = new URL("exewrap:file:/" + path.replace('\\', '/') + '/' + name + "!/");
66+ ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
67+ URL.setURLStreamHandlerFactory(new URLStreamHandlerFactory(systemClassLoader));
68+ context = new URL("exewrap:file:/" + path.replace('\\', '/') + '/' + name + "!/");
6669
6770 URL url = new URL("file:/" + path.replace('\\', '/') + '/' + name);
6871 CodeSource codesource = new CodeSource(url, (Certificate[])null);
6972 PermissionCollection permissions = Policy.getPolicy().getPermissions(new CodeSource(null, (Certificate[])null));
70- this.protectionDomain = new ProtectionDomain(codesource, permissions, this, null);
73+ protectionDomain = new ProtectionDomain(codesource, permissions, systemClassLoader, null);
7174 }
7275
73- public void register() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException {
74- Thread.currentThread().setContextClassLoader(this);
75- }
76-
77- public void loadUtilities(String utilities) throws ClassNotFoundException {
76+ public static void loadUtilities(String utilities) throws ClassNotFoundException {
7877 if(utilities == null) {
7978 return;
8079 }
8180 if(utilities.contains("UncaughtExceptionHandler;")) {
82- Class.forName("exewrap.util.UncaughtExceptionHandler", true, this);
81+ Class.forName("exewrap.util.UncaughtExceptionHandler");
8382 }
8483 if(utilities.contains("FileLogStream;")) {
85- Class.forName("exewrap.util.FileLogStream", true, this);
84+ Class.forName("exewrap.util.FileLogStream");
8685 }
8786 if(utilities.contains("EventLogStream;")) {
88- Class.forName("exewrap.util.EventLogStream", true, this);
87+ Class.forName("exewrap.util.EventLogStream");
8988 }
9089 if(utilities.contains("EventLogHandler;")) {
91- Class.forName("exewrap.util.EventLogHandler", true, this);
90+ Class.forName("exewrap.util.EventLogHandler");
9291 }
9392 if(utilities.contains("ConsoleOutputStream;")) {
94- Class.forName("exewrap.util.ConsoleOutputStream", true, this);
93+ Class.forName("exewrap.util.ConsoleOutputStream");
9594 }
9695 }
9796
98- public Class<?> getMainClass(String mainClassName) throws ClassNotFoundException {
97+ public static Class<?> getMainClass(String mainClassName) throws ClassNotFoundException {
98+ ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
99+
99100 if(mainClassName != null) {
100- return loadClass(mainClassName);
101+ return Class.forName(mainClassName, true, systemClassLoader);
101102 }
102- if(this.mainClassName != null) {
103- return loadClass(this.mainClassName);
103+ if(ExewrapClassLoader.mainClassName != null) {
104+ return Class.forName(ExewrapClassLoader.mainClassName, true, systemClassLoader);
104105 }
105106 return null;
106107 }
107108
108- public void setSplashScreenResource(String name, byte[] image) {
109- this.resources.put(name, image);
109+ public static void setSplashScreenResource(String name, byte[] image) {
110+ resources.put(name, image);
110111 }
111112
113+ public static native void WriteConsole(byte[] b, int off, int len);
114+ public static native void WriteEventLog(int type, String message);
115+ public static native void UncaughtException(String thread, String message, String trace);
116+ public static native String SetEnvironment(String key, String value);
117+
118+
119+ public ExewrapClassLoader(ClassLoader parent) {
120+ super(parent);
121+ }
122+
112123 protected Class<?> findClass(String name) throws ClassNotFoundException {
113124 String entryName = name.replace('.', '/') + ".class";
114125 byte[] bytes = this.classes.remove(entryName);
@@ -193,9 +204,4 @@
193204 }
194205 return buf.toByteArray();
195206 }
196-
197- public static native void WriteConsole(byte[] b, int off, int len);
198- public static native void WriteEventLog(int type, String message);
199- public static native void UncaughtException(String thread, String message, String trace);
200- public static native String SetEnvironment(String key, String value);
201207 }
--- exewrap/trunk/exewrap/src/java/exewrap/tool/JarOptimizer.java (revision 38)
+++ exewrap/trunk/exewrap/src/java/exewrap/tool/JarOptimizer.java (revision 39)
@@ -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-}
Show on old repository browser