Port de4dot.mdecrypt to dot10

This commit is contained in:
de4dot 2012-11-01 09:33:02 +01:00
parent 14d27c7941
commit e6ab87e5ed
3 changed files with 15 additions and 17 deletions

View File

@ -19,7 +19,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Mono.MyStuff;
namespace de4dot.mdecrypt { namespace de4dot.mdecrypt {
[Serializable] [Serializable]

View File

@ -22,8 +22,7 @@ using System.IO;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Reflection; using System.Reflection;
using Mono.MyStuff; using dot10.DotNet;
using Mono.Cecil;
using de4dot.blocks; using de4dot.blocks;
using de4dot.PE; using de4dot.PE;
@ -70,7 +69,7 @@ namespace de4dot.mdecrypt {
class DecryptContext { class DecryptContext {
public DumpedMethod dm; public DumpedMethod dm;
public MethodDefinition method; public MethodDef method;
} }
FuncPtrInfo<CompileMethod> ourCompileMethodInfo = new FuncPtrInfo<CompileMethod>(); FuncPtrInfo<CompileMethod> ourCompileMethodInfo = new FuncPtrInfo<CompileMethod>();
@ -93,8 +92,8 @@ namespace de4dot.mdecrypt {
de4dot.PE.MetadataType methodDefTable; de4dot.PE.MetadataType methodDefTable;
IntPtr methodDefTablePtr; IntPtr methodDefTablePtr;
ModuleDefinition monoModule; ModuleDefMD dot10Module;
MethodDefinition moduleCctor; MethodDef moduleCctor;
uint moduleCctorCodeRva; uint moduleCctorCodeRva;
IntPtr moduleToDecryptScope; IntPtr moduleToDecryptScope;
@ -175,16 +174,16 @@ namespace de4dot.mdecrypt {
} }
unsafe void initializeMonoCecilMethods() { unsafe void initializeMonoCecilMethods() {
monoModule = ModuleDefinition.ReadModule(moduleToDecrypt.FullyQualifiedName); dot10Module = ModuleDefMD.Load(moduleToDecrypt.FullyQualifiedName);
moduleCctor = DotNetUtils.getModuleTypeCctor(monoModule); moduleCctor = DotNetUtils.getModuleTypeCctor(dot10Module);
if (moduleCctor == null) if (moduleCctor == null)
moduleCctorCodeRva = 0; moduleCctorCodeRva = 0;
else { else {
byte* p = (byte*)hInstModule + moduleCctor.RVA; byte* p = (byte*)hInstModule + (uint)moduleCctor.RVA;
if ((*p & 3) == 2) if ((*p & 3) == 2)
moduleCctorCodeRva = (uint)moduleCctor.RVA + 1; moduleCctorCodeRva = (uint)moduleCctor.RVA + 1;
else else
moduleCctorCodeRva = (uint)(moduleCctor.RVA + (p[1] >> 4) * 4); moduleCctorCodeRva = (uint)((uint)moduleCctor.RVA + (p[1] >> 4) * 4);
} }
} }
@ -442,11 +441,11 @@ namespace de4dot.mdecrypt {
} }
string returnNameOfMethod() { string returnNameOfMethod() {
return ctx.method.Name; return ctx.method.Name.String;
} }
int returnMethodToken() { int returnMethodToken() {
return ctx.method.MetadataToken.ToInt32(); return ctx.method.MDToken.ToInt32();
} }
public DumpedMethods decryptMethods() { public DumpedMethods decryptMethods() {
@ -476,11 +475,11 @@ namespace de4dot.mdecrypt {
ctx.dm = new DumpedMethod(); ctx.dm = new DumpedMethod();
ctx.dm.token = token; ctx.dm.token = token;
ctx.method = monoModule.LookupToken((int)token) as MethodDefinition; ctx.method = dot10Module.ResolveToken(token) as MethodDef;
if (ctx.method == null) if (ctx.method == null)
throw new ApplicationException(string.Format("Could not find method {0:X8}", token)); throw new ApplicationException(string.Format("Could not find method {0:X8}", token));
byte* mh = (byte*)hInstModule + ctx.method.RVA; byte* mh = (byte*)hInstModule + (uint)ctx.method.RVA;
byte* code; byte* code;
if (mh == (byte*)hInstModule) { if (mh == (byte*)hInstModule) {
ctx.dm.mhMaxStack = 0; ctx.dm.mhMaxStack = 0;

View File

@ -46,9 +46,9 @@
<Project>{045B96F2-AF80-4C4C-8D27-E38635AC705E}</Project> <Project>{045B96F2-AF80-4C4C-8D27-E38635AC705E}</Project>
<Name>blocks</Name> <Name>blocks</Name>
</ProjectReference> </ProjectReference>
<ProjectReference Include="..\cecil\Mono.Cecil.csproj"> <ProjectReference Include="..\dot10\src\dot10.csproj">
<Project>{D68133BD-1E63-496E-9EDE-4FBDBF77B486}</Project> <Project>{FDFC1237-143F-4919-8318-4926901F4639}</Project>
<Name>Mono.Cecil</Name> <Name>dot10</Name>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />