2012-02-20 10:26:27 +08:00
|
|
|
|
/*
|
|
|
|
|
Copyright (C) 2011-2012 de4dot@gmail.com
|
|
|
|
|
|
|
|
|
|
This file is part of de4dot.
|
|
|
|
|
|
|
|
|
|
de4dot is free software: you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
de4dot is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with de4dot. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2012-02-21 00:20:29 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Mono.Cecil;
|
|
|
|
|
using Mono.MyStuff;
|
|
|
|
|
|
2012-02-20 10:26:27 +08:00
|
|
|
|
namespace de4dot.code.deobfuscators.MaxtoCode {
|
|
|
|
|
public class DeobfuscatorInfo : DeobfuscatorInfoBase {
|
|
|
|
|
public const string THE_NAME = "MaxtoCode";
|
|
|
|
|
public const string THE_TYPE = "mc";
|
2012-03-08 20:54:07 +08:00
|
|
|
|
const string DEFAULT_REGEX = @"!^[oO01l]+$&" + DeobfuscatorBase.DEFAULT_VALID_NAME_REGEX;
|
2012-02-20 10:26:27 +08:00
|
|
|
|
public DeobfuscatorInfo()
|
2012-02-23 18:52:19 +08:00
|
|
|
|
: base(DEFAULT_REGEX) {
|
2012-02-20 10:26:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string Name {
|
|
|
|
|
get { return THE_NAME; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string Type {
|
|
|
|
|
get { return THE_TYPE; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override IDeobfuscator createDeobfuscator() {
|
|
|
|
|
return new Deobfuscator(new Deobfuscator.Options {
|
|
|
|
|
RenameResourcesInCode = false,
|
|
|
|
|
ValidNameRegex = validNameRegex.get(),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class Deobfuscator : DeobfuscatorBase {
|
2012-02-21 00:20:29 +08:00
|
|
|
|
Options options;
|
2012-02-20 11:55:59 +08:00
|
|
|
|
MainType mainType;
|
|
|
|
|
|
2012-02-20 10:26:27 +08:00
|
|
|
|
internal class Options : OptionsBase {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string Type {
|
|
|
|
|
get { return DeobfuscatorInfo.THE_TYPE; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string TypeLong {
|
|
|
|
|
get { return DeobfuscatorInfo.THE_NAME; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override string Name {
|
|
|
|
|
get { return DeobfuscatorInfo.THE_NAME; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
internal Deobfuscator(Options options)
|
|
|
|
|
: base(options) {
|
2012-02-21 00:20:29 +08:00
|
|
|
|
this.options = options;
|
2012-02-20 10:26:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override int detectInternal() {
|
2012-02-20 11:55:59 +08:00
|
|
|
|
int val = 0;
|
|
|
|
|
|
|
|
|
|
if (mainType.Detected)
|
|
|
|
|
val = 150;
|
|
|
|
|
|
|
|
|
|
return val;
|
2012-02-20 10:26:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void scanForObfuscator() {
|
2012-02-20 11:55:59 +08:00
|
|
|
|
mainType = new MainType(module);
|
|
|
|
|
mainType.find();
|
2012-02-20 10:26:27 +08:00
|
|
|
|
}
|
2012-02-21 00:20:29 +08:00
|
|
|
|
|
2012-02-27 05:57:55 +08:00
|
|
|
|
public override bool getDecryptedModule(ref byte[] newFileData, ref DumpedMethods dumpedMethods) {
|
2012-02-21 00:20:29 +08:00
|
|
|
|
if (!mainType.Detected)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
var fileDecrypter = new FileDecrypter(mainType);
|
|
|
|
|
|
|
|
|
|
var fileData = DeobUtils.readModule(module);
|
|
|
|
|
if (!fileDecrypter.decrypt(fileData, ref dumpedMethods))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
newFileData = fileData;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override IDeobfuscator moduleReloaded(ModuleDefinition module) {
|
|
|
|
|
var newOne = new Deobfuscator(options);
|
|
|
|
|
newOne.setModule(module);
|
|
|
|
|
newOne.mainType = new MainType(module, mainType);
|
|
|
|
|
return newOne;
|
|
|
|
|
}
|
2012-02-21 18:57:47 +08:00
|
|
|
|
|
|
|
|
|
public override void deobfuscateBegin() {
|
|
|
|
|
base.deobfuscateBegin();
|
|
|
|
|
|
|
|
|
|
foreach (var method in mainType.InitMethods)
|
|
|
|
|
addCctorInitCallToBeRemoved(method);
|
|
|
|
|
addTypeToBeRemoved(mainType.Type, "Obfuscator type");
|
|
|
|
|
addModuleReferencesToBeRemoved(mainType.ModuleReferences, "MC runtime module reference");
|
|
|
|
|
}
|
2012-02-27 05:57:55 +08:00
|
|
|
|
|
|
|
|
|
public override IEnumerable<int> getStringDecrypterMethods() {
|
|
|
|
|
return new List<int>();
|
|
|
|
|
}
|
2012-02-20 10:26:27 +08:00
|
|
|
|
}
|
|
|
|
|
}
|