internal void RunTest(string name, out PdbFunction original, out PdbFunction rewritten) { int originalAge; Guid originalGuid; PdbFunction[] originalFunctions; using (var file = File.OpenRead(pdbFileName)) originalFunctions = PdbFile.LoadFunctions(file, true, out originalAge, out originalGuid); var method = GetMethod(name); original = originalFunctions.Single(f => f.token == method.MetadataToken.ToUInt32()); var pdb = ProgramDatabase.Read(pdbFileName); pdb.Write(pdbFileName, new CecilMetadataProvider(module)); int rewrittenAge; Guid rewrittenGuid; PdbFunction[] rewrittenFunctions; using (var file = File.OpenRead(pdbFileName)) rewrittenFunctions = PdbFile.LoadFunctions(file, true, out rewrittenAge, out rewrittenGuid); rewritten = rewrittenFunctions.Single(f => f.token == method.MetadataToken.ToUInt32()); Assert.AreEqual(originalAge, rewrittenAge); Assert.AreEqual(originalGuid, rewrittenGuid); }
bool TryFindConstructor(string typeName, out ObjectConstructorDelegate ctor) { return(ProgramDatabase.TryGetDelegateForSymbol( $"??0{typeName}@@QEAA@UMemLabelId@@W4ObjectCreationMode@@@Z", out ctor )); }
unsafe static PdbImportAttribute() { foreach (var field in GetFieldsWithAttribute <PdbImportAttribute>()) { if (!field.IsStatic) { Debug.LogErrorFormat("{0} must be static.", field.Name); continue; } var attr = field.GetCustomAttribute <PdbImportAttribute>(); if (ProgramDatabase.TryGetAddressForSymbol(attr.SymbolName, out IntPtr address)) { if (field.FieldType == typeof(IntPtr)) { field.SetValue(null, address); } else if (field.FieldType == typeof(UIntPtr)) { field.SetValue(null, new UIntPtr(address.ToPointer())); } else if (field.FieldType.IsSubclassOf(typeof(Delegate))) { field.SetValue(null, Marshal.GetDelegateForFunctionPointer(address, field.FieldType)); } else { Debug.LogErrorFormat("{0} must be of IntPtr, UIntPtr or delegate type.", field.Name); } } } }
public void MapSourceFiles() { var pdb = ProgramDatabase.Read(pdbFileName); var mappingFiles = new Dictionary <string, string> { { "MappingTest.cs", "NewMappingTest.cs" }, }; var documents = pdb.Functions.SelectMany(f => f.Sources).Select(s => s.Document); foreach (var document in documents) { string mappedFile; if (mappingFiles.TryGetValue(Path.GetFileName(document.Name), out mappedFile)) { document.Name = Path.Combine(Path.GetDirectoryName(document.Name), mappedFile); } } pdb.Write(pdbFileName, new CecilMetadataProvider(module)); pdb = ProgramDatabase.Read(pdbFileName); documents = pdb.Functions.SelectMany(f => f.Sources).Select(s => s.Document).ToList(); Assert.IsFalse(documents.Any(d => Path.GetFileName(d.Name) == "MappingTest.cs")); }
public MigrateProgramDatabaseStep( ProgramDatabase programDatabase, ILogger <MigrateProgramDatabaseStep> logger) { _programDatabase = programDatabase; _logger = logger; Description = "Migrating database..."; SuccessMessage = ""; FailureMessage = "Cannot migrate database. Program might behave incorrectly."; }
bool TryHookTransfer(string typeName, out LocalHook hook) { if (ProgramDatabase.TryGetAddressForSymbol($"?VirtualRedirectTransfer@{typeName}@@UEAAXAEAVGenerateTypeTreeTransfer@@@Z", out var original) && ProgramDatabase.TryGetAddressForSymbol($"??$Transfer@VGenerateTypeTreeTransfer@@@{typeName}@@IEAAXAEAVGenerateTypeTreeTransfer@@@Z", out var transfer)) { LocalHook.Release(); hook = LocalHook.CreateUnmanaged(original, transfer, IntPtr.Zero); hook.ThreadACL.SetInclusiveACL(new[] { 0 }); return(true); } hook = null; return(false); }
public SettingsService(ProgramDatabase database) { _database = database; }