Attempted to add debug symbols to UIX build

This commit is contained in:
Yoshi Askharoun
2021-11-01 10:39:19 -05:00
parent c6801a08ab
commit a47242afac
7 changed files with 147 additions and 8 deletions
+20
View File
@@ -47,6 +47,26 @@
<AssemblyOriginatorKeyFile>
</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
<Reference Include="Accessibility" />
<Reference Include="System" />
+47 -5
View File
@@ -1,4 +1,9 @@
using dnlib.DotNet;
using dnlib.DotNet.Pdb;
using dnlib.DotNet.Writer;
using dnlib.IO;
using dnlib.PE;
using System;
using System.IO;
namespace UIXSign
@@ -8,17 +13,54 @@ namespace UIXSign
static void Main(string[] args)
{
string dll = args[0];
string outputName = args.Length >= 2 ? args[1] : "UIX_signed.dll";
string outputDir = Path.GetDirectoryName(dll);
string dllCopy = Path.Combine(outputDir, "UIX_signed.dll");
string dllCopy = Path.Combine(outputDir, outputName);
File.Copy(dll, dllCopy, true);
Console.WriteLine("Created working copy");
var module = ModuleDefMD.Load(dllCopy);
// Load DLL
using var module = ModuleDefMD.Load(dllCopy);
var asm = module.Assembly;
asm.PublicKey = new PublicKey("00240000048000009400000006020000002400005253413100040000010001001dc70401884cdfad2010ce192e1f08a30fb034cf504759943eec3359d4ed09af3ce1616dbb124e479617ec73e4162903766e7a5e7bf1984bb318040118fe0f69dfb8b6e5c7c47a0e1bc9a8984b22f7221cc235986c09c74cab38ea3562c18adb8e3a95b73faf1ed71d7c309058b86d951af2165eb215b47de335e360a6a25da7");
asm.Write(dll);
var writeOptions = new ModuleWriterOptions(module);
Console.WriteLine("Loaded copy");
module.Dispose();
if (module.Metadata.PEImage.ImageDebugDirectories.Count > 0)
Console.WriteLine(module.Metadata.PEImage.ImageDebugDirectories[0]);
Console.WriteLine("Original public key: " + asm.PublicKey.ToString());
// 'Sign' the library so it can be loaded by unmodified Zune executables
asm.PublicKey = new PublicKey("00240000048000009400000006020000002400005253413100040000010001001dc70401884cdfad2010ce192e1f08a30fb034cf504759943eec3359d4ed09af3ce1616dbb124e479617ec73e4162903766e7a5e7bf1984bb318040118fe0f69dfb8b6e5c7c47a0e1bc9a8984b22f7221cc235986c09c74cab38ea3562c18adb8e3a95b73faf1ed71d7c309058b86d951af2165eb215b47de335e360a6a25da7");
module.IsStrongNameSigned = true;
Console.WriteLine("Signed assembly");
if (module.Metadata.PEImage.ImageDebugDirectories.Count > 0)
Console.WriteLine(module.Metadata.PEImage.ImageDebugDirectories[0]);
// Set up PDB to enable debugging
if (module.Metadata.PEImage.ImageDebugDirectories.Count <= 0)
module.CreatePdbState(PdbFileKind.WindowsPDB);
using FileStream pdbFile = File.OpenRead(Path.ChangeExtension(dll, "pdb"));
writeOptions.WritePdb = true;
writeOptions.PdbOptions = PdbWriterOptions.PdbChecksum;
writeOptions.PdbFileName = Path.GetFileName(pdbFile.Name);
writeOptions.PdbFileNameInDebugDirectory = Path.GetFileName(pdbFile.Name);
//writeOptions.PdbFileNameInDebugDirectory = Path.ChangeExtension(Path.GetFileName(dll), ".dn2.pdb");
//module.CreatePdbState(PdbFileKind.EmbeddedPortablePDB);
//var pdbBytes = File.ReadAllBytes(Path.ChangeExtension(dll, "pdb"));
//var pdbStream = DataStreamFactory.Create(pdbBytes);
//var pdbReader = ByteArrayDataReaderFactory.CreateReader(pdbBytes);
//module.Metadata.PEImage.ImageDebugDirectories.Add(new ImageDebugDirectory(ref pdbReader, true));
Console.WriteLine("Loaded PDB");
if (module.Metadata.PEImage.ImageDebugDirectories.Count > 0)
Console.WriteLine(module.Metadata.PEImage.ImageDebugDirectories[0]);
// Replace the raw build with the modded DLL
module.Write(dll, writeOptions);
File.Delete(dllCopy);
Console.WriteLine("DLL modded:");
Console.WriteLine(dll);
}
}
}
+23 -2
View File
@@ -12,6 +12,7 @@
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
@@ -32,9 +33,29 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>latest</LangVersion>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>latest</LangVersion>
<ErrorReport>prompt</ErrorReport>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="dnlib, Version=3.3.2.0, Culture=neutral, PublicKeyToken=50e96378b6e77999, processorArchitecture=MSIL">
<HintPath>..\packages\dnlib.3.3.2\lib\net45\dnlib.dll</HintPath>
<Reference Include="dnlib, Version=3.3.4.0, Culture=neutral, PublicKeyToken=50e96378b6e77999, processorArchitecture=MSIL">
<HintPath>..\..\packages\dnlib.3.3.4\lib\net45\dnlib.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
+1 -1
View File
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="dnlib" version="3.3.2" targetFramework="net48" />
<package id="dnlib" version="3.3.4" targetFramework="net48" />
</packages>
+18
View File
@@ -36,6 +36,24 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
+20
View File
@@ -37,6 +37,26 @@
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" />
+18
View File
@@ -13,25 +13,43 @@ EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E93CFFA3-1EEB-4E71-9E83-7377C1422119}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E93CFFA3-1EEB-4E71-9E83-7377C1422119}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E93CFFA3-1EEB-4E71-9E83-7377C1422119}.Debug|x64.ActiveCfg = Debug|x64
{E93CFFA3-1EEB-4E71-9E83-7377C1422119}.Debug|x64.Build.0 = Debug|x64
{E93CFFA3-1EEB-4E71-9E83-7377C1422119}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E93CFFA3-1EEB-4E71-9E83-7377C1422119}.Release|Any CPU.Build.0 = Release|Any CPU
{E93CFFA3-1EEB-4E71-9E83-7377C1422119}.Release|x64.ActiveCfg = Release|x64
{E93CFFA3-1EEB-4E71-9E83-7377C1422119}.Release|x64.Build.0 = Release|x64
{5681A1BD-B3EC-450B-BF6E-38187204B6BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5681A1BD-B3EC-450B-BF6E-38187204B6BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5681A1BD-B3EC-450B-BF6E-38187204B6BE}.Debug|x64.ActiveCfg = Debug|x64
{5681A1BD-B3EC-450B-BF6E-38187204B6BE}.Debug|x64.Build.0 = Debug|x64
{5681A1BD-B3EC-450B-BF6E-38187204B6BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5681A1BD-B3EC-450B-BF6E-38187204B6BE}.Release|Any CPU.Build.0 = Release|Any CPU
{5681A1BD-B3EC-450B-BF6E-38187204B6BE}.Release|x64.ActiveCfg = Release|x64
{5681A1BD-B3EC-450B-BF6E-38187204B6BE}.Release|x64.Build.0 = Release|x64
{56AE007D-B441-4294-8582-D5C63CC1C206}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{56AE007D-B441-4294-8582-D5C63CC1C206}.Debug|Any CPU.Build.0 = Debug|Any CPU
{56AE007D-B441-4294-8582-D5C63CC1C206}.Debug|x64.ActiveCfg = Debug|x64
{56AE007D-B441-4294-8582-D5C63CC1C206}.Debug|x64.Build.0 = Debug|x64
{56AE007D-B441-4294-8582-D5C63CC1C206}.Release|Any CPU.ActiveCfg = Release|Any CPU
{56AE007D-B441-4294-8582-D5C63CC1C206}.Release|Any CPU.Build.0 = Release|Any CPU
{56AE007D-B441-4294-8582-D5C63CC1C206}.Release|x64.ActiveCfg = Release|x64
{56AE007D-B441-4294-8582-D5C63CC1C206}.Release|x64.Build.0 = Release|x64
{F0323473-F9B6-4875-93B2-DF657C3F7197}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F0323473-F9B6-4875-93B2-DF657C3F7197}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F0323473-F9B6-4875-93B2-DF657C3F7197}.Debug|x64.ActiveCfg = Debug|x64
{F0323473-F9B6-4875-93B2-DF657C3F7197}.Debug|x64.Build.0 = Debug|x64
{F0323473-F9B6-4875-93B2-DF657C3F7197}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F0323473-F9B6-4875-93B2-DF657C3F7197}.Release|Any CPU.Build.0 = Release|Any CPU
{F0323473-F9B6-4875-93B2-DF657C3F7197}.Release|x64.ActiveCfg = Release|x64
{F0323473-F9B6-4875-93B2-DF657C3F7197}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE