• R/O
  • SSH
  • HTTPS

exewrap: コミット


コミットメタ情報

リビジョン91 (tree)
日時2020-07-14 10:50:01
作者hirukawa_ryo

ログメッセージ

* exewrap 1.6.2
JARマニフェストのClass-Path、exewrapのEXTDIRSの展開処理をC(jvm.c)ではなくJava(Loader.java)側で行うように変更しました。
C側で展開を行うとパス文字列が長くなり64KBのバッファサイズを超える可能性があったためです。

変更サマリ

差分

--- exewrap/trunk/exewrap/src/exewrap.c (revision 90)
+++ exewrap/trunk/exewrap/src/exewrap.c (revision 91)
@@ -318,7 +318,7 @@
318318 exit_process(ERROR_NOT_ENOUGH_MEMORY, L"malloc");
319319 }
320320
321- if(load_main_class(argc, argv, NULL, &result) == FALSE)
321+ if(load_main_class(argc, argv, NULL, NULL, NULL, &result) == FALSE)
322322 {
323323 wcerrf(L"ERROR: load_main_class: tool.jar exewrap.tool.JarProcessor: %ls\r\n", result.msg);
324324
--- exewrap/trunk/exewrap/src/image_console.c (revision 90)
+++ exewrap/trunk/exewrap/src/image_console.c (revision 91)
@@ -59,17 +59,6 @@
5959 use_side_by_side_jre = (ext_flags == NULL) || (wcsstr(ext_flags, L"NOSIDEBYSIDE") == NULL);
6060 initialize_path(relative_classpath, relative_extdirs, use_server_vm, use_side_by_side_jre);
6161
62- if(relative_classpath != NULL)
63- {
64- free(relative_classpath);
65- relative_classpath = NULL;
66- }
67- if(relative_extdirs != NULL)
68- {
69- free(relative_extdirs);
70- relative_extdirs = NULL;
71- }
72-
7362 if(ext_flags != NULL)
7463 {
7564 if(wcsstr(ext_flags, L"SHARE") != NULL)
@@ -192,7 +181,7 @@
192181 free(target_version);
193182 }
194183
195- if(load_main_class(argc, argv, utilities, &result) == FALSE)
184+ if(load_main_class(argc, argv, utilities, relative_classpath, relative_extdirs, &result) == FALSE)
196185 {
197186 wcerr(result.msg);
198187 wcerr(L"\r\n");
@@ -206,6 +195,18 @@
206195
207196 ExitProcess(ERROR_INVALID_DATA);
208197 }
198+
199+ if(relative_classpath != NULL)
200+ {
201+ free(relative_classpath);
202+ relative_classpath = NULL;
203+ }
204+ if(relative_extdirs != NULL)
205+ {
206+ free(relative_extdirs);
207+ relative_extdirs = NULL;
208+ }
209+
209210 if(synchronize_mutex_handle != NULL)
210211 {
211212 ReleaseMutex(synchronize_mutex_handle);
--- exewrap/trunk/exewrap/src/image_gui.c (revision 90)
+++ exewrap/trunk/exewrap/src/image_gui.c (revision 91)
@@ -86,17 +86,6 @@
8686 use_side_by_side_jre = (ext_flags == NULL) || (wcsstr(ext_flags, L"NOSIDEBYSIDE") == NULL);
8787 initialize_path(relative_classpath, relative_extdirs, use_server_vm, use_side_by_side_jre);
8888
89- if(relative_classpath != NULL)
90- {
91- free(relative_classpath);
92- relative_classpath = NULL;
93- }
94- if(relative_extdirs != NULL)
95- {
96- free(relative_extdirs);
97- relative_extdirs = NULL;
98- }
99-
10089 if(ext_flags != NULL)
10190 {
10291 if(wcsstr(ext_flags, L"SHARE") != NULL)
@@ -251,7 +240,7 @@
251240 free(target_version);
252241 }
253242
254- if(load_main_class(argc, argv, utilities, &result) == FALSE)
243+ if(load_main_class(argc, argv, utilities, relative_classpath, relative_extdirs, &result) == FALSE)
255244 {
256245 if((*env)->ExceptionCheck(env) == JNI_TRUE)
257246 {
@@ -277,6 +266,17 @@
277266 ExitProcess(ERROR_INVALID_DATA);
278267 }
279268
269+ if(relative_classpath != NULL)
270+ {
271+ free(relative_classpath);
272+ relative_classpath = NULL;
273+ }
274+ if(relative_extdirs != NULL)
275+ {
276+ free(relative_extdirs);
277+ relative_extdirs = NULL;
278+ }
279+
280280 if(get_resource(L"SPLASH_SCREEN_IMAGE", &res) != NULL)
281281 {
282282 BYTE* splash_screen_image_buf = res.buf;
--- exewrap/trunk/exewrap/src/image_service.c (revision 90)
+++ exewrap/trunk/exewrap/src/image_service.c (revision 91)
@@ -246,17 +246,6 @@
246246 use_side_by_side_jre = (ext_flags == NULL) || (wcsstr(ext_flags, L"NOSIDEBYSIDE") == NULL);
247247 initialize_path(relative_classpath, relative_extdirs, use_server_vm, use_side_by_side_jre);
248248
249- if(relative_classpath != NULL)
250- {
251- free(relative_classpath);
252- relative_classpath = NULL;
253- }
254- if(relative_extdirs != NULL)
255- {
256- free(relative_extdirs);
257- relative_extdirs = NULL;
258- }
259-
260249 if(ext_flags == NULL || wcsstr(ext_flags, L"NOENCODINGFIX") == NULL)
261250 {
262251 wcscat_s(utilities, BUFFER_SIZE, UTIL_ENCODING_FIX);
@@ -358,7 +347,7 @@
358347 free(target_version);
359348 }
360349
361- if(load_main_class(argc, argv, utilities, &result) == FALSE)
350+ if(load_main_class(argc, argv, utilities, relative_classpath, relative_extdirs, &result) == FALSE)
362351 {
363352 if((*env)->ExceptionCheck(env) == JNI_TRUE)
364353 {
@@ -379,6 +368,17 @@
379368 }
380369 MainClass = result.MainClass;
381370
371+ if(relative_classpath != NULL)
372+ {
373+ free(relative_classpath);
374+ relative_classpath = NULL;
375+ }
376+ if(relative_extdirs != NULL)
377+ {
378+ free(relative_extdirs);
379+ relative_extdirs = NULL;
380+ }
381+
382382 MainClass_start = (*env)->GetStaticMethodID(env, result.MainClass, "start", "([Ljava/lang/String;)V");
383383 if(MainClass_start == NULL)
384384 {
--- exewrap/trunk/exewrap/src/include/jvm.h (revision 90)
+++ exewrap/trunk/exewrap/src/include/jvm.h (revision 91)
@@ -19,7 +19,6 @@
1919 extern JNIEnv* attach_java_vm(void);
2020 extern jint detach_java_vm(void);
2121 extern BOOL set_application_properties(SYSTEMTIME* startup);
22-extern wchar_t* get_classpath(void);
2322 extern void get_java_runtime_version(const wchar_t* version_string, DWORD* major, DWORD* minor, DWORD* build, DWORD* revision);
2423 extern wchar_t* get_java_version_string(DWORD major, DWORD minor, DWORD build, DWORD revision);
2524 extern wchar_t* get_module_version(wchar_t* buf, size_t size);
--- exewrap/trunk/exewrap/src/include/loader.h (revision 90)
+++ exewrap/trunk/exewrap/src/include/loader.h (revision 91)
@@ -34,7 +34,7 @@
3434 #endif
3535
3636 extern wchar_t* install_security_manager(JNIEnv* env);
37-extern BOOL load_main_class(int argc, const wchar_t* argv[], const wchar_t* utilities, LOAD_RESULT* result);
37+extern BOOL load_main_class(int argc, const wchar_t* argv[], const wchar_t* utilities, const wchar_t* relative_classpath, const wchar_t* relative_extdirs, LOAD_RESULT* result);
3838 extern BOOL set_splash_screen_resource(const wchar_t* splash_screen_name, const BYTE* splash_screen_image_buf, DWORD splash_screen_image_len);
3939 extern wchar_t* get_module_object_name(const wchar_t* prefix);
4040 extern BYTE* get_resource(const wchar_t* name, RESOURCE* resource);
--- exewrap/trunk/exewrap/src/java/Loader.java (revision 90)
+++ exewrap/trunk/exewrap/src/java/Loader.java (revision 91)
@@ -8,6 +8,7 @@
88 import java.net.MalformedURLException;
99 import java.net.URL;
1010 import java.net.URLClassLoader;
11+import java.net.URLDecoder;
1112 import java.net.URLEncoder;
1213 import java.net.URLStreamHandler;
1314 import java.net.URLStreamHandlerFactory;
@@ -16,8 +17,10 @@
1617 import java.security.Policy;
1718 import java.security.ProtectionDomain;
1819 import java.security.cert.Certificate;
20+import java.util.ArrayList;
1921 import java.util.HashMap;
2022 import java.util.HashSet;
23+import java.util.List;
2124 import java.util.LinkedList;
2225 import java.util.Map;
2326 import java.util.Queue;
@@ -45,7 +48,7 @@
4548 private static URL context;
4649 private static URLStreamHandler handler;
4750
48- public static Class<?> initialize(JarInputStream[] jars, URLStreamHandlerFactory factory, String utilities, String classPath, String mainClassName, int consoleCodePage) throws MalformedURLException, ClassNotFoundException {
51+ public static Class<?> initialize(JarInputStream[] jars, URLStreamHandlerFactory factory, String utilities, String relativeClassPath, String relativeExtDirs, String mainClassName, int consoleCodePage) throws MalformedURLException, ClassNotFoundException {
4952 URL.setURLStreamHandlerFactory(factory);
5053 handler = factory.createURLStreamHandler("exewrap");
5154 context = new URL("exewrap:" + CONTEXT_PATH + "!/");
@@ -107,19 +110,28 @@
107110 }
108111 }
109112
113+ Set<String> paths = new HashSet<String>();
110114 if(systemClassLoader instanceof Loader) {
111115 Loader loader = (Loader)systemClassLoader;
116+ String appDir = System.getProperty("java.application.path");
112117
113118 try {
114- // カレントディレクトリをCLASS_PATHに追加します。
115- classPath = new File(".").getCanonicalPath() + ";" + classPath;
119+ File file = new File(appDir);
120+ URL url = file.toURI().toURL();
121+ loader.addURL(url);
122+ paths.add(file.toString().toLowerCase());
116123 } catch(Exception ignore) {}
117124
118- Set<String> paths = new HashSet<String>();
119- for(String path : classPath.split(";")) {
120- try {
121- if(path.length() > 0) {
122- File file = new File(path).getCanonicalFile();
125+ if(relativeClassPath != null) {
126+ for(String path : relativeClassPath.split(" ")) {
127+ if(path.length() == 0) {
128+ continue;
129+ }
130+ try {
131+ path = URLDecoder.decode(path, "UTF-8");
132+ path = path.replace('/', '\\');
133+ path = appDir + '\\' + path;
134+ File file = new File(path);
123135 String s = file.toString().toLowerCase();
124136 if(!paths.contains(s)) {
125137 URL url = file.toURI().toURL();
@@ -126,8 +138,41 @@
126138 loader.addURL(url);
127139 paths.add(s);
128140 }
141+ } catch(Exception ignore) {}
142+ }
143+ }
144+
145+ if(relativeExtDirs != null) {
146+ for(String path : relativeExtDirs.split(";")) {
147+ if(path.length() == 0) {
148+ continue;
129149 }
130- } catch(Exception ignore) {}
150+ path = path.replace('/', '\\');
151+ path = appDir + '\\' + path;
152+ File dir = new File(path);
153+ try {
154+ String s = dir.toString().toLowerCase();
155+ if(!paths.contains(s)) {
156+ URL url = dir.toURI().toURL();
157+ loader.addURL(url);
158+ paths.add(s);
159+ }
160+ } catch(Exception ignore) {}
161+
162+ if(dir.isDirectory()) {
163+ List<File> files = retrieveJars(dir);
164+ for(File file : files) {
165+ try {
166+ String s = file.toString().toLowerCase();
167+ if(!paths.contains(s)) {
168+ URL url = file.toURI().toURL();
169+ loader.addURL(url);
170+ paths.add(s);
171+ }
172+ } catch(Exception ignore) {}
173+ }
174+ }
175+ }
131176 }
132177 }
133178
@@ -137,8 +182,24 @@
137182 return Class.forName(MAIN_CLASS, true, systemClassLoader);
138183 }
139184 }
185+
186+ private static List<File> retrieveJars(File dir) {
187+ List<File> list = new ArrayList<File>();
188+ for(File child : dir.listFiles()) {
189+ if(!child.isDirectory() && child.getName().toLowerCase().endsWith(".jar")) {
190+ list.add(child);
191+ }
192+ if(child.isDirectory()) {
193+ List<File> subList = retrieveJars(child);
194+ if(subList.size() > 0) {
195+ list.addAll(subList);
196+ }
197+ }
198+ }
199+ return list;
200+ }
201+
140202
141-
142203 private ProtectionDomain protectionDomain;
143204
144205 public Loader(ClassLoader parent) throws MalformedURLException {
--- exewrap/trunk/exewrap/src/jvm.c (revision 90)
+++ exewrap/trunk/exewrap/src/jvm.c (revision 91)
@@ -52,7 +52,6 @@
5252 static BOOL path_initialized = FALSE;
5353 static wchar_t* binpath = NULL;
5454 static wchar_t* jvmpath = NULL;
55-static wchar_t* classpath = NULL;
5655 static wchar_t* libpath = NULL;
5756
5857 static HMODULE jvmdll = NULL;
@@ -442,11 +441,6 @@
442441 jvm = NULL;
443442 }
444443
445- if(classpath != NULL)
446- {
447- free(classpath);
448- classpath = NULL;
449- }
450444 if(libpath != NULL)
451445 {
452446 free(libpath);
@@ -837,12 +831,6 @@
837831 }
838832
839833
840-wchar_t* get_classpath()
841-{
842- return classpath;
843-}
844-
845-
846834 BOOL initialize_path(const wchar_t* relative_classpath, const wchar_t* relative_extdirs, BOOL use_server_vm, BOOL use_side_by_side_jre)
847835 {
848836 wchar_t* module_path = NULL;
@@ -886,14 +874,6 @@
886874 goto EXIT;
887875 }
888876 }
889- if(classpath == NULL)
890- {
891- classpath = (wchar_t*)malloc(BUFFER_SIZE * sizeof(wchar_t));
892- if(classpath == NULL)
893- {
894- goto EXIT;
895- }
896- }
897877 if(libpath == NULL)
898878 {
899879 libpath = (wchar_t*)malloc(BUFFER_SIZE * sizeof(wchar_t));
@@ -1367,8 +1347,6 @@
13671347
13681348
13691349 GetModuleFileName(NULL, buffer, BUFFER_SIZE);
1370- wcscpy_s(classpath, BUFFER_SIZE, L"");
1371-
13721350 wcscpy_s(libpath, BUFFER_SIZE, L".;");
13731351 wcscat_s(libpath, BUFFER_SIZE, jvmpath);
13741352 wcscat_s(libpath, BUFFER_SIZE, L";");
@@ -1377,7 +1355,8 @@
13771355
13781356 if(relative_classpath != NULL)
13791357 {
1380- wchar_t* p = buffer;
1358+ wchar_t* p = buffer;
1359+ wchar_t* path = search;
13811360
13821361 wcscpy_s(p, BUFFER_SIZE, relative_classpath);
13831362 while((token = wcstok_s(p, L" ", &context)) != NULL)
@@ -1385,13 +1364,18 @@
13851364 token = urldecode(search, MAX_LONG_PATH, token);
13861365 if(token != NULL)
13871366 {
1367+ wcscpy_s(path, BUFFER_SIZE, L"");
13881368 if(wcsstr(token, L":") == NULL) // パスに : を含んでいない場合は相対パスと見なしてmodule_pathを付加します。
13891369 {
1390- wcscat_s(classpath, BUFFER_SIZE, module_path);
1391- wcscat_s(classpath, BUFFER_SIZE, L"\\");
1370+ wcscat_s(path, BUFFER_SIZE, module_path);
1371+ wcscat_s(path, BUFFER_SIZE, L"\\");
13921372 }
1393- wcscat_s(classpath, BUFFER_SIZE, token);
1394- wcscat_s(classpath, BUFFER_SIZE, L";");
1373+ wcscat_s(path, BUFFER_SIZE, token);
1374+ if(is_directory(path))
1375+ {
1376+ add_path_env(path);
1377+ add_dll_directory(path);
1378+ }
13951379 }
13961380 p = NULL;
13971381 }
@@ -1427,24 +1411,6 @@
14271411 wchar_t* dir = dirs;
14281412 while(*dir)
14291413 {
1430- wchar_t* jars = get_jars(dir);
1431- if(jars != NULL)
1432- {
1433- wchar_t* jar = jars;
1434- while(*jar)
1435- {
1436- if(wcsstr(classpath, jar) == NULL)
1437- {
1438- wcscat_s(classpath, BUFFER_SIZE, L";");
1439- wcscat_s(classpath, BUFFER_SIZE, jar);
1440- }
1441- jar += wcslen(jar) + 1;
1442- }
1443- free(jars);
1444- }
1445- wcscat_s(classpath, BUFFER_SIZE, L";");
1446- wcscat_s(classpath, BUFFER_SIZE, dir);
1447-
14481414 add_path_env(dir);
14491415 add_dll_directory(dir);
14501416
--- exewrap/trunk/exewrap/src/loader.c (revision 90)
+++ exewrap/trunk/exewrap/src/loader.c (revision 91)
@@ -15,7 +15,7 @@
1515 #define MAX_LONG_PATH 32768
1616
1717 wchar_t* install_security_manager(JNIEnv* env);
18-BOOL load_main_class(int argc, const wchar_t* argv[], const wchar_t* utilities, LOAD_RESULT* result);
18+BOOL load_main_class(int argc, const wchar_t* argv[], const wchar_t* utilities, const wchar_t* relative_classpath, const wchar_t* relative_extdirs, LOAD_RESULT* result);
1919 BOOL set_splash_screen_resource(const wchar_t* splash_screen_name, const BYTE* splash_screen_image_buf, DWORD splash_screen_image_len);
2020 wchar_t* get_module_object_name(const wchar_t* prefix);
2121 BYTE* get_resource(const wchar_t* name, RESOURCE* resource);
@@ -99,7 +99,7 @@
9999 return buf;
100100 }
101101
102-BOOL load_main_class(int argc, const wchar_t* argv[], const wchar_t* utilities, LOAD_RESULT* result)
102+BOOL load_main_class(int argc, const wchar_t* argv[], const wchar_t* utilities, const wchar_t* relative_classpath, const wchar_t* relative_extdirs, LOAD_RESULT* result)
103103 {
104104 RESOURCE res;
105105 jclass ClassLoader;
@@ -179,11 +179,11 @@
179179 swprintf_s(result->msg, LOAD_RESULT_MAX_MESSAGE_LENGTH, _(MSG_ID_ERR_GET_FIELD), L"Loader.resources");
180180 goto EXIT;
181181 }
182- Loader_initialize = (*env)->GetStaticMethodID(env, Loader, "initialize", "([Ljava/util/jar/JarInputStream;Ljava/net/URLStreamHandlerFactory;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)Ljava/lang/Class;");
182+ Loader_initialize = (*env)->GetStaticMethodID(env, Loader, "initialize", "([Ljava/util/jar/JarInputStream;Ljava/net/URLStreamHandlerFactory;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)Ljava/lang/Class;");
183183 if(Loader_initialize == NULL)
184184 {
185185 result->msg_id = MSG_ID_ERR_GET_METHOD;
186- swprintf_s(result->msg, LOAD_RESULT_MAX_MESSAGE_LENGTH, _(MSG_ID_ERR_GET_METHOD), L"Loader.initialize(java.util.jar.JarInputStream[], java.net.URLStreamHandlerFactory, java.lang.String, java.lang.String, java.lang.String, int)");
186+ swprintf_s(result->msg, LOAD_RESULT_MAX_MESSAGE_LENGTH, _(MSG_ID_ERR_GET_METHOD), L"Loader.initialize(java.util.jar.JarInputStream[], java.net.URLStreamHandlerFactory, java.lang.String, java.lang.String, java.lang.String, java.lang.String, int)");
187187 goto EXIT;
188188 }
189189
@@ -404,7 +404,7 @@
404404 // call Loader.initialize
405405 main_class = from_utf8((char*)get_resource(L"MAIN_CLASS", NULL)); // MAIN_CLASSは定義されていない場合は main_class = NULL のまま処理を進めます。
406406 console_code_page = GetConsoleOutputCP();
407- MainClass = (*env)->CallStaticObjectMethod(env, Loader, Loader_initialize, jars, urlStreamHandlerFactory, to_jstring(env, utilities), to_jstring(env, get_classpath()), to_jstring(env, main_class), console_code_page);
407+ MainClass = (*env)->CallStaticObjectMethod(env, Loader, Loader_initialize, jars, urlStreamHandlerFactory, to_jstring(env, utilities), to_jstring(env, relative_classpath), to_jstring(env, relative_extdirs), to_jstring(env, main_class), console_code_page);
408408 if(MainClass == NULL)
409409 {
410410 result->msg_id = MSG_ID_ERR_LOAD_MAIN_CLASS;
旧リポジトリブラウザで表示