Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Unified Diff: courgette/courgette_tool.cc

Issue 8558009: Add -supported command line option to describe if a given file is supported (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Add return value for -supported Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « courgette/courgette.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: courgette/courgette_tool.cc
diff --git a/courgette/courgette_tool.cc b/courgette/courgette_tool.cc
index cd398299d538dd27f8ad5f0c72b014863716c59c..2714e0fe8fe40c4bd447c0c30be5413a06edf784 100644
--- a/courgette/courgette_tool.cc
+++ b/courgette/courgette_tool.cc
@@ -22,6 +22,7 @@
void PrintHelp() {
fprintf(stderr,
"Usage:\n"
+ " courgette -supported <executable_file>\n"
" courgette -dis <executable_file> <binary_assembly_file>\n"
" courgette -asm <binary_assembly_file> <executable_file>\n"
" courgette -disadj <executable_file> <reference> <binary_assembly_file>\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 <executable_file> <courgette_file>");
- Disassemble(values[0], values[1]);
+ if (cmd_sup) {
+ if (values.size() != 1)
+ UsageProblem("-supported <executable_file>");
+ return !Supported(values[0]);
+ } else if (cmd_dis) {
+ if (values.size() != 2)
+ UsageProblem("-dis <executable_file> <courgette_file>");
+ Disassemble(values[0], values[1]);
} else if (cmd_asm) {
if (values.size() != 2)
UsageProblem("-asm <courgette_file_input> <executable_file_output>");
@@ -461,4 +503,6 @@ int main(int argc, const char* argv[]) {
UsageProblem("No operation specified");
}
}
+
+ return 0;
}
« no previous file with comments | « courgette/courgette.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698