| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <vector> | 5 #include <vector> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/at_exit.h" | 8 #include "base/at_exit.h" |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 if (static_cast<size_t>(count) != sink->Length()) | 78 if (static_cast<size_t>(count) != sink->Length()) |
| 79 Problem("Incomplete write."); | 79 Problem("Incomplete write."); |
| 80 } | 80 } |
| 81 | 81 |
| 82 void Disassemble(const std::wstring& input_file, | 82 void Disassemble(const std::wstring& input_file, |
| 83 const std::wstring& output_file) { | 83 const std::wstring& output_file) { |
| 84 std::string buffer = ReadOrFail(input_file, "input"); | 84 std::string buffer = ReadOrFail(input_file, "input"); |
| 85 | 85 |
| 86 courgette::AssemblyProgram* program = NULL; | 86 courgette::AssemblyProgram* program = NULL; |
| 87 const courgette::Status parse_status = | 87 const courgette::Status parse_status = |
| 88 courgette::ParseWin32X86PE(buffer.c_str(), buffer.length(), &program); | 88 courgette::ParseDetectedExecutable(buffer.c_str(), buffer.length(), |
| 89 &program); |
| 89 | 90 |
| 90 if (parse_status != courgette::C_OK) | 91 if (parse_status != courgette::C_OK) |
| 91 Problem("Can't parse input."); | 92 Problem("Can't parse input."); |
| 92 | 93 |
| 93 courgette::EncodedProgram* encoded = NULL; | 94 courgette::EncodedProgram* encoded = NULL; |
| 94 const courgette::Status encode_status = Encode(program, &encoded); | 95 const courgette::Status encode_status = Encode(program, &encoded); |
| 95 | 96 |
| 96 courgette::DeleteAssemblyProgram(program); | 97 courgette::DeleteAssemblyProgram(program); |
| 97 | 98 |
| 98 if (encode_status != courgette::C_OK) | 99 if (encode_status != courgette::C_OK) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 115 } | 116 } |
| 116 | 117 |
| 117 void DisassembleAndAdjust(const std::wstring& program_file, | 118 void DisassembleAndAdjust(const std::wstring& program_file, |
| 118 const std::wstring& model_file, | 119 const std::wstring& model_file, |
| 119 const std::wstring& output_file) { | 120 const std::wstring& output_file) { |
| 120 std::string program_buffer = ReadOrFail(program_file, "program"); | 121 std::string program_buffer = ReadOrFail(program_file, "program"); |
| 121 std::string model_buffer = ReadOrFail(model_file, "reference"); | 122 std::string model_buffer = ReadOrFail(model_file, "reference"); |
| 122 | 123 |
| 123 courgette::AssemblyProgram* program = NULL; | 124 courgette::AssemblyProgram* program = NULL; |
| 124 const courgette::Status parse_program_status = | 125 const courgette::Status parse_program_status = |
| 125 courgette::ParseWin32X86PE(program_buffer.c_str(), | 126 courgette::ParseDetectedExecutable(program_buffer.c_str(), |
| 126 program_buffer.length(), | 127 program_buffer.length(), |
| 127 &program); | 128 &program); |
| 128 if (parse_program_status != courgette::C_OK) | 129 if (parse_program_status != courgette::C_OK) |
| 129 Problem("Can't parse program input."); | 130 Problem("Can't parse program input."); |
| 130 | 131 |
| 131 courgette::AssemblyProgram* model = NULL; | 132 courgette::AssemblyProgram* model = NULL; |
| 132 const courgette::Status parse_model_status = | 133 const courgette::Status parse_model_status = |
| 133 courgette::ParseWin32X86PE(model_buffer.c_str(), | 134 courgette::ParseDetectedExecutable(model_buffer.c_str(), |
| 134 model_buffer.length(), | 135 model_buffer.length(), |
| 135 &model); | 136 &model); |
| 136 if (parse_model_status != courgette::C_OK) | 137 if (parse_model_status != courgette::C_OK) |
| 137 Problem("Can't parse model input."); | 138 Problem("Can't parse model input."); |
| 138 | 139 |
| 139 const courgette::Status adjust_status = Adjust(*model, program); | 140 const courgette::Status adjust_status = Adjust(*model, program); |
| 140 if (adjust_status != courgette::C_OK) | 141 if (adjust_status != courgette::C_OK) |
| 141 Problem("Can't adjust program."); | 142 Problem("Can't adjust program."); |
| 142 | 143 |
| 143 courgette::EncodedProgram* encoded = NULL; | 144 courgette::EncodedProgram* encoded = NULL; |
| 144 const courgette::Status encode_status = Encode(program, &encoded); | 145 const courgette::Status encode_status = Encode(program, &encoded); |
| 145 | 146 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 171 // streams are contributing to the final file size. Adjustment is optional. | 172 // streams are contributing to the final file size. Adjustment is optional. |
| 172 void DisassembleAdjustDiff(const std::wstring& model_file, | 173 void DisassembleAdjustDiff(const std::wstring& model_file, |
| 173 const std::wstring& program_file, | 174 const std::wstring& program_file, |
| 174 const std::wstring& output_file_root, | 175 const std::wstring& output_file_root, |
| 175 bool adjust) { | 176 bool adjust) { |
| 176 std::string model_buffer = ReadOrFail(model_file, "'old'"); | 177 std::string model_buffer = ReadOrFail(model_file, "'old'"); |
| 177 std::string program_buffer = ReadOrFail(program_file, "'new'"); | 178 std::string program_buffer = ReadOrFail(program_file, "'new'"); |
| 178 | 179 |
| 179 courgette::AssemblyProgram* model = NULL; | 180 courgette::AssemblyProgram* model = NULL; |
| 180 const courgette::Status parse_model_status = | 181 const courgette::Status parse_model_status = |
| 181 courgette::ParseWin32X86PE(model_buffer.c_str(), | 182 courgette::ParseDetectedExecutable(model_buffer.c_str(), |
| 182 model_buffer.length(), | 183 model_buffer.length(), |
| 183 &model); | 184 &model); |
| 184 if (parse_model_status != courgette::C_OK) | 185 if (parse_model_status != courgette::C_OK) |
| 185 Problem("Can't parse model input."); | 186 Problem("Can't parse model input."); |
| 186 | 187 |
| 187 courgette::AssemblyProgram* program = NULL; | 188 courgette::AssemblyProgram* program = NULL; |
| 188 const courgette::Status parse_program_status = | 189 const courgette::Status parse_program_status = |
| 189 courgette::ParseWin32X86PE(program_buffer.c_str(), | 190 courgette::ParseDetectedExecutable(program_buffer.c_str(), |
| 190 program_buffer.length(), | 191 program_buffer.length(), |
| 191 &program); | 192 &program); |
| 192 if (parse_program_status != courgette::C_OK) | 193 if (parse_program_status != courgette::C_OK) |
| 193 Problem("Can't parse program input."); | 194 Problem("Can't parse program input."); |
| 194 | 195 |
| 195 if (adjust) { | 196 if (adjust) { |
| 196 const courgette::Status adjust_status = Adjust(*model, program); | 197 const courgette::Status adjust_status = Adjust(*model, program); |
| 197 if (adjust_status != courgette::C_OK) | 198 if (adjust_status != courgette::C_OK) |
| 198 Problem("Can't adjust program."); | 199 Problem("Can't adjust program."); |
| 199 } | 200 } |
| 200 | 201 |
| 201 courgette::EncodedProgram* encoded_program = NULL; | 202 courgette::EncodedProgram* encoded_program = NULL; |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 } else if (cmd_spread_1_adjusted || cmd_spread_1_unadjusted) { | 477 } else if (cmd_spread_1_adjusted || cmd_spread_1_unadjusted) { |
| 477 if (values.size() != 3) | 478 if (values.size() != 3) |
| 478 UsageProblem("-gen1[au] <old_file> <new_file> <patch_files_root>"); | 479 UsageProblem("-gen1[au] <old_file> <new_file> <patch_files_root>"); |
| 479 DisassembleAdjustDiff(values[0], values[1], values[2], | 480 DisassembleAdjustDiff(values[0], values[1], values[2], |
| 480 cmd_spread_1_adjusted); | 481 cmd_spread_1_adjusted); |
| 481 } else { | 482 } else { |
| 482 UsageProblem("No operation specified"); | 483 UsageProblem("No operation specified"); |
| 483 } | 484 } |
| 484 } | 485 } |
| 485 } | 486 } |
| OLD | NEW |