| 830 | |
| 831 | |
| 832 | BinaryNinja::Ref<BinaryNinja::BinaryView> KCViewType::Parse(BinaryNinja::BinaryView* data) |
| 833 | { |
| 834 | uint32_t magic; |
| 835 | data->Read(&magic, data->GetStart(), 4); |
| 836 | if (magic != MH_CIGAM_64 && magic != MH_MAGIC_64) // FIXME 32 bit |
| 837 | { |
| 838 | uint32_t im4pMagic; |
| 839 | data->Read(&im4pMagic, data->GetStart() + 0x8, 4); |
| 840 | if (im4pMagic == 0x50344d49) // P4MI |
| 841 | { |
| 842 | auto img4 = Transform::GetByName("IMG4-Unencrypted"); |
| 843 | auto lzfse = Transform::GetByName("LZFSE"); |
| 844 | |
| 845 | DataBuffer img4Payload; |
| 846 | img4->Decode(data->ReadBuffer(data->GetStart(), data->GetLength()), img4Payload); |
| 847 | DataBuffer machOPayload; |
| 848 | lzfse->Decode(img4Payload, machOPayload); |
| 849 | |
| 850 | uint32_t magic = ((uint32_t*)machOPayload.GetData())[0]; |
| 851 | auto id = data->BeginUndoActions(); |
| 852 | if (magic == FAT_MAGIC_64) |
| 853 | { |
| 854 | DataBuffer output = machOPayload.GetSlice(0x1c, machOPayload.GetLength()-0x1c); |
| 855 | data->WriteBuffer(0, output); |
| 856 | } |
| 857 | else |
| 858 | { |
| 859 | data->WriteBuffer(0, machOPayload); |
| 860 | } |
| 861 | data->ForgetUndoActions(id); |
| 862 | return new KCView(KC_VIEW_NAME, data, true); |
| 863 | } |
| 864 | |
| 865 | return nullptr; |
| 866 | } |
| 867 | |
| 868 | return new KCView(KC_VIEW_NAME, data, true); |
| 869 | } |
| 870 | |
| 871 | bool KCViewType::IsTypeValidForData(BinaryNinja::BinaryView* data) |
| 872 | { |
no test coverage detected