mirror of
https://github.com/sampletext32/ParkanPlayground.git
synced 2025-05-19 11:51:17 +03:00
Separate construction from parsing in PEFormat class
This commit is contained in:
parent
666a592217
commit
61a86f6681
@ -57,7 +57,7 @@ namespace X86Disassembler.PE
|
|||||||
public List<ImportDescriptor> ImportDescriptors { get; private set; }
|
public List<ImportDescriptor> ImportDescriptors { get; private set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Parses a PE file from the given byte array
|
/// Initializes a new instance of the PEFormat class
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fileData">The raw file data</param>
|
/// <param name="fileData">The raw file data</param>
|
||||||
public PEFormat(byte[] fileData)
|
public PEFormat(byte[] fileData)
|
||||||
@ -66,13 +66,15 @@ namespace X86Disassembler.PE
|
|||||||
SectionHeaders = new List<SectionHeader>();
|
SectionHeaders = new List<SectionHeader>();
|
||||||
ExportedFunctions = new List<ExportedFunction>();
|
ExportedFunctions = new List<ExportedFunction>();
|
||||||
ImportDescriptors = new List<ImportDescriptor>();
|
ImportDescriptors = new List<ImportDescriptor>();
|
||||||
Parse();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Parses the PE file structure
|
/// Parses the PE file structure
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void Parse()
|
/// <returns>True if parsing was successful, false otherwise</returns>
|
||||||
|
public bool Parse()
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
using (MemoryStream stream = new MemoryStream(_fileData))
|
using (MemoryStream stream = new MemoryStream(_fileData))
|
||||||
using (BinaryReader reader = new BinaryReader(stream))
|
using (BinaryReader reader = new BinaryReader(stream))
|
||||||
@ -117,6 +119,14 @@ namespace X86Disassembler.PE
|
|||||||
ImportDescriptors = ParseImportDescriptors(reader, OptionalHeader.DataDirectories[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress);
|
ImportDescriptors = ParseImportDescriptors(reader, OptionalHeader.DataDirectories[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Error parsing PE file: {ex.Message}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -22,9 +22,16 @@ namespace X86Disassembler
|
|||||||
Console.WriteLine($"Successfully loaded {DllPath}");
|
Console.WriteLine($"Successfully loaded {DllPath}");
|
||||||
Console.WriteLine($"File size: {binaryData.Length} bytes");
|
Console.WriteLine($"File size: {binaryData.Length} bytes");
|
||||||
|
|
||||||
|
// Create the PE format parser
|
||||||
|
PEFormat peFile = new PEFormat(binaryData);
|
||||||
|
|
||||||
// Parse the PE format
|
// Parse the PE format
|
||||||
Console.WriteLine("\nParsing PE format...");
|
Console.WriteLine("\nParsing PE format...");
|
||||||
PEFormat peFile = new PEFormat(binaryData);
|
if (!peFile.Parse())
|
||||||
|
{
|
||||||
|
Console.WriteLine("Failed to parse PE file. Exiting.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Display basic PE information
|
// Display basic PE information
|
||||||
DisplayPEInfo(peFile);
|
DisplayPEInfo(peFile);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user