aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/unexw32.c48
1 files changed, 29 insertions, 19 deletions
diff --git a/src/unexw32.c b/src/unexw32.c
index 0d150cf34db..7b907beda6e 100644
--- a/src/unexw32.c
+++ b/src/unexw32.c
@@ -67,17 +67,17 @@ void dump_bss_and_heap (file_data *p_infile, file_data *p_outfile);
67 67
68/* Cached info about the .data section in the executable. */ 68/* Cached info about the .data section in the executable. */
69PIMAGE_SECTION_HEADER data_section; 69PIMAGE_SECTION_HEADER data_section;
70PUCHAR data_start = 0; 70PCHAR data_start = 0;
71DWORD data_size = 0; 71DWORD data_size = 0;
72 72
73/* Cached info about the .bss section in the executable. */ 73/* Cached info about the .bss section in the executable. */
74PIMAGE_SECTION_HEADER bss_section; 74PIMAGE_SECTION_HEADER bss_section;
75PUCHAR bss_start = 0; 75PCHAR bss_start = 0;
76DWORD bss_size = 0; 76DWORD bss_size = 0;
77DWORD extra_bss_size = 0; 77DWORD extra_bss_size = 0;
78/* bss data that is static might be discontiguous from non-static. */ 78/* bss data that is static might be discontiguous from non-static. */
79PIMAGE_SECTION_HEADER bss_section_static; 79PIMAGE_SECTION_HEADER bss_section_static;
80PUCHAR bss_start_static = 0; 80PCHAR bss_start_static = 0;
81DWORD bss_size_static = 0; 81DWORD bss_size_static = 0;
82DWORD extra_bss_size_static = 0; 82DWORD extra_bss_size_static = 0;
83 83
@@ -284,7 +284,7 @@ offset_to_section (DWORD offset, IMAGE_NT_HEADERS * nt_header)
284/* Return offset to an object in dst, given offset in src. We assume 284/* Return offset to an object in dst, given offset in src. We assume
285 there is at least one section in both src and dst images, and that 285 there is at least one section in both src and dst images, and that
286 the some sections may have been added to dst (after sections in src). */ 286 the some sections may have been added to dst (after sections in src). */
287static DWORD 287DWORD
288relocate_offset (DWORD offset, 288relocate_offset (DWORD offset,
289 IMAGE_NT_HEADERS * src_nt_header, 289 IMAGE_NT_HEADERS * src_nt_header,
290 IMAGE_NT_HEADERS * dst_nt_header) 290 IMAGE_NT_HEADERS * dst_nt_header)
@@ -331,14 +331,14 @@ relocate_offset (DWORD offset,
331#define PTR_TO_RVA(ptr) ((DWORD)(ptr) - (DWORD) GetModuleHandle (NULL)) 331#define PTR_TO_RVA(ptr) ((DWORD)(ptr) - (DWORD) GetModuleHandle (NULL))
332 332
333#define PTR_TO_OFFSET(ptr, pfile_data) \ 333#define PTR_TO_OFFSET(ptr, pfile_data) \
334 ((char *)(ptr) - (pfile_data)->file_base) 334 ((unsigned char *)(ptr) - (pfile_data)->file_base)
335 335
336#define OFFSET_TO_PTR(offset, pfile_data) \ 336#define OFFSET_TO_PTR(offset, pfile_data) \
337 ((pfile_data)->file_base + (DWORD)(offset)) 337 ((pfile_data)->file_base + (DWORD)(offset))
338 338
339 339
340/* Flip through the executable and cache the info necessary for dumping. */ 340/* Flip through the executable and cache the info necessary for dumping. */
341static void 341void
342get_section_info (file_data *p_infile) 342get_section_info (file_data *p_infile)
343{ 343{
344 PIMAGE_DOS_HEADER dos_header; 344 PIMAGE_DOS_HEADER dos_header;
@@ -481,7 +481,7 @@ get_section_info (file_data *p_infile)
481 481
482/* The dump routines. */ 482/* The dump routines. */
483 483
484static void 484void
485copy_executable_and_dump_data (file_data *p_infile, 485copy_executable_and_dump_data (file_data *p_infile,
486 file_data *p_outfile) 486 file_data *p_outfile)
487{ 487{
@@ -617,7 +617,7 @@ copy_executable_and_dump_data (file_data *p_infile,
617 } 617 }
618 if (section == heap_section) 618 if (section == heap_section)
619 { 619 {
620 DWORD heap_start = get_heap_start (); 620 DWORD heap_start = (DWORD) get_heap_start ();
621 DWORD heap_size = get_committed_heap_size (); 621 DWORD heap_size = get_committed_heap_size ();
622 622
623 /* Dump the used portion of the predump heap, adjusting the 623 /* Dump the used portion of the predump heap, adjusting the
@@ -719,18 +719,28 @@ unexec (char *new_name, char *old_name, void *start_data, void *start_bss,
719 file_data in_file, out_file; 719 file_data in_file, out_file;
720 char out_filename[MAX_PATH], in_filename[MAX_PATH]; 720 char out_filename[MAX_PATH], in_filename[MAX_PATH];
721 unsigned long size; 721 unsigned long size;
722 char *ptr; 722 char *p;
723 char *q;
724
725 /* Ignore old_name, and get our actual location from the OS. */
726 if (!GetModuleFileName (NULL, in_filename, MAX_PATH))
727 abort ();
728 dostounix_filename (in_filename);
729 strcpy (out_filename, in_filename);
730
731 /* Change the base of the output filename to match the requested name. */
732 if ((p = strrchr (out_filename, '/')) == NULL)
733 abort ();
734 /* The filenames have already been expanded, and will be in Unix
735 format, so it is safe to expect an absolute name. */
736 if ((q = strrchr (new_name, '/')) == NULL)
737 abort ();
738 strcpy (p, q);
723 739
724 /* Make sure that the input and output filenames have the 740 /* Make sure that the output filename has the ".exe" extension...patch
725 ".exe" extension...patch them up if they don't. */ 741 it up if not. */
726 strcpy (in_filename, old_name); 742 p = out_filename + strlen (out_filename) - 4;
727 ptr = in_filename + strlen (in_filename) - 4; 743 if (strcmp (p, ".exe"))
728 if (strcmp (ptr, ".exe"))
729 strcat (in_filename, ".exe");
730
731 strcpy (out_filename, new_name);
732 ptr = out_filename + strlen (out_filename) - 4;
733 if (strcmp (ptr, ".exe"))
734 strcat (out_filename, ".exe"); 744 strcat (out_filename, ".exe");
735 745
736 printf ("Dumping from %s\n", in_filename); 746 printf ("Dumping from %s\n", in_filename);