mirror of
https://github.com/SabreTools/BinaryObjectScanner.git
synced 2026-02-10 13:52:16 +00:00
Add and use byte array extension methods
This commit is contained in:
@@ -39,7 +39,7 @@ namespace BurnOutSharp.ExecutableType.Microsoft.Entries
|
||||
{
|
||||
var eate = new ExportAddressTableEntry();
|
||||
|
||||
eate.ExportRVA = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
eate.ExportRVA = content.ReadUInt32(ref offset);
|
||||
eate.ForwarderRVA = eate.ExportRVA;
|
||||
|
||||
return eate;
|
||||
|
||||
@@ -62,7 +62,7 @@ namespace BurnOutSharp.ExecutableType.Microsoft.Entries
|
||||
{
|
||||
var hnte = new HintNameTableEntry();
|
||||
|
||||
hnte.Hint = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
hnte.Hint = content.ReadUInt16(ref offset);
|
||||
hnte.Name = string.Empty;
|
||||
while (true)
|
||||
{
|
||||
|
||||
@@ -70,11 +70,11 @@ namespace BurnOutSharp.ExecutableType.Microsoft.Entries
|
||||
{
|
||||
var iate = new ImportAddressTableEntry();
|
||||
|
||||
iate.ImportLookupTableRVA = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
iate.TimeDateStamp = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
iate.ForwarderChain = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
iate.NameRVA = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
iate.ImportAddressTableRVA = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
iate.ImportLookupTableRVA = content.ReadUInt32(ref offset);
|
||||
iate.TimeDateStamp = content.ReadUInt32(ref offset);
|
||||
iate.ForwarderChain = content.ReadUInt32(ref offset);
|
||||
iate.NameRVA = content.ReadUInt32(ref offset);
|
||||
iate.ImportAddressTableRVA = content.ReadUInt32(ref offset);
|
||||
|
||||
return iate;
|
||||
}
|
||||
|
||||
@@ -70,11 +70,11 @@ namespace BurnOutSharp.ExecutableType.Microsoft.Entries
|
||||
{
|
||||
var idte = new ImportDirectoryTableEntry();
|
||||
|
||||
idte.ImportLookupTableRVA = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
idte.TimeDateStamp = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
idte.ForwarderChain = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
idte.NameRVA = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
idte.ImportAddressTableRVA = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
idte.ImportLookupTableRVA = content.ReadUInt32(ref offset);
|
||||
idte.TimeDateStamp = content.ReadUInt32(ref offset);
|
||||
idte.ForwarderChain = content.ReadUInt32(ref offset);
|
||||
idte.NameRVA = content.ReadUInt32(ref offset);
|
||||
idte.ImportAddressTableRVA = content.ReadUInt32(ref offset);
|
||||
|
||||
return idte;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace BurnOutSharp.ExecutableType.Microsoft.Entries
|
||||
{
|
||||
var rds = new NEResourceNameString();
|
||||
|
||||
rds.Length = content[offset++];
|
||||
rds.Length = content.ReadByte(ref offset);
|
||||
rds.Value = Encoding.ASCII.GetChars(content, offset, rds.Length); offset += rds.Length;
|
||||
|
||||
return rds;
|
||||
|
||||
@@ -63,12 +63,12 @@ namespace BurnOutSharp.ExecutableType.Microsoft.Entries
|
||||
{
|
||||
var ni = new NEResourceTableEntry();
|
||||
|
||||
ni.Offset = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
ni.Length = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
ni.Flags = (ResourceTableEntryFlags)BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
ni.ResourceID = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
ni.Handle = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
ni.Usage = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
ni.Offset = content.ReadUInt16(ref offset);
|
||||
ni.Length = content.ReadUInt16(ref offset);
|
||||
ni.Flags = (ResourceTableEntryFlags)content.ReadUInt16(ref offset);
|
||||
ni.ResourceID = content.ReadUInt16(ref offset);
|
||||
ni.Handle = content.ReadUInt16(ref offset);
|
||||
ni.Usage = content.ReadUInt16(ref offset);
|
||||
|
||||
return ni;
|
||||
}
|
||||
|
||||
@@ -51,10 +51,10 @@ namespace BurnOutSharp.ExecutableType.Microsoft.Entries
|
||||
{
|
||||
var nste = new NESegmentTableEntry();
|
||||
|
||||
nste.StartFileSector = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
nste.BytesInFile = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
nste.Flags = (SegmentTableEntryFlags)BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
nste.MinimumAllocation = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
nste.StartFileSector = content.ReadUInt16(ref offset);
|
||||
nste.BytesInFile = content.ReadUInt16(ref offset);
|
||||
nste.Flags = (SegmentTableEntryFlags)content.ReadUInt16(ref offset);
|
||||
nste.MinimumAllocation = content.ReadUInt16(ref offset);
|
||||
|
||||
return nste;
|
||||
}
|
||||
|
||||
@@ -89,10 +89,10 @@ namespace BurnOutSharp.ExecutableType.Microsoft.Entries
|
||||
{
|
||||
var rde = new ResourceDataEntry();
|
||||
|
||||
rde.OffsetToData = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
rde.Size = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
rde.CodePage = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
rde.Reserved = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
rde.OffsetToData = content.ReadUInt32(ref offset);
|
||||
rde.Size = content.ReadUInt32(ref offset);
|
||||
rde.CodePage = content.ReadUInt32(ref offset);
|
||||
rde.Reserved = content.ReadUInt32(ref offset);
|
||||
|
||||
int realOffsetToData = (int)PortableExecutable.ConvertVirtualAddress(rde.OffsetToData, sections);
|
||||
if (realOffsetToData > -1 && realOffsetToData < content.Length && (int)rde.Size > 0 && realOffsetToData + (int)rde.Size < content.Length)
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace BurnOutSharp.ExecutableType.Microsoft.Entries
|
||||
{
|
||||
var rds = new ResourceDirectoryString();
|
||||
|
||||
rds.Length = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
rds.Length = content.ReadUInt16(ref offset);
|
||||
if (rds.Length + offset > content.Length)
|
||||
return null;
|
||||
|
||||
|
||||
@@ -113,7 +113,7 @@ namespace BurnOutSharp.ExecutableType.Microsoft.Entries
|
||||
{
|
||||
var rdte = new ResourceDirectoryTableEntry();
|
||||
|
||||
rdte.IntegerId = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
rdte.IntegerId = content.ReadUInt32(ref offset);
|
||||
if (!rdte.IsIntegerIDEntry())
|
||||
{
|
||||
int nameAddress = (int)(rdte.NameOffset + sectionStart);
|
||||
@@ -121,7 +121,7 @@ namespace BurnOutSharp.ExecutableType.Microsoft.Entries
|
||||
rdte.Name = ResourceDirectoryString.Deserialize(content, ref nameAddress);
|
||||
}
|
||||
|
||||
rdte.DataEntryOffset = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
rdte.DataEntryOffset = content.ReadUInt32(ref offset);
|
||||
if (rdte.IsResourceDataEntry())
|
||||
{
|
||||
int dataEntryAddress = (int)(rdte.DataEntryOffset + sectionStart);
|
||||
|
||||
@@ -54,9 +54,9 @@ namespace BurnOutSharp.ExecutableType.Microsoft.Entries
|
||||
{
|
||||
var rtib = new ResourceTypeInformationBlock();
|
||||
|
||||
rtib.TypeID = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
rtib.ResourceCount = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
rtib.Reserved = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
rtib.TypeID = content.ReadUInt16(ref offset);
|
||||
rtib.ResourceCount = content.ReadUInt16(ref offset);
|
||||
rtib.Reserved = content.ReadUInt32(ref offset);
|
||||
|
||||
rtib.ResourceTable = new NEResourceTableEntry[rtib.ResourceCount];
|
||||
for (int i = 0; i < rtib.ResourceCount; i++)
|
||||
|
||||
@@ -73,14 +73,14 @@ namespace BurnOutSharp.ExecutableType.Microsoft.Headers
|
||||
{
|
||||
var ifh = new CommonObjectFileFormatHeader();
|
||||
|
||||
ifh.Signature = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ifh.Machine = (MachineType)BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
ifh.NumberOfSections = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
ifh.TimeDateStamp = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ifh.PointerToSymbolTable = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ifh.NumberOfSymbols = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ifh.SizeOfOptionalHeader = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
ifh.Characteristics = (ImageObjectCharacteristics)BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
ifh.Signature = content.ReadUInt32(ref offset);
|
||||
ifh.Machine = (MachineType)content.ReadUInt16(ref offset);
|
||||
ifh.NumberOfSections = content.ReadUInt16(ref offset);
|
||||
ifh.TimeDateStamp = content.ReadUInt32(ref offset);
|
||||
ifh.PointerToSymbolTable = content.ReadUInt32(ref offset);
|
||||
ifh.NumberOfSymbols = content.ReadUInt32(ref offset);
|
||||
ifh.SizeOfOptionalHeader = content.ReadUInt16(ref offset);
|
||||
ifh.Characteristics = (ImageObjectCharacteristics)content.ReadUInt16(ref offset);
|
||||
|
||||
return ifh;
|
||||
}
|
||||
|
||||
@@ -31,8 +31,8 @@ namespace BurnOutSharp.ExecutableType.Microsoft.Headers
|
||||
{
|
||||
var ddh = new DataDirectoryHeader();
|
||||
|
||||
ddh.VirtualAddress = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ddh.Size = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ddh.VirtualAddress = content.ReadUInt32(ref offset);
|
||||
ddh.Size = content.ReadUInt32(ref offset);
|
||||
|
||||
return ddh;
|
||||
}
|
||||
|
||||
@@ -168,20 +168,20 @@ namespace BurnOutSharp.ExecutableType.Microsoft.Headers
|
||||
{
|
||||
MSDOSExecutableHeader idh = new MSDOSExecutableHeader();
|
||||
|
||||
idh.Magic = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
idh.LastPageBytes = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
idh.Pages = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
idh.Relocations = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
idh.HeaderParagraphSize = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
idh.MinimumExtraParagraphs = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
idh.MaximumExtraParagraphs = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
idh.InitialSSValue = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
idh.InitialSPValue = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
idh.Checksum = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
idh.InitialIPValue = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
idh.InitialCSValue = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
idh.RelocationTableAddr = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
idh.OverlayNumber = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
idh.Magic = content.ReadUInt16(ref offset);
|
||||
idh.LastPageBytes = content.ReadUInt16(ref offset);
|
||||
idh.Pages = content.ReadUInt16(ref offset);
|
||||
idh.Relocations = content.ReadUInt16(ref offset);
|
||||
idh.HeaderParagraphSize = content.ReadUInt16(ref offset);
|
||||
idh.MinimumExtraParagraphs = content.ReadUInt16(ref offset);
|
||||
idh.MaximumExtraParagraphs = content.ReadUInt16(ref offset);
|
||||
idh.InitialSSValue = content.ReadUInt16(ref offset);
|
||||
idh.InitialSPValue = content.ReadUInt16(ref offset);
|
||||
idh.Checksum = content.ReadUInt16(ref offset);
|
||||
idh.InitialIPValue = content.ReadUInt16(ref offset);
|
||||
idh.InitialCSValue = content.ReadUInt16(ref offset);
|
||||
idh.RelocationTableAddr = content.ReadUInt16(ref offset);
|
||||
idh.OverlayNumber = content.ReadUInt16(ref offset);
|
||||
|
||||
// If we're not reading as a stub, return now
|
||||
if (!asStub)
|
||||
@@ -190,16 +190,16 @@ namespace BurnOutSharp.ExecutableType.Microsoft.Headers
|
||||
idh.Reserved1 = new ushort[Constants.ERES1WDS];
|
||||
for (int i = 0; i < Constants.ERES1WDS; i++)
|
||||
{
|
||||
idh.Reserved1[i] = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
idh.Reserved1[i] = content.ReadUInt16(ref offset);
|
||||
}
|
||||
idh.OEMIdentifier = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
idh.OEMInformation = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
idh.OEMIdentifier = content.ReadUInt16(ref offset);
|
||||
idh.OEMInformation = content.ReadUInt16(ref offset);
|
||||
idh.Reserved2 = new ushort[Constants.ERES2WDS];
|
||||
for (int i = 0; i < Constants.ERES2WDS; i++)
|
||||
{
|
||||
idh.Reserved2[i] = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
idh.Reserved2[i] = content.ReadUInt16(ref offset);
|
||||
}
|
||||
idh.NewExeHeaderAddr = BitConverter.ToInt32(content, offset); offset += 4;
|
||||
idh.NewExeHeaderAddr = content.ReadInt32(ref offset);
|
||||
|
||||
return idh;
|
||||
}
|
||||
|
||||
@@ -218,38 +218,38 @@ namespace BurnOutSharp.ExecutableType.Microsoft.Headers
|
||||
{
|
||||
var neh = new NewExecutableHeader();
|
||||
|
||||
neh.Magic = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
neh.LinkerVersion = content[offset++];
|
||||
neh.LinkerRevision = content[offset++];
|
||||
neh.EntryTableOffset = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
neh.EntryTableSize = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
neh.CrcChecksum = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
neh.ProgramFlags = content[offset++];
|
||||
neh.ApplicationFlags = content[offset++];
|
||||
neh.Autodata = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
neh.InitialHeapAlloc = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
neh.InitialStackAlloc = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
neh.InitialCSIPSetting = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
neh.InitialSSSPSetting = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
neh.FileSegmentCount = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
neh.ModuleReferenceTableSize = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
neh.NonResidentNameTableSize = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
neh.SegmentTableOffset = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
neh.ResourceTableOffset = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
neh.ResidentNameTableOffset = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
neh.ModuleReferenceTableOffset = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
neh.ImportedNamesTableOffset = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
neh.NonResidentNamesTableOffset = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
neh.MovableEntriesCount = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
neh.SegmentAlignmentShiftCount = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
neh.ResourceEntriesCount = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
neh.TargetOperatingSystem = content[offset++];
|
||||
neh.AdditionalFlags = content[offset++];
|
||||
neh.ReturnThunkOffset = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
neh.SegmentReferenceThunkOffset = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
neh.MinCodeSwapAreaSize = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
neh.WindowsSDKRevision = content[offset++];
|
||||
neh.WindowsSDKVersion = content[offset++];
|
||||
neh.Magic = content.ReadUInt16(ref offset);
|
||||
neh.LinkerVersion = content.ReadByte(ref offset);
|
||||
neh.LinkerRevision = content.ReadByte(ref offset);
|
||||
neh.EntryTableOffset = content.ReadUInt16(ref offset);
|
||||
neh.EntryTableSize = content.ReadUInt16(ref offset);
|
||||
neh.CrcChecksum = content.ReadUInt32(ref offset);
|
||||
neh.ProgramFlags = content.ReadByte(ref offset);
|
||||
neh.ApplicationFlags = content.ReadByte(ref offset);
|
||||
neh.Autodata = content.ReadUInt16(ref offset);
|
||||
neh.InitialHeapAlloc = content.ReadUInt16(ref offset);
|
||||
neh.InitialStackAlloc = content.ReadUInt16(ref offset);
|
||||
neh.InitialCSIPSetting = content.ReadUInt32(ref offset);
|
||||
neh.InitialSSSPSetting = content.ReadUInt32(ref offset);
|
||||
neh.FileSegmentCount = content.ReadUInt16(ref offset);
|
||||
neh.ModuleReferenceTableSize = content.ReadUInt16(ref offset);
|
||||
neh.NonResidentNameTableSize = content.ReadUInt16(ref offset);
|
||||
neh.SegmentTableOffset = content.ReadUInt16(ref offset);
|
||||
neh.ResourceTableOffset = content.ReadUInt16(ref offset);
|
||||
neh.ResidentNameTableOffset = content.ReadUInt16(ref offset);
|
||||
neh.ModuleReferenceTableOffset = content.ReadUInt16(ref offset);
|
||||
neh.ImportedNamesTableOffset = content.ReadUInt16(ref offset);
|
||||
neh.NonResidentNamesTableOffset = content.ReadUInt32(ref offset);
|
||||
neh.MovableEntriesCount = content.ReadUInt16(ref offset);
|
||||
neh.SegmentAlignmentShiftCount = content.ReadUInt16(ref offset);
|
||||
neh.ResourceEntriesCount = content.ReadUInt16(ref offset);
|
||||
neh.TargetOperatingSystem = content.ReadByte(ref offset);
|
||||
neh.AdditionalFlags = content.ReadByte(ref offset);
|
||||
neh.ReturnThunkOffset = content.ReadUInt16(ref offset);
|
||||
neh.SegmentReferenceThunkOffset = content.ReadUInt16(ref offset);
|
||||
neh.MinCodeSwapAreaSize = content.ReadUInt16(ref offset);
|
||||
neh.WindowsSDKRevision = content.ReadByte(ref offset);
|
||||
neh.WindowsSDKVersion = content.ReadByte(ref offset);
|
||||
|
||||
return neh;
|
||||
}
|
||||
|
||||
@@ -302,62 +302,62 @@ namespace BurnOutSharp.ExecutableType.Microsoft.Headers
|
||||
{
|
||||
var ioh = new OptionalHeader();
|
||||
|
||||
ioh.Magic = (OptionalHeaderType)BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
ioh.Magic = (OptionalHeaderType)content.ReadUInt16(ref offset);
|
||||
ioh.MajorLinkerVersion = content[offset]; offset++;
|
||||
ioh.MinorLinkerVersion = content[offset]; offset++;
|
||||
ioh.SizeOfCode = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ioh.SizeOfInitializedData = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ioh.SizeOfUninitializedData = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ioh.AddressOfEntryPoint = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ioh.BaseOfCode = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ioh.SizeOfCode = content.ReadUInt32(ref offset);
|
||||
ioh.SizeOfInitializedData = content.ReadUInt32(ref offset);
|
||||
ioh.SizeOfUninitializedData = content.ReadUInt32(ref offset);
|
||||
ioh.AddressOfEntryPoint = content.ReadUInt32(ref offset);
|
||||
ioh.BaseOfCode = content.ReadUInt32(ref offset);
|
||||
|
||||
// Only standard PE32 has this value
|
||||
if (ioh.Magic == OptionalHeaderType.PE32)
|
||||
ioh.BaseOfData = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ioh.BaseOfData = content.ReadUInt32(ref offset);
|
||||
|
||||
// PE32+ has an 8-bit value here
|
||||
if (ioh.Magic == OptionalHeaderType.PE32Plus)
|
||||
{
|
||||
ioh.ImageBasePE32Plus = BitConverter.ToUInt64(content, offset); offset += 8;
|
||||
ioh.ImageBasePE32Plus = content.ReadUInt64(ref offset);
|
||||
}
|
||||
else
|
||||
{
|
||||
ioh.ImageBasePE32 = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ioh.ImageBasePE32 = content.ReadUInt32(ref offset);
|
||||
}
|
||||
|
||||
ioh.SectionAlignment = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ioh.FileAlignment = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ioh.MajorOperatingSystemVersion = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
ioh.MinorOperatingSystemVersion = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
ioh.MajorImageVersion = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
ioh.MinorImageVersion = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
ioh.MajorSubsystemVersion = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
ioh.MinorSubsystemVersion = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
ioh.Reserved1 = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ioh.SizeOfImage = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ioh.SizeOfHeaders = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ioh.CheckSum = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ioh.Subsystem = (WindowsSubsystem)BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
ioh.DllCharacteristics = (DllCharacteristics)BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
ioh.SectionAlignment = content.ReadUInt32(ref offset);
|
||||
ioh.FileAlignment = content.ReadUInt32(ref offset);
|
||||
ioh.MajorOperatingSystemVersion = content.ReadUInt16(ref offset);
|
||||
ioh.MinorOperatingSystemVersion = content.ReadUInt16(ref offset);
|
||||
ioh.MajorImageVersion = content.ReadUInt16(ref offset);
|
||||
ioh.MinorImageVersion = content.ReadUInt16(ref offset);
|
||||
ioh.MajorSubsystemVersion = content.ReadUInt16(ref offset);
|
||||
ioh.MinorSubsystemVersion = content.ReadUInt16(ref offset);
|
||||
ioh.Reserved1 = content.ReadUInt32(ref offset);
|
||||
ioh.SizeOfImage = content.ReadUInt32(ref offset);
|
||||
ioh.SizeOfHeaders = content.ReadUInt32(ref offset);
|
||||
ioh.CheckSum = content.ReadUInt32(ref offset);
|
||||
ioh.Subsystem = (WindowsSubsystem)content.ReadUInt16(ref offset);
|
||||
ioh.DllCharacteristics = (DllCharacteristics)content.ReadUInt16(ref offset);
|
||||
|
||||
// PE32+ uses 8-byte values
|
||||
if (ioh.Magic == OptionalHeaderType.PE32Plus)
|
||||
{
|
||||
ioh.SizeOfStackReservePE32Plus = BitConverter.ToUInt64(content, offset); offset += 8;
|
||||
ioh.SizeOfStackCommitPE32Plus = BitConverter.ToUInt64(content, offset); offset += 8;
|
||||
ioh.SizeOfHeapReservePE32Plus = BitConverter.ToUInt64(content, offset); offset += 8;
|
||||
ioh.SizeOfHeapCommitPE32Plus = BitConverter.ToUInt64(content, offset); offset += 8;
|
||||
ioh.SizeOfStackReservePE32Plus = content.ReadUInt64(ref offset);
|
||||
ioh.SizeOfStackCommitPE32Plus = content.ReadUInt64(ref offset);
|
||||
ioh.SizeOfHeapReservePE32Plus = content.ReadUInt64(ref offset);
|
||||
ioh.SizeOfHeapCommitPE32Plus = content.ReadUInt64(ref offset);
|
||||
}
|
||||
else
|
||||
{
|
||||
ioh.SizeOfStackReservePE32 = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ioh.SizeOfStackCommitPE32 = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ioh.SizeOfHeapReservePE32 = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ioh.SizeOfHeapCommitPE32 = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ioh.SizeOfStackReservePE32 = content.ReadUInt32(ref offset);
|
||||
ioh.SizeOfStackCommitPE32 = content.ReadUInt32(ref offset);
|
||||
ioh.SizeOfHeapReservePE32 = content.ReadUInt32(ref offset);
|
||||
ioh.SizeOfHeapCommitPE32 = content.ReadUInt32(ref offset);
|
||||
}
|
||||
|
||||
ioh.LoaderFlags = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ioh.NumberOfRvaAndSizes = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ioh.LoaderFlags = content.ReadUInt32(ref offset);
|
||||
ioh.NumberOfRvaAndSizes = content.ReadUInt32(ref offset);
|
||||
ioh.DataDirectories = new DataDirectoryHeader[Constants.IMAGE_NUMBEROF_DIRECTORY_ENTRIES];
|
||||
for (int i = 0; i < Constants.IMAGE_NUMBEROF_DIRECTORY_ENTRIES; i++)
|
||||
{
|
||||
|
||||
@@ -113,15 +113,15 @@ namespace BurnOutSharp.ExecutableType.Microsoft.Headers
|
||||
|
||||
ish.Name = new byte[Constants.IMAGE_SIZEOF_SHORT_NAME];
|
||||
Array.Copy(content, offset, ish.Name, 0, Constants.IMAGE_SIZEOF_SHORT_NAME); offset += Constants.IMAGE_SIZEOF_SHORT_NAME;
|
||||
ish.VirtualSize = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ish.VirtualAddress = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ish.SizeOfRawData = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ish.PointerToRawData = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ish.PointerToRelocations = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ish.PointerToLinenumbers = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ish.NumberOfRelocations = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
ish.NumberOfLinenumbers = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
ish.Characteristics = (SectionCharacteristics)BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ish.VirtualSize = content.ReadUInt32(ref offset);
|
||||
ish.VirtualAddress = content.ReadUInt32(ref offset);
|
||||
ish.SizeOfRawData = content.ReadUInt32(ref offset);
|
||||
ish.PointerToRawData = content.ReadUInt32(ref offset);
|
||||
ish.PointerToRelocations = content.ReadUInt32(ref offset);
|
||||
ish.PointerToLinenumbers = content.ReadUInt32(ref offset);
|
||||
ish.NumberOfRelocations = content.ReadUInt16(ref offset);
|
||||
ish.NumberOfLinenumbers = content.ReadUInt16(ref offset);
|
||||
ish.Characteristics = (SectionCharacteristics)content.ReadUInt32(ref offset);
|
||||
|
||||
return ish;
|
||||
}
|
||||
|
||||
@@ -120,28 +120,27 @@ namespace BurnOutSharp.ExecutableType.Microsoft.Resources
|
||||
|
||||
ushort temp;
|
||||
bool padded = false;
|
||||
while ((temp = BitConverter.ToUInt16(content, offset)) == 0x0000)
|
||||
while ((temp = content.ReadUInt16(ref offset)) == 0x0000)
|
||||
{
|
||||
offset += 2;
|
||||
padded = true;
|
||||
}
|
||||
|
||||
if (padded)
|
||||
offset -= 2;
|
||||
|
||||
ffi.Signature = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ffi.StrucVersion = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ffi.FileVersionMS = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ffi.FileVersionLS = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ffi.ProductVersionMS = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ffi.ProductVersionLS = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ffi.FileFlagsMask = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ffi.FileFlags = (FileInfoFileFlags)BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ffi.FileOS = (FileInfoOS)BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ffi.FileType = (FileInfoFileType)BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ffi.FileSubtype = (FileInfoFileSubtype)BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ffi.FileDateMS = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ffi.FileDateLS = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
ffi.Signature = content.ReadUInt32(ref offset);
|
||||
ffi.StrucVersion = content.ReadUInt32(ref offset);
|
||||
ffi.FileVersionMS = content.ReadUInt32(ref offset);
|
||||
ffi.FileVersionLS = content.ReadUInt32(ref offset);
|
||||
ffi.ProductVersionMS = content.ReadUInt32(ref offset);
|
||||
ffi.ProductVersionLS = content.ReadUInt32(ref offset);
|
||||
ffi.FileFlagsMask = content.ReadUInt32(ref offset);
|
||||
ffi.FileFlags = (FileInfoFileFlags)content.ReadUInt32(ref offset);
|
||||
ffi.FileOS = (FileInfoOS)content.ReadUInt32(ref offset);
|
||||
ffi.FileType = (FileInfoFileType)content.ReadUInt32(ref offset);
|
||||
ffi.FileSubtype = (FileInfoFileSubtype)content.ReadUInt32(ref offset);
|
||||
ffi.FileDateMS = content.ReadUInt32(ref offset);
|
||||
ffi.FileDateLS = content.ReadUInt32(ref offset);
|
||||
|
||||
return ffi;
|
||||
}
|
||||
|
||||
@@ -37,8 +37,8 @@ namespace BurnOutSharp.ExecutableType.Microsoft.Resources
|
||||
{
|
||||
LanguageCodePage lcp = new LanguageCodePage();
|
||||
|
||||
lcp.MicrosoftLanguageIdentifier = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
lcp.IBMCodePageNumber = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
lcp.MicrosoftLanguageIdentifier = content.ReadUInt16(ref offset);
|
||||
lcp.IBMCodePageNumber = content.ReadUInt16(ref offset);
|
||||
|
||||
return lcp;
|
||||
}
|
||||
|
||||
@@ -49,14 +49,11 @@ namespace BurnOutSharp.ExecutableType.Microsoft.Resources
|
||||
{
|
||||
Resource r = new Resource();
|
||||
|
||||
while ((r.Length = BitConverter.ToUInt16(content, offset)) == 0x0000)
|
||||
{
|
||||
offset += 2;
|
||||
}
|
||||
while ((r.Length = content.ReadUInt16(ref offset)) == 0x0000);
|
||||
|
||||
offset += 2;
|
||||
r.ValueLength = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
r.Type = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
r.ValueLength = content.ReadUInt16(ref offset);
|
||||
r.Type = content.ReadUInt16(ref offset);
|
||||
|
||||
List<char> keyChars = new List<char>();
|
||||
while (BitConverter.ToUInt16(content, offset) != 0x0000)
|
||||
|
||||
@@ -94,17 +94,17 @@ namespace BurnOutSharp.ExecutableType.Microsoft.Tables
|
||||
{
|
||||
var edt = new ExportDirectoryTable();
|
||||
|
||||
edt.ExportFlags = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
edt.TimeDateStamp = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
edt.MajorVersion = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
edt.MinorVersion = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
edt.NameRVA = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
edt.OrdinalBase = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
edt.AddressTableEntries = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
edt.NumberOfNamePointers = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
edt.ExportAddressTableRVA = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
edt.NamePointerRVA = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
edt.OrdinalTableRVA = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
edt.ExportFlags = content.ReadUInt32(ref offset);
|
||||
edt.TimeDateStamp = content.ReadUInt32(ref offset);
|
||||
edt.MajorVersion = content.ReadUInt16(ref offset);
|
||||
edt.MinorVersion = content.ReadUInt16(ref offset);
|
||||
edt.NameRVA = content.ReadUInt32(ref offset);
|
||||
edt.OrdinalBase = content.ReadUInt32(ref offset);
|
||||
edt.AddressTableEntries = content.ReadUInt32(ref offset);
|
||||
edt.NumberOfNamePointers = content.ReadUInt32(ref offset);
|
||||
edt.ExportAddressTableRVA = content.ReadUInt32(ref offset);
|
||||
edt.NamePointerRVA = content.ReadUInt32(ref offset);
|
||||
edt.OrdinalTableRVA = content.ReadUInt32(ref offset);
|
||||
|
||||
return edt;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace BurnOutSharp.ExecutableType.Microsoft.Tables
|
||||
enpt.Entries = new uint[count];
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
enpt.Entries[i] = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
enpt.Entries[i] = content.ReadUInt32(ref offset);
|
||||
}
|
||||
|
||||
return enpt;
|
||||
|
||||
@@ -35,7 +35,7 @@ namespace BurnOutSharp.ExecutableType.Microsoft.Tables
|
||||
edt.Entries = new ushort[count];
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
edt.Entries[i] = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
edt.Entries[i] = content.ReadUInt16(ref offset);
|
||||
}
|
||||
|
||||
return edt;
|
||||
|
||||
@@ -68,7 +68,7 @@ namespace BurnOutSharp.ExecutableType.Microsoft.Tables
|
||||
List<ulong> tempEntries = new List<ulong>();
|
||||
while (true)
|
||||
{
|
||||
ulong bitfield = BitConverter.ToUInt64(content, offset); offset += 8;
|
||||
ulong bitfield = content.ReadUInt64(ref offset);
|
||||
tempEntries.Add(bitfield);
|
||||
if (bitfield == 0)
|
||||
break;
|
||||
@@ -82,7 +82,7 @@ namespace BurnOutSharp.ExecutableType.Microsoft.Tables
|
||||
List<uint> tempEntries = new List<uint>();
|
||||
while (true)
|
||||
{
|
||||
uint bitfield = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
uint bitfield = content.ReadUInt32(ref offset);
|
||||
tempEntries.Add(bitfield);
|
||||
if (bitfield == 0)
|
||||
break;
|
||||
|
||||
@@ -71,7 +71,7 @@ namespace BurnOutSharp.ExecutableType.Microsoft.Tables
|
||||
{
|
||||
var nrt = new NEResourceTable();
|
||||
|
||||
nrt.AlignmentShiftCount = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
nrt.AlignmentShiftCount = content.ReadUInt16(ref offset);
|
||||
var typeInformationBlocks = new List<ResourceTypeInformationBlock>();
|
||||
while (true)
|
||||
{
|
||||
|
||||
@@ -93,12 +93,12 @@ namespace BurnOutSharp.ExecutableType.Microsoft.Tables
|
||||
{
|
||||
var rdt = new ResourceDirectoryTable();
|
||||
|
||||
rdt.Characteristics = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
rdt.TimeDateStamp = BitConverter.ToUInt32(content, offset); offset += 4;
|
||||
rdt.MajorVersion = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
rdt.MinorVersion = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
rdt.NumberOfNamedEntries = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
rdt.NumberOfIdEntries = BitConverter.ToUInt16(content, offset); offset += 2;
|
||||
rdt.Characteristics = content.ReadUInt32(ref offset);
|
||||
rdt.TimeDateStamp = content.ReadUInt32(ref offset);
|
||||
rdt.MajorVersion = content.ReadUInt16(ref offset);
|
||||
rdt.MinorVersion = content.ReadUInt16(ref offset);
|
||||
rdt.NumberOfNamedEntries = content.ReadUInt16(ref offset);
|
||||
rdt.NumberOfIdEntries = content.ReadUInt16(ref offset);
|
||||
|
||||
rdt.NamedEntries = new ResourceDirectoryTableEntry[rdt.NumberOfNamedEntries];
|
||||
for (int i = 0; i < rdt.NumberOfNamedEntries; i++)
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using BurnOutSharp.ExecutableType.Microsoft;
|
||||
using BurnOutSharp.Matching;
|
||||
using BurnOutSharp.Tools;
|
||||
|
||||
namespace BurnOutSharp.ProtectionType
|
||||
{
|
||||
@@ -74,21 +75,17 @@ namespace BurnOutSharp.ProtectionType
|
||||
public static string GetVersion(string file, byte[] fileContent, List<int> positions)
|
||||
{
|
||||
int index = positions[0] + 20; // Begin reading after "BoG_ *90.0&!! Yy>" for old SafeDisc
|
||||
int version = BitConverter.ToInt32(fileContent, index);
|
||||
index += 4;
|
||||
int subVersion = BitConverter.ToInt32(fileContent, index);
|
||||
index += 4;
|
||||
int subsubVersion = BitConverter.ToInt32(fileContent, index);
|
||||
int version = fileContent.ReadInt32(ref index);
|
||||
int subVersion = fileContent.ReadInt32(ref index);
|
||||
int subsubVersion = fileContent.ReadInt32(ref index);
|
||||
|
||||
if (version != 0)
|
||||
return $"{version}.{subVersion:00}.{subsubVersion:000}";
|
||||
|
||||
index = positions[0] + 18 + 14; // Begin reading after "BoG_ *90.0&!! Yy>" for newer SafeDisc
|
||||
version = BitConverter.ToInt32(fileContent, index);
|
||||
index += 4;
|
||||
subVersion = BitConverter.ToInt32(fileContent, index);
|
||||
index += 4;
|
||||
subsubVersion = BitConverter.ToInt32(fileContent, index);
|
||||
version = fileContent.ReadInt32(ref index);
|
||||
subVersion = fileContent.ReadInt32(ref index);
|
||||
subsubVersion = fileContent.ReadInt32(ref index);
|
||||
|
||||
if (version == 0)
|
||||
return string.Empty;
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using BurnOutSharp.ExecutableType.Microsoft;
|
||||
using BurnOutSharp.Matching;
|
||||
using BurnOutSharp.Tools;
|
||||
|
||||
namespace BurnOutSharp.ProtectionType
|
||||
{
|
||||
@@ -163,21 +164,17 @@ namespace BurnOutSharp.ProtectionType
|
||||
public static string GetVersion(string file, byte[] fileContent, List<int> positions)
|
||||
{
|
||||
int index = positions[0] + 20; // Begin reading after "BoG_ *90.0&!! Yy>" for old SafeDisc
|
||||
int version = BitConverter.ToInt32(fileContent, index);
|
||||
index += 4;
|
||||
int subVersion = BitConverter.ToInt32(fileContent, index);
|
||||
index += 4;
|
||||
int subsubVersion = BitConverter.ToInt32(fileContent, index);
|
||||
int version = fileContent.ReadInt32(ref index);
|
||||
int subVersion = fileContent.ReadInt32(ref index);
|
||||
int subsubVersion = fileContent.ReadInt32(ref index);
|
||||
|
||||
if (version != 0)
|
||||
return $"{version}.{subVersion:00}.{subsubVersion:000}";
|
||||
|
||||
index = positions[0] + 18 + 14; // Begin reading after "BoG_ *90.0&!! Yy>" for newer SafeDisc
|
||||
version = BitConverter.ToInt32(fileContent, index);
|
||||
index += 4;
|
||||
subVersion = BitConverter.ToInt32(fileContent, index);
|
||||
index += 4;
|
||||
subsubVersion = BitConverter.ToInt32(fileContent, index);
|
||||
version = fileContent.ReadInt32(ref index);
|
||||
subVersion = fileContent.ReadInt32(ref index);
|
||||
subsubVersion = fileContent.ReadInt32(ref index);
|
||||
|
||||
if (version == 0)
|
||||
return string.Empty;
|
||||
|
||||
@@ -9,9 +9,129 @@ namespace BurnOutSharp.Tools
|
||||
{
|
||||
internal static class Extensions
|
||||
{
|
||||
// TODO: Add extensions for BitConverter.ToX(); offset += x;
|
||||
#region Byte Arrays
|
||||
|
||||
/// <summary>
|
||||
/// Read a byte and increment the pointer to an array
|
||||
/// </summary>
|
||||
public static byte ReadByte(this byte[] content, ref int offset)
|
||||
{
|
||||
return content[offset++];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a char and increment the pointer to an array
|
||||
/// </summary>
|
||||
public static char ReadChar(this byte[] content, ref int offset)
|
||||
{
|
||||
return (char)content[offset++];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a character array and increment the pointer to an array
|
||||
/// </summary>
|
||||
public static char[] ReadChars(this byte[] content, ref int offset, int count) => content.ReadChars(ref offset, count, Encoding.Default);
|
||||
|
||||
/// <summary>
|
||||
/// Read a character array and increment the pointer to an array
|
||||
/// </summary>
|
||||
public static char[] ReadChars(this byte[] content, ref int offset, int count, Encoding encoding)
|
||||
{
|
||||
// TODO: Fix the code below to make it work with byte arrays and not streams
|
||||
return null;
|
||||
|
||||
// byte[] buffer = new byte[count];
|
||||
// stream.Read(buffer, 0, count);
|
||||
// return encoding.GetString(buffer).ToCharArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a short and increment the pointer to an array
|
||||
/// </summary>
|
||||
public static short ReadInt16(this byte[] content, ref int offset)
|
||||
{
|
||||
short value = BitConverter.ToInt16(content, offset);
|
||||
offset += 2;
|
||||
return value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a ushort and increment the pointer to an array
|
||||
/// </summary>
|
||||
public static ushort ReadUInt16(this byte[] content, ref int offset)
|
||||
{
|
||||
ushort value = BitConverter.ToUInt16(content, offset);
|
||||
offset += 2;
|
||||
return value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a int and increment the pointer to an array
|
||||
/// </summary>
|
||||
public static int ReadInt32(this byte[] content, ref int offset)
|
||||
{
|
||||
int value = BitConverter.ToInt32(content, offset);
|
||||
offset += 4;
|
||||
return value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a uint and increment the pointer to an array
|
||||
/// </summary>
|
||||
public static uint ReadUInt32(this byte[] content, ref int offset)
|
||||
{
|
||||
uint value = BitConverter.ToUInt32(content, offset);
|
||||
offset += 4;
|
||||
return value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a long and increment the pointer to an array
|
||||
/// </summary>
|
||||
public static long ReadInt64(this byte[] content, ref int offset)
|
||||
{
|
||||
long value = BitConverter.ToInt64(content, offset);
|
||||
offset += 8;
|
||||
return value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a ulong and increment the pointer to an array
|
||||
/// </summary>
|
||||
public static ulong ReadUInt64(this byte[] content, ref int offset)
|
||||
{
|
||||
ulong value = BitConverter.ToUInt64(content, offset);
|
||||
offset += 8;
|
||||
return value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a null-terminated string from the stream
|
||||
/// </summary>
|
||||
public static string ReadString(this byte[] content, ref int offset) => content.ReadString(ref offset, Encoding.Default);
|
||||
|
||||
/// <summary>
|
||||
/// Read a null-terminated string from the stream
|
||||
/// </summary>
|
||||
public static string ReadString(this byte[] content, ref int offset, Encoding encoding)
|
||||
{
|
||||
// TODO: Fix the code below to make it work with byte arrays and not streams
|
||||
return null;
|
||||
|
||||
// byte[] nullTerminator = encoding.GetBytes(new char[] { '\0' });
|
||||
// int charWidth = nullTerminator.Length;
|
||||
|
||||
// List<byte> tempBuffer = new List<byte>();
|
||||
|
||||
// byte[] buffer = new byte[charWidth];
|
||||
// while (stream.Read(buffer, 0, charWidth) != 0 && buffer.SequenceEqual(nullTerminator))
|
||||
// {
|
||||
// tempBuffer.AddRange(buffer);
|
||||
// }
|
||||
|
||||
// return encoding.GetString(tempBuffer.ToArray());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find all positions of one array in another, if possible, if possible
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user