From f6db11ac0967ed5ffcc94f06174216b98f199df5 Mon Sep 17 00:00:00 2001 From: de4dot Date: Wed, 9 May 2012 19:32:52 +0200 Subject: [PATCH] Don't print the full stack trace. Too confusing for most people. --- de4dot.cui/Program.cs | 40 ++++++++++++++++++++++++++++++++++------ 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/de4dot.cui/Program.cs b/de4dot.cui/Program.cs index 9a772e25..b5ff9e53 100644 --- a/de4dot.cui/Program.cs +++ b/de4dot.cui/Program.cs @@ -79,9 +79,18 @@ namespace de4dot.cui { exitCode = 1; } catch (Exception ex) { - 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"); + 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"); + } exitCode = 1; } @@ -97,11 +106,30 @@ namespace de4dot.cui { return exitCode; } + 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; + } + static bool isN00bUser() { - var env = Environment.GetEnvironmentVariables(); - if (env["VisualStudioDir"] != null) + if (hasEnv("VisualStudioDir")) return false; - return env["windir"] != null && env["PROMPT"] == null; + return hasEnv("windir") && !hasEnv("PROMPT"); } public static void printStackTrace(Exception ex, Log.LogLevel logLevel = Log.LogLevel.error) {