Skip to content

Commit

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

git-svn-id: http://svn.osdn.net/svnroot/exewrap/exewrap/trunk/exewrap@91 d83a06de-854e-4732-85b7-fdf7162022b6
  • Loading branch information
hirukawa_ryo committed Jul 14, 2020
1 parent 1d9d88c commit a69950d
Show file tree
Hide file tree
Showing 9 changed files with 126 additions and 99 deletions.
2 changes: 1 addition & 1 deletion src/exewrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ int wmain(int argc, wchar_t* argv[])
exit_process(ERROR_NOT_ENOUGH_MEMORY, L"malloc");
}

if(load_main_class(argc, argv, NULL, &result) == FALSE)
if(load_main_class(argc, argv, NULL, NULL, NULL, &result) == FALSE)
{
wcerrf(L"ERROR: load_main_class: tool.jar exewrap.tool.JarProcessor: %ls\r\n", result.msg);

Expand Down
25 changes: 13 additions & 12 deletions src/image_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,6 @@ int wmain(int argc, wchar_t* argv[])
use_side_by_side_jre = (ext_flags == NULL) || (wcsstr(ext_flags, L"NOSIDEBYSIDE") == NULL);
initialize_path(relative_classpath, relative_extdirs, use_server_vm, use_side_by_side_jre);

if(relative_classpath != NULL)
{
free(relative_classpath);
relative_classpath = NULL;
}
if(relative_extdirs != NULL)
{
free(relative_extdirs);
relative_extdirs = NULL;
}

if(ext_flags != NULL)
{
if(wcsstr(ext_flags, L"SHARE") != NULL)
Expand Down Expand Up @@ -192,7 +181,7 @@ int wmain(int argc, wchar_t* argv[])
free(target_version);
}

if(load_main_class(argc, argv, utilities, &result) == FALSE)
if(load_main_class(argc, argv, utilities, relative_classpath, relative_extdirs, &result) == FALSE)
{
wcerr(result.msg);
wcerr(L"\r\n");
Expand All @@ -206,6 +195,18 @@ int wmain(int argc, wchar_t* argv[])

ExitProcess(ERROR_INVALID_DATA);
}

if(relative_classpath != NULL)
{
free(relative_classpath);
relative_classpath = NULL;
}
if(relative_extdirs != NULL)
{
free(relative_extdirs);
relative_extdirs = NULL;
}

if(synchronize_mutex_handle != NULL)
{
ReleaseMutex(synchronize_mutex_handle);
Expand Down
24 changes: 12 additions & 12 deletions src/image_gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,6 @@ INT WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, wchar_t* lpCmd
use_side_by_side_jre = (ext_flags == NULL) || (wcsstr(ext_flags, L"NOSIDEBYSIDE") == NULL);
initialize_path(relative_classpath, relative_extdirs, use_server_vm, use_side_by_side_jre);

if(relative_classpath != NULL)
{
free(relative_classpath);
relative_classpath = NULL;
}
if(relative_extdirs != NULL)
{
free(relative_extdirs);
relative_extdirs = NULL;
}

if(ext_flags != NULL)
{
if(wcsstr(ext_flags, L"SHARE") != NULL)
Expand Down Expand Up @@ -251,7 +240,7 @@ INT WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, wchar_t* lpCmd
free(target_version);
}

if(load_main_class(argc, argv, utilities, &result) == FALSE)
if(load_main_class(argc, argv, utilities, relative_classpath, relative_extdirs, &result) == FALSE)
{
if((*env)->ExceptionCheck(env) == JNI_TRUE)
{
Expand All @@ -277,6 +266,17 @@ INT WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, wchar_t* lpCmd
ExitProcess(ERROR_INVALID_DATA);
}

if(relative_classpath != NULL)
{
free(relative_classpath);
relative_classpath = NULL;
}
if(relative_extdirs != NULL)
{
free(relative_extdirs);
relative_extdirs = NULL;
}

if(get_resource(L"SPLASH_SCREEN_IMAGE", &res) != NULL)
{
BYTE* splash_screen_image_buf = res.buf;
Expand Down
24 changes: 12 additions & 12 deletions src/image_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,17 +246,6 @@ static int service_main(int argc, const wchar_t* argv[])
use_side_by_side_jre = (ext_flags == NULL) || (wcsstr(ext_flags, L"NOSIDEBYSIDE") == NULL);
initialize_path(relative_classpath, relative_extdirs, use_server_vm, use_side_by_side_jre);

if(relative_classpath != NULL)
{
free(relative_classpath);
relative_classpath = NULL;
}
if(relative_extdirs != NULL)
{
free(relative_extdirs);
relative_extdirs = NULL;
}

if(ext_flags == NULL || wcsstr(ext_flags, L"NOENCODINGFIX") == NULL)
{
wcscat_s(utilities, BUFFER_SIZE, UTIL_ENCODING_FIX);
Expand Down Expand Up @@ -358,7 +347,7 @@ static int service_main(int argc, const wchar_t* argv[])
free(target_version);
}

if(load_main_class(argc, argv, utilities, &result) == FALSE)
if(load_main_class(argc, argv, utilities, relative_classpath, relative_extdirs, &result) == FALSE)
{
if((*env)->ExceptionCheck(env) == JNI_TRUE)
{
Expand All @@ -379,6 +368,17 @@ static int service_main(int argc, const wchar_t* argv[])
}
MainClass = result.MainClass;

if(relative_classpath != NULL)
{
free(relative_classpath);
relative_classpath = NULL;
}
if(relative_extdirs != NULL)
{
free(relative_extdirs);
relative_extdirs = NULL;
}

MainClass_start = (*env)->GetStaticMethodID(env, result.MainClass, "start", "([Ljava/lang/String;)V");
if(MainClass_start == NULL)
{
Expand Down
1 change: 0 additions & 1 deletion src/include/jvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ extern jint destroy_java_vm(void);
extern JNIEnv* attach_java_vm(void);
extern jint detach_java_vm(void);
extern BOOL set_application_properties(SYSTEMTIME* startup);
extern wchar_t* get_classpath(void);
extern void get_java_runtime_version(const wchar_t* version_string, DWORD* major, DWORD* minor, DWORD* build, DWORD* revision);
extern wchar_t* get_java_version_string(DWORD major, DWORD minor, DWORD build, DWORD revision);
extern wchar_t* get_module_version(wchar_t* buf, size_t size);
Expand Down
2 changes: 1 addition & 1 deletion src/include/loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ extern "C" {
#endif

extern wchar_t* install_security_manager(JNIEnv* env);
extern BOOL load_main_class(int argc, const wchar_t* argv[], const wchar_t* utilities, LOAD_RESULT* result);
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);
extern BOOL set_splash_screen_resource(const wchar_t* splash_screen_name, const BYTE* splash_screen_image_buf, DWORD splash_screen_image_len);
extern wchar_t* get_module_object_name(const wchar_t* prefix);
extern BYTE* get_resource(const wchar_t* name, RESOURCE* resource);
Expand Down
81 changes: 71 additions & 10 deletions src/java/Loader.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.net.URLStreamHandler;
import java.net.URLStreamHandlerFactory;
Expand All @@ -16,8 +17,10 @@
import java.security.Policy;
import java.security.ProtectionDomain;
import java.security.cert.Certificate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.LinkedList;
import java.util.Map;
import java.util.Queue;
Expand Down Expand Up @@ -45,7 +48,7 @@ public class Loader extends URLClassLoader {
private static URL context;
private static URLStreamHandler handler;

public static Class<?> initialize(JarInputStream[] jars, URLStreamHandlerFactory factory, String utilities, String classPath, String mainClassName, int consoleCodePage) throws MalformedURLException, ClassNotFoundException {
public static Class<?> initialize(JarInputStream[] jars, URLStreamHandlerFactory factory, String utilities, String relativeClassPath, String relativeExtDirs, String mainClassName, int consoleCodePage) throws MalformedURLException, ClassNotFoundException {
URL.setURLStreamHandlerFactory(factory);
handler = factory.createURLStreamHandler("exewrap");
context = new URL("exewrap:" + CONTEXT_PATH + "!/");
Expand Down Expand Up @@ -107,27 +110,69 @@ public static Class<?> initialize(JarInputStream[] jars, URLStreamHandlerFactory
}
}

Set<String> paths = new HashSet<String>();
if(systemClassLoader instanceof Loader) {
Loader loader = (Loader)systemClassLoader;
String appDir = System.getProperty("java.application.path");

try {
// カレントディレクトリをCLASS_PATHに追加します。
classPath = new File(".").getCanonicalPath() + ";" + classPath;
File file = new File(appDir);
URL url = file.toURI().toURL();
loader.addURL(url);
paths.add(file.toString().toLowerCase());
} catch(Exception ignore) {}

Set<String> paths = new HashSet<String>();
for(String path : classPath.split(";")) {
try {
if(path.length() > 0) {
File file = new File(path).getCanonicalFile();
if(relativeClassPath != null) {
for(String path : relativeClassPath.split(" ")) {
if(path.length() == 0) {
continue;
}
try {
path = URLDecoder.decode(path, "UTF-8");
path = path.replace('/', '\\');
path = appDir + '\\' + path;
File file = new File(path);
String s = file.toString().toLowerCase();
if(!paths.contains(s)) {
URL url = file.toURI().toURL();
loader.addURL(url);
paths.add(s);
}
} catch(Exception ignore) {}
}
}

if(relativeExtDirs != null) {
for(String path : relativeExtDirs.split(";")) {
if(path.length() == 0) {
continue;
}
path = path.replace('/', '\\');
path = appDir + '\\' + path;
File dir = new File(path);
try {
String s = dir.toString().toLowerCase();
if(!paths.contains(s)) {
URL url = dir.toURI().toURL();
loader.addURL(url);
paths.add(s);
}
} catch(Exception ignore) {}

if(dir.isDirectory()) {
List<File> files = retrieveJars(dir);
for(File file : files) {
try {
String s = file.toString().toLowerCase();
if(!paths.contains(s)) {
URL url = file.toURI().toURL();
loader.addURL(url);
paths.add(s);
}
} catch(Exception ignore) {}
}
}
} catch(Exception ignore) {}
}
}
}

Expand All @@ -137,7 +182,23 @@ public static Class<?> initialize(JarInputStream[] jars, URLStreamHandlerFactory
return Class.forName(MAIN_CLASS, true, systemClassLoader);
}
}


private static List<File> retrieveJars(File dir) {
List<File> list = new ArrayList<File>();
for(File child : dir.listFiles()) {
if(!child.isDirectory() && child.getName().toLowerCase().endsWith(".jar")) {
list.add(child);
}
if(child.isDirectory()) {
List<File> subList = retrieveJars(child);
if(subList.size() > 0) {
list.addAll(subList);
}
}
}
return list;
}


private ProtectionDomain protectionDomain;

Expand Down
Loading

0 comments on commit a69950d

Please sign in to comment.