Skip to content

Instantly share code, notes, and snippets.

@jappelbe
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jappelbe/b0cfa0ff48e739e4755f to your computer and use it in GitHub Desktop.
Save jappelbe/b0cfa0ff48e739e4755f to your computer and use it in GitHub Desktop.
Add support to read the encryption_info_64 on mach-o
diff -uprN binutils-2.25-clean/bfd/mach-o.c binutils-2.25-only_code_changes/bfd/mach-o.c
--- binutils-2.25-clean/bfd/mach-o.c 2014-11-04 11:54:41.000000000 +0200
+++ binutils-2.25-only_code_changes/bfd/mach-o.c 2015-04-22 16:37:41.971345115 +0300
@@ -4386,6 +4386,23 @@ bfd_mach_o_read_encryption_info (bfd *ab
}
static bfd_boolean
+bfd_mach_o_read_encryption_info_64 (bfd *abfd, bfd_mach_o_load_command *command)
+{
+ bfd_mach_o_encryption_info_command_64 *cmd = &command->command.encryption_info_64;
+ 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 bfd_boolean
bfd_mach_o_read_main (bfd *abfd, bfd_mach_o_load_command *command)
{
bfd_mach_o_main_command *cmd = &command->command.main;
@@ -4637,6 +4654,10 @@ bfd_mach_o_read_command (bfd *abfd, bfd_
if (!bfd_mach_o_read_source_version (abfd, command))
return FALSE;
break;
+ case BFD_MACH_O_LC_ENCRYPTION_INFO_64:
+ if (!bfd_mach_o_read_encryption_info_64 (abfd, command))
+ return FALSE;
+ break;
default:
(*_bfd_error_handler)(_("%B: unknown load command 0x%lx"),
abfd, (unsigned long) command->type);
diff -uprN binutils-2.25-clean/bfd/mach-o.h binutils-2.25-only_code_changes/bfd/mach-o.h
--- binutils-2.25-clean/bfd/mach-o.h 2014-11-04 11:54:41.000000000 +0200
+++ binutils-2.25-only_code_changes/bfd/mach-o.h 2015-04-22 16:37:38.975286608 +0300
@@ -529,6 +529,14 @@ typedef struct bfd_mach_o_encryption_inf
}
bfd_mach_o_encryption_info_command;
+typedef struct bfd_mach_o_encryption_info_command_64
+{
+ unsigned int cryptoff;
+ unsigned int cryptsize;
+ unsigned int cryptid;
+}
+bfd_mach_o_encryption_info_command_64;
+
typedef struct bfd_mach_o_main_command
{
bfd_uint64_t entryoff;
@@ -576,6 +584,7 @@ typedef struct bfd_mach_o_load_command
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_encryption_info_command_64 encryption_info_64;
bfd_mach_o_fvmlib_command fvmlib;
bfd_mach_o_main_command main;
bfd_mach_o_source_version_command source_version;
diff -uprN binutils-2.25-clean/binutils/od-macho.c binutils-2.25-only_code_changes/binutils/od-macho.c
--- binutils-2.25-clean/binutils/od-macho.c 2014-10-14 10:32:02.000000000 +0300
+++ binutils-2.25-only_code_changes/binutils/od-macho.c 2015-04-22 16:36:59.510515917 +0300
@@ -203,6 +203,7 @@ static const bfd_mach_o_xlat_name bfd_ma
{ "data_in_code", BFD_MACH_O_LC_DATA_IN_CODE},
{ "source_version", BFD_MACH_O_LC_SOURCE_VERSION},
{ "dylib_code_sign_drs", BFD_MACH_O_LC_DYLIB_CODE_SIGN_DRS},
+ { "encryption_info_64", BFD_MACH_O_LC_ENCRYPTION_INFO_64},
{ NULL, 0}
};
@@ -1634,6 +1635,17 @@ dump_load_command (bfd *abfd, bfd_mach_o
printf ("\n");
break;
}
+ case BFD_MACH_O_LC_ENCRYPTION_INFO_64:
+ {
+ bfd_mach_o_encryption_info_command_64 *cryp =
+ &cmd->command.encryption_info_64;
+ printf (" cryptoff: 0x%08x cryptsize: 0x%08x (endoff 0x%08x)"
+ " cryptid: %u\n",
+ cryp->cryptoff, cryp->cryptsize,
+ cryp->cryptoff + cryp->cryptsize,
+ cryp->cryptid);
+ }
+ break;
default:
break;
}
diff -uprN binutils-2.25-clean/include/mach-o/loader.h binutils-2.25-only_code_changes/include/mach-o/loader.h
--- binutils-2.25-clean/include/mach-o/loader.h 2014-10-14 10:32:04.000000000 +0300
+++ binutils-2.25-only_code_changes/include/mach-o/loader.h 2015-04-22 16:47:00.270243938 +0300
@@ -176,7 +176,8 @@ typedef enum bfd_mach_o_load_command_typ
BFD_MACH_O_LC_MAIN = 0x28, /* Entry point. */
BFD_MACH_O_LC_DATA_IN_CODE = 0x29, /* Table of non-instructions. */
BFD_MACH_O_LC_SOURCE_VERSION = 0x2a, /* Source version. */
- BFD_MACH_O_LC_DYLIB_CODE_SIGN_DRS = 0x2b /* DRs from dylibs. */
+ BFD_MACH_O_LC_DYLIB_CODE_SIGN_DRS = 0x2b, /* DRs from dylibs. */
+ BFD_MACH_O_LC_ENCRYPTION_INFO_64 = 0x2c /* Encrypted segment info. 64bit */
}
bfd_mach_o_load_command_type;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment