aboutsummaryrefslogtreecommitdiffstats
path: root/nt/addsection.c
diff options
context:
space:
mode:
authorEli Zaretskii2005-06-10 12:55:36 +0000
committerEli Zaretskii2005-06-10 12:55:36 +0000
commitd2fcf7697dc75ecdacfc2d6e58185f75aaa3294b (patch)
treea0c59bfe2f7c72999fa7e10bb6b2d4423955e8b4 /nt/addsection.c
parent7bdd8beba6ae2debc950d824b55db09bd2325a56 (diff)
downloademacs-d2fcf7697dc75ecdacfc2d6e58185f75aaa3294b.tar.gz
emacs-d2fcf7697dc75ecdacfc2d6e58185f75aaa3294b.zip
(copy_executable_and_add_section): Pass non-zero
`verbose' arg to COPY_CHUNK only if DEBUG_DUMP is defined in the environment. Print section names with %.8s. (COPY_CHUNK): New 4th arg `verbose'; print diagnostic messages only if non-zero. All callers changed.
Diffstat (limited to 'nt/addsection.c')
-rw-r--r--nt/addsection.c29
1 files changed, 18 insertions, 11 deletions
diff --git a/nt/addsection.c b/nt/addsection.c
index ae44c7f943c..4b2c8d1cd6e 100644
--- a/nt/addsection.c
+++ b/nt/addsection.c
@@ -283,15 +283,19 @@ copy_executable_and_add_section (file_data *p_infile,
283 PIMAGE_SECTION_HEADER dst_section; 283 PIMAGE_SECTION_HEADER dst_section;
284 DWORD offset; 284 DWORD offset;
285 int i; 285 int i;
286 int be_verbose = GetEnvironmentVariable ("DEBUG_DUMP", NULL, 0) > 0;
286 287
287#define COPY_CHUNK(message, src, size) \ 288#define COPY_CHUNK(message, src, size, verbose) \
288 do { \ 289 do { \
289 unsigned char *s = (void *)(src); \ 290 unsigned char *s = (void *)(src); \
290 unsigned long count = (size); \ 291 unsigned long count = (size); \
291 printf ("%s\n", (message)); \ 292 if (verbose) \
292 printf ("\t0x%08x Offset in input file.\n", s - p_infile->file_base); \ 293 { \
293 printf ("\t0x%08x Offset in output file.\n", dst - p_outfile->file_base); \ 294 printf ("%s\n", (message)); \
294 printf ("\t0x%08x Size in bytes.\n", count); \ 295 printf ("\t0x%08x Offset in input file.\n", s - p_infile->file_base); \
296 printf ("\t0x%08x Offset in output file.\n", dst - p_outfile->file_base); \
297 printf ("\t0x%08x Size in bytes.\n", count); \
298 } \
295 memcpy (dst, s, count); \ 299 memcpy (dst, s, count); \
296 dst += count; \ 300 dst += count; \
297 } while (0) 301 } while (0)
@@ -321,13 +325,14 @@ copy_executable_and_add_section (file_data *p_infile,
321 dst = (unsigned char *) p_outfile->file_base; 325 dst = (unsigned char *) p_outfile->file_base;
322 326
323 COPY_CHUNK ("Copying DOS header...", dos_header, 327 COPY_CHUNK ("Copying DOS header...", dos_header,
324 (DWORD) nt_header - (DWORD) dos_header); 328 (DWORD) nt_header - (DWORD) dos_header, be_verbose);
325 dst_nt_header = (PIMAGE_NT_HEADERS) dst; 329 dst_nt_header = (PIMAGE_NT_HEADERS) dst;
326 COPY_CHUNK ("Copying NT header...", nt_header, 330 COPY_CHUNK ("Copying NT header...", nt_header,
327 (DWORD) section - (DWORD) nt_header); 331 (DWORD) section - (DWORD) nt_header, be_verbose);
328 dst_section = (PIMAGE_SECTION_HEADER) dst; 332 dst_section = (PIMAGE_SECTION_HEADER) dst;
329 COPY_CHUNK ("Copying section table...", section, 333 COPY_CHUNK ("Copying section table...", section,
330 nt_header->FileHeader.NumberOfSections * sizeof (*section)); 334 nt_header->FileHeader.NumberOfSections * sizeof (*section),
335 be_verbose);
331 336
332 /* To improve the efficiency of demand loading, make the file 337 /* To improve the efficiency of demand loading, make the file
333 alignment match the section alignment (VC++ 6.0 does this by 338 alignment match the section alignment (VC++ 6.0 does this by
@@ -351,7 +356,9 @@ copy_executable_and_add_section (file_data *p_infile,
351 for (i = 0; i < nt_header->FileHeader.NumberOfSections; i++) 356 for (i = 0; i < nt_header->FileHeader.NumberOfSections; i++)
352 { 357 {
353 char msg[100]; 358 char msg[100];
354 sprintf (msg, "Copying raw data for %s...", section->Name); 359 /* Windows section names are fixed 8-char strings, only
360 zero-terminated if the name is shorter than 8 characters. */
361 sprintf (msg, "Copying raw data for %.8s...", section->Name);
355 362
356 /* Update the file-relative offset for this section's raw data (if 363 /* Update the file-relative offset for this section's raw data (if
357 it has any) in case things have been relocated; we will update 364 it has any) in case things have been relocated; we will update
@@ -362,7 +369,7 @@ copy_executable_and_add_section (file_data *p_infile,
362 /* Can always copy the original raw data. */ 369 /* Can always copy the original raw data. */
363 COPY_CHUNK 370 COPY_CHUNK
364 (msg, OFFSET_TO_PTR (section->PointerToRawData, p_infile), 371 (msg, OFFSET_TO_PTR (section->PointerToRawData, p_infile),
365 section->SizeOfRawData); 372 section->SizeOfRawData, be_verbose);
366 373
367 /* Round up the raw data size to the new alignment. */ 374 /* Round up the raw data size to the new alignment. */
368 dst_section->SizeOfRawData = 375 dst_section->SizeOfRawData =
@@ -402,7 +409,7 @@ copy_executable_and_add_section (file_data *p_infile,
402 COPY_CHUNK 409 COPY_CHUNK
403 ("Copying remainder of executable...", 410 ("Copying remainder of executable...",
404 OFFSET_TO_PTR (offset, p_infile), 411 OFFSET_TO_PTR (offset, p_infile),
405 p_infile->size - offset); 412 p_infile->size - offset, be_verbose);
406 413
407 /* Final size for new image. */ 414 /* Final size for new image. */
408 p_outfile->size = DST_TO_OFFSET (); 415 p_outfile->size = DST_TO_OFFSET ();