MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / Parse

Method Parse

view/kernelcache/core/KCView.cpp:832–869  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

830
831
832BinaryNinja::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
871bool KCViewType::IsTypeValidForData(BinaryNinja::BinaryView* data)
872{

Callers 1

LoadFromStringMethod · 0.45

Calls 10

GetSliceMethod · 0.80
ReadMethod · 0.45
GetStartMethod · 0.45
DecodeMethod · 0.45
ReadBufferMethod · 0.45
GetLengthMethod · 0.45
GetDataMethod · 0.45
BeginUndoActionsMethod · 0.45
WriteBufferMethod · 0.45
ForgetUndoActionsMethod · 0.45

Tested by

no test coverage detected