• R/O
  • SSH
  • HTTPS

exewrap: Commit


Commit MetaInfo

Revision26 (tree)
Time2015-07-21 13:50:32
Authorhirukawa_ryo

Log Message

v1.1.0 *JRE検索でアーキテクチャ(x86/x64)の異なるjvm.dllは除外するようにしました。

Change Summary

Incremental Difference

--- exewrap/trunk/exewrap/src/jvm.c (revision 25)
+++ exewrap/trunk/exewrap/src/jvm.c (revision 26)
@@ -25,6 +25,7 @@
2525 char* GetSubDirs(char* dir);
2626 char* AddSubDirs(char* buf, char* dir, int* size);
2727 char** GetArgsOpt(char* vm_args_opt, int* argc);
28+int GetArchitectureBits(const char* jvmpath);
2829 static LPWSTR A2W(LPCSTR s);
2930 static LPSTR W2A(LPCWSTR s);
3031
@@ -356,14 +357,21 @@
356357 FindClose(hSearch);
357358 if (found)
358359 {
359- SetEnvironmentVariable("JAVA_HOME", jre1);
360- lstrcpy(binpath, jre1);
361- lstrcat(binpath, "\\bin");
362- lstrcpy(extpath, jre1);
363- lstrcat(extpath, "\\lib\\ext");
364- if (FindJavaVM(jvmpath, jre1, useServerVM) == FALSE)
360+ if (FindJavaVM(jvmpath, jre1, useServerVM))
365361 {
366- jvmpath[0] = '\0';
362+ int bits = GetArchitectureBits(jvmpath);
363+ if (bits == 0 || bits == GetProcessArchitecture())
364+ {
365+ SetEnvironmentVariable("JAVA_HOME", jre1);
366+ lstrcpy(binpath, jre1);
367+ lstrcat(binpath, "\\bin");
368+ lstrcpy(extpath, jre1);
369+ lstrcat(extpath, "\\lib\\ext");
370+ }
371+ else
372+ {
373+ jvmpath[0] = '\0';
374+ }
367375 }
368376 }
369377 }
@@ -390,14 +398,21 @@
390398 FindClose(hSearch);
391399 if (found)
392400 {
393- SetEnvironmentVariable("JAVA_HOME", jre2);
394- lstrcpy(binpath, jre2);
395- lstrcat(binpath, "\\bin");
396- lstrcpy(extpath, jre2);
397- lstrcat(extpath, "\\lib\\ext");
398401 if (FindJavaVM(jvmpath, jre2, useServerVM) == FALSE)
399402 {
400- jvmpath[0] = '\0';
403+ int bits = GetArchitectureBits(jvmpath);
404+ if (bits == 0 || bits == GetProcessArchitecture())
405+ {
406+ SetEnvironmentVariable("JAVA_HOME", jre2);
407+ lstrcpy(binpath, jre2);
408+ lstrcat(binpath, "\\bin");
409+ lstrcpy(extpath, jre2);
410+ lstrcat(extpath, "\\lib\\ext");
411+ }
412+ else
413+ {
414+ jvmpath[0] = '\0';
415+ }
401416 }
402417 }
403418 }
@@ -787,7 +802,68 @@
787802 return (LPTSTR*)argvA;
788803 }
789804
805+int GetArchitectureBits(const char* jvmpath)
806+{
807+ int bits = 0;
808+ char* file = NULL;
809+ HANDLE hFile = NULL;
810+ BYTE* buf = NULL;
811+ DWORD size = 512;
812+ DWORD read_size;
813+ UINT i;
790814
815+ file = (char*)malloc(1024);
816+ sprintf(file, "%s\\jvm.dll", jvmpath);
817+
818+ buf = (BYTE*)malloc(size);
819+
820+ hFile = CreateFile(file, GENERIC_READ, FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
821+ if (hFile == INVALID_HANDLE_VALUE)
822+ {
823+ goto EXIT;
824+ }
825+
826+ if (ReadFile(hFile, buf, size, &read_size, NULL) == 0)
827+ {
828+ goto EXIT;
829+ }
830+ CloseHandle(hFile);
831+ hFile = NULL;
832+
833+ for (i = 0; i < size - 6; i++)
834+ {
835+ if (buf[i + 0] == 'P' && buf[i + 1] == 'E' && buf[i + 2] == 0x00 && buf[i + 3] == 0x00)
836+ {
837+ if (buf[i + 4] == 0x4C && buf[i + 5] == 0x01)
838+ {
839+ bits = 32;
840+ goto EXIT;
841+ }
842+ if (buf[i + 4] == 0x64 && buf[i + 5] == 0x86)
843+ {
844+ bits = 64;
845+ goto EXIT;
846+ }
847+ }
848+ }
849+
850+EXIT:
851+ if (hFile != NULL)
852+ {
853+ CloseHandle(hFile);
854+ }
855+ if (buf != NULL)
856+ {
857+ free(buf);
858+ }
859+ if (file != NULL)
860+ {
861+ free(file);
862+ }
863+
864+ return bits;
865+}
866+
791867 static LPWSTR A2W(LPCSTR s)
792868 {
793869 LPWSTR buf;
--- exewrap/trunk/exewrap/src/java/jremin/JreMin.java (revision 25)
+++ exewrap/trunk/exewrap/src/java/jremin/JreMin.java (revision 26)
@@ -138,7 +138,7 @@
138138 System.out.println("JRE not found.");
139139 return;
140140 }
141- File target = new File(jre.getName());
141+ File target = new File(jre.getName() + "_min");
142142
143143 Set<String> appends = new HashSet<String>();
144144
Show on old repository browser