comparison src/unexnt.c @ 408:501cfd01ee6d r21-2-34

Import from CVS: tag r21-2-34
author cvs
date Mon, 13 Aug 2007 11:18:11 +0200
parents a86b2b5e0111
children de805c49cfc1
comparison
equal deleted inserted replaced
407:ed6218a7d4d3 408:501cfd01ee6d
59 #include <stdlib.h> /* _fmode */ 59 #include <stdlib.h> /* _fmode */
60 #include <stdio.h> 60 #include <stdio.h>
61 #include <fcntl.h> 61 #include <fcntl.h>
62 #include <windows.h> 62 #include <windows.h>
63 63
64 #include "nt.h"
65 #include "ntheap.h"
66
64 /* From IMAGEHLP.H which is not installed by default by MSVC < 5 */ 67 /* From IMAGEHLP.H which is not installed by default by MSVC < 5 */
65 /* The IMAGEHLP.DLL library is not distributed by default with Windows95 */ 68 /* The IMAGEHLP.DLL library is not distributed by default with Windows95 */
66 typedef PIMAGE_NT_HEADERS 69 typedef PIMAGE_NT_HEADERS
67 (__stdcall * pfnCheckSumMappedFile_t) (LPVOID BaseAddress, DWORD FileLength, 70 (__stdcall * pfnCheckSumMappedFile_t) (LPVOID BaseAddress, DWORD FileLength,
68 LPDWORD HeaderSum, LPDWORD CheckSum); 71 LPDWORD HeaderSum, LPDWORD CheckSum);
70 73
71 #if 0 74 #if 0
72 extern BOOL ctrl_c_handler (unsigned long type); 75 extern BOOL ctrl_c_handler (unsigned long type);
73 #endif 76 #endif
74 77
75 #include "ntheap.h" 78 /* Sync with FSF Emacs 19.34.6
76 79 note: struct file_data is now defined in nt.h */
77 /* Sync with FSF Emacs 19.34.6 note: struct file_data is now defined in ntheap.h */
78 80
79 enum { 81 enum {
80 HEAP_UNINITIALIZED = 1, 82 HEAP_UNINITIALIZED = 1,
81 HEAP_UNLOADED, 83 HEAP_UNLOADED,
82 HEAP_LOADED 84 HEAP_LOADED
280 282
281 close_file_data (&in_file); 283 close_file_data (&in_file);
282 close_file_data (&out_file); 284 close_file_data (&out_file);
283 } 285 }
284 286
285
286 /* File handling. */
287
288
289 int
290 open_output_file (file_data *p_file, const char *filename, unsigned long size)
291 {
292 HANDLE file;
293 HANDLE file_mapping;
294 void *file_base;
295
296 file = CreateFile (filename, GENERIC_READ | GENERIC_WRITE, 0, NULL,
297 CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
298 if (file == INVALID_HANDLE_VALUE)
299 return FALSE;
300
301 file_mapping = CreateFileMapping (file, NULL, PAGE_READWRITE,
302 0, size, NULL);
303 if (!file_mapping)
304 return FALSE;
305
306 file_base = MapViewOfFile (file_mapping, FILE_MAP_WRITE, 0, 0, size);
307 if (file_base == NULL)
308 return FALSE;
309
310 p_file->name = filename;
311 p_file->size = size;
312 p_file->file = file;
313 p_file->file_mapping = file_mapping;
314 p_file->file_base = (char*) file_base;
315
316 return TRUE;
317 }
318
319 /* Routines to manipulate NT executable file sections. */ 287 /* Routines to manipulate NT executable file sections. */
320 288
321 #ifndef DUMP_SEPARATE_SECTION 289 #ifndef DUMP_SEPARATE_SECTION
322 static void 290 static void
323 get_bss_info_from_map_file (file_data *p_infile, PUCHAR *p_bss_start, 291 get_bss_info_from_map_file (file_data *p_infile, PUCHAR *p_bss_start,