]> git.saurik.com Git - ldid.git/blobdiff - ldid.cpp
Add special cases to support old codesign_allocate.
[ldid.git] / ldid.cpp
index 438866d91631a96da033162969f75288793fbf90..20fbd64117decfd49175ca71e4c7304e6662669c 100644 (file)
--- a/ldid.cpp
+++ b/ldid.cpp
@@ -67,6 +67,7 @@ struct mach_header {
 
 #define MH_DYLDLINK   0x4
 
+#define MH_OBJECT     0x1
 #define MH_EXECUTE    0x2
 #define MH_DYLIB      0x6
 #define MH_BUNDLE     0x8
@@ -277,6 +278,22 @@ struct encryption_info_command {
     uint32_t cryptid;
 } _packed;
 
+#define BIND_OPCODE_MASK                             0xf0
+#define BIND_IMMEDIATE_MASK                          0x0f
+#define BIND_OPCODE_DONE                             0x00
+#define BIND_OPCODE_SET_DYLIB_ORDINAL_IMM            0x10
+#define BIND_OPCODE_SET_DYLIB_ORDINAL_ULEB           0x20
+#define BIND_OPCODE_SET_DYLIB_SPECIAL_IMM            0x30
+#define BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM    0x40
+#define BIND_OPCODE_SET_TYPE_IMM                     0x50
+#define BIND_OPCODE_SET_ADDEND_SLEB                  0x60
+#define BIND_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB      0x70
+#define BIND_OPCODE_ADD_ADDR_ULEB                    0x80
+#define BIND_OPCODE_DO_BIND                          0x90
+#define BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB            0xa0
+#define BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED      0xb0
+#define BIND_OPCODE_DO_BIND_ULEB_TIMES_SKIPPING_ULEB 0xc0
+
 uint16_t Swap_(uint16_t value) {
     return
         ((value >>  8) & 0x00ff) |
@@ -929,13 +946,37 @@ int main(int argc, const char *argv[]) {
                 args.push_back(path);
 
                 _foreach (allocation, allocations) {
-                    args.push_back("-A");
+                    if (allocation.type_ == 12 && (
+                        allocation.subtype_ == 0 ||
+                        allocation.subtype_ == 6 ||
+                    false)) {
+                        // Telesphoreo codesign_allocate
+                        args.push_back("-a");
+
+                        const char *arch;
+                        switch (allocation.subtype_) {
+                            case 0:
+                                arch = "arm";
+                                break;
+                            case 6:
+                                arch = "armv6";
+                                break;
+                            default:
+                                arch = NULL;
+                                break;
+                        }
 
-                    asprintf(&arg, "%u", allocation.type_);
-                    args.push_back(arg);
+                        _assert(arch != NULL);
+                        args.push_back(arch);
+                    } else {
+                        args.push_back("-A");
 
-                    asprintf(&arg, "%u", allocation.subtype_);
-                    args.push_back(arg);
+                        asprintf(&arg, "%u", allocation.type_);
+                        args.push_back(arg);
+
+                        asprintf(&arg, "%u", allocation.subtype_);
+                        args.push_back(arg);
+                    }
 
                     size_t alloc(0);
                     alloc += sizeof(struct SuperBlob);
@@ -995,7 +1036,7 @@ int main(int argc, const char *argv[]) {
         if (flag_p)
             printf("path%zu='%s'\n", filei, file.c_str());
 
-        FatHeader fat_header(Map(temp == NULL ? path : temp, !(flag_R | flag_T | flag_s | flag_S | flag_O | flag_D)));
+        FatHeader fat_header(Map(temp == NULL ? path : temp, !(flag_R || flag_T || flag_s || flag_S || flag_O || flag_D)));
         struct linkedit_data_command *signature(NULL);
 
         _foreach (mach_header, fat_header.GetMachHeaders()) {