Files
libexeinfo/exeinfo/Program.cs

59 lines
1.7 KiB
C#
Raw Normal View History

2017-10-03 13:26:49 +01:00
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace exeinfo
{
class MainClass
{
static MZ.Header mzHdr;
2017-10-03 14:54:11 +01:00
static NE.Header neHdr;
2017-10-03 13:26:49 +01:00
public static void Main(string[] args)
{
if(args.Length != 1)
{
Console.WriteLine("exeinfo version 0.1 © 2017 Natalia Portillo");
Console.WriteLine("Usage: exeinfo file.exe");
return;
}
FileStream exeFs = File.Open(args[0], FileMode.Open, FileAccess.Read);
bool recognized = false;
byte[] buffer = new byte[Marshal.SizeOf(typeof(MZ.Header))];
exeFs.Read(buffer, 0, buffer.Length);
IntPtr hdrPtr = Marshal.AllocHGlobal(buffer.Length);
Marshal.Copy(buffer, 0, hdrPtr, buffer.Length);
mzHdr = (MZ.Header)Marshal.PtrToStructure(hdrPtr, typeof(MZ.Header));
Marshal.FreeHGlobal(hdrPtr);
if(mzHdr.signature == MZ.Signature)
{
recognized = true;
MZ.PrintInfo(mzHdr);
2017-10-03 14:54:11 +01:00
if (mzHdr.new_offset < exeFs.Length)
{
exeFs.Seek(mzHdr.new_offset, SeekOrigin.Begin);
buffer = new byte[Marshal.SizeOf(typeof(NE.Header))];
exeFs.Read(buffer, 0, buffer.Length);
hdrPtr = Marshal.AllocHGlobal(buffer.Length);
Marshal.Copy(buffer, 0, hdrPtr, buffer.Length);
neHdr = (NE.Header)Marshal.PtrToStructure(hdrPtr, typeof(NE.Header));
Marshal.FreeHGlobal(hdrPtr);
if (neHdr.signature == NE.Signature)
NE.PrintInfo(neHdr);
}
2017-10-03 13:26:49 +01:00
}
if (!recognized)
Console.WriteLine("Executalbe format not recognized");
}
}
}