Initial import
This commit is contained in:
48
PdbFind.Lib/Locator.cs
Normal file
48
PdbFind.Lib/Locator.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using PeNet;
|
||||
|
||||
namespace PdbFind.Lib
|
||||
{
|
||||
public class Locator
|
||||
{
|
||||
public static (string? pdbName, string? checksum) GetPdbChecksum(string path)
|
||||
{
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
throw new FileNotFoundException("PE File not found", path);
|
||||
}
|
||||
|
||||
var peFile = new PeFile(path);
|
||||
|
||||
var pdb70 = peFile.ImageDebugDirectory?.Where(d => d.CvInfoPdb70 != null).Select(d => d.CvInfoPdb70).FirstOrDefault();
|
||||
|
||||
var pdbName = (pdb70?.PdbFileName != null) ? Path.GetFileName(pdb70.PdbFileName) : null;
|
||||
|
||||
var checksum = pdb70?.Signature != null ? $"{pdb70.Signature:N}{pdb70.Age}" : null;
|
||||
|
||||
return (pdbName, checksum);
|
||||
}
|
||||
|
||||
public static string LocatePdbInStore(string path, string store)
|
||||
{
|
||||
if (!Directory.Exists(store))
|
||||
{
|
||||
throw new DirectoryNotFoundException($"Directory \"{store}\" not found.");
|
||||
}
|
||||
|
||||
var (pdbName, checksum) = GetPdbChecksum(path);
|
||||
|
||||
_ = pdbName ?? throw new InvalidOperationException("PDB name not found in PE header.");
|
||||
_ = checksum ?? throw new InvalidOperationException("Checksum not found in PE header.");
|
||||
|
||||
var isIndex2 = File.Exists(Path.Combine(store, "index2.txt"));
|
||||
|
||||
var pdbPath = Path.Combine(pdbName, checksum, pdbName);
|
||||
if (isIndex2)
|
||||
{
|
||||
pdbPath = Path.Combine(pdbName.Substring(0, 2), pdbName, checksum, pdbName);
|
||||
}
|
||||
|
||||
return Path.Combine(store, pdbPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
13
PdbFind.Lib/PdbFind.Lib.csproj
Normal file
13
PdbFind.Lib/PdbFind.Lib.csproj
Normal file
@@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="PeNet" Version="2.9.8" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
Reference in New Issue
Block a user