From 6e1a740e7505a6455ca8d595eead0c69e822a0c4 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Fri, 13 Nov 2015 00:14:42 -0800 Subject: Remove a number of now-ancient MachHeader helpers. --- ldid.cpp | 115 ++------------------------------------------------------------- 1 file changed, 2 insertions(+), 113 deletions(-) diff --git a/ldid.cpp b/ldid.cpp index 461433f..c0fde4c 100644 --- a/ldid.cpp +++ b/ldid.cpp @@ -542,9 +542,6 @@ static inline int64_t Swap(int64_t value) { return Swap(static_cast(value)); } -template -class Pointer; - class Swapped { protected: bool swapped_; @@ -669,85 +666,9 @@ class MachHeader : return load_commands; } - std::vector GetSegments(const char *segment_name) const { - std::vector segment_commands; - - _foreach (load_command, GetLoadCommands()) { - if (Swap(load_command->cmd) == LC_SEGMENT) { - segment_command *segment_command = reinterpret_cast(load_command); - if (strncmp(segment_command->segname, segment_name, 16) == 0) - segment_commands.push_back(segment_command); - } - } - - return segment_commands; - } - - std::vector GetSegments64(const char *segment_name) const { - std::vector segment_commands; - - _foreach (load_command, GetLoadCommands()) { - if (Swap(load_command->cmd) == LC_SEGMENT_64) { - segment_command_64 *segment_command = reinterpret_cast(load_command); - if (strncmp(segment_command->segname, segment_name, 16) == 0) - segment_commands.push_back(segment_command); - } - } - - return segment_commands; - } - - std::vector
GetSections(const char *segment_name, const char *section_name) const { - std::vector
sections; - - _foreach (segment, GetSegments(segment_name)) { - section *section = (struct section *) (segment + 1); - - uint32_t sect; - for (sect = 0; sect != Swap(segment->nsects); ++sect) { - if (strncmp(section->sectname, section_name, 16) == 0) - sections.push_back(section); - ++section; - } - } - - return sections; - } - - template - Pointer GetPointer(uint32_t address, const char *segment_name = NULL) const { - load_command *load_command = (struct load_command *) (mach_header_ + 1); - uint32_t cmd; - - for (cmd = 0; cmd != Swap(mach_header_->ncmds); ++cmd) { - if (Swap(load_command->cmd) == LC_SEGMENT) { - segment_command *segment_command = (struct segment_command *) load_command; - if (segment_name != NULL && strncmp(segment_command->segname, segment_name, 16) != 0) - goto next_command; - - section *sections = (struct section *) (segment_command + 1); - - uint32_t sect; - for (sect = 0; sect != Swap(segment_command->nsects); ++sect) { - section *section = §ions[sect]; - //printf("%s %u %p %p %u\n", segment_command->segname, sect, address, section->addr, section->size); - if (address >= Swap(section->addr) && address < Swap(section->addr) + Swap(section->size)) { - //printf("0x%.8x %s\n", address, segment_command->segname); - return Pointer(this, reinterpret_cast(address - Swap(section->addr) + Swap(section->offset) + (char *) mach_header_)); - } - } - } - - next_command: - load_command = (struct load_command *) ((char *) load_command + Swap(load_command->cmdsize)); - } - - return Pointer(this); - } - template - Pointer GetOffset(uint32_t offset) { - return Pointer(this, reinterpret_cast(offset + (uint8_t *) mach_header_)); + Target_ *GetOffset(uint32_t offset) const { + return reinterpret_cast(offset + (uint8_t *) mach_header_); } }; @@ -818,38 +739,6 @@ class FatHeader : } }; -template -class Pointer { - private: - const MachHeader *framework_; - const Target_ *pointer_; - - public: - Pointer(const MachHeader *framework = NULL, const Target_ *pointer = NULL) : - framework_(framework), - pointer_(pointer) - { - } - - operator const Target_ *() const { - return pointer_; - } - - const Target_ *operator ->() const { - return pointer_; - } - - Pointer &operator ++() { - ++pointer_; - return *this; - } - - template - Value_ Swap(Value_ value) { - return framework_->Swap(value); - } -}; - #define CSMAGIC_REQUIREMENT uint32_t(0xfade0c00) #define CSMAGIC_REQUIREMENTS uint32_t(0xfade0c01) #define CSMAGIC_CODEDIRECTORY uint32_t(0xfade0c02) -- cgit v1.2.3-56-ge451