Stackdb
Stackdb is a stackable, multi-target and -level source debugger and memory forensics library.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
disasm.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2013 The University of Utah
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of
7  * the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 #ifndef __DISASM_H__
20 #define __DISASM_H__
21 
22 #include <mnemonics.h>
23 #include <distorm.h>
24 #include "common.h"
25 
26 typedef _InstructionType dis_inst_t;
27 typedef _RegisterType dis_reg_t;
28 
29 typedef enum {
32 } decode_t;
33 
34 struct inst_data {
38  uint8_t size;
39 };
40 
41 #define INST_NAME(inst_type) GET_MNEMONIC_NAME((inst_type))
42 #define REG_NAME(reg_type) GET_REGISTER_NAME((reg_type))
43 
44 extern char *const inst_type_names[];
45 
46 typedef enum {
47  INST_NONE = 0,
61 } inst_type_t;
62 
63 #define INST_TYPE_NAME(inst_type) (((inst_type) < (sizeof(inst_type_names) \
64  / sizeof(inst_type_names[0]))) \
65  ? inst_type_names[(inst_type)] : "UNKNOWN")
66 
67 typedef enum {
83 
84 #define INST_TO_CF_FLAG(inst) (1 << (inst))
85 
86 #define LOGDUMPDISASMCFIDATA(dl,lt,idata) \
87  vdebugc((dl),(lt), \
88  "cf_inst_data(%s:+%"PRIdOFFSET":%s%s%s%s:disp=%"PRIu64"," \
89  "target=0x%"PRIxADDR")\n", \
90  INST_TYPE_NAME((idata)->type),(idata)->offset, \
91  ((idata)->cf.is_relative) ? "relative," : "", \
92  ((idata)->cf.is_mem) ? "mem," : "", \
93  ((idata)->cf.is_reg) ? "reg," : "", \
94  ((idata)->cf.target_in_segment) ? "target_in_segment," : "", \
95  ((idata)->cf.target_is_valid) ? "target_is_valid," : "", \
96  (idata)->cf.disp,(idata)->target);
97 
98 struct cf_inst_data {
101  uint8_t size;
102 
103  struct {
104  int is_relative:1,
105  is_mem:1,
106  is_reg:1,
108  target_is_valid:1;
109 
110  uint64_t disp;
111  union {
112  /* If it's an interrupt, which number. */
113  uint8_t intnum;
114  /* If it's an indirect jump/call, which register or mem
115  * contains the target address.
116  */
117  struct {
120  uint8_t scale;
121  };
123  /* If it's a relative branch, the offset. */
125  /* If it's an absolute branch, the dest addr. */
127  };
128  /* If the base address of the bytes to disasm is available, and the
129  * branch is an absolute branch, we can compute the actual
130  * destination.
131  */
133  } cf;
134 };
135 
136 struct disasm_data {
137  struct bsymbol *bsymbol;
139  unsigned int len;
140  unsigned char *code;
141 };
142 
143 #endif /* __DISASM_H__ */
uint8_t intnum
Definition: disasm.h:113
SMOFFSET offset
Definition: disasm.h:35
uint8_t size
Definition: disasm.h:38
decode_t
Definition: disasm.h:29
struct bsymbol * bsymbol
Definition: disasm.h:137
uint8_t size
Definition: disasm.h:101
int is_mem
Definition: disasm.h:104
OFFSET offset
Definition: disasm.h:100
uint8_t scale
Definition: disasm.h:120
uint64_t disp
Definition: disasm.h:110
inst_type_t type
Definition: disasm.h:99
int is_relative
Definition: disasm.h:104
int32_t SMOFFSET
Definition: common.h:100
int target_in_segment
Definition: disasm.h:104
OFFSET reloffset
Definition: disasm.h:124
int32_t OFFSET
Definition: common.h:65
ADDR start
Definition: disasm.h:138
dis_reg_t index_reg
Definition: disasm.h:119
_InstructionType dis_inst_t
Definition: disasm.h:26
int target_is_valid
Definition: disasm.h:104
unsigned int len
Definition: disasm.h:139
inst_cf_flags_t
Definition: disasm.h:67
int is_reg
Definition: disasm.h:104
struct cf_inst_data::@12 cf
ADDR target
Definition: disasm.h:132
char *const inst_type_names[]
Definition: disasm.c:641
_RegisterType dis_reg_t
Definition: disasm.h:27
uint32_t ADDR
Definition: common.h:64
dis_inst_t type
Definition: disasm.h:36
dis_reg_t base_reg
Definition: disasm.h:118
decode_t dtype
Definition: disasm.h:37
inst_type_t
Definition: disasm.h:46
unsigned char * code
Definition: disasm.h:140
ADDR mem
Definition: disasm.h:122
ADDR addr
Definition: disasm.h:126