Initial Commit
This commit is contained in:
commit
3ae6eae9e3
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
.vs
|
||||
x64
|
||||
x86
|
||||
*/x64
|
||||
*/x86
|
||||
*.ipch
|
||||
31
collabdbg.sln
Normal file
31
collabdbg.sln
Normal file
@ -0,0 +1,31 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.14.36717.8 d17.14
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "collabdbg", "collabdbg\collabdbg.vcxproj", "{87BBF3DB-CC1E-48B4-9E32-9842FB6CE595}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|x64 = Debug|x64
|
||||
Debug|x86 = Debug|x86
|
||||
Release|x64 = Release|x64
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{87BBF3DB-CC1E-48B4-9E32-9842FB6CE595}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{87BBF3DB-CC1E-48B4-9E32-9842FB6CE595}.Debug|x64.Build.0 = Debug|x64
|
||||
{87BBF3DB-CC1E-48B4-9E32-9842FB6CE595}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{87BBF3DB-CC1E-48B4-9E32-9842FB6CE595}.Debug|x86.Build.0 = Debug|Win32
|
||||
{87BBF3DB-CC1E-48B4-9E32-9842FB6CE595}.Release|x64.ActiveCfg = Release|x64
|
||||
{87BBF3DB-CC1E-48B4-9E32-9842FB6CE595}.Release|x64.Build.0 = Release|x64
|
||||
{87BBF3DB-CC1E-48B4-9E32-9842FB6CE595}.Release|x86.ActiveCfg = Release|Win32
|
||||
{87BBF3DB-CC1E-48B4-9E32-9842FB6CE595}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {C1FBA06C-003D-41BF-8633-90A39BBFC210}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
139
collabdbg/collabdbg.vcxproj
Normal file
139
collabdbg/collabdbg.vcxproj
Normal file
@ -0,0 +1,139 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>17.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{87bbf3db-cc1e-48b4-9e32-9842fb6ce595}</ProjectGuid>
|
||||
<RootNamespace>collabdbg</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v143</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="Shared">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||
<LanguageStandard_C>stdclatest</LanguageStandard_C>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<LanguageStandard>stdcpplatest</LanguageStandard>
|
||||
<LanguageStandard_C>stdclatest</LanguageStandard_C>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp" />
|
||||
<ClCompile Include="collabdbg_PortableExecutable.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="collabdbg_PortableExecutable.h" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
30
collabdbg/collabdbg.vcxproj.filters
Normal file
30
collabdbg/collabdbg.vcxproj.filters
Normal file
@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Resource Files">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="main.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="collabdbg_PortableExecutable.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="collabdbg_PortableExecutable.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
4
collabdbg/collabdbg.vcxproj.user
Normal file
4
collabdbg/collabdbg.vcxproj.user
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup />
|
||||
</Project>
|
||||
44
collabdbg/collabdbg_PortableExecutable.cpp
Normal file
44
collabdbg/collabdbg_PortableExecutable.cpp
Normal file
@ -0,0 +1,44 @@
|
||||
#include "collabdbg_PortableExecutable.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
collabdbg::Microsoft::PortableExecutable::PortableExecutable()
|
||||
{
|
||||
}
|
||||
|
||||
collabdbg::Microsoft::PortableExecutable::PortableExecutable(std::string path)
|
||||
{
|
||||
LoadFrom(path);
|
||||
}
|
||||
|
||||
void collabdbg::Microsoft::PortableExecutable::LoadFrom(std::string path)
|
||||
{
|
||||
|
||||
std::ifstream fileHandle(path);
|
||||
std::stringstream fileContentHandle; fileContentHandle << fileHandle.rdbuf();
|
||||
std::string fileContent = fileContentHandle.str();
|
||||
fileHandle.close(); // close file asap
|
||||
|
||||
if (fileContent.size() <= 256) {
|
||||
throw std::logic_error("File is too small to possibly be an executable of this type.");
|
||||
}
|
||||
|
||||
std::memcpy(&dosHeader, fileContent.data(), sizeof(DOSHeader));
|
||||
|
||||
if (dosHeader.magic[0] != 'M' || dosHeader.magic[1] != 'Z') {
|
||||
throw std::logic_error("This executable lacks a DOS header.");
|
||||
}
|
||||
|
||||
if (fileContent.size() - sizeof(COFFHeader) < dosHeader.coffHeaderPointer) {
|
||||
throw std::out_of_range("This executable's COFF header cannot possibly exist in the file.");
|
||||
}
|
||||
|
||||
std::memcpy(&coffHeader, fileContent.data() + dosHeader.coffHeaderPointer - 1, sizeof(COFFHeader));
|
||||
|
||||
}
|
||||
|
||||
collabdbg::Microsoft::PortableExecutable::~PortableExecutable()
|
||||
{
|
||||
}
|
||||
101
collabdbg/collabdbg_PortableExecutable.h
Normal file
101
collabdbg/collabdbg_PortableExecutable.h
Normal file
@ -0,0 +1,101 @@
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
|
||||
namespace collabdbg {
|
||||
namespace Microsoft {
|
||||
|
||||
struct DOSHeader {
|
||||
char magic[2];
|
||||
unsigned short extraPageSize;
|
||||
unsigned short pageCount;
|
||||
unsigned short relocations;
|
||||
unsigned short headerSizeInParagraphs;
|
||||
unsigned short minimumAllocatedParagraphs;
|
||||
unsigned short maximumAllocatedParagraphs;
|
||||
unsigned short initialSSValue;
|
||||
unsigned short initialRelativeSPValue;
|
||||
unsigned short checksum;
|
||||
unsigned short initialRelativeIPValue;
|
||||
unsigned short initialCSValue;
|
||||
unsigned short relocationsTablePointer;
|
||||
unsigned short overlayNumber;
|
||||
unsigned short reservedWords[4];
|
||||
unsigned short oemIdentifier;
|
||||
unsigned short oemInformation;
|
||||
unsigned short otherReservedWords[10];
|
||||
unsigned coffHeaderPointer;
|
||||
|
||||
};
|
||||
|
||||
|
||||
enum ExeArchType : short {
|
||||
EXE_ARCH_UNKNOWN = 0x0000,
|
||||
EXE_ARCH_ALPHAAXP_OLD = 0x0183,
|
||||
EXE_ARCH_ALPHAAXP = 0x0184,
|
||||
EXE_ARCH_ALPHAAXP_64 = 0x0284,
|
||||
EXE_ARCH_AM33 = 0x01D3,
|
||||
EXE_ARCH_AMD64 = 0x8664,
|
||||
EXE_ARCH_ARM = 0x01C0,
|
||||
EXE_ARCH_ARM64 = 0xAA64,
|
||||
EXE_ARCH_ARMNT = 0x01C4,
|
||||
EXE_ARCH_CLR_PURE_MSIL = 0xC0EE,
|
||||
EXE_ARCH_EBC = 0x0EBC,
|
||||
EXE_ARCH_I386 = 0x014C,
|
||||
EXE_ARCH_I860 = 0x014D,
|
||||
EXE_ARCH_IA64 = 0x0200,
|
||||
EXE_ARCH_LOONGARCH_32 = 0x6232,
|
||||
EXE_ARCH_LOONGARCH_64 = 0x6264,
|
||||
EXE_ARCH_M32R = 0x9041,
|
||||
EXE_ARCH_MIPS_16 = 0x0266,
|
||||
EXE_ARCH_MIPS_FPU = 0x0366,
|
||||
EXE_ARCH_MIPS_FPU_16 = 0x0466,
|
||||
EXE_ARCH_MOTOROLA_68000 = 0x0268,
|
||||
EXE_ARCH_POWERPC = 0x01F0,
|
||||
EXE_ARCH_POWERPC_FP = 0x01F1,
|
||||
EXE_ARCH_POWERPC_64 = 0x01F2,
|
||||
EXE_ARCH_R3000 = 0x0162,
|
||||
EXE_ARCH_R4000 = 0x0166,
|
||||
EXE_ARCH_R10000 = 0x0168,
|
||||
EXE_ARCH_RISCV_32 = 0x5032,
|
||||
EXE_ARCH_RISCV_64 = 0x5064,
|
||||
EXE_ARCH_RISCV_128 = 0x5128,
|
||||
EXE_ARCH_SH3 = 0x01A2,
|
||||
EXE_ARCH_SH3DSP = 0x01A3,
|
||||
EXE_ARCH_SH4 = 0x01A6,
|
||||
EXE_ARCH_SH5 = 0x01A8,
|
||||
EXE_ARCH_THUMB = 0x01C2,
|
||||
EXE_ARCH_WCE_MIPS_V2 = 0x0169
|
||||
};
|
||||
|
||||
enum ExePeFormat : short {
|
||||
EXE_FORMAT_ROM = 0x0107,
|
||||
EXE_FORMAT_PE32 = 0x010B,
|
||||
EXE_FORMAT_PE32_PLUS = 0x020B
|
||||
};
|
||||
|
||||
struct COFFHeader {
|
||||
char magic[4];
|
||||
ExeArchType architecture;
|
||||
unsigned short sectionCount;
|
||||
unsigned timedatestamp;
|
||||
unsigned pointerToSymbolTable;
|
||||
unsigned symbolTableCount;
|
||||
unsigned short optionalHeaderSize;
|
||||
unsigned short characteristics;
|
||||
|
||||
};
|
||||
|
||||
class PortableExecutable {
|
||||
DOSHeader dosHeader;
|
||||
COFFHeader coffHeader;
|
||||
public:
|
||||
PortableExecutable();
|
||||
PortableExecutable(std::string path); // constructor shortcut to LoadFrom(path);
|
||||
void LoadFrom(std::string path);
|
||||
DOSHeader getDOSHeader() { return dosHeader; };
|
||||
COFFHeader getCOFFHeader() { return coffHeader; };
|
||||
~PortableExecutable();
|
||||
};
|
||||
}
|
||||
}
|
||||
29
collabdbg/main.cpp
Normal file
29
collabdbg/main.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
#include <iostream>
|
||||
#include <print>
|
||||
#include "collabdbg_PortableExecutable.h"
|
||||
|
||||
|
||||
int main() {
|
||||
|
||||
collabdbg::Microsoft::PortableExecutable pe;
|
||||
|
||||
try{
|
||||
pe.LoadFrom("C:\\Windows\\write.exe");
|
||||
}
|
||||
catch (std::logic_error e) {
|
||||
std::println("LOGIC : {}", e.what());
|
||||
}
|
||||
catch (std::out_of_range e) {
|
||||
std::println("OUT OF RANGE : {}", e.what());
|
||||
}
|
||||
catch (std::exception& e) {
|
||||
std::println("GENERIC : {}", e.what());
|
||||
}
|
||||
catch (...) {
|
||||
std::println("UNKNOWN EXCEPTION TYPE! FATAL!");
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
std::print("{}", pe.getCOFFHeader().architecture == collabdbg::Microsoft::EXE_ARCH_AMD64 ? "AMD64 Executable" : "Not the expected arch");
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user