Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #include <stdio.h> | 1 #include <stdio.h> |
| 2 #include <stdlib.h> | 2 #include <stdlib.h> |
| 3 #include <string.h> | 3 #include <string.h> |
| 4 | 4 |
| 5 #include "libdis.h" | 5 #include "libdis.h" |
| 6 #include "ia32_insn.h" | 6 #include "ia32_insn.h" |
| 7 #include "ia32_invariant.h" | 7 #include "ia32_invariant.h" |
| 8 #include "x86_operand_list.h" | 8 #include "x86_operand_list.h" |
| 9 | 9 |
| 10 | 10 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 /* ensure we are all NULLed up */ | 28 /* ensure we are all NULLed up */ |
| 29 memset( insn, 0, sizeof(x86_insn_t) ); | 29 memset( insn, 0, sizeof(x86_insn_t) ); |
| 30 insn->addr = buf_rva + offset; | 30 insn->addr = buf_rva + offset; |
| 31 insn->offset = offset; | 31 insn->offset = offset; |
| 32 /* default to invalid insn */ | 32 /* default to invalid insn */ |
| 33 insn->type = insn_invalid; | 33 insn->type = insn_invalid; |
| 34 insn->group = insn_none; | 34 insn->group = insn_none; |
| 35 | 35 |
| 36 if ( offset >= buf_len ) { | 36 if ( offset >= buf_len ) { |
| 37 /* another caller screwup ;) */ | 37 /* another caller screwup ;) */ |
| 38 x86_report_error(report_disasm_bounds, (void*)(long)buf_rva+offs et); | 38 x86_report_error(report_disasm_bounds, (void*)(long)(buf_rva+off set)); |
|
brucedawson
2016/01/08 21:19:11
Too late for this change, but why are we casting t
| |
| 39 return 0; | 39 return 0; |
| 40 } | 40 } |
| 41 | 41 |
| 42 len = buf_len - offset; | 42 len = buf_len - offset; |
| 43 | 43 |
| 44 /* copy enough bytes for disassembly into buffer : this | 44 /* copy enough bytes for disassembly into buffer : this |
| 45 * helps prevent buffer overruns at the end of a file */ | 45 * helps prevent buffer overruns at the end of a file */ |
| 46 memset( bytes, 0, MAX_INSTRUCTION_SIZE ); | 46 memset( bytes, 0, MAX_INSTRUCTION_SIZE ); |
| 47 memcpy( bytes, &buf[offset], (len < MAX_INSTRUCTION_SIZE) ? len : | 47 memcpy( bytes, &buf[offset], (len < MAX_INSTRUCTION_SIZE) ? len : |
| 48 MAX_INSTRUCTION_SIZE ); | 48 MAX_INSTRUCTION_SIZE ); |
| 49 | 49 |
| 50 /* actually do the disassembly */ | 50 /* actually do the disassembly */ |
| 51 /* TODO: allow switching when more disassemblers are added */ | 51 /* TODO: allow switching when more disassemblers are added */ |
| 52 size = ia32_disasm_addr( bytes, len, insn); | 52 size = ia32_disasm_addr( bytes, len, insn); |
| 53 | 53 |
| 54 /* check and see if we had an invalid instruction */ | 54 /* check and see if we had an invalid instruction */ |
| 55 if (! size ) { | 55 if (! size ) { |
| 56 x86_report_error(report_invalid_insn, (void*)(long)buf_rva+offse t ); | 56 x86_report_error(report_invalid_insn, (void*)(long)(buf_rva+offs et)); |
| 57 return 0; | 57 return 0; |
| 58 } | 58 } |
| 59 | 59 |
| 60 /* check if we overran the end of the buffer */ | 60 /* check if we overran the end of the buffer */ |
| 61 if ( size > len ) { | 61 if ( size > len ) { |
| 62 x86_report_error( report_insn_bounds, (void*)(long)buf_rva + off set ); | 62 x86_report_error( report_insn_bounds, (void*)(long)(buf_rva + of fset)); |
| 63 MAKE_INVALID( insn, bytes ); | 63 MAKE_INVALID( insn, bytes ); |
| 64 return 0; | 64 return 0; |
| 65 } | 65 } |
| 66 | 66 |
| 67 /* fill bytes field of insn */ | 67 /* fill bytes field of insn */ |
| 68 memcpy( insn->bytes, bytes, size ); | 68 memcpy( insn->bytes, bytes, size ); |
| 69 | 69 |
| 70 return size; | 70 return size; |
| 71 } | 71 } |
| 72 | 72 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 201 | 201 |
| 202 return ia32_disasm_invariant(buf, buf_len, inv); | 202 return ia32_disasm_invariant(buf, buf_len, inv); |
| 203 } | 203 } |
| 204 size_t x86_size_disasm( unsigned char *buf, unsigned int buf_len ) { | 204 size_t x86_size_disasm( unsigned char *buf, unsigned int buf_len ) { |
| 205 if (! buf || ! buf_len ) { | 205 if (! buf || ! buf_len ) { |
| 206 return(0); | 206 return(0); |
| 207 } | 207 } |
| 208 | 208 |
| 209 return ia32_disasm_size(buf, buf_len); | 209 return ia32_disasm_size(buf, buf_len); |
| 210 } | 210 } |
| OLD | NEW |