Pause before exiting if not started from cmd.exe (n00b proof)

This commit is contained in:
de4dot 2012-02-14 21:51:31 +01:00
parent 9e16d9cd40
commit db9e7bb414
2 changed files with 32 additions and 3 deletions

View File

@ -280,7 +280,7 @@ namespace de4dot.cui {
} }
void exit(int exitCode) { void exit(int exitCode) {
Environment.Exit(exitCode); throw new ExitException(exitCode);
} }
void usage() { void usage() {

View File

@ -24,6 +24,13 @@ using de4dot.code;
using de4dot.code.deobfuscators; using de4dot.code.deobfuscators;
namespace de4dot.cui { namespace de4dot.cui {
class ExitException : Exception {
public readonly int code;
public ExitException(int code) {
this.code = code;
}
}
public class Program { public class Program {
static IList<IDeobfuscatorInfo> deobfuscatorInfos = createDeobfuscatorInfos(); static IList<IDeobfuscatorInfo> deobfuscatorInfos = createDeobfuscatorInfos();
@ -48,6 +55,8 @@ namespace de4dot.cui {
} }
public static int main(string[] args) { public static int main(string[] args) {
int exitCode = 0;
try { try {
if (Console.OutputEncoding.IsSingleByte) if (Console.OutputEncoding.IsSingleByte)
Console.OutputEncoding = new UTF8Encoding(false); Console.OutputEncoding = new UTF8Encoding(false);
@ -61,16 +70,36 @@ namespace de4dot.cui {
parseCommandLine(args, options); parseCommandLine(args, options);
new FilesDeobfuscator(options).doIt(); new FilesDeobfuscator(options).doIt();
} }
catch (ExitException ex) {
exitCode = ex.code;
}
catch (UserException ex) { catch (UserException ex) {
Log.e("ERROR: {0}", ex.Message); Log.e("ERROR: {0}", ex.Message);
exitCode = 1;
} }
catch (Exception ex) { catch (Exception ex) {
printStackTrace(ex); printStackTrace(ex);
Log.e("\nTry the latest version before reporting this problem!"); Log.e("\nTry the latest version before reporting this problem!");
return 1; exitCode = 1;
} }
return 0; if (isN00bUser()) {
Console.Error.WriteLine("\n\nPress any key to exit...\n");
try {
Console.ReadKey(true);
}
catch (InvalidOperationException) {
}
}
return exitCode;
}
static bool isN00bUser() {
var env = Environment.GetEnvironmentVariables();
if (env["VisualStudioDir"] != null)
return false;
return env["windir"] != null && env["PROMPT"] == null;
} }
public static void printStackTrace(Exception ex, Log.LogLevel logLevel = Log.LogLevel.error) { public static void printStackTrace(Exception ex, Log.LogLevel logLevel = Log.LogLevel.error) {