Skip to content

Commit

Permalink
Added support CPD struct (11+ me ver)
Browse files Browse the repository at this point in the history
I have nothing to test, so tell me if that shhitt works or not.
  • Loading branch information
kolyandex committed Nov 8, 2018
1 parent 9e8409c commit 3aca0aa
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions MEInject/MEInject/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,23 @@ private MEinfo GetMEFileInfo(Stream stream, string path, uint startoffset = 0, u
handle = GCHandle.Alloc(new BinaryReader(stream).ReadBytes(Marshal.SizeOf(typeof(FptEntry))), GCHandleType.Pinned);
var fptEntry = (FptEntry)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(FptEntry));
handle.Free();

fptEntries.Add(fptEntry);
}

var mn2Manifests = new List<Mn2Manifest>();
foreach (var fptEntry in fptEntries.Where(fptEntry => (fptEntry.Flags & 0x00FF) == 0x80))
//foreach (var fptEntry in fptEntries.Where(fptEntry => (fptEntry.Flags & 0x00FF) == 0x80))
foreach (var fptEntry in fptEntries.Where(fptEntry => (new string(fptEntry.Name) == "FTPR")))
{
stream.Seek(fptEntry.Offset + startoffset, SeekOrigin.Begin);

var o = 0;
if (new string(new BinaryReader(stream).ReadChars(4)) == "$CPD")
{
o = new BinaryReader(stream).ReadByte() * 0x18 + 0x10;
}
stream.Seek(fptEntry.Offset + startoffset + o, SeekOrigin.Begin);

handle = GCHandle.Alloc(new BinaryReader(stream).ReadBytes(Marshal.SizeOf(typeof(Mn2Manifest))), GCHandleType.Pinned);
mn2Manifests.Add((Mn2Manifest)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(Mn2Manifest)));
handle.Free();
Expand Down Expand Up @@ -244,7 +254,7 @@ private void LoadBIOS(string path)
var nr = flmap0 >> 24 & 0x7;
var frba = flmap0 >> 12 & 0xff0;
//var fmba = (flmap1 & 0xff) << 4;
if (nr >= 2)
if (nr >= 2 || true)
{
Log("Intel BIOS image detected! :D", LogLevel.Info);
stream.Seek(frba, SeekOrigin.Begin);
Expand All @@ -268,14 +278,16 @@ private void LoadBIOS(string path)
{
throw new Exception("The ME/TXE region is corrupted or missing");
}


BIOS_ME_info = GetMEFileInfo(stream, path, BIOS_ME_start_offset, BIOS_ME_end_offset);

_mode = BIOS_ME_info.Major < 3 ? Mode.TXE : Mode.ME;
_mode = BIOS_ME_info.Major < 4 ? Mode.TXE : Mode.ME;
UpdateGUI();

Log("BIOS read successful! " + path.SafeFileName(), LogLevel.Info);
Log($"The {_mode} region goes from {BIOS_ME_start_offset:X8} to {BIOS_ME_end_offset:X8}", LogLevel.Info);

UpdateComboBox();

var offset = Find(BIOSfile, MSDM_table_pattern) + MSDM_offset;
Expand All @@ -294,6 +306,9 @@ private void LoadBIOS(string path)
stream.Close();
return;
}

MessageBox.Show(flmap0 + " " + flmap1);

stream.Close();
throw new Exception("Number of partitions in file is less than 2! " + path.SafeFileName());
}
Expand All @@ -317,7 +332,7 @@ private void ExtractButton_Click(object sender, EventArgs e)
};

if (sfd.ShowDialog() != DialogResult.OK) return;

try
{
var me = new byte[BIOS_ME_end_offset - BIOS_ME_start_offset];
Expand Down Expand Up @@ -375,14 +390,14 @@ private void SaveButton_Click(object sender, EventArgs e)
return;
}
MEfile = File.ReadAllBytes(_validMEfiles[MEsComboBox.SelectedIndex]);

for (var i = 0; i < BIOS_ME_end_offset - BIOS_ME_start_offset; i++)
{
if (i < MEfile.Length)
{
BIOSfile[i + BIOS_ME_start_offset] = MEfile[i];
continue;
}
}
BIOSfile[i + BIOS_ME_start_offset] = (byte)0xFF;
}
var sfd = new SaveFileDialog
Expand Down Expand Up @@ -519,7 +534,7 @@ private void MainForm_DragDrop(object sender, DragEventArgs e)
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);

try
{
LoadBIOS(files[0]);
Expand Down

0 comments on commit 3aca0aa

Please sign in to comment.