X-Git-Url: https://git.saurik.com/ldid.git/blobdiff_plain/1a982df59e2831119a352833d91e45aee31727ea..9b4ef9a50c9de548ddb65bdc8d157d4b8155b9e7:/ldid.cpp
diff --git a/ldid.cpp b/ldid.cpp
index 6250a7d..f561fa6 100644
--- a/ldid.cpp
+++ b/ldid.cpp
@@ -2,18 +2,19 @@
* Copyright (C) 2007-2012 Jay Freeman (saurik)
*/
-/* GNU Lesser General Public License, Version 3 {{{ */
-/* This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
+/* GNU Affero General Public License, Version 3 {{{ */
+/*
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
- *
+
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
+ * GNU Affero General Public License for more details.
+
+ * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see .
**/
/* }}} */
@@ -66,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
@@ -276,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) |
@@ -819,6 +837,13 @@ int main(int argc, const char *argv[]) {
uint32_t clip(0); {
FatHeader fat_header(Map(path));
_foreach (mach_header, fat_header.GetMachHeaders()) {
+ if (flag_A) {
+ if (mach_header.GetCPUType() != flag_CPUType)
+ continue;
+ if (mach_header.GetCPUSubtype() != flag_CPUSubtype)
+ continue;
+ }
+
mach_header->flags = mach_header.Swap(mach_header.Swap(mach_header->flags) | MH_DYLDLINK);
uint32_t size(_not(uint32_t)); {
@@ -865,8 +890,8 @@ int main(int argc, const char *argv[]) {
}
}
- _assert(clip != 0);
- _syscall(truncate(path, clip));
+ if (clip != 0)
+ _syscall(truncate(path, clip));
}
if (flag_S) {
@@ -878,6 +903,13 @@ int main(int argc, const char *argv[]) {
std::vector allocations; {
FatHeader fat_header(Map(path));
_foreach (mach_header, fat_header.GetMachHeaders()) {
+ if (flag_A) {
+ if (mach_header.GetCPUType() != flag_CPUType)
+ continue;
+ if (mach_header.GetCPUSubtype() != flag_CPUSubtype)
+ continue;
+ }
+
mach_header->flags = mach_header.Swap(mach_header.Swap(mach_header->flags) | MH_DYLDLINK);
size_t size(_not(size_t)); {
@@ -899,6 +931,8 @@ int main(int argc, const char *argv[]) {
}
}
+ if (!allocations.empty()) {
+
pid_t pid = fork();
_syscall(pid);
if (pid == 0) {
@@ -971,12 +1005,14 @@ int main(int argc, const char *argv[]) {
_syscall(waitpid(pid, &status, 0));
_assert(WIFEXITED(status));
_assert(WEXITSTATUS(status) == 0);
+
+ }
}
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()) {