This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[darwin/committed]: Decode fvmlib


Hi,

just for analyzing legacy mach-o binary, I added the decoding for FVM libs.

Committed on trunk.

Tristan.

bfd/
2012-01-04  Tristan Gingold  <gingold@adacore.com>

	* mach-o.h (bfd_mach_o_fvmlib_command): New structure.
	(bfd_mach_o_load_command): Add fvmlib field.

	* mach-o.c (bfd_mach_o_read_fvmlib): New function.
	(bfd_mach_o_read_command): Handle fvmlib.

binutils/
2012-01-04  Tristan Gingold  <gingold@adacore.com>

	* od-macho.c (dump_load_command): Handle fvmlib.

include/mach-o/
2012-01-04  Tristan Gingold  <gingold@adacore.com>

	* external.h (mach_o_fvmlib_command_external): New structure.

Index: bfd/mach-o.c
===================================================================
RCS file: /cvs/src/src/bfd/mach-o.c,v
retrieving revision 1.88
diff -c -r1.88 mach-o.c
*** bfd/mach-o.c	4 Jan 2012 10:25:14 -0000	1.88
--- bfd/mach-o.c	4 Jan 2012 10:29:30 -0000
***************
*** 3045,3050 ****
--- 3045,3076 ----
  }
  
  static int
+ bfd_mach_o_read_fvmlib (bfd *abfd, bfd_mach_o_load_command *command)
+ {
+   bfd_mach_o_fvmlib_command *fvm = &command->command.fvmlib;
+   struct mach_o_fvmlib_command_external raw;
+   unsigned int nameoff;
+ 
+   if (bfd_seek (abfd, command->offset + BFD_MACH_O_LC_SIZE, SEEK_SET) != 0
+       || bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
+     return -1;
+ 
+   nameoff = bfd_h_get_32 (abfd, raw.name);
+   fvm->minor_version = bfd_h_get_32 (abfd, raw.minor_version);
+   fvm->header_addr = bfd_h_get_32 (abfd, raw.header_addr);
+ 
+   fvm->name_offset = command->offset + nameoff;
+   fvm->name_len = command->len - nameoff;
+   fvm->name_str = bfd_alloc (abfd, fvm->name_len);
+   if (fvm->name_str == NULL)
+     return -1;
+   if (bfd_seek (abfd, fvm->name_offset, SEEK_SET) != 0
+       || bfd_bread (fvm->name_str, fvm->name_len, abfd) != fvm->name_len)
+     return -1;
+   return 0;
+ }
+ 
+ static int
  bfd_mach_o_read_thread (bfd *abfd, bfd_mach_o_load_command *command)
  {
    bfd_mach_o_data_struct *mdata = bfd_mach_o_get_data (abfd);
***************
*** 3618,3623 ****
--- 3644,3652 ----
        break;
      case BFD_MACH_O_LC_LOADFVMLIB:
      case BFD_MACH_O_LC_IDFVMLIB:
+       if (bfd_mach_o_read_fvmlib (abfd, command) != 0)
+ 	return -1;
+       break;
      case BFD_MACH_O_LC_IDENT:
      case BFD_MACH_O_LC_FVMFILE:
      case BFD_MACH_O_LC_PREPAGE:
Index: bfd/mach-o.h
===================================================================
RCS file: /cvs/src/src/bfd/mach-o.h,v
retrieving revision 1.39
diff -c -r1.39 mach-o.h
*** bfd/mach-o.h	4 Jan 2012 09:58:54 -0000	1.39
--- bfd/mach-o.h	4 Jan 2012 10:29:30 -0000
***************
*** 450,455 ****
--- 450,465 ----
  }
  bfd_mach_o_str_command;
  
+ typedef struct bfd_mach_o_fvmlib_command
+ {
+   unsigned int name_offset;
+   unsigned int name_len;
+   char *name_str;
+   unsigned int minor_version;
+   unsigned int header_addr;
+ }
+ bfd_mach_o_fvmlib_command;
+ 
  typedef struct bfd_mach_o_dyld_info_command
  {
    /* File offset and size to rebase info.  */
***************
*** 512,517 ****
--- 522,528 ----
      bfd_mach_o_dyld_info_command dyld_info;
      bfd_mach_o_version_min_command version_min;
      bfd_mach_o_encryption_info_command encryption_info;
+     bfd_mach_o_fvmlib_command fvmlib;
    }
    command;
  }
Index: binutils/od-macho.c
===================================================================
RCS file: /cvs/src/src/binutils/od-macho.c,v
retrieving revision 1.3
diff -c -r1.3 od-macho.c
*** binutils/od-macho.c	4 Jan 2012 09:58:55 -0000	1.3
--- binutils/od-macho.c	4 Jan 2012 10:29:31 -0000
***************
*** 896,903 ****
                  dylib->current_version);
          printf ("  comptibility version: 0x%08lx\n",
                  dylib->compatibility_version);
-         break;
        }
      case BFD_MACH_O_LC_LOAD_DYLINKER:
      case BFD_MACH_O_LC_ID_DYLINKER:
        printf (" %s\n", cmd->command.dylinker.name_str);
--- 896,903 ----
                  dylib->current_version);
          printf ("  comptibility version: 0x%08lx\n",
                  dylib->compatibility_version);
        }
+       break;
      case BFD_MACH_O_LC_LOAD_DYLINKER:
      case BFD_MACH_O_LC_ID_DYLINKER:
        printf (" %s\n", cmd->command.dylinker.name_str);
***************
*** 920,925 ****
--- 920,934 ----
        putchar ('\n');
        dump_dysymtab (abfd, cmd, verbose);
        break;
+     case BFD_MACH_O_LC_LOADFVMLIB:
+     case BFD_MACH_O_LC_IDFVMLIB:
+       {
+         bfd_mach_o_fvmlib_command *fvmlib = &cmd->command.fvmlib;
+         printf (" %s\n", fvmlib->name_str);
+         printf ("         minor version: 0x%08x\n", fvmlib->minor_version);
+         printf ("        header address: 0x%08x\n", fvmlib->header_addr);
+       }
+       break;
      case BFD_MACH_O_LC_CODE_SIGNATURE:
      case BFD_MACH_O_LC_SEGMENT_SPLIT_INFO:
      case BFD_MACH_O_LC_FUNCTION_STARTS:
Index: include/mach-o/external.h
===================================================================
RCS file: /cvs/src/src/include/mach-o/external.h,v
retrieving revision 1.3
diff -c -r1.3 external.h
*** include/mach-o/external.h	4 Jan 2012 09:58:55 -0000	1.3
--- include/mach-o/external.h	4 Jan 2012 10:29:34 -0000
***************
*** 262,267 ****
--- 262,274 ----
    unsigned char cryptid[4];	/* Encryption method.  */
  };
  
+ struct mach_o_fvmlib_command_external
+ {
+   unsigned char name[4];	/* Offset of the name.  */
+   unsigned char minor_version[4];
+   unsigned char header_addr[4];
+ };
+ 
  struct mach_o_fat_header_external
  {
    unsigned char magic[4];


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]