summaryrefslogtreecommitdiffstats
path: root/courgette
diff options
context:
space:
mode:
Diffstat (limited to 'courgette')
-rw-r--r--courgette/courgette.h2
-rw-r--r--courgette/courgette_tool.cc58
2 files changed, 51 insertions, 9 deletions
diff --git a/courgette/courgette.h b/courgette/courgette.h
index a58f16d..2cd4cd7 100644
--- a/courgette/courgette.h
+++ b/courgette/courgette.h
@@ -77,7 +77,6 @@ Status ApplyEnsemblePatch(SourceStream* old, SourceStream* patch,
// Returns C_OK unless something went wrong.
// This function first validates that the patch file has a proper header, so the
// function can be used to 'try' a patch.
-
Status ApplyEnsemblePatch(const FilePath::CharType* old_file_name,
const FilePath::CharType* patch_file_name,
const FilePath::CharType* new_file_name);
@@ -112,7 +111,6 @@ Status ParseDetectedExecutable(const void* buffer, size_t length,
// sets |*output| to NULL
Status Encode(AssemblyProgram* program, EncodedProgram** output);
-
// Serializes |encoded| into the stream set.
// Returns C_OK if succeeded, otherwise returns an error status.
Status WriteEncodedProgram(EncodedProgram* encoded, SinkStreamSet* sink);
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 <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;
}