リビジョン | 635cfa50126aeb19528258de62476ab6b3c3afbb (tree) |
---|---|
日時 | 2014-04-22 00:30:02 |
作者 | zolgear <> |
コミッター | zolgear <> |
Cygwinのアーキテクチャ判定が出来なくなっていたのを修正
@@ -27,38 +27,52 @@ | ||
27 | 27 | // |
28 | 28 | // Get Cygwin architecture |
29 | 29 | // |
30 | -WORD GetCygwinArch(const char *CygDir) | |
30 | +WORD GetCygwinArch(const char CygDir[]) | |
31 | 31 | { |
32 | 32 | WORD result = IMAGE_FILE_MACHINE_UNKNOWN; |
33 | 33 | char cygdll[MAX_PATH]; |
34 | - FILE *fp = NULL; | |
35 | - IMAGE_DOS_HEADER DosHeader; | |
36 | - IMAGE_NT_HEADERS32 Cygwin1DllHeader; | |
34 | + IMAGE_DOS_HEADER DosHeader = { 0x00 }; | |
35 | + IMAGE_NT_HEADERS32 Cygwin1DllHeader = { 0x00 }; | |
36 | + DWORD theReadBytes; | |
37 | + HANDLE theFH = INVALID_HANDLE_VALUE; | |
37 | 38 | |
38 | 39 | strcpy(cygdll, CygDir); |
39 | 40 | strcat(cygdll, "\\bin\\cygwin1.dll"); |
40 | 41 | |
41 | 42 | // Get PE header |
42 | - fp = fopen(cygdll, "r"); | |
43 | - if(fp == NULL) { | |
44 | - goto finally; | |
43 | + if((theFH = CreateFile(cygdll, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) | |
44 | + { | |
45 | + goto FIN; | |
45 | 46 | } |
46 | - if(fread(&DosHeader, sizeof(DosHeader), 1, fp) < 1) { | |
47 | - goto finally; | |
47 | + if(ReadFile(theFH, &DosHeader, sizeof(DosHeader), &theReadBytes, NULL) == FALSE) | |
48 | + { | |
49 | + goto FIN; | |
48 | 50 | } |
49 | - if(fseek(fp, DosHeader.e_lfanew, SEEK_SET) != 0) { | |
50 | - goto finally; | |
51 | + if(DosHeader.e_magic != IMAGE_DOS_SIGNATURE) | |
52 | + { | |
53 | + goto FIN; | |
51 | 54 | } |
52 | - if(fread(&Cygwin1DllHeader, sizeof(Cygwin1DllHeader), 1, fp) < 1) { | |
53 | - goto finally; | |
55 | + if(SetFilePointer(theFH, DosHeader.e_lfanew, 0, FILE_BEGIN) == INVALID_SET_FILE_POINTER) | |
56 | + { | |
57 | + goto FIN; | |
58 | + } | |
59 | + if(ReadFile(theFH, &Cygwin1DllHeader, sizeof(Cygwin1DllHeader), &theReadBytes, NULL) == FALSE) | |
60 | + { | |
61 | + goto FIN; | |
62 | + } | |
63 | + if(Cygwin1DllHeader.Signature != IMAGE_NT_SIGNATURE) | |
64 | + { | |
65 | + goto FIN; | |
54 | 66 | } |
55 | 67 | |
56 | 68 | // check architecture |
57 | 69 | result = Cygwin1DllHeader.FileHeader.Machine; |
58 | 70 | |
59 | -finally: | |
60 | - if(fp != NULL) { | |
61 | - fclose(fp); | |
71 | +FIN: | |
72 | + if(theFH != NULL && theFH != INVALID_HANDLE_VALUE) | |
73 | + { | |
74 | + CloseHandle(theFH); | |
75 | + theFH = INVALID_HANDLE_VALUE; | |
62 | 76 | } |
63 | 77 | return result; |
64 | 78 | } |
@@ -121,7 +135,7 @@ | ||
121 | 135 | |
122 | 136 | found_path:; |
123 | 137 | memset(&si, 0, sizeof(si)); |
124 | - si.cb = sizeof(si); | |
138 | + GetStartupInfo(&si); | |
125 | 139 | memset(&pi, 0, sizeof(pi)); |
126 | 140 | |
127 | 141 | for(i = (GetCygwinArch(CygwinDirectory) == IMAGE_FILE_MACHINE_AMD64 ? 0 : 1); |
@@ -138,8 +152,6 @@ | ||
138 | 152 | NULL, NULL, FALSE, 0, |
139 | 153 | NULL, curdir, |
140 | 154 | &si, &pi)) { |
141 | - CloseHandle(pi.hProcess); | |
142 | - CloseHandle(pi.hThread); | |
143 | 155 | break; |
144 | 156 | } |
145 | 157 | } |