Commit 45e2d0a9 authored by dgarrett@chromium.org's avatar dgarrett@chromium.org

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
parent 753ab8c8
...@@ -77,7 +77,6 @@ Status ApplyEnsemblePatch(SourceStream* old, SourceStream* patch, ...@@ -77,7 +77,6 @@ Status ApplyEnsemblePatch(SourceStream* old, SourceStream* patch,
// Returns C_OK unless something went wrong. // Returns C_OK unless something went wrong.
// This function first validates that the patch file has a proper header, so the // This function first validates that the patch file has a proper header, so the
// function can be used to 'try' a patch. // function can be used to 'try' a patch.
Status ApplyEnsemblePatch(const FilePath::CharType* old_file_name, Status ApplyEnsemblePatch(const FilePath::CharType* old_file_name,
const FilePath::CharType* patch_file_name, const FilePath::CharType* patch_file_name,
const FilePath::CharType* new_file_name); const FilePath::CharType* new_file_name);
...@@ -112,7 +111,6 @@ Status ParseDetectedExecutable(const void* buffer, size_t length, ...@@ -112,7 +111,6 @@ Status ParseDetectedExecutable(const void* buffer, size_t length,
// sets |*output| to NULL // sets |*output| to NULL
Status Encode(AssemblyProgram* program, EncodedProgram** output); Status Encode(AssemblyProgram* program, EncodedProgram** output);
// Serializes |encoded| into the stream set. // Serializes |encoded| into the stream set.
// Returns C_OK if succeeded, otherwise returns an error status. // Returns C_OK if succeeded, otherwise returns an error status.
Status WriteEncodedProgram(EncodedProgram* encoded, SinkStreamSet* sink); Status WriteEncodedProgram(EncodedProgram* encoded, SinkStreamSet* sink);
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
void PrintHelp() { void PrintHelp() {
fprintf(stderr, fprintf(stderr,
"Usage:\n" "Usage:\n"
" courgette -supported <executable_file>\n"
" courgette -dis <executable_file> <binary_assembly_file>\n" " courgette -dis <executable_file> <binary_assembly_file>\n"
" courgette -asm <binary_assembly_file> <executable_file>\n" " courgette -asm <binary_assembly_file> <executable_file>\n"
" courgette -disadj <executable_file> <reference> <binary_assembly_file>\n" " courgette -disadj <executable_file> <reference> <binary_assembly_file>\n"
...@@ -105,6 +106,41 @@ void Disassemble(const FilePath& input_file, ...@@ -105,6 +106,41 @@ void Disassemble(const FilePath& input_file,
WriteSinkToFile(&sink, output_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, void DisassembleAndAdjust(const FilePath& program_file,
const FilePath& model_file, const FilePath& model_file,
const FilePath& output_file) { const FilePath& output_file) {
...@@ -391,6 +427,7 @@ int main(int argc, const char* argv[]) { ...@@ -391,6 +427,7 @@ int main(int argc, const char* argv[]) {
logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS); logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS);
logging::SetMinLogLevel(logging::LOG_VERBOSE); logging::SetMinLogLevel(logging::LOG_VERBOSE);
bool cmd_sup = command_line.HasSwitch("supported");
bool cmd_dis = command_line.HasSwitch("dis"); bool cmd_dis = command_line.HasSwitch("dis");
bool cmd_asm = command_line.HasSwitch("asm"); bool cmd_asm = command_line.HasSwitch("asm");
bool cmd_disadj = command_line.HasSwitch("disadj"); bool cmd_disadj = command_line.HasSwitch("disadj");
...@@ -415,19 +452,24 @@ int main(int argc, const char* argv[]) { ...@@ -415,19 +452,24 @@ int main(int argc, const char* argv[]) {
if (!base::StringToInt(repeat_switch, &repeat_count)) if (!base::StringToInt(repeat_switch, &repeat_count))
repeat_count = 1; repeat_count = 1;
if (cmd_dis + cmd_asm + cmd_disadj + cmd_make_patch + cmd_apply_patch + if (cmd_sup + cmd_dis + cmd_asm + cmd_disadj + cmd_make_patch +
cmd_make_bsdiff_patch + cmd_apply_bsdiff_patch + cmd_apply_patch + cmd_make_bsdiff_patch + cmd_apply_bsdiff_patch +
cmd_spread_1_adjusted + cmd_spread_1_unadjusted cmd_spread_1_adjusted + cmd_spread_1_unadjusted
!= 1) != 1)
UsageProblem( UsageProblem(
"Must have exactly one of:\n" "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) { while (repeat_count-- > 0) {
if (cmd_dis) { if (cmd_sup) {
if (values.size() != 2) if (values.size() != 1)
UsageProblem("-dis <executable_file> <courgette_file>"); UsageProblem("-supported <executable_file>");
Disassemble(values[0], values[1]); 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) { } else if (cmd_asm) {
if (values.size() != 2) if (values.size() != 2)
UsageProblem("-asm <courgette_file_input> <executable_file_output>"); UsageProblem("-asm <courgette_file_input> <executable_file_output>");
...@@ -461,4 +503,6 @@ int main(int argc, const char* argv[]) { ...@@ -461,4 +503,6 @@ int main(int argc, const char* argv[]) {
UsageProblem("No operation specified"); UsageProblem("No operation specified");
} }
} }
return 0;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment