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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 BufferedFileReader buffer(input_file, "input"); | 117 BufferedFileReader buffer(input_file, "input"); |
118 | 118 |
119 courgette::ExecutableType type; | 119 courgette::ExecutableType type; |
120 size_t detected_length; | 120 size_t detected_length; |
121 | 121 |
122 DetectExecutableType(buffer.data(), buffer.length(), &type, &detected_length); | 122 DetectExecutableType(buffer.data(), buffer.length(), &type, &detected_length); |
123 | 123 |
124 // If the detection fails, we just fall back on UNKNOWN | 124 // If the detection fails, we just fall back on UNKNOWN |
125 std::string format = "Unsupported"; | 125 std::string format = "Unsupported"; |
126 | 126 |
127 switch (type) | 127 switch (type) { |
128 { | |
129 case courgette::EXE_UNKNOWN: | 128 case courgette::EXE_UNKNOWN: |
130 break; | 129 break; |
131 | 130 |
132 case courgette::EXE_WIN_32_X86: | 131 case courgette::EXE_WIN_32_X86: |
133 format = "Windows 32 PE"; | 132 format = "Windows 32 PE"; |
134 result = true; | 133 result = true; |
135 break; | 134 break; |
136 | 135 |
137 case courgette::EXE_ELF_32_X86: | 136 case courgette::EXE_ELF_32_X86: |
138 format = "ELF 32 X86"; | 137 format = "ELF 32 X86"; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 // original file's stream and the new file's stream. This is completely | 206 // original file's stream and the new file's stream. This is completely |
208 // uninteresting to users, but it is handy for seeing how much each which | 207 // uninteresting to users, but it is handy for seeing how much each which |
209 // streams are contributing to the final file size. Adjustment is optional. | 208 // streams are contributing to the final file size. Adjustment is optional. |
210 void DisassembleAdjustDiff(const base::FilePath& model_file, | 209 void DisassembleAdjustDiff(const base::FilePath& model_file, |
211 const base::FilePath& program_file, | 210 const base::FilePath& program_file, |
212 const base::FilePath& output_file_root, | 211 const base::FilePath& output_file_root, |
213 bool adjust) { | 212 bool adjust) { |
214 BufferedFileReader model_buffer(model_file, "old"); | 213 BufferedFileReader model_buffer(model_file, "old"); |
215 BufferedFileReader program_buffer(program_file, "new"); | 214 BufferedFileReader program_buffer(program_file, "new"); |
216 | 215 |
| 216 auto parser = adjust ? courgette::ParseDetectedExecutableWithAnnotation |
| 217 : courgette::ParseDetectedExecutable; |
| 218 |
217 std::unique_ptr<courgette::AssemblyProgram> model; | 219 std::unique_ptr<courgette::AssemblyProgram> model; |
218 const courgette::Status parse_model_status = | 220 const courgette::Status parse_model_status = |
219 courgette::ParseDetectedExecutable(model_buffer.data(), | 221 parser(model_buffer.data(), model_buffer.length(), &model); |
220 model_buffer.length(), &model); | |
221 if (parse_model_status != courgette::C_OK) | 222 if (parse_model_status != courgette::C_OK) |
222 Problem("Can't parse model input (code = %d).", parse_model_status); | 223 Problem("Can't parse model input (code = %d).", parse_model_status); |
223 | 224 |
224 std::unique_ptr<courgette::AssemblyProgram> program; | 225 std::unique_ptr<courgette::AssemblyProgram> program; |
225 const courgette::Status parse_program_status = | 226 const courgette::Status parse_program_status = |
226 courgette::ParseDetectedExecutable(program_buffer.data(), | 227 parser(program_buffer.data(), program_buffer.length(), &program); |
227 program_buffer.length(), &program); | |
228 if (parse_program_status != courgette::C_OK) | 228 if (parse_program_status != courgette::C_OK) |
229 Problem("Can't parse program input (code = %d).", parse_program_status); | 229 Problem("Can't parse program input (code = %d).", parse_program_status); |
230 | 230 |
231 if (adjust) { | 231 if (adjust) { |
232 const courgette::Status adjust_status = Adjust(*model, program.get()); | 232 const courgette::Status adjust_status = Adjust(*model, program.get()); |
233 if (adjust_status != courgette::C_OK) | 233 if (adjust_status != courgette::C_OK) |
234 Problem("Can't adjust program."); | 234 Problem("Can't adjust program."); |
235 } | 235 } |
236 | 236 |
237 std::unique_ptr<courgette::EncodedProgram> encoded_program; | 237 std::unique_ptr<courgette::EncodedProgram> encoded_program; |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 UsageProblem("-gen1[au] <old_file> <new_file> <patch_files_root>"); | 514 UsageProblem("-gen1[au] <old_file> <new_file> <patch_files_root>"); |
515 DisassembleAdjustDiff(values[0], values[1], values[2], | 515 DisassembleAdjustDiff(values[0], values[1], values[2], |
516 cmd_spread_1_adjusted); | 516 cmd_spread_1_adjusted); |
517 } else { | 517 } else { |
518 UsageProblem("No operation specified"); | 518 UsageProblem("No operation specified"); |
519 } | 519 } |
520 } | 520 } |
521 | 521 |
522 return 0; | 522 return 0; |
523 } | 523 } |
OLD | NEW |