12 /* This should be set in a Makefile somehow */
13 #define TARGET "i686-pc-linux-gnu"
17 static void dump_data(bfd *abfd)
22 bfd_size_type addr_offset;
23 bfd_size_type stop_offset;
24 unsigned int opb = bfd_octets_per_byte(abfd);
27 for (section = abfd->sections; section != NULL; section = section->next) {
28 if (section->flags & SEC_HAS_CONTENTS) {
29 if (bfd_section_size(abfd, section) == 0)
32 /* We only care about sections with "text" or "data" in their names */
33 if ((strstr(section->name, "text") == NULL) &&
34 (strstr(section->name, "data") == NULL))
39 size = bfd_section_size(abfd, section) / opb;
41 printf("Contents of section %s size %lu", section->name, size);
43 data = (bfd_byte *) malloc(size);
45 bfd_get_section_contents(abfd, section, (PTR) data, 0, size);
49 printf(" idata %02x%02x%02x%02x", data[0], data[1], data[2], data[3]);
51 for (addr_offset = 0; addr_offset < stop_offset; ++addr_offset) {
52 cksum += (unsigned int) data[addr_offset];
53 fputc(data[addr_offset], out);
57 printf(" checksum %08x\n", cksum);
62 void set_default_bfd_target(void)
64 const char *target = TARGET;
66 if (!bfd_set_default_target(target))
67 fprintf(stderr, "can't set BFD default target to `%s': %s", target, bfd_errmsg (bfd_get_error ()));
70 int main (int argc, char *argv[])
78 fprintf(stderr, "%s [infile] [outfile]\n", argv[0]);
86 set_default_bfd_target();
89 // file = bfd_openr(in_file, "elf32-i386");
90 file = bfd_openr(in_file, NULL);
92 fprintf(stderr, "error \"%s\" trying to open %s\n", strerror(errno), in_file);
96 out = fopen(out_file, "w");
98 fprintf(stderr, "error \"%s\" trying to create %s\n", strerror(errno), out_file);
102 if (bfd_check_format_matches(file, bfd_object, &matching)) {