2011-09-22 10:55:30 +08:00
|
|
|
|
/*
|
2012-01-10 06:02:47 +08:00
|
|
|
|
Copyright (C) 2011-2012 de4dot@gmail.com
|
2011-09-22 10:55:30 +08:00
|
|
|
|
|
|
|
|
|
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/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
2011-12-09 16:02:06 +08:00
|
|
|
|
using de4dot.code;
|
|
|
|
|
using de4dot.code.deobfuscators;
|
2011-09-22 10:55:30 +08:00
|
|
|
|
|
2011-12-09 16:02:06 +08:00
|
|
|
|
namespace de4dot.cui {
|
2012-02-15 04:51:31 +08:00
|
|
|
|
class ExitException : Exception {
|
|
|
|
|
public readonly int code;
|
|
|
|
|
public ExitException(int code) {
|
|
|
|
|
this.code = code;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-03-29 10:58:10 +08:00
|
|
|
|
class Program {
|
2011-09-22 10:55:30 +08:00
|
|
|
|
static IList<IDeobfuscatorInfo> deobfuscatorInfos = createDeobfuscatorInfos();
|
|
|
|
|
|
|
|
|
|
static IList<IDeobfuscatorInfo> createDeobfuscatorInfos() {
|
|
|
|
|
return new List<IDeobfuscatorInfo> {
|
2011-12-09 16:02:06 +08:00
|
|
|
|
new de4dot.code.deobfuscators.Unknown.DeobfuscatorInfo(),
|
2012-01-08 03:27:07 +08:00
|
|
|
|
new de4dot.code.deobfuscators.Babel_NET.DeobfuscatorInfo(),
|
2011-12-09 16:02:06 +08:00
|
|
|
|
new de4dot.code.deobfuscators.CliSecure.DeobfuscatorInfo(),
|
2012-02-07 11:45:59 +08:00
|
|
|
|
new de4dot.code.deobfuscators.CodeVeil.DeobfuscatorInfo(),
|
2011-12-09 16:02:06 +08:00
|
|
|
|
new de4dot.code.deobfuscators.CryptoObfuscator.DeobfuscatorInfo(),
|
2012-01-23 02:58:31 +08:00
|
|
|
|
new de4dot.code.deobfuscators.DeepSea.DeobfuscatorInfo(),
|
2011-12-09 16:02:06 +08:00
|
|
|
|
new de4dot.code.deobfuscators.Dotfuscator.DeobfuscatorInfo(),
|
2011-12-22 01:55:36 +08:00
|
|
|
|
new de4dot.code.deobfuscators.dotNET_Reactor.v3.DeobfuscatorInfo(),
|
|
|
|
|
new de4dot.code.deobfuscators.dotNET_Reactor.v4.DeobfuscatorInfo(),
|
2012-02-12 23:46:39 +08:00
|
|
|
|
new de4dot.code.deobfuscators.Eazfuscator_NET.DeobfuscatorInfo(),
|
2011-12-29 15:26:36 +08:00
|
|
|
|
new de4dot.code.deobfuscators.Goliath_NET.DeobfuscatorInfo(),
|
2012-02-20 10:26:27 +08:00
|
|
|
|
new de4dot.code.deobfuscators.MaxtoCode.DeobfuscatorInfo(),
|
2011-12-31 20:14:02 +08:00
|
|
|
|
new de4dot.code.deobfuscators.Skater_NET.DeobfuscatorInfo(),
|
2011-12-09 16:02:06 +08:00
|
|
|
|
new de4dot.code.deobfuscators.SmartAssembly.DeobfuscatorInfo(),
|
2012-02-02 13:56:14 +08:00
|
|
|
|
new de4dot.code.deobfuscators.Spices_Net.DeobfuscatorInfo(),
|
2011-12-09 16:02:06 +08:00
|
|
|
|
new de4dot.code.deobfuscators.Xenocode.DeobfuscatorInfo(),
|
2011-09-22 10:55:30 +08:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-09 16:02:06 +08:00
|
|
|
|
public static int main(string[] args) {
|
2012-02-15 04:51:31 +08:00
|
|
|
|
int exitCode = 0;
|
|
|
|
|
|
2011-09-22 10:55:30 +08:00
|
|
|
|
try {
|
2011-09-28 07:27:46 +08:00
|
|
|
|
if (Console.OutputEncoding.IsSingleByte)
|
|
|
|
|
Console.OutputEncoding = new UTF8Encoding(false);
|
2011-09-22 10:55:30 +08:00
|
|
|
|
|
|
|
|
|
Log.n("");
|
2012-01-10 06:02:47 +08:00
|
|
|
|
Log.n("de4dot v{0} Copyright (C) 2011-2012 de4dot@gmail.com", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version);
|
2011-09-22 10:55:30 +08:00
|
|
|
|
Log.n("Latest version and source code: https://github.com/0xd4d/de4dot");
|
|
|
|
|
Log.n("");
|
|
|
|
|
|
|
|
|
|
var options = new FilesDeobfuscator.Options();
|
|
|
|
|
parseCommandLine(args, options);
|
|
|
|
|
new FilesDeobfuscator(options).doIt();
|
|
|
|
|
}
|
2012-02-15 04:51:31 +08:00
|
|
|
|
catch (ExitException ex) {
|
|
|
|
|
exitCode = ex.code;
|
|
|
|
|
}
|
2011-09-22 10:55:30 +08:00
|
|
|
|
catch (UserException ex) {
|
|
|
|
|
Log.e("ERROR: {0}", ex.Message);
|
2012-02-15 04:51:31 +08:00
|
|
|
|
exitCode = 1;
|
2011-09-22 10:55:30 +08:00
|
|
|
|
}
|
|
|
|
|
catch (Exception ex) {
|
2012-05-10 01:32:52 +08:00
|
|
|
|
if (printFullStackTrace()) {
|
|
|
|
|
printStackTrace(ex);
|
|
|
|
|
Log.e("\nTry the latest version before reporting this problem!");
|
|
|
|
|
Log.e("Send bug reports to de4dot@gmail.com or go to https://github.com/0xd4d/de4dot/issues");
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
Log.e("\n\n");
|
|
|
|
|
Log.e("Hmmmm... something didn't work. Try the latest version. ({0})", ex.GetType());
|
|
|
|
|
Log.e("If it's a supported obfuscator, it could be a bug or a new obfuscator version.");
|
|
|
|
|
Log.e("If it's an unsupported obfuscator, make sure the methods are decrypted!");
|
|
|
|
|
Log.e("Send bug reports to de4dot@gmail.com or go to https://github.com/0xd4d/de4dot/issues");
|
|
|
|
|
}
|
2012-02-15 04:51:31 +08:00
|
|
|
|
exitCode = 1;
|
2011-09-22 10:55:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
2012-02-15 04:51:31 +08:00
|
|
|
|
if (isN00bUser()) {
|
|
|
|
|
Console.Error.WriteLine("\n\nPress any key to exit...\n");
|
|
|
|
|
try {
|
|
|
|
|
Console.ReadKey(true);
|
|
|
|
|
}
|
|
|
|
|
catch (InvalidOperationException) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return exitCode;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-10 01:32:52 +08:00
|
|
|
|
static bool printFullStackTrace() {
|
|
|
|
|
if (Log.isAtLeast(Log.LogLevel.verbose))
|
|
|
|
|
return true;
|
|
|
|
|
if (hasEnv("STACKTRACE"))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static bool hasEnv(string name) {
|
|
|
|
|
foreach (var tmp in Environment.GetEnvironmentVariables().Keys) {
|
|
|
|
|
var env = tmp as string;
|
|
|
|
|
if (env == null)
|
|
|
|
|
continue;
|
|
|
|
|
if (string.Equals(env, name, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-02-15 04:51:31 +08:00
|
|
|
|
static bool isN00bUser() {
|
2012-05-10 01:32:52 +08:00
|
|
|
|
if (hasEnv("VisualStudioDir"))
|
2012-02-15 04:51:31 +08:00
|
|
|
|
return false;
|
2012-05-10 01:32:52 +08:00
|
|
|
|
return hasEnv("windir") && !hasEnv("PROMPT");
|
2011-09-22 10:55:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
2011-12-09 16:02:06 +08:00
|
|
|
|
public static void printStackTrace(Exception ex, Log.LogLevel logLevel = Log.LogLevel.error) {
|
|
|
|
|
var line = new string('-', 78);
|
|
|
|
|
Log.log(logLevel, "\n\n");
|
|
|
|
|
Log.log(logLevel, line);
|
|
|
|
|
Log.log(logLevel, "Stack trace:\n{0}", ex.StackTrace);
|
|
|
|
|
Log.log(logLevel, "\n\nERROR: Caught an exception:\n");
|
|
|
|
|
Log.log(logLevel, line);
|
|
|
|
|
Log.log(logLevel, "Message:");
|
|
|
|
|
Log.log(logLevel, " {0}", ex.Message);
|
|
|
|
|
Log.log(logLevel, "Type:");
|
|
|
|
|
Log.log(logLevel, " {0}", ex.GetType());
|
|
|
|
|
Log.log(logLevel, line);
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-22 10:55:30 +08:00
|
|
|
|
static void parseCommandLine(string[] args, FilesDeobfuscator.Options options) {
|
|
|
|
|
new CommandLineParser(deobfuscatorInfos, options).parse(args);
|
|
|
|
|
|
|
|
|
|
Log.vv("Args:");
|
|
|
|
|
Log.indent();
|
|
|
|
|
foreach (var arg in args)
|
|
|
|
|
Log.vv("{0}", Utils.toCsharpString(arg));
|
|
|
|
|
Log.deIndent();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|