OLD | NEW |
1 /* simple-object-mach-o.c -- routines to manipulate Mach-O object files. | 1 /* simple-object-mach-o.c -- routines to manipulate Mach-O object files. |
2 Copyright 2010, 2011 Free Software Foundation, Inc. | 2 Copyright 2010, 2011, 2013 Free Software Foundation, Inc. |
3 Written by Ian Lance Taylor, Google. | 3 Written by Ian Lance Taylor, Google. |
4 | 4 |
5 This program is free software; you can redistribute it and/or modify it | 5 This program is free software; you can redistribute it and/or modify it |
6 under the terms of the GNU General Public License as published by the | 6 under the terms of the GNU General Public License as published by the |
7 Free Software Foundation; either version 2, or (at your option) any | 7 Free Software Foundation; either version 2, or (at your option) any |
8 later version. | 8 later version. |
9 | 9 |
10 This program is distributed in the hope that it will be useful, | 10 This program is distributed in the hope that it will be useful, |
11 but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 unsigned int nametab_index; | 425 unsigned int nametab_index; |
426 unsigned int sections_index; | 426 unsigned int sections_index; |
427 char *strtab; | 427 char *strtab; |
428 char *nametab; | 428 char *nametab; |
429 unsigned char *index; | 429 unsigned char *index; |
430 size_t strtab_size; | 430 size_t strtab_size; |
431 size_t nametab_size; | 431 size_t nametab_size; |
432 size_t index_size; | 432 size_t index_size; |
433 unsigned int n_wrapped_sects; | 433 unsigned int n_wrapped_sects; |
434 size_t wrapper_sect_size; | 434 size_t wrapper_sect_size; |
435 off_t wrapper_sect_offset; | 435 off_t wrapper_sect_offset = 0; |
436 | 436 |
437 fetch_32 = (omr->is_big_endian | 437 fetch_32 = (omr->is_big_endian |
438 ? simple_object_fetch_big_32 | 438 ? simple_object_fetch_big_32 |
439 : simple_object_fetch_little_32); | 439 : simple_object_fetch_little_32); |
440 | 440 |
441 is_32 = omr->magic == MACH_O_MH_MAGIC; | 441 is_32 = omr->magic == MACH_O_MH_MAGIC; |
442 | 442 |
443 if (is_32) | 443 if (is_32) |
444 { | 444 { |
445 seghdrsize = sizeof (struct mach_o_segment_command_32); | 445 seghdrsize = sizeof (struct mach_o_segment_command_32); |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
694 | 694 |
695 name = strtab + stringoffset; | 695 name = strtab + stringoffset; |
696 } | 696 } |
697 } | 697 } |
698 } | 698 } |
699 else | 699 else |
700 { | 700 { |
701 /* Otherwise, make a name like __segment,__section as per the | 701 /* Otherwise, make a name like __segment,__section as per the |
702 convention in mach-o asm. */ | 702 convention in mach-o asm. */ |
703 name = &namebuf[0]; | 703 name = &namebuf[0]; |
704 memset (namebuf, 0, MACH_O_NAME_LEN * 2 + 2); | |
705 memcpy (namebuf, (char *) sechdr + segname_offset, MACH_O_NAME_LEN); | 704 memcpy (namebuf, (char *) sechdr + segname_offset, MACH_O_NAME_LEN); |
| 705 namebuf[MACH_O_NAME_LEN] = '\0'; |
706 l = strlen (namebuf); | 706 l = strlen (namebuf); |
707 namebuf[l] = ','; | 707 namebuf[l] = ','; |
708 memcpy (namebuf + l + 1, (char *) sechdr + sectname_offset, | 708 memcpy (namebuf + l + 1, (char *) sechdr + sectname_offset, |
709 MACH_O_NAME_LEN); | 709 MACH_O_NAME_LEN); |
| 710 namebuf[l + 1 + MACH_O_NAME_LEN] = '\0'; |
710 } | 711 } |
711 | 712 |
712 simple_object_mach_o_section_info (omr->is_big_endian, is_32, sechdr, | 713 simple_object_mach_o_section_info (omr->is_big_endian, is_32, sechdr, |
713 &secoffset, &secsize); | 714 &secoffset, &secsize); |
714 | 715 |
715 if (!(*pfn) (data, name, secoffset, secsize)) | 716 if (!(*pfn) (data, name, secoffset, secsize)) |
716 { | 717 { |
717 *errmsg = NULL; | 718 *errmsg = NULL; |
718 *err = 0; | 719 *err = 0; |
719 XDELETEVEC (index); | 720 XDELETEVEC (index); |
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1368 simple_object_mach_o_match, | 1369 simple_object_mach_o_match, |
1369 simple_object_mach_o_find_sections, | 1370 simple_object_mach_o_find_sections, |
1370 simple_object_mach_o_fetch_attributes, | 1371 simple_object_mach_o_fetch_attributes, |
1371 simple_object_mach_o_release_read, | 1372 simple_object_mach_o_release_read, |
1372 simple_object_mach_o_attributes_merge, | 1373 simple_object_mach_o_attributes_merge, |
1373 simple_object_mach_o_release_attributes, | 1374 simple_object_mach_o_release_attributes, |
1374 simple_object_mach_o_start_write, | 1375 simple_object_mach_o_start_write, |
1375 simple_object_mach_o_write_to_file, | 1376 simple_object_mach_o_write_to_file, |
1376 simple_object_mach_o_release_write | 1377 simple_object_mach_o_release_write |
1377 }; | 1378 }; |
OLD | NEW |