| 7 | using namespace BinaryNinja; |
| 8 | |
| 9 | std::vector<uint64_t> SharedCacheMachOHeader::ReadFunctionTable(VirtualMemory& vm) const |
| 10 | { |
| 11 | // NOTE: The funcoff is relative to the file of the linkedit segment. |
| 12 | uint64_t funcStartsAddress = GetLinkEditFileBase() + functionStarts.funcoff; |
| 13 | auto funcStarts = vm.ReadBuffer(funcStartsAddress, functionStarts.funcsize); |
| 14 | uint64_t curfunc = textBase; |
| 15 | uint64_t curOffset = 0; |
| 16 | |
| 17 | std::vector<uint64_t> functionTable = {}; |
| 18 | auto current = static_cast<const uint8_t*>(funcStarts.GetData()); |
| 19 | auto end = current + funcStarts.GetLength(); |
| 20 | while (current != end) |
| 21 | { |
| 22 | curOffset = readLEB128(current, end); |
| 23 | // TODO: Verify this is the correct behavior. |
| 24 | // Skip unmapped functions. |
| 25 | if (curOffset == 0 || !vm.IsAddressMapped(curfunc)) |
| 26 | continue; |
| 27 | curfunc += curOffset; |
| 28 | uint64_t target = curfunc; |
| 29 | functionTable.push_back(target); |
| 30 | } |
| 31 | return functionTable; |
| 32 | } |
| 33 | |
| 34 | std::optional<SharedCacheMachOHeader> SharedCacheMachOHeader::ParseHeaderForAddress( |
| 35 | std::shared_ptr<VirtualMemory> vm, uint64_t address, const std::string& imagePath) |
no test coverage detected