aboutsummaryrefslogtreecommitdiff
path: root/src/main/extractor_ipc_w32.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/extractor_ipc_w32.c')
-rw-r--r--src/main/extractor_ipc_w32.c184
1 files changed, 83 insertions, 101 deletions
diff --git a/src/main/extractor_ipc_w32.c b/src/main/extractor_ipc_w32.c
index 2839e53..2ca0735 100644
--- a/src/main/extractor_ipc_w32.c
+++ b/src/main/extractor_ipc_w32.c
@@ -20,10 +20,8 @@
20 20
21 21
22/** 22/**
23 * Definition of an IPC communication channel with
24 * some plugin.
25 */ 23 */
26struct EXTRACTOR_Channel 24struct EXTRACTOR_SharedMemory
27{ 25{
28 26
29 /** 27 /**
@@ -60,6 +58,57 @@ struct EXTRACTOR_Channel
60}; 58};
61 59
62 60
61/**
62 * Definition of an IPC communication channel with
63 * some plugin.
64 */
65struct EXTRACTOR_Channel
66{
67
68 /**
69 * Process ID of the child process for this plugin. 0 for none.
70 */
71 HANDLE hProcess;
72
73 /**
74 * Pipe used to communicate information to the plugin child process.
75 * NULL if not initialized.
76 */
77 HANDLE cpipe_in;
78
79 /**
80 * Handle of the shm object
81 */
82 HANDLE map_handle;
83
84 /**
85 * Pipe used to read information about extracted meta data from
86 * the plugin child process. -1 if not initialized.
87 */
88 HANDLE cpipe_out;
89
90 /**
91 * Page size. Mmap offset is a multiple of this number.
92 */
93 DWORD allocation_granularity;
94
95 /**
96 * A structure for overlapped reads on W32.
97 */
98 OVERLAPPED ov_read;
99
100 /**
101 * A structure for overlapped writes on W32.
102 */
103 OVERLAPPED ov_write;
104
105 /**
106 * A write buffer for overlapped writes on W32
107 */
108 unsigned char *ov_write_buffer;
109
110};
111
63 112
64/** 113/**
65 * Initializes an extracting session for a plugin. 114 * Initializes an extracting session for a plugin.
@@ -437,71 +486,6 @@ write_plugin_data (struct EXTRACTOR_PluginList *plugin)
437 486
438 487
439/** 488/**
440 * Reads plugin data from the LE server process.
441 * Also initializes allocation granularity (duh...).
442 *
443 * @param fd the pipe to read from
444 *
445 * @return newly allocated plugin context
446 */
447static struct EXTRACTOR_PluginList *
448read_plugin_data (int fd)
449{
450 struct EXTRACTOR_PluginList *ret;
451 size_t i;
452
453 ret = malloc (sizeof (struct EXTRACTOR_PluginList));
454 if (ret == NULL)
455 return NULL;
456 read (fd, &i, sizeof (size_t));
457 ret->libname = malloc (i);
458 if (ret->libname == NULL)
459 {
460 free (ret);
461 return NULL;
462 }
463 read (fd, ret->libname, i);
464 ret->libname[i - 1] = '\0';
465
466 read (fd, &i, sizeof (size_t));
467 ret->short_libname = malloc (i);
468 if (ret->short_libname == NULL)
469 {
470 free (ret->libname);
471 free (ret);
472 return NULL;
473 }
474 read (fd, ret->short_libname, i);
475 ret->short_libname[i - 1] = '\0';
476
477 read (fd, &i, sizeof (size_t));
478 if (i == 0)
479 {
480 ret->plugin_options = NULL;
481 }
482 else
483 {
484 ret->plugin_options = malloc (i);
485 if (ret->plugin_options == NULL)
486 {
487 free (ret->short_libname);
488 free (ret->libname);
489 free (ret);
490 return NULL;
491 }
492 read (fd, ret->plugin_options, i);
493 ret->plugin_options[i - 1] = '\0';
494 }
495 {
496 SYSTEM_INFO si;
497 GetSystemInfo (&si);
498 ret->allocation_granularity = si.dwAllocationGranularity;
499 }
500 return ret;
501}
502
503
504/**
505 * Start the process for the given plugin. 489 * Start the process for the given plugin.
506 */ 490 */
507static void 491static void
@@ -513,7 +497,8 @@ start_process (struct EXTRACTOR_PluginList *plugin)
513 PROCESS_INFORMATION proc; 497 PROCESS_INFORMATION proc;
514 char cmd[MAX_PATH + 1]; 498 char cmd[MAX_PATH + 1];
515 char arg1[10], arg2[10]; 499 char arg1[10], arg2[10];
516 HANDLE p10_os_inh = INVALID_HANDLE_VALUE, p21_os_inh = INVALID_HANDLE_VALUE; 500 HANDLE p10_os_inh = INVALID_HANDLE_VALUE;
501 HANDLE p21_os_inh = INVALID_HANDLE_VALUE;
517 SECURITY_ATTRIBUTES sa; 502 SECURITY_ATTRIBUTES sa;
518 503
519 switch (plugin->flags) 504 switch (plugin->flags)
@@ -614,6 +599,35 @@ start_process (struct EXTRACTOR_PluginList *plugin)
614 599
615 600
616/** 601/**
602 * Receive 'size' bytes from channel, store them in 'buf'
603 *
604 * @param plugin plugin context
605 * @param buf buffer to fill
606 * @param size number of bytes to read
607 * @return number of bytes read, 0 on EOS, < 0 on error
608 */
609static int
610plugin_read (struct EXTRACTOR_PluginList *plugin,
611 void *buf,
612 size_t size)
613{
614 char *rb = buf;
615 ssize_t read_result;
616 size_t read_count = 0;
617
618 while (read_count < size)
619 {
620 read_result = read (plugin->cpipe_out,
621 &rb[read_count], size - read_count);
622 if (read_result <= 0)
623 return read_result;
624 read_count += read_result;
625 }
626 return read_count;
627}
628
629
630/**
617 * Stop the child process of this plugin. 631 * Stop the child process of this plugin.
618 */ 632 */
619static void 633static void
@@ -731,38 +745,6 @@ destroy_file_backed_shm_w32 (HANDLE map)
731#define plugin_write(plug, buf, size) write_all (fileno (plug->cpipe_in), buf, size) 745#define plugin_write(plug, buf, size) write_all (fileno (plug->cpipe_in), buf, size)
732 746
733 747
734void CALLBACK
735RundllEntryPoint (HWND hwnd,
736 HINSTANCE hinst,
737 LPSTR lpszCmdLine,
738 int nCmdShow)
739{
740 intptr_t in_h;
741 intptr_t out_h;
742 int in;
743 int out;
744
745 sscanf (lpszCmdLine, "%lu %lu", &in_h, &out_h);
746 in = _open_osfhandle (in_h, _O_RDONLY);
747 out = _open_osfhandle (out_h, 0);
748 setmode (in, _O_BINARY);
749 setmode (out, _O_BINARY);
750 plugin_main (read_plugin_data (in),
751 in, out);
752}
753
754
755void CALLBACK
756RundllEntryPointA (HWND hwnd,
757 HINSTANCE hinst,
758 LPSTR lpszCmdLine,
759 int nCmdShow)
760{
761 return RundllEntryPoint (hwnd, hinst, lpszCmdLine, nCmdShow);
762}
763
764
765
766/** 748/**
767 * Receive 'size' bytes from plugin, store them in 'buf' 749 * Receive 'size' bytes from plugin, store them in 'buf'
768 * 750 *