mirror of
https://github.com/claunia/libexeinfo.git
synced 2025-12-16 19:14:24 +00:00
Added support for DOS MZ executables.
This commit is contained in:
40
.gitignore
vendored
Normal file
40
.gitignore
vendored
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
# Autosave files
|
||||||
|
*~
|
||||||
|
|
||||||
|
# build
|
||||||
|
[Oo]bj/
|
||||||
|
[Bb]in/
|
||||||
|
packages/
|
||||||
|
TestResults/
|
||||||
|
|
||||||
|
# globs
|
||||||
|
Makefile.in
|
||||||
|
*.DS_Store
|
||||||
|
*.sln.cache
|
||||||
|
*.suo
|
||||||
|
*.cache
|
||||||
|
*.pidb
|
||||||
|
*.userprefs
|
||||||
|
*.usertasks
|
||||||
|
config.log
|
||||||
|
config.make
|
||||||
|
config.status
|
||||||
|
aclocal.m4
|
||||||
|
install-sh
|
||||||
|
autom4te.cache/
|
||||||
|
*.user
|
||||||
|
*.tar.gz
|
||||||
|
tarballs/
|
||||||
|
test-results/
|
||||||
|
Thumbs.db
|
||||||
|
|
||||||
|
# Mac bundle stuff
|
||||||
|
*.dmg
|
||||||
|
*.app
|
||||||
|
|
||||||
|
# resharper
|
||||||
|
*_Resharper.*
|
||||||
|
*.Resharper
|
||||||
|
|
||||||
|
# dotCover
|
||||||
|
*.dotCover
|
||||||
17
exeinfo.sln
Normal file
17
exeinfo.sln
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio 2012
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "exeinfo", "exeinfo\exeinfo.csproj", "{504F0A15-25DC-42B1-81FE-BA22A8EF24B5}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|x86 = Debug|x86
|
||||||
|
Release|x86 = Release|x86
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{504F0A15-25DC-42B1-81FE-BA22A8EF24B5}.Debug|x86.ActiveCfg = Debug|x86
|
||||||
|
{504F0A15-25DC-42B1-81FE-BA22A8EF24B5}.Debug|x86.Build.0 = Debug|x86
|
||||||
|
{504F0A15-25DC-42B1-81FE-BA22A8EF24B5}.Release|x86.ActiveCfg = Release|x86
|
||||||
|
{504F0A15-25DC-42B1-81FE-BA22A8EF24B5}.Release|x86.Build.0 = Release|x86
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
64
exeinfo/MZ.cs
Normal file
64
exeinfo/MZ.cs
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
using System;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace exeinfo
|
||||||
|
{
|
||||||
|
public static class MZ
|
||||||
|
{
|
||||||
|
public const ushort Signature = 0x5A4D;
|
||||||
|
|
||||||
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||||
|
public struct Header
|
||||||
|
{
|
||||||
|
public ushort signature;
|
||||||
|
public ushort bytes_in_last_block;
|
||||||
|
public ushort blocks_in_file;
|
||||||
|
public ushort num_relocs;
|
||||||
|
public ushort header_paragraphs;
|
||||||
|
public ushort min_extra_paragraphs;
|
||||||
|
public ushort max_extra_paragraphs;
|
||||||
|
public ushort ss;
|
||||||
|
public ushort sp;
|
||||||
|
public ushort checksum;
|
||||||
|
public ushort ip;
|
||||||
|
public ushort cs;
|
||||||
|
public ushort reloc_table_offset;
|
||||||
|
public ushort overlay_number;
|
||||||
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)]
|
||||||
|
public ushort[] reserved;
|
||||||
|
public ushort oem_id;
|
||||||
|
public ushort oem_info;
|
||||||
|
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
|
||||||
|
public ushort[] reserved2;
|
||||||
|
public uint new_offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||||
|
struct RelocationTableEntry
|
||||||
|
{
|
||||||
|
public ushort offset;
|
||||||
|
public ushort segment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void PrintInfo(Header header)
|
||||||
|
{
|
||||||
|
Console.WriteLine("DOS MZ executable:");
|
||||||
|
Console.WriteLine("\tBlocks in file: {0}", header.blocks_in_file);
|
||||||
|
Console.WriteLine("\t{0} bytes used in last block", header.bytes_in_last_block == 0 ? 512 : header.bytes_in_last_block);
|
||||||
|
Console.WriteLine("\t{0} relocations present after the header", header.num_relocs);
|
||||||
|
Console.WriteLine("\t{0} paragraphs in header", header.header_paragraphs);
|
||||||
|
Console.WriteLine("\t{0} paragraphs of additional memory required", header.min_extra_paragraphs);
|
||||||
|
Console.WriteLine("\t{0} paragraphs of additional memory requested", header.max_extra_paragraphs);
|
||||||
|
Console.WriteLine("\tSegment address for SS: {0:X4}h", header.ss);
|
||||||
|
Console.WriteLine("\tInitial value of SP: {0:X4}h", header.sp);
|
||||||
|
Console.WriteLine("\tInitial value of IP: {0:X4}h", header.ip);
|
||||||
|
Console.WriteLine("\tInitial value of CS: {0:X4}h", header.cs);
|
||||||
|
Console.WriteLine("\tOffset to relocation table: {0}", header.reloc_table_offset);
|
||||||
|
Console.WriteLine("\tFile contains {0} overlays", header.overlay_number);
|
||||||
|
Console.WriteLine("\tFile checksum: 0x{0:X4}", header.checksum);
|
||||||
|
Console.WriteLine("\tOEM ID: {0}", header.oem_id);
|
||||||
|
Console.WriteLine("\tOEM information: 0x{0:X4}", header.oem_info);
|
||||||
|
Console.WriteLine("\tOffset to new header: {0}", header.new_offset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
42
exeinfo/Program.cs
Normal file
42
exeinfo/Program.cs
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
|
namespace exeinfo
|
||||||
|
{
|
||||||
|
class MainClass
|
||||||
|
{
|
||||||
|
static MZ.Header mzHdr;
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!recognized)
|
||||||
|
Console.WriteLine("Executalbe format not recognized");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
26
exeinfo/Properties/AssemblyInfo.cs
Normal file
26
exeinfo/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
using System.Reflection;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
|
// Information about this assembly is defined by the following attributes.
|
||||||
|
// Change them to the values specific to your project.
|
||||||
|
|
||||||
|
[assembly: AssemblyTitle("exeinfo")]
|
||||||
|
[assembly: AssemblyDescription("")]
|
||||||
|
[assembly: AssemblyConfiguration("")]
|
||||||
|
[assembly: AssemblyCompany("Claunia.com")]
|
||||||
|
[assembly: AssemblyProduct("")]
|
||||||
|
[assembly: AssemblyCopyright("Copyright © Claunia.com")]
|
||||||
|
[assembly: AssemblyTrademark("")]
|
||||||
|
[assembly: AssemblyCulture("")]
|
||||||
|
|
||||||
|
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
|
||||||
|
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
|
||||||
|
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
|
||||||
|
|
||||||
|
[assembly: AssemblyVersion("1.0.*")]
|
||||||
|
|
||||||
|
// The following attributes are used to specify the signing key for the assembly,
|
||||||
|
// if desired. See the Mono documentation for more information about signing.
|
||||||
|
|
||||||
|
//[assembly: AssemblyDelaySign(false)]
|
||||||
|
//[assembly: AssemblyKeyFile("")]
|
||||||
40
exeinfo/exeinfo.csproj
Normal file
40
exeinfo/exeinfo.csproj
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
<PropertyGroup>
|
||||||
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
|
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
|
||||||
|
<ProjectGuid>{504F0A15-25DC-42B1-81FE-BA22A8EF24B5}</ProjectGuid>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<RootNamespace>exeinfo</RootNamespace>
|
||||||
|
<AssemblyName>exeinfo</AssemblyName>
|
||||||
|
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
|
||||||
|
<DebugSymbols>true</DebugSymbols>
|
||||||
|
<DebugType>full</DebugType>
|
||||||
|
<Optimize>false</Optimize>
|
||||||
|
<OutputPath>bin\Debug</OutputPath>
|
||||||
|
<DefineConstants>DEBUG;</DefineConstants>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
<ExternalConsole>true</ExternalConsole>
|
||||||
|
<PlatformTarget>x86</PlatformTarget>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
|
||||||
|
<Optimize>true</Optimize>
|
||||||
|
<OutputPath>bin\Release</OutputPath>
|
||||||
|
<ErrorReport>prompt</ErrorReport>
|
||||||
|
<WarningLevel>4</WarningLevel>
|
||||||
|
<ExternalConsole>true</ExternalConsole>
|
||||||
|
<PlatformTarget>x86</PlatformTarget>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="System" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="Program.cs" />
|
||||||
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="MZ.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
|
</Project>
|
||||||
Reference in New Issue
Block a user