Skip to content

Commit

Permalink
Support VS2008
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfsck committed Jul 7, 2012
1 parent 0c3d2a9 commit ad6c640
Show file tree
Hide file tree
Showing 23 changed files with 126 additions and 30 deletions.
2 changes: 2 additions & 0 deletions AssemblyServer-x64/AssemblyServer-x64.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -34,6 +35,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NoStdLib>true</NoStdLib>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.cs" />
Expand Down
6 changes: 5 additions & 1 deletion blocks/DotNetUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,11 @@ public static FieldDefinition findFieldType(TypeDefinition typeDefinition, strin
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;
Expand Down
18 changes: 15 additions & 3 deletions blocks/MemberRefInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ public class TypeReferenceInstance : TypeReferenceUpdaterBase {
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();
Expand Down Expand Up @@ -88,7 +92,11 @@ public abstract class MultiTypeRefInstance {
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;
}
Expand All @@ -112,7 +120,11 @@ protected T getResult<T>(T orig, T newOne) {
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();
Expand Down
6 changes: 5 additions & 1 deletion blocks/MemberReferenceHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,11 @@ public static CecilType getMemberReferenceType(MemberReference memberReference)
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;
Expand Down
6 changes: 5 additions & 1 deletion blocks/ScopeBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ void addBlocks<T>(IList<T> list, ScopeBlock scopeBlock) where T : BaseBlock {
}
}

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;
Expand Down
18 changes: 15 additions & 3 deletions blocks/cflow/MethodCallInlinerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,11 @@ protected bool inlineLoadMethod(int patchIndex, MethodDefinition methodToInline,
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));
}

Expand All @@ -95,7 +99,11 @@ protected bool patchMethod(MethodDefinition methodToInline, InstructionPatcher p
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;
Expand Down Expand Up @@ -183,7 +191,11 @@ protected virtual bool isReturn(MethodDefinition methodToInline, int instrIndex)
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)
Expand Down
2 changes: 2 additions & 0 deletions de4dot-x64/de4dot-x64.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -34,6 +35,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NoStdLib>true</NoStdLib>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.cs" />
Expand Down
6 changes: 5 additions & 1 deletion de4dot.code/NameRegexes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ public class NameRegexes {
public bool DefaultValue { get; set; }
public const char regexSeparatorChar = '&';

public NameRegexes(string regex = "") {
public NameRegexes()
: this("") {
}

public NameRegexes(string regex) {
set(regex);
}

Expand Down
6 changes: 5 additions & 1 deletion de4dot.code/Option.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,11 @@ public override bool NeedArgument {
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;
}
Expand Down
6 changes: 5 additions & 1 deletion de4dot.code/deobfuscators/ArrayFinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ You should have received a copy of the GNU General Public License

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++) {
Expand Down
6 changes: 5 additions & 1 deletion de4dot.code/deobfuscators/Babel_NET/InflaterCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ public static Inflater create(TypeDefinition inflaterType, bool noHeader) {
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);
Expand Down
6 changes: 5 additions & 1 deletion de4dot.code/deobfuscators/DeobfuscatorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,11 @@ protected void addModuleReferences(string reason) {
}
}

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;
Expand Down
6 changes: 5 additions & 1 deletion de4dot.code/deobfuscators/DeobfuscatorInfoBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion de4dot.code/deobfuscators/IDeobfuscatedFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ You should have received a copy of the GNU General Public License
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();
}
}
6 changes: 5 additions & 1 deletion de4dot.code/deobfuscators/MPRESS/Deobfuscator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ class MethodInfo {
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;
Expand Down
2 changes: 1 addition & 1 deletion de4dot.code/deobfuscators/SmartAssembly/Deobfuscator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ void initDecrypters() {
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));
}
}
Expand Down
6 changes: 5 additions & 1 deletion de4dot.code/deobfuscators/TypesRestorer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ public TypeInfo(T arg) {
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ void dumpEmbeddedAssemblies() {
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));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ T lookup<T>(T def, string errorMessage) where T : MemberReference {
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)
Expand Down
16 changes: 12 additions & 4 deletions de4dot.code/renamer/NameCreators.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ public override string create() {
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;
}
Expand All @@ -82,7 +86,11 @@ class NameCreator2 : NameCreatorCounter {
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;
}
Expand All @@ -99,7 +107,7 @@ public override string create() {
}

interface ITypeNameCreator {
string create(TypeDefinition typeDefinition, string newBaseTypeName = null);
string create(TypeDefinition typeDefinition, string newBaseTypeName);
}

class NameInfos {
Expand Down Expand Up @@ -164,7 +172,7 @@ protected virtual NameCreator createNameCreator(string prefix) {
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);
}
Expand Down
6 changes: 5 additions & 1 deletion de4dot.code/renamer/TypeInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,11 @@ static bool isEventHandler(MethodDef methodDef) {
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();

Expand Down
10 changes: 7 additions & 3 deletions de4dot.cui/FilesDeobfuscator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ void deobfuscateAll() {
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,
Expand Down Expand Up @@ -172,7 +176,7 @@ public IEnumerable<IObfuscatedFile> load() {
}
}

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);
Expand Down Expand Up @@ -301,7 +305,7 @@ IObfuscatedFile createObfuscatedFile(SearchDir searchDir, string filename) {
}

var obfuscatedFile = new ObfuscatedFile(fileOptions, options.AssemblyClientFactory);
if (add(obfuscatedFile, searchDir.SkipUnknownObfuscators))
if (add(obfuscatedFile, searchDir.SkipUnknownObfuscators, false))
return obfuscatedFile;
return null;
}
Expand Down
6 changes: 5 additions & 1 deletion de4dot.cui/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ static bool isN00bUser() {
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);
Expand Down

0 comments on commit ad6c640

Please sign in to comment.