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]

[committed] Darwin: decode LC_ENCRYPTION_INFO


Hi,

with this patch, LC_ENCRYPTION_INFO are now read by the mach-o backend, and could be displayed by objdump.

Committed on trunk.

Tristan.

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

	* mach-o.h: Reindent header.
	(bfd_mach_o_encryption_info_command): New structure.
	(bfd_mach_o_load_command): Add encryption_info field.

	* mach-o.c (bfd_mach_o_read_encryption_info): New function.
	(bfd_mach_o_read_command): Handle BFD_MACH_O_LC_ENCRYPTION_INFO.
	(bfd_mach_o_read_command): Adjust error message.

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

	* od-macho.c: Update copyright year.
	(dump_load_command): Handle BFD_MACH_O_LC_ENCRYPTION_INFO.

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

	* external.h: Update copyright year.
	(mach_o_symtab_command_external): Add comments.
	(mach_o_encryption_info_command_external): New structure.

Index: bfd/mach-o.c
===================================================================
RCS file: /cvs/src/src/bfd/mach-o.c,v
retrieving revision 1.85
diff -c -r1.85 mach-o.c
*** bfd/mach-o.c	4 Jan 2012 08:44:04 -0000	1.85
--- bfd/mach-o.c	4 Jan 2012 09:56:39 -0000
***************
*** 3411,3416 ****
--- 3411,3432 ----
    return TRUE;
  }
  
+ static bfd_boolean
+ bfd_mach_o_read_encryption_info (bfd *abfd, bfd_mach_o_load_command *command)
+ {
+   bfd_mach_o_encryption_info_command *cmd = &command->command.encryption_info;
+   struct mach_o_encryption_info_command_external raw;
+ 
+   if (bfd_seek (abfd, command->offset + BFD_MACH_O_LC_SIZE, SEEK_SET) != 0
+       || bfd_bread (&raw, sizeof (raw), abfd) != sizeof (raw))
+     return FALSE;
+ 
+   cmd->cryptoff = bfd_get_32 (abfd, raw.cryptoff);
+   cmd->cryptsize = bfd_get_32 (abfd, raw.cryptsize);
+   cmd->cryptid = bfd_get_32 (abfd, raw.cryptid);
+   return TRUE;
+ }
+ 
  static int
  bfd_mach_o_read_segment (bfd *abfd,
                           bfd_mach_o_load_command *command,
***************
*** 3587,3592 ****
--- 3603,3612 ----
        if (bfd_mach_o_read_linkedit (abfd, command) != 0)
  	return -1;
        break;
+     case BFD_MACH_O_LC_ENCRYPTION_INFO:
+       if (!bfd_mach_o_read_encryption_info (abfd, command))
+ 	return -1;
+       break;
      case BFD_MACH_O_LC_DYLD_INFO:
        if (bfd_mach_o_read_dyld_info (abfd, command) != 0)
  	return -1;
***************
*** 3597,3603 ****
  	return -1;
        break;
      default:
!       (*_bfd_error_handler)(_("%B: unable to read unknown load command 0x%lx"),
           abfd, (unsigned long) command->type);
        break;
      }
--- 3617,3623 ----
  	return -1;
        break;
      default:
!       (*_bfd_error_handler)(_("%B: unknown load command 0x%lx"),
           abfd, (unsigned long) command->type);
        break;
      }
Index: bfd/mach-o.h
===================================================================
RCS file: /cvs/src/src/bfd/mach-o.h,v
retrieving revision 1.38
diff -c -r1.38 mach-o.h
*** bfd/mach-o.h	4 Jan 2012 08:44:04 -0000	1.38
--- bfd/mach-o.h	4 Jan 2012 09:56:39 -0000
***************
*** 1,6 ****
  /* Mach-O support for BFD.
     Copyright 1999, 2000, 2001, 2002, 2003, 2005, 2007, 2008, 2009, 2011,
!    2012 Free Software Foundation, Inc.
  
     This file is part of BFD, the Binary File Descriptor library.
  
--- 1,7 ----
  /* Mach-O support for BFD.
     Copyright 1999, 2000, 2001, 2002, 2003, 2005, 2007, 2008, 2009, 2011,
!    2012
!    Free Software Foundation, Inc.
  
     This file is part of BFD, the Binary File Descriptor library.
  
***************
*** 482,487 ****
--- 483,496 ----
  }
  bfd_mach_o_version_min_command;
  
+ typedef struct bfd_mach_o_encryption_info_command
+ {
+   unsigned int cryptoff;
+   unsigned int cryptsize;
+   unsigned int cryptid;
+ }
+ bfd_mach_o_encryption_info_command;
+ 
  typedef struct bfd_mach_o_load_command
  {
    bfd_mach_o_load_command_type type;
***************
*** 502,507 ****
--- 511,517 ----
      bfd_mach_o_str_command str;
      bfd_mach_o_dyld_info_command dyld_info;
      bfd_mach_o_version_min_command version_min;
+     bfd_mach_o_encryption_info_command encryption_info;
    }
    command;
  }
Index: binutils/od-macho.c
===================================================================
RCS file: /cvs/src/src/binutils/od-macho.c,v
retrieving revision 1.2
diff -c -r1.2 od-macho.c
*** binutils/od-macho.c	16 Dec 2011 10:23:01 -0000	1.2
--- binutils/od-macho.c	4 Jan 2012 09:56:40 -0000
***************
*** 1,5 ****
  /* od-macho.c -- dump information about an Mach-O object file.
!    Copyright 2011 Free Software Foundation, Inc.
     Written by Tristan Gingold, Adacore.
  
     This file is part of GNU Binutils.
--- 1,5 ----
  /* od-macho.c -- dump information about an Mach-O object file.
!    Copyright 2011, 2012 Free Software Foundation, Inc.
     Written by Tristan Gingold, Adacore.
  
     This file is part of GNU Binutils.
***************
*** 949,954 ****
--- 949,967 ----
      case BFD_MACH_O_LC_UNIXTHREAD:
        dump_thread (abfd, cmd);
        break;
+     case BFD_MACH_O_LC_ENCRYPTION_INFO:
+       {
+         bfd_mach_o_encryption_info_command *cryp =
+           &cmd->command.encryption_info;
+         printf
+           ("\n"
+            "  cryptoff: 0x%08x  cryptsize: 0x%08x (endoff 0x%08x)"
+            " cryptid: %u\n",
+            cryp->cryptoff, cryp->cryptsize,
+            cryp->cryptoff + cryp->cryptsize,
+            cryp->cryptid);
+       }
+       break;
      case BFD_MACH_O_LC_DYLD_INFO:
        putchar ('\n');
        dump_dyld_info (abfd, cmd);
ndex: include/mach-o/external.h
===================================================================
RCS file: /cvs/src/src/include/mach-o/external.h,v
retrieving revision 1.2
diff -c -r1.2 external.h
*** include/mach-o/external.h	8 Aug 2011 10:21:02 -0000	1.2
--- include/mach-o/external.h	4 Jan 2012 09:56:40 -0000
***************
*** 1,5 ****
  /* Mach-O support for BFD.
!    Copyright 2011
     Free Software Foundation, Inc.
  
     This file is part of BFD, the Binary File Descriptor library.
--- 1,5 ----
  /* Mach-O support for BFD.
!    Copyright 2011, 2012
     Free Software Foundation, Inc.
  
     This file is part of BFD, the Binary File Descriptor library.
***************
*** 118,127 ****
  
  struct mach_o_symtab_command_external
  {
!   unsigned char symoff[4];
!   unsigned char nsyms[4];
!   unsigned char stroff[4];
!   unsigned char strsize[4];
  };
  
  struct mach_o_nlist_external
--- 118,127 ----
  
  struct mach_o_symtab_command_external
  {
!   unsigned char symoff[4];	/* File offset of the symbol table.  */
!   unsigned char nsyms[4];	/* Number of symbols.  */
!   unsigned char stroff[4];	/* File offset of the string table.  */
!   unsigned char strsize[4];	/* String table size.  */
  };
  
  struct mach_o_nlist_external
***************
*** 255,260 ****
--- 255,267 ----
    unsigned char reserved[4];
  };
  
+ struct mach_o_encryption_info_command_external
+ {
+   unsigned char cryptoff[4];	/* File offset of the encrypted area.  */
+   unsigned char cryptsize[4];	/* Size of the encrypted area.  */
+   unsigned char cryptid[4];	/* Encryption method.  */
+ };
+ 
  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]