276 |
|
|
277 |
if (object_name != MACH_PORT_NULL) |
if (object_name != MACH_PORT_NULL) |
278 |
mach_port_deallocate (target_task, object_name); |
mach_port_deallocate (target_task, object_name); |
279 |
|
|
280 |
address += size; |
address += size; |
281 |
} |
} |
282 |
} |
} |
329 |
else |
else |
330 |
{ |
{ |
331 |
r = (struct region_t *) malloc (sizeof (struct region_t)); |
r = (struct region_t *) malloc (sizeof (struct region_t)); |
332 |
|
|
333 |
if (!r) |
if (!r) |
334 |
unexec_error ("cannot allocate region structure"); |
unexec_error ("cannot allocate region structure"); |
335 |
|
|
336 |
r->address = address; |
r->address = address; |
337 |
r->size = size; |
r->size = size; |
338 |
r->protection = info.protection; |
r->protection = info.protection; |
339 |
r->max_protection = info.max_protection; |
r->max_protection = info.max_protection; |
340 |
|
|
341 |
r->next = 0; |
r->next = 0; |
342 |
if (region_list_head == 0) |
if (region_list_head == 0) |
343 |
{ |
{ |
349 |
region_list_tail->next = r; |
region_list_tail->next = r; |
350 |
region_list_tail = r; |
region_list_tail = r; |
351 |
} |
} |
352 |
|
|
353 |
/* Deallocate (unused) object name returned by |
/* Deallocate (unused) object name returned by |
354 |
vm_region. */ |
vm_region. */ |
355 |
if (object_name != MACH_PORT_NULL) |
if (object_name != MACH_PORT_NULL) |
356 |
mach_port_deallocate (target_task, object_name); |
mach_port_deallocate (target_task, object_name); |
357 |
} |
} |
358 |
|
|
359 |
address += size; |
address += size; |
360 |
} |
} |
361 |
|
|
498 |
|
|
499 |
nlc = mh.ncmds; |
nlc = mh.ncmds; |
500 |
lca = (struct load_command **) malloc (nlc * sizeof (struct load_command *)); |
lca = (struct load_command **) malloc (nlc * sizeof (struct load_command *)); |
501 |
|
|
502 |
for (i = 0; i < nlc; i++) |
for (i = 0; i < nlc; i++) |
503 |
{ |
{ |
504 |
struct load_command lc; |
struct load_command lc; |
513 |
if (lc.cmd == LC_SEGMENT) |
if (lc.cmd == LC_SEGMENT) |
514 |
{ |
{ |
515 |
struct segment_command *scp = (struct segment_command *) lca[i]; |
struct segment_command *scp = (struct segment_command *) lca[i]; |
516 |
|
|
517 |
if (scp->vmaddr + scp->vmsize > infile_lc_highest_addr) |
if (scp->vmaddr + scp->vmsize > infile_lc_highest_addr) |
518 |
infile_lc_highest_addr = scp->vmaddr + scp->vmsize; |
infile_lc_highest_addr = scp->vmaddr + scp->vmsize; |
519 |
|
|
647 |
} |
} |
648 |
else |
else |
649 |
unexec_error ("unrecognized section name in __DATA segment"); |
unexec_error ("unrecognized section name in __DATA segment"); |
650 |
|
|
651 |
printf (" section %-16.16s at %#8x - %#8x (sz: %#8x)\n", |
printf (" section %-16.16s at %#8x - %#8x (sz: %#8x)\n", |
652 |
sectp->sectname, sectp->offset, sectp->offset + sectp->size, |
sectp->sectname, sectp->offset, sectp->offset + sectp->size, |
653 |
sectp->size); |
sectp->size); |
675 |
for (j = 0; j < num_unexec_regions; j++) |
for (j = 0; j < num_unexec_regions; j++) |
676 |
{ |
{ |
677 |
struct segment_command sc; |
struct segment_command sc; |
678 |
|
|
679 |
sc.cmd = LC_SEGMENT; |
sc.cmd = LC_SEGMENT; |
680 |
sc.cmdsize = sizeof (struct segment_command); |
sc.cmdsize = sizeof (struct segment_command); |
681 |
strncpy (sc.segname, SEG_DATA, 16); |
strncpy (sc.segname, SEG_DATA, 16); |
687 |
sc.initprot = VM_PROT_READ | VM_PROT_WRITE; |
sc.initprot = VM_PROT_READ | VM_PROT_WRITE; |
688 |
sc.nsects = 0; |
sc.nsects = 0; |
689 |
sc.flags = 0; |
sc.flags = 0; |
690 |
|
|
691 |
printf ("Writing segment %-16.16s at %#8x - %#8x (sz: %#8x)\n", |
printf ("Writing segment %-16.16s at %#8x - %#8x (sz: %#8x)\n", |
692 |
sc.segname, sc.fileoff, sc.fileoff + sc.filesize, |
sc.segname, sc.fileoff, sc.fileoff + sc.filesize, |
693 |
sc.filesize); |
sc.filesize); |
696 |
unexec_error ("cannot write new __DATA segment"); |
unexec_error ("cannot write new __DATA segment"); |
697 |
delta += sc.filesize; |
delta += sc.filesize; |
698 |
file_offset += sc.filesize; |
file_offset += sc.filesize; |
699 |
|
|
700 |
if (!unexec_write (curr_header_offset, &sc, sc.cmdsize)) |
if (!unexec_write (curr_header_offset, &sc, sc.cmdsize)) |
701 |
unexec_error ("cannot write new __DATA segment's header"); |
unexec_error ("cannot write new __DATA segment's header"); |
702 |
curr_header_offset += sc.cmdsize; |
curr_header_offset += sc.cmdsize; |
850 |
{ |
{ |
851 |
unexec_error ("cannot open input file `%s'", infile); |
unexec_error ("cannot open input file `%s'", infile); |
852 |
} |
} |
853 |
|
|
854 |
outfd = open (outfile, O_WRONLY | O_TRUNC | O_CREAT, 0755); |
outfd = open (outfile, O_WRONLY | O_TRUNC | O_CREAT, 0755); |
855 |
if (outfd < 0) |
if (outfd < 0) |
856 |
{ |
{ |