67 |
|
|
68 |
file = CreateFile (filename, GENERIC_READ, FILE_SHARE_READ, NULL, |
file = CreateFile (filename, GENERIC_READ, FILE_SHARE_READ, NULL, |
69 |
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); |
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); |
70 |
if (file == INVALID_HANDLE_VALUE) |
if (file == INVALID_HANDLE_VALUE) |
71 |
return FALSE; |
return FALSE; |
72 |
|
|
73 |
size = GetFileSize (file, &upper_size); |
size = GetFileSize (file, &upper_size); |
74 |
file_mapping = CreateFileMapping (file, NULL, PAGE_READONLY, |
file_mapping = CreateFileMapping (file, NULL, PAGE_READONLY, |
75 |
0, size, NULL); |
0, size, NULL); |
76 |
if (!file_mapping) |
if (!file_mapping) |
77 |
return FALSE; |
return FALSE; |
78 |
|
|
79 |
file_base = MapViewOfFile (file_mapping, FILE_MAP_READ, 0, 0, size); |
file_base = MapViewOfFile (file_mapping, FILE_MAP_READ, 0, 0, size); |
80 |
if (file_base == 0) |
if (file_base == 0) |
81 |
return FALSE; |
return FALSE; |
82 |
|
|
83 |
p_file->name = filename; |
p_file->name = filename; |
98 |
|
|
99 |
file = CreateFile (filename, GENERIC_READ | GENERIC_WRITE, 0, NULL, |
file = CreateFile (filename, GENERIC_READ | GENERIC_WRITE, 0, NULL, |
100 |
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); |
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0); |
101 |
if (file == INVALID_HANDLE_VALUE) |
if (file == INVALID_HANDLE_VALUE) |
102 |
return FALSE; |
return FALSE; |
103 |
|
|
104 |
file_mapping = CreateFileMapping (file, NULL, PAGE_READWRITE, |
file_mapping = CreateFileMapping (file, NULL, PAGE_READWRITE, |
105 |
0, size, NULL); |
0, size, NULL); |
106 |
if (!file_mapping) |
if (!file_mapping) |
107 |
return FALSE; |
return FALSE; |
108 |
|
|
109 |
file_base = MapViewOfFile (file_mapping, FILE_MAP_WRITE, 0, 0, size); |
file_base = MapViewOfFile (file_mapping, FILE_MAP_WRITE, 0, 0, size); |
110 |
if (file_base == 0) |
if (file_base == 0) |
111 |
return FALSE; |
return FALSE; |
112 |
|
|
113 |
p_file->name = filename; |
p_file->name = filename; |
114 |
p_file->size = size; |
p_file->size = size; |
115 |
p_file->file = file; |
p_file->file = file; |
270 |
|
|
271 |
|
|
272 |
static void |
static void |
273 |
copy_executable_and_add_section (file_data *p_infile, |
copy_executable_and_add_section (file_data *p_infile, |
274 |
file_data *p_outfile, |
file_data *p_outfile, |
275 |
char *new_section_name, |
char *new_section_name, |
276 |
DWORD new_section_size) |
DWORD new_section_size) |
314 |
Note that dst is updated implicitly by each COPY_CHUNK. */ |
Note that dst is updated implicitly by each COPY_CHUNK. */ |
315 |
|
|
316 |
dos_header = (PIMAGE_DOS_HEADER) p_infile->file_base; |
dos_header = (PIMAGE_DOS_HEADER) p_infile->file_base; |
317 |
nt_header = (PIMAGE_NT_HEADERS) (((unsigned long) dos_header) + |
nt_header = (PIMAGE_NT_HEADERS) (((unsigned long) dos_header) + |
318 |
dos_header->e_lfanew); |
dos_header->e_lfanew); |
319 |
section = IMAGE_FIRST_SECTION (nt_header); |
section = IMAGE_FIRST_SECTION (nt_header); |
320 |
|
|
321 |
dst = (unsigned char *) p_outfile->file_base; |
dst = (unsigned char *) p_outfile->file_base; |
322 |
|
|
323 |
COPY_CHUNK ("Copying DOS header...", dos_header, |
COPY_CHUNK ("Copying DOS header...", dos_header, |
477 |
/* Open the undumped executable file. */ |
/* Open the undumped executable file. */ |
478 |
if (!open_input_file (&in_file, in_filename)) |
if (!open_input_file (&in_file, in_filename)) |
479 |
{ |
{ |
480 |
printf ("Failed to open %s (%d)...bailing.\n", |
printf ("Failed to open %s (%d)...bailing.\n", |
481 |
in_filename, GetLastError ()); |
in_filename, GetLastError ()); |
482 |
exit (1); |
exit (1); |
483 |
} |
} |
491 |
* nt_header->FileHeader.NumberOfSections; |
* nt_header->FileHeader.NumberOfSections; |
492 |
if (!open_output_file (&out_file, out_filename, size)) |
if (!open_output_file (&out_file, out_filename, size)) |
493 |
{ |
{ |
494 |
printf ("Failed to open %s (%d)...bailing.\n", |
printf ("Failed to open %s (%d)...bailing.\n", |
495 |
out_filename, GetLastError ()); |
out_filename, GetLastError ()); |
496 |
exit (1); |
exit (1); |
497 |
} |
} |