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.Collections.Generic;
using Mono.MyStuff;
namespace de4dot.mdecrypt {
[Serializable]

View File

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

View File

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