Support VS2008

This commit is contained in:
de4dot 2012-07-07 07:11:32 +02:00
parent 0c3d2a9c43
commit ad6c6401b9
23 changed files with 126 additions and 30 deletions

View File

@ -24,6 +24,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoStdLib>true</NoStdLib>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<PlatformTarget>x64</PlatformTarget>
@ -34,6 +35,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NoStdLib>true</NoStdLib>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.cs" />

View File

@ -362,7 +362,11 @@ namespace de4dot.blocks {
return null;
}
public static IEnumerable<MethodDefinition> findMethods(IEnumerable<MethodDefinition> methods, string returnType, string[] argsTypes, bool isStatic = true) {
public static IEnumerable<MethodDefinition> findMethods(IEnumerable<MethodDefinition> methods, string returnType, string[] argsTypes) {
return findMethods(methods, returnType, argsTypes, true);
}
public static IEnumerable<MethodDefinition> findMethods(IEnumerable<MethodDefinition> methods, string returnType, string[] argsTypes, bool isStatic) {
foreach (var method in methods) {
if (!method.HasBody || method.CallingConvention != MethodCallingConvention.Default)
continue;

View File

@ -31,7 +31,11 @@ namespace de4dot.blocks {
IGenericInstance gim;
bool modified;
public static TypeReference make(TypeReference typeReference, GenericInstanceType git, IGenericInstance gim = null) {
public static TypeReference make(TypeReference typeReference, GenericInstanceType git) {
return make(typeReference, git, null);
}
public static TypeReference make(TypeReference typeReference, GenericInstanceType git, IGenericInstance gim) {
if (git == null && gim == null)
return typeReference;
return new TypeReferenceInstance(typeReference, git, gim).makeInstance();
@ -88,7 +92,11 @@ namespace de4dot.blocks {
IGenericInstance gim;
bool modified;
public MultiTypeRefInstance(GenericInstanceType git, IGenericInstance gim = null) {
public MultiTypeRefInstance(GenericInstanceType git)
: this(git, null) {
}
public MultiTypeRefInstance(GenericInstanceType git, IGenericInstance gim) {
this.git = git;
this.gim = gim;
}
@ -112,7 +120,11 @@ namespace de4dot.blocks {
public class MethodReferenceInstance : MultiTypeRefInstance {
MethodReference methodReference;
public static MethodReference make(MethodReference methodReference, GenericInstanceType git, IGenericInstance gim = null) {
public static MethodReference make(MethodReference methodReference, GenericInstanceType git) {
return make(methodReference, git, null);
}
public static MethodReference make(MethodReference methodReference, GenericInstanceType git, IGenericInstance gim) {
if (git == null && gim == null)
return methodReference;
return new MethodReferenceInstance(methodReference, git, gim).makeInstance();

View File

@ -815,7 +815,11 @@ namespace de4dot.blocks {
throw new ApplicationException(string.Format("Unknown MemberReference type: {0}", type));
}
public static bool verifyType(TypeReference typeReference, string assembly, string type, string extra = "") {
public static bool verifyType(TypeReference typeReference, string assembly, string type) {
return verifyType(typeReference, assembly, type, "");
}
public static bool verifyType(TypeReference typeReference, string assembly, string type, string extra) {
return typeReference != null &&
MemberReferenceHelper.getCanonicalizedTypeRefName(typeReference.GetElementType()) == "[" + assembly + "]" + type &&
typeReference.FullName == type + extra;

View File

@ -71,7 +71,11 @@ namespace de4dot.blocks {
}
}
List<Block> findBlocks(Func<Block, bool> blockChecker = null) {
List<Block> findBlocks() {
return findBlocks(null);
}
List<Block> findBlocks(Func<Block, bool> blockChecker) {
var blocks = new List<Block>();
foreach (var bb in getBaseBlocks()) {
Block block = bb as Block;

View File

@ -80,7 +80,11 @@ namespace de4dot.blocks.cflow {
return true;
}
protected bool inlineOtherMethod(int patchIndex, MethodDefinition methodToInline, Instruction instr, int instrIndex, int popLastArgs = 0) {
protected bool inlineOtherMethod(int patchIndex, MethodDefinition methodToInline, Instruction instr, int instrIndex) {
return inlineOtherMethod(patchIndex, methodToInline, instr, instrIndex, 0);
}
protected bool inlineOtherMethod(int patchIndex, MethodDefinition methodToInline, Instruction instr, int instrIndex, int popLastArgs) {
return patchMethod(methodToInline, tryInlineOtherMethod(patchIndex, methodToInline, instr, instrIndex, popLastArgs));
}
@ -95,7 +99,11 @@ namespace de4dot.blocks.cflow {
return true;
}
protected InstructionPatcher tryInlineOtherMethod(int patchIndex, MethodDefinition methodToInline, Instruction instr, int instrIndex, int popLastArgs = 0) {
protected InstructionPatcher tryInlineOtherMethod(int patchIndex, MethodDefinition methodToInline, Instruction instr, int instrIndex) {
return tryInlineOtherMethod(patchIndex, methodToInline, instr, instrIndex, 0);
}
protected InstructionPatcher tryInlineOtherMethod(int patchIndex, MethodDefinition methodToInline, Instruction instr, int instrIndex, int popLastArgs) {
int loadIndex = 0;
int methodArgsCount = DotNetUtils.getArgsCount(methodToInline);
bool foundLdarga = false;
@ -183,7 +191,11 @@ namespace de4dot.blocks.cflow {
return instr != null && instr.OpCode.Code == Code.Ret;
}
protected bool checkSameMethods(MethodReference method, MethodDefinition methodToInline, int ignoreLastMethodToInlineArgs = 0) {
protected bool checkSameMethods(MethodReference method, MethodDefinition methodToInline) {
return checkSameMethods(method, methodToInline, 0);
}
protected bool checkSameMethods(MethodReference method, MethodDefinition methodToInline, int ignoreLastMethodToInlineArgs) {
var methodToInlineArgs = DotNetUtils.getArgs(methodToInline);
var methodArgs = DotNetUtils.getArgs(method);
if (methodToInlineArgs.Count - ignoreLastMethodToInlineArgs != methodArgs.Count)

View File

@ -24,6 +24,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<NoStdLib>true</NoStdLib>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<PlatformTarget>x64</PlatformTarget>
@ -34,6 +35,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NoStdLib>true</NoStdLib>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.cs" />

View File

@ -55,7 +55,11 @@ namespace de4dot.code {
public bool DefaultValue { get; set; }
public const char regexSeparatorChar = '&';
public NameRegexes(string regex = "") {
public NameRegexes()
: this("") {
}
public NameRegexes(string regex) {
set(regex);
}

View File

@ -214,7 +214,11 @@ namespace de4dot.code {
get { return false; }
}
public NoArgOption(string shortName, string longName, string description, Action action = null)
public NoArgOption(string shortName, string longName, string description)
: this(shortName, longName, description, null) {
}
public NoArgOption(string shortName, string longName, string description, Action action)
: base(shortName, longName, description) {
this.action = action;
}

View File

@ -25,7 +25,11 @@ using de4dot.blocks.cflow;
namespace de4dot.code.deobfuscators {
static class ArrayFinder {
public static List<byte[]> getArrays(MethodDefinition method, TypeReference arrayElemntType = null) {
public static List<byte[]> getArrays(MethodDefinition method) {
return getArrays(method, null);
}
public static List<byte[]> getArrays(MethodDefinition method, TypeReference arrayElemntType) {
var arrays = new List<byte[]>();
var instrs = method.Body.Instructions;
for (int i = 0; i < instrs.Count; i++) {

View File

@ -40,7 +40,11 @@ namespace de4dot.code.deobfuscators.Babel_NET {
return new BabelInflater(noHeader, magic.Value);
}
static Inflater createNormal(bool noHeader, string errorMessage = null) {
static Inflater createNormal(bool noHeader) {
return createNormal(noHeader, null);
}
static Inflater createNormal(bool noHeader, string errorMessage) {
if (errorMessage != null)
Log.w("{0}", errorMessage);
return new Inflater(noHeader);

View File

@ -663,7 +663,11 @@ namespace de4dot.code.deobfuscators {
}
}
protected void removeProxyDelegates(ProxyCallFixerBase proxyCallFixer, bool removeCreators = true) {
protected void removeProxyDelegates(ProxyCallFixerBase proxyCallFixer) {
removeProxyDelegates(proxyCallFixer, true);
}
protected void removeProxyDelegates(ProxyCallFixerBase proxyCallFixer, bool removeCreators) {
if (proxyCallFixer.Errors != 0) {
Log.v("Not removing proxy delegates and creator type since errors were detected.");
return;

View File

@ -23,7 +23,11 @@ namespace de4dot.code.deobfuscators {
public abstract class DeobfuscatorInfoBase : IDeobfuscatorInfo {
protected NameRegexOption validNameRegex;
public DeobfuscatorInfoBase(string nameRegex = null) {
public DeobfuscatorInfoBase()
: this(null) {
}
public DeobfuscatorInfoBase(string nameRegex) {
validNameRegex = new NameRegexOption(null, makeArgName("name"), "Valid name regex pattern", nameRegex ?? DeobfuscatorBase.DEFAULT_VALID_NAME_REGEX);
}

View File

@ -20,7 +20,7 @@
namespace de4dot.code.deobfuscators {
public interface IDeobfuscatedFile : ISimpleDeobfuscator {
IDeobfuscatorContext DeobfuscatorContext { get; }
void createAssemblyFile(byte[] data, string assemblyName, string extension = null);
void createAssemblyFile(byte[] data, string assemblyName, string extension);
void stringDecryptersAdded();
}
}

View File

@ -109,7 +109,11 @@ namespace de4dot.code.deobfuscators.MPRESS {
public readonly string parameters;
public readonly string name;
public MethodInfo(string returnType, string parameters, string name = null) {
public MethodInfo(string returnType, string parameters)
: this(returnType, parameters, null) {
}
public MethodInfo(string returnType, string parameters, string name) {
this.returnType = returnType;
this.parameters = parameters;
this.name = name;

View File

@ -336,7 +336,7 @@ namespace de4dot.code.deobfuscators.SmartAssembly {
void dumpEmbeddedAssemblies() {
assemblyResolver.resolveResources();
foreach (var tuple in assemblyResolver.getDecryptedResources()) {
DeobfuscatedFile.createAssemblyFile(tuple.Item2, tuple.Item1.simpleName);
DeobfuscatedFile.createAssemblyFile(tuple.Item2, tuple.Item1.simpleName, null);
addResourceToBeRemoved(tuple.Item1.resource, string.Format("Embedded assembly: {0}", tuple.Item1.assemblyName));
}
}

View File

@ -71,7 +71,11 @@ namespace de4dot.code.deobfuscators {
this.arg = arg;
}
public void add(TypeReference type, bool wasNewobj = false) {
public void add(TypeReference type) {
add(type, false);
}
public void add(TypeReference type, bool wasNewobj) {
if (wasNewobj) {
if (!newobjTypes)
clear();

View File

@ -521,7 +521,7 @@ namespace de4dot.code.deobfuscators.dotNET_Reactor.v4 {
return;
foreach (var info in assemblyResolver.getEmbeddedAssemblies(DeobfuscatedFile, this)) {
var simpleName = Utils.getAssemblySimpleName(info.name);
DeobfuscatedFile.createAssemblyFile(info.resource.GetResourceData(), simpleName);
DeobfuscatedFile.createAssemblyFile(info.resource.GetResourceData(), simpleName, null);
addResourceToBeRemoved(info.resource, string.Format("Embedded assembly: {0}", info.name));
}
}

View File

@ -69,7 +69,11 @@ namespace de4dot.code.deobfuscators.dotNET_Reactor.v4 {
return DeobUtils.lookup(module, def, errorMessage);
}
public bool couldBeResourceDecrypter(MethodDefinition method, IEnumerable<string> additionalTypes, bool checkResource = true) {
public bool couldBeResourceDecrypter(MethodDefinition method, IEnumerable<string> additionalTypes) {
return couldBeResourceDecrypter(method, additionalTypes, true);
}
public bool couldBeResourceDecrypter(MethodDefinition method, IEnumerable<string> additionalTypes, bool checkResource) {
if (!method.IsStatic)
return false;
if (method.Body == null)

View File

@ -63,7 +63,11 @@ namespace de4dot.code.renamer {
class NameCreator : NameCreatorCounter {
string prefix;
public NameCreator(string prefix, int num = 0) {
public NameCreator(string prefix)
: this(prefix, 0) {
}
public NameCreator(string prefix, int num) {
this.prefix = prefix;
this.num = num;
}
@ -82,7 +86,11 @@ namespace de4dot.code.renamer {
string prefix;
const string separator = "_";
public NameCreator2(string prefix, int num = 0) {
public NameCreator2(string prefix)
: this(prefix, 0) {
}
public NameCreator2(string prefix, int num) {
this.prefix = prefix;
this.num = num;
}
@ -99,7 +107,7 @@ namespace de4dot.code.renamer {
}
interface ITypeNameCreator {
string create(TypeDefinition typeDefinition, string newBaseTypeName = null);
string create(TypeDefinition typeDefinition, string newBaseTypeName);
}
class NameInfos {
@ -164,7 +172,7 @@ namespace de4dot.code.renamer {
return new NameCreator(prefix);
}
public string create(TypeDefinition typeDefinition, string newBaseTypeName = null) {
public string create(TypeDefinition typeDefinition, string newBaseTypeName) {
var nameCreator = getNameCreator(typeDefinition, newBaseTypeName);
return existingNames.getName(typeDefinition.Name, nameCreator);
}

View File

@ -405,7 +405,11 @@ namespace de4dot.code.renamer {
return true;
}
void prepareRenameGenericParams(IEnumerable<GenericParamDef> genericParams, INameChecker checker, IEnumerable<GenericParamDef> otherGenericParams = null) {
void prepareRenameGenericParams(IEnumerable<GenericParamDef> genericParams, INameChecker checker) {
prepareRenameGenericParams(genericParams, checker, null);
}
void prepareRenameGenericParams(IEnumerable<GenericParamDef> genericParams, INameChecker checker, IEnumerable<GenericParamDef> otherGenericParams) {
var usedNames = new Dictionary<string, bool>(StringComparer.Ordinal);
var nameCreator = new GenericParamNameCreator();

View File

@ -120,7 +120,11 @@ namespace de4dot.cui {
saveAllFiles(allFiles);
}
IEnumerable<IObfuscatedFile> loadAllFiles(bool onlyScan = false) {
IEnumerable<IObfuscatedFile> loadAllFiles() {
return loadAllFiles(false);
}
IEnumerable<IObfuscatedFile> loadAllFiles(bool onlyScan) {
var loader = new DotNetFileLoader(new DotNetFileLoader.Options {
PossibleFiles = options.Files,
SearchDirs = options.SearchDirs,
@ -172,7 +176,7 @@ namespace de4dot.cui {
}
}
bool add(IObfuscatedFile file, bool skipUnknownObfuscator = false, bool isFromPossibleFiles = false) {
bool add(IObfuscatedFile file, bool skipUnknownObfuscator, bool isFromPossibleFiles) {
var key = Utils.getFullPath(file.Filename);
if (allFiles.ContainsKey(key)) {
Log.w("Ingoring duplicate file: {0}", file.Filename);
@ -301,7 +305,7 @@ namespace de4dot.cui {
}
var obfuscatedFile = new ObfuscatedFile(fileOptions, options.AssemblyClientFactory);
if (add(obfuscatedFile, searchDir.SkipUnknownObfuscators))
if (add(obfuscatedFile, searchDir.SkipUnknownObfuscators, false))
return obfuscatedFile;
return null;
}

View File

@ -138,7 +138,11 @@ namespace de4dot.cui {
return hasEnv("windir") && !hasEnv("PROMPT");
}
public static void printStackTrace(Exception ex, Log.LogLevel logLevel = Log.LogLevel.error) {
public static void printStackTrace(Exception ex) {
printStackTrace(ex, Log.LogLevel.error);
}
public static void printStackTrace(Exception ex, Log.LogLevel logLevel) {
var line = new string('-', 78);
Log.log(logLevel, "\n\n");
Log.log(logLevel, line);