From 45e2d0a90855351b80681a84e071f0a55a18cd08 Mon Sep 17 00:00:00 2001 From: "dgarrett@chromium.org" Date: Mon, 21 Nov 2011 20:26:56 +0000 Subject: Add -supported command line option to describe if a given file is supported and what type of executable it is, if it is. BUG=None TEST=None Review URL: http://codereview.chromium.org/8558009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110993 0039d316-1c4b-4281-b951-d872f2087c98 --- courgette/courgette_tool.cc | 58 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 51 insertions(+), 7 deletions(-) (limited to 'courgette/courgette_tool.cc') diff --git a/courgette/courgette_tool.cc b/courgette/courgette_tool.cc index cd39829..2714e0f 100644 --- a/courgette/courgette_tool.cc +++ b/courgette/courgette_tool.cc @@ -22,6 +22,7 @@ void PrintHelp() { fprintf(stderr, "Usage:\n" + " courgette -supported \n" " courgette -dis \n" " courgette -asm \n" " courgette -disadj \n" @@ -105,6 +106,41 @@ void Disassemble(const FilePath& input_file, WriteSinkToFile(&sink, output_file); } +bool Supported(const FilePath& input_file) { + bool result = false; + + std::string buffer = ReadOrFail(input_file, "input"); + + courgette::ExecutableType type; + size_t detected_length; + + DetectExecutableType(buffer.c_str(), buffer.length(), + &type, + &detected_length); + + // If the detection fails, we just fall back on UNKNOWN + std::string format = "Unsupported"; + + switch (type) + { + case courgette::EXE_UNKNOWN: + break; + + case courgette::EXE_WIN_32_X86: + format = "Windows 32 PE"; + result = true; + break; + + case courgette::EXE_ELF_32_X86: + format = "ELF 32 X86"; + result = true; + break; + } + + printf("%s Executable\n", format.c_str()); + return result; +} + void DisassembleAndAdjust(const FilePath& program_file, const FilePath& model_file, const FilePath& output_file) { @@ -391,6 +427,7 @@ int main(int argc, const char* argv[]) { logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS); logging::SetMinLogLevel(logging::LOG_VERBOSE); + bool cmd_sup = command_line.HasSwitch("supported"); bool cmd_dis = command_line.HasSwitch("dis"); bool cmd_asm = command_line.HasSwitch("asm"); bool cmd_disadj = command_line.HasSwitch("disadj"); @@ -415,19 +452,24 @@ int main(int argc, const char* argv[]) { if (!base::StringToInt(repeat_switch, &repeat_count)) repeat_count = 1; - if (cmd_dis + cmd_asm + cmd_disadj + cmd_make_patch + cmd_apply_patch + - cmd_make_bsdiff_patch + cmd_apply_bsdiff_patch + + if (cmd_sup + cmd_dis + cmd_asm + cmd_disadj + cmd_make_patch + + cmd_apply_patch + cmd_make_bsdiff_patch + cmd_apply_bsdiff_patch + cmd_spread_1_adjusted + cmd_spread_1_unadjusted != 1) UsageProblem( "Must have exactly one of:\n" - " -asm, -dis, -disadj, -gen or -apply, -genbsdiff or -applybsdiff."); + " -supported -asm, -dis, -disadj, -gen or -apply, -genbsdiff" + " or -applybsdiff."); while (repeat_count-- > 0) { - if (cmd_dis) { - if (values.size() != 2) - UsageProblem("-dis "); - Disassemble(values[0], values[1]); + if (cmd_sup) { + if (values.size() != 1) + UsageProblem("-supported "); + return !Supported(values[0]); + } else if (cmd_dis) { + if (values.size() != 2) + UsageProblem("-dis "); + Disassemble(values[0], values[1]); } else if (cmd_asm) { if (values.size() != 2) UsageProblem("-asm "); @@ -461,4 +503,6 @@ int main(int argc, const char* argv[]) { UsageProblem("No operation specified"); } } + + return 0; } -- cgit v1.1