diff options
-rw-r--r-- | src/main/extractor.c | 115 |
1 files changed, 54 insertions, 61 deletions
diff --git a/src/main/extractor.c b/src/main/extractor.c index 98723ac..26540ec 100644 --- a/src/main/extractor.c +++ b/src/main/extractor.c | |||
@@ -133,21 +133,13 @@ struct EXTRACTOR_PluginList | |||
133 | * Pipe used to send information about shared memory segments to | 133 | * Pipe used to send information about shared memory segments to |
134 | * the child process. NULL if not initialized. | 134 | * the child process. NULL if not initialized. |
135 | */ | 135 | */ |
136 | #ifndef WINDOWS | ||
137 | FILE *cpipe_in; | 136 | FILE *cpipe_in; |
138 | #else | ||
139 | HANDLE cpipe_in; | ||
140 | #endif | ||
141 | 137 | ||
142 | /** | 138 | /** |
143 | * Pipe used to read information about extracted meta data from | 139 | * Pipe used to read information about extracted meta data from |
144 | * the child process. -1 if not initialized. | 140 | * the child process. -1 if not initialized. |
145 | */ | 141 | */ |
146 | #ifndef WINDOWS | ||
147 | int cpipe_out; | 142 | int cpipe_out; |
148 | #else | ||
149 | HANDLE cpipe_out; | ||
150 | #endif | ||
151 | }; | 143 | }; |
152 | 144 | ||
153 | 145 | ||
@@ -1002,11 +994,7 @@ write_all (int fd, | |||
1002 | 994 | ||
1003 | static int | 995 | static int |
1004 | read_all ( | 996 | read_all ( |
1005 | #ifndef WINDOWS | ||
1006 | int fd, | 997 | int fd, |
1007 | #else | ||
1008 | HANDLE fd, | ||
1009 | #endif | ||
1010 | void *buf, | 998 | void *buf, |
1011 | size_t size) | 999 | size_t size) |
1012 | { | 1000 | { |
@@ -1016,11 +1004,7 @@ read_all ( | |||
1016 | 1004 | ||
1017 | while (off < size) | 1005 | while (off < size) |
1018 | { | 1006 | { |
1019 | #ifndef WINDOWS | ||
1020 | ret = read (fd, &data[off], size - off); | 1007 | ret = read (fd, &data[off], size - off); |
1021 | #else | ||
1022 | ReadFile (fd, &data[off], size - off, &ret, NULL); | ||
1023 | #endif | ||
1024 | if (ret <= 0) | 1008 | if (ret <= 0) |
1025 | return -1; | 1009 | return -1; |
1026 | off += ret; | 1010 | off += ret; |
@@ -1225,48 +1209,54 @@ process_requests (struct EXTRACTOR_PluginList *plugin, | |||
1225 | 1209 | ||
1226 | 1210 | ||
1227 | #ifdef WINDOWS | 1211 | #ifdef WINDOWS |
1228 | static void | 1212 | static void |
1229 | write_plugin_data (HANDLE h, const struct EXTRACTOR_PluginList *plugin) | 1213 | write_plugin_data (int fd, const struct EXTRACTOR_PluginList *plugin) |
1230 | { | 1214 | { |
1231 | size_t i; | 1215 | size_t i; |
1232 | DWORD len; | 1216 | DWORD len; |
1217 | char *str; | ||
1233 | 1218 | ||
1234 | i = strlen (plugin->libname); | 1219 | i = strlen (plugin->libname) + 1; |
1235 | WriteFile (h, &i, sizeof (size_t), &len, NULL); | 1220 | write (fd, &i, sizeof (size_t)); |
1236 | WriteFile (h, plugin->libname, i, &len, NULL); | 1221 | write (fd, plugin->libname, i); |
1237 | 1222 | ||
1238 | i = strlen (plugin->short_libname); | 1223 | i = strlen (plugin->short_libname) + 1; |
1239 | WriteFile (h, &i, sizeof (size_t), &len, NULL); | 1224 | write (fd, &i, sizeof (size_t)); |
1240 | WriteFile (h, plugin->short_libname,i, &len, NULL); | 1225 | write (fd, plugin->short_libname, i); |
1241 | 1226 | ||
1242 | if (plugin->plugin_options != NULL) | 1227 | if (plugin->plugin_options != NULL) |
1243 | i = strlen (plugin->plugin_options); | 1228 | { |
1229 | i = strlen (plugin->plugin_options) + 1; | ||
1230 | str = plugin->plugin_options; | ||
1231 | } | ||
1244 | else | 1232 | else |
1245 | i = 0; | 1233 | { |
1246 | WriteFile (h, &i, sizeof (size_t), &len, NULL); | 1234 | i = 1; |
1247 | WriteFile (h, plugin->plugin_options, i, &len, NULL); | 1235 | str = ""; |
1236 | } | ||
1237 | write (fd, &i, sizeof (size_t)); | ||
1238 | write (fd, str, i); | ||
1248 | } | 1239 | } |
1249 | 1240 | ||
1250 | |||
1251 | static struct EXTRACTOR_PluginList * | 1241 | static struct EXTRACTOR_PluginList * |
1252 | read_plugin_data (FILE *f) | 1242 | read_plugin_data (int fd) |
1253 | { | 1243 | { |
1254 | struct EXTRACTOR_PluginList *ret; | 1244 | struct EXTRACTOR_PluginList *ret; |
1255 | size_t i; | 1245 | size_t i; |
1256 | 1246 | ||
1257 | ret = malloc (sizeof (struct EXTRACTOR_PluginList)); | 1247 | ret = malloc (sizeof (struct EXTRACTOR_PluginList)); |
1258 | 1248 | ||
1259 | fread (&i, sizeof (size_t), 1, f); | 1249 | read (fd, &i, sizeof (size_t)); |
1260 | ret->libname = malloc (i); | 1250 | ret->libname = malloc (i); |
1261 | fread (ret->libname, i, 1, f); | 1251 | read (fd, ret->libname, i); |
1262 | 1252 | ||
1263 | fread (&i, sizeof (size_t), 1, f); | 1253 | read (fd, &i, sizeof (size_t)); |
1264 | ret->short_libname = malloc (i); | 1254 | ret->short_libname = malloc (i); |
1265 | fread (ret->short_libname, i, 1, f); | 1255 | read (fd, ret->short_libname, i); |
1266 | 1256 | ||
1267 | fread (&i, sizeof (size_t), 1, f); | 1257 | read (fd, &i, sizeof (size_t)); |
1268 | ret->plugin_options = malloc (i); | 1258 | ret->plugin_options = malloc (i); |
1269 | fread (ret->plugin_options, i, 1, f); | 1259 | read (fd, ret->plugin_options, i); |
1270 | 1260 | ||
1271 | return ret; | 1261 | return ret; |
1272 | } | 1262 | } |
@@ -1277,13 +1267,12 @@ RundllEntryPoint(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow) | |||
1277 | { | 1267 | { |
1278 | int in, out; | 1268 | int in, out; |
1279 | 1269 | ||
1280 | in = fileno (stdin); | 1270 | sscanf(lpszCmdLine, "%u %u", &in, &out); |
1281 | out = fileno (stdout); | ||
1282 | 1271 | ||
1283 | setmode (in, _O_BINARY); | 1272 | setmode (in, _O_BINARY); |
1284 | setmode (out, _O_BINARY); | 1273 | setmode (out, _O_BINARY); |
1285 | 1274 | ||
1286 | process_requests (read_plugin_data (stdin), in, out); | 1275 | process_requests (read_plugin_data (in), in, out); |
1287 | } | 1276 | } |
1288 | #endif | 1277 | #endif |
1289 | 1278 | ||
@@ -1294,18 +1283,25 @@ RundllEntryPoint(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow) | |||
1294 | static void | 1283 | static void |
1295 | start_process (struct EXTRACTOR_PluginList *plugin) | 1284 | start_process (struct EXTRACTOR_PluginList *plugin) |
1296 | { | 1285 | { |
1297 | #ifndef WINDOWS | ||
1298 | int p1[2]; | 1286 | int p1[2]; |
1299 | int p2[2]; | 1287 | int p2[2]; |
1300 | pid_t pid; | 1288 | pid_t pid; |
1301 | 1289 | ||
1290 | #ifndef WINDOWS | ||
1302 | if (0 != pipe (p1)) | 1291 | if (0 != pipe (p1)) |
1292 | #else | ||
1293 | if (0 != _pipe (p1, 0, _O_BINARY)) | ||
1294 | #endif | ||
1303 | { | 1295 | { |
1304 | plugin->cpid = -1; | 1296 | plugin->cpid = -1; |
1305 | plugin->flags = EXTRACTOR_OPTION_DISABLED; | 1297 | plugin->flags = EXTRACTOR_OPTION_DISABLED; |
1306 | return; | 1298 | return; |
1307 | } | 1299 | } |
1300 | #ifndef WINDOWS | ||
1308 | if (0 != pipe (p2)) | 1301 | if (0 != pipe (p2)) |
1302 | #else | ||
1303 | if (0 != _pipe (p2, 0, _O_BINARY)) | ||
1304 | #endif | ||
1309 | { | 1305 | { |
1310 | close (p1[0]); | 1306 | close (p1[0]); |
1311 | close (p1[1]); | 1307 | close (p1[1]); |
@@ -1313,7 +1309,23 @@ start_process (struct EXTRACTOR_PluginList *plugin) | |||
1313 | plugin->flags = EXTRACTOR_OPTION_DISABLED; | 1309 | plugin->flags = EXTRACTOR_OPTION_DISABLED; |
1314 | return; | 1310 | return; |
1315 | } | 1311 | } |
1312 | #ifndef WINDOWS | ||
1316 | pid = fork (); | 1313 | pid = fork (); |
1314 | #else | ||
1315 | STARTUPINFO startup; | ||
1316 | PROCESS_INFORMATION proc; | ||
1317 | char cmd[100]; | ||
1318 | char arg1[10], arg2[10]; | ||
1319 | |||
1320 | memset (&startup, 0, sizeof (STARTUPINFO)); | ||
1321 | write_plugin_data (p1[1], plugin); | ||
1322 | |||
1323 | |||
1324 | itoa(p1[0], arg1, 10); | ||
1325 | itoa(p2[1], arg2, 10); | ||
1326 | pid = _spawnl(_P_NOWAIT, "C:\\WINDOWS\\SYSTEM32\\rundll32.exe", "C:\\WINDOWS\\SYSTEM32\\rundll32.exe", | ||
1327 | "libextractor-3.dll,RundllEntryPoint@16", arg1, arg2, NULL); | ||
1328 | #endif | ||
1317 | if (pid == -1) | 1329 | if (pid == -1) |
1318 | { | 1330 | { |
1319 | close (p1[0]); | 1331 | close (p1[0]); |
@@ -1326,8 +1338,8 @@ start_process (struct EXTRACTOR_PluginList *plugin) | |||
1326 | } | 1338 | } |
1327 | if (pid == 0) | 1339 | if (pid == 0) |
1328 | { | 1340 | { |
1329 | close (p1[1]); | 1341 | close (p1[1]); |
1330 | close (p2[0]); | 1342 | close (p2[0]); |
1331 | process_requests (plugin, p1[0], p2[1]); | 1343 | process_requests (plugin, p1[0], p2[1]); |
1332 | _exit (0); | 1344 | _exit (0); |
1333 | } | 1345 | } |
@@ -1338,25 +1350,6 @@ start_process (struct EXTRACTOR_PluginList *plugin) | |||
1338 | if (plugin->cpipe_in == NULL) | 1350 | if (plugin->cpipe_in == NULL) |
1339 | perror ("fdopen"); | 1351 | perror ("fdopen"); |
1340 | plugin->cpipe_out = p2[0]; | 1352 | plugin->cpipe_out = p2[0]; |
1341 | #else | ||
1342 | STARTUPINFO startup; | ||
1343 | PROCESS_INFORMATION proc; | ||
1344 | |||
1345 | memset (&startup, 0, sizeof (STARTUPINFO)); | ||
1346 | if (!CreatePipe (&startup.hStdInput, &plugin->cpipe_in, NULL, 0)) | ||
1347 | perror ("CreatePipe"); | ||
1348 | if (!CreatePipe (&plugin->cpipe_out, &startup.hStdOutput, NULL, 0)) | ||
1349 | perror ("CreatePipe"); | ||
1350 | |||
1351 | write_plugin_data (plugin->cpipe_in, plugin); | ||
1352 | CloseHandle (plugin->cpipe_in); | ||
1353 | |||
1354 | // FIXME library name | ||
1355 | CreateProcess (NULL, "rundll32 libextractor-3.dll,RundllEntryPoint@16", NULL, NULL, FALSE, 0, NULL, NULL, &startup, &proc); | ||
1356 | CloseHandle (proc.hProcess); | ||
1357 | CloseHandle (proc.hThread); | ||
1358 | plugin->cpid = proc.dwProcessId; | ||
1359 | #endif | ||
1360 | } | 1353 | } |
1361 | 1354 | ||
1362 | 1355 | ||