public void Read(ReadingContext SR) { SectionName = SR.ReadFixedASCII(16); SegmentName = SR.ReadFixedASCII(16); Addr = SR.ReadUInt(AddressSize); Size = SR.ReadUInt(AddressSize); UInt32 FileOffset = SR.ReadUInt32(); LogAlignment = SR.ReadUInt32(); RelocationOffset = SR.ReadUInt32(); NumRelocations = SR.ReadUInt32(); Flags = (int)SR.ReadUInt32(); Reserved1 = SR.ReadUInt32(); Reserved2 = SR.ReadUInt32(); if (AddressSize == Bits.Num._64) Reserved3 = SR.ReadUInt32(); if ((SectionType == S_ZEROFILL) || (SectionType == S_GB_ZEROFILL)) { Debug.Assert(FileOffset == 0); SectionData = null; } else { SR.PushPositionAndJump((long)FileOffset); SectionData = SR.ReadBytes((int)Size); SR.PopPosition(); } if (Config.bCodeSignVerbose) { Console.WriteLine(" v Read Section '{0}' in segment '{1}' with size {2} and offset 0x{3:X} and align {4} and flags {5:X}", SectionName, SegmentName, Size, FileOffset, 1 << (byte)LogAlignment, Flags); } }
protected override void UnpackageData(ReadingContext SR, UInt32 Length) { long StartOfBlob = SR.Position - sizeof(UInt32) * 2; Version = SR.ReadUInt32(); Flags = SR.ReadUInt32(); UInt32 HashOffset = SR.ReadUInt32(); UInt32 IdentifierStringOffset = SR.ReadUInt32(); SpecialSlotCount = SR.ReadUInt32(); CodeSlotCount = SR.ReadUInt32(); MainImageSignatureLimit = SR.ReadUInt32(); BytesPerHash = SR.ReadByte(); HashType = SR.ReadByte(); Spare1 = SR.ReadByte(); LogPageSize = SR.ReadByte(); Spare2 = SR.ReadUInt32(); ScatterCount = SR.ReadUInt32(); // Read the identifier string SR.PushPositionAndJump(StartOfBlob + IdentifierStringOffset); Identifier = SR.ReadASCIIZ(); SR.PopPosition(); // Read the hashes long TotalNumHashes = SpecialSlotCount + CodeSlotCount; Hashes = new byte[TotalNumHashes * BytesPerHash]; SR.PushPositionAndJump(StartOfBlob + HashOffset - BytesPerHash * SpecialSlotCount); for (long i = 0; i < TotalNumHashes; ++i) { byte[] Hash = SR.ReadBytes(BytesPerHash); Array.Copy(Hash, 0, Hashes, i * BytesPerHash, BytesPerHash); } SR.PopPosition(); if (Config.bCodeSignVerbose) { PrintHash("Info:", cdSlotMax - cdInfoSlot); PrintHash("Requirements:", cdSlotMax - cdRequirementsSlot); PrintHash("ResourceDir:", cdSlotMax - cdResourceDirSlot); PrintHash("Application:", cdSlotMax - cdApplicationSlot); PrintHash("Entitlements:", cdSlotMax - cdEntitlementSlot); } }
protected override void UnpackageData(ReadingContext SR, int CommandSize) { base.UnpackageData(SR, CommandSize); SR.PushPositionAndJump(BlobFileOffset); SR.bStreamLittleEndian = false; long SavedPosition = SR.Position; // Parse the blob Payload = AbstractBlob.CreateFromStream(SR) as CodeSigningTableBlob; if (Config.bCodeSignVerbose) { Console.WriteLine(Payload.ToString()); } //SR.VerifyStreamPosition(SavedPosition, BlobFileSize); SR.PopPosition(); SR.bStreamLittleEndian = true; }
/// <summary> /// Reads in a data blob, preserving the stream read pointer (Offset is relative to the start of the underlying stream) /// </summary> AbstractBlob ReadBlob(ReadingContext SR, long Offset) { SR.PushPositionAndJump(Offset); AbstractBlob Result = AbstractBlob.CreateFromStream(SR); SR.PopPosition(); return Result; }