IDA C++ SDK 9.2
Loading...
Searching...
No Matches
ua.hpp
Go to the documentation of this file.
1/*
2 * Interactive disassembler (IDA).
3 * Copyright (c) 1990-2025 Hex-Rays
4 * ALL RIGHTS RESERVED.
5 *
6 */
7
8#ifndef _UA_HPP
9#define _UA_HPP
10
11#include <kernwin.hpp> // for btoa()
12#include <lines.hpp> // for colors
13#include <xref.hpp> // add_cref()
14#include <bytes.hpp> // get_byte(), ...
15
55
56struct procmod_t;
57struct processor_t;
58struct asm_t;
59
62
63//--------------------------------------------------------------------------
64// T Y P E O F O P E R A N D
65//--------------------------------------------------------------------------
66typedef uchar optype_t;
81const optype_t
82 o_void = 0,
83 o_reg = 1,
84 o_mem = 2,
89 o_displ = 4,
92 o_imm = 5,
93 o_far = 6,
94 o_near = 7,
103
154
155//--------------------------------------------------------------------------
156// O P E R A N D O F I N S T R U C T I O N
157//--------------------------------------------------------------------------
161
169class op_t
170{
171public:
172
175 uchar n = 0;
176
179
189 char offb = 0;
190
195 char offo = 0;
196
202#define OF_NO_BASE_DISP 0x80
206#define OF_OUTER_DISP 0x40
209#define PACK_FORM_DEF 0x20
211#define OF_NUMBER 0x10
212#define OF_SHOW 0x08
214
216 void set_shown() { flags |= OF_SHOW; }
218 void clr_shown() { flags &= ~OF_SHOW; }
220 bool shown() const { return (flags & OF_SHOW) != 0; }
221
230// from here..
231#define dt_byte 0
232#define dt_word 1
233#define dt_dword 2
234#define dt_float 3
235#define dt_double 4
236#define dt_tbyte 5
237#define dt_packreal 6
238// ...to here the order should not be changed, see mc68000
239#define dt_qword 7
240#define dt_byte16 8
241#define dt_code 9
242#define dt_void 10
243#define dt_fword 11
244#define dt_bitfild 12
245#define dt_string 13
246#define dt_unicode 14
247#define dt_ldbl 15
248#define dt_byte32 16
249#define dt_byte64 17
250#define dt_half 18
252
253 // REG
254 union
255 {
260 };
261
263 bool is_reg(int r) const { return type == o_reg && reg == r; }
264
265 // Next fields (value, addr) bytes are used by mc68k for some float types
266
267 // VALUE
268 union
269 {
277
280 struct
281 {
285 };
286
288 bool is_imm(uval_t v) const { return type == o_imm && value == v; }
289
290 // VIRTUAL ADDRESS (offset within the segment)
291 union
292 {
295
298 struct
299 {
300 uint16 low;
301 uint16 high;
303 };
304
305 // IDP SPECIFIC INFORMATION
306 union
307 {
311 struct
312 {
313 uint16 low;
314 uint16 high;
316 };
317
323 char specflag1 = 0;
324 char specflag2 = 0;
325 char specflag3 = 0;
326 char specflag4 = 0;
328
330 {
331 reg = 0;
332 value = 0;
333 addr = 0;
334 specval = 0;
335 specflag1 = 0;
336 specflag2 = 0;
337 specflag3 = 0;
338 specflag4 = 0;
339 }
340};
341
342
343//--------------------------------------------------------------------------
344// I N S T R U C T I O N
345//--------------------------------------------------------------------------
348
354
355class insn_t;
356#define DECLARE_INSN_HELPERS(decl) \
357decl uint8 ida_export insn_get_next_byte(insn_t *insn); \
358decl uint16 ida_export insn_get_next_word(insn_t *insn); \
359decl uint32 ida_export insn_get_next_dword(insn_t *insn); \
360decl uint64 ida_export insn_get_next_qword(insn_t *insn); \
361decl bool ida_export insn_create_op_data(const insn_t &insn, ea_t ea, int opoff, op_dtype_t dtype); \
362decl void ida_export insn_add_cref(const insn_t &insn, ea_t to, int opoff, cref_t type); \
363decl void ida_export insn_add_dref(const insn_t &insn, ea_t to, int opoff, dref_t type); \
364decl ea_t ida_export insn_add_off_drefs(const insn_t &insn, const op_t &x, dref_t type, int outf); \
365decl bool ida_export insn_create_stkvar(const insn_t &insn, const op_t &x, adiff_t v, int flags);
366
367DECLARE_INSN_HELPERS(idaman)
368
369
370class insn_t
371{
372public:
373 insn_t() : auxpref(0) {}
374
376 ea_t cs = BADADDR;
377
380 ea_t ip = BADADDR;
381
384 ea_t ea = BADADDR;
385
390 uint16 itype = 0;
391
392 inline bool is_canon_insn(const processor_t &ph) const;
393 inline uint32 get_canon_feature(const processor_t &ph) const;
394 inline const char *get_canon_mnem(const processor_t &ph) const;
395
398 uint16 size = 0;
399
400 union
401 {
402 uint32 auxpref;
403 uint16 auxpref_u16[2];
404 uint8 auxpref_u8[4];
405 };
406 /*u*/ char segpref = 0;
407 /*u*/ char insnpref = 0;
408
409 /*u*/ int16 flags = 0;
410
411 op_t ops[UA_MAXOP];
412
417 #define Op1 ops[0]
418 #define Op2 ops[1]
419 #define Op3 ops[2]
420 #define Op4 ops[3]
421 #define Op5 ops[4]
422 #define Op6 ops[5]
423 #define Op7 ops[6]
424 #define Op8 ops[7]
426
431#define INSN_MACRO 0x01
432#define INSN_MODMAC 0x02
433#define INSN_64BIT 0x04
435
437 bool is_macro(void) const { return (flags & INSN_MACRO) != 0; }
438
440#ifdef __EA64__
441 bool is_64bit(void) const { return (flags & INSN_64BIT) != 0; }
442#else
443 bool is_64bit(void) const { return false; }
444#endif
445
452 uint8 get_next_byte()
453 {
454 return insn_get_next_byte(this);
455 }
456 uint16 get_next_word()
457 {
458 return insn_get_next_word(this);
459 }
460 uint32 get_next_dword()
461 {
462 return insn_get_next_dword(this);
463 }
464 uint64 get_next_qword()
465 {
466 return insn_get_next_qword(this);
467 }
469
472
483
484 bool create_op_data(ea_t ea_, int opoff, op_dtype_t dtype) const
485 {
486 return insn_create_op_data(*this, ea_, opoff, dtype);
487 }
488
490 bool create_op_data(ea_t ea_, const op_t &op) const
491 {
492 return insn_create_op_data(*this, ea_, op.offb, op.dtype);
493 }
494
495
505
506 bool create_stkvar(const op_t &x, adiff_t v, int flags_) const
507 {
508 return insn_create_stkvar(*this, x, v, flags_);
509 }
510
514#define STKVAR_VALID_SIZE 0x0001
518#define STKVAR_KEEP_EXISTING 0x0002
521
522
528
529 void add_cref(ea_t to, int opoff, cref_t type) const
530 {
531 insn_add_cref(*this, to, opoff, type);
532 }
533
534
541
542 void add_dref(ea_t to, int opoff, dref_t type) const
543 {
544 insn_add_dref(*this, to, opoff, type);
545 }
546
547
559
560 ea_t add_off_drefs(const op_t &x, dref_t type, int outf) const
561 {
562 return insn_add_off_drefs(*this, x, type, outf);
563 }
564
566
567};
568#ifdef __EA64__
569CASSERT(sizeof(insn_t) == 360);
570#else
571CASSERT(sizeof(insn_t) == 216);
572#endif
573
574//--------------------------------------------------------------------------
575// V A L U E O F O P E R A N D
576//--------------------------------------------------------------------------
577#ifndef SWIG
591
592#endif // SWIG
593
609
610idaman size_t ida_export get_immvals(
611 uval_t *out,
612 ea_t ea,
613 int n,
614 flags64_t F,
615 insn_t *cache=nullptr);
616
617
628
630 uval_t *out,
631 ea_t ea,
632 int n,
633 flags64_t F,
634 insn_t *cache=nullptr)
635{
636 F &= ~0x100; // no FF_IVL...
637 F |= 0xFF; // ...but a value of 0xFF
638 return get_immvals(out, ea, n, F, cache);
639}
640
641
648
649idaman int ida_export get_lookback(void);
650
651
652//--------------------------------------------------------------------------
653// I D P H E L P E R F U N C T I O N S - C O M M O N
654//--------------------------------------------------------------------------
655
669
673
674idaman ea_t ida_export calc_dataseg(const insn_t &insn, int n=-1, int rgnum=-1);
675
680
681inline ea_t map_data_ea(const insn_t &insn, ea_t addr, int opnum=-1)
682{
683 return to_ea(calc_dataseg(insn, opnum), addr);
684}
685
686inline ea_t map_data_ea(const insn_t &insn, const op_t &op)
687{
688 return map_data_ea(insn, op.addr, op.n);
689}
690
696
697idaman ea_t ida_export map_code_ea(const insn_t &insn, ea_t addr, int opnum);
698
699inline ea_t map_code_ea(const insn_t &insn, const op_t &op)
700{
701 return map_code_ea(insn, op.addr, op.n);
702}
703
704inline ea_t map_ea(const insn_t &insn, const op_t &op, bool iscode)
705{
706 return iscode ? map_code_ea(insn, op) : map_data_ea(insn, op);
707}
708
709inline ea_t map_ea(const insn_t &insn, ea_t addr, int opnum, bool iscode)
710{
711 return iscode ? map_code_ea(insn, addr, opnum) : map_data_ea(insn, addr, opnum);
712}
713
715
716//--------------------------------------------------------------------------
717// I D P H E L P E R F U N C T I O N S - O U T P U T
718//--------------------------------------------------------------------------
720{
722 // information for creating one line
727 int suspop;
729 uval_t *outvalues = nullptr;
731 void *user_data = nullptr;
732 void *kern_data = nullptr;
733
734 // information for generating many lines
735 qstrvec_t *lnar = nullptr;
736 int lnar_maxsize = 0;
737 int default_lnnum = -1;
738
741 int ctxflags = 0;
742#define CTXF_MAIN 0x00001
743#define CTXF_MULTI 0x00002
744#define CTXF_CODE 0x00004
745#define CTXF_STACK 0x00008
746#define CTXF_GEN_XREFS 0x00010
747#define CTXF_XREF_STATE 0x00060
748#define XREFSTATE_NONE 0x00
749#define XREFSTATE_GO 0x20
750#define XREFSTATE_DONE 0x40
751#define CTXF_GEN_CMT 0x00080
752#define CTXF_CMT_STATE 0x00300
753#define COMMSTATE_NONE 0x000
754#define COMMSTATE_GO 0x100
755#define COMMSTATE_DONE 0x200
756#define CTXF_VOIDS 0x00400
757#define CTXF_NORMAL_LABEL 0x00800
758#define CTXF_DEMANGLED_LABEL 0x01000
759#define CTXF_LABEL_OK 0x02000
760#define CTXF_DEMANGLED_OK 0x04000
761#define CTXF_OVSTORE_PRNT 0x08000
762#define CTXF_OUTCTX_T 0x10000
763#define CTXF_DBLIND_OPND 0x20000
764#define CTXF_BINOP_STATE 0xC0000
765#define BINOPSTATE_NONE 0x00000
766#define BINOPSTATE_GO 0x40000
767#define BINOPSTATE_DONE 0x80000
768#define CTXF_HIDDEN_ADDR 0x100000
769#define CTXF_BIT_PREFIX 0x200000
770#define CTXF_UNHIDE 0x400000
771
772 // internal data used by the kernel
773 int ind0 = 0;
774 ea_t cmt_ea = BADADDR;
776 const char *cmtptr = nullptr;
778
779 inline bool only_main_line() const { return (ctxflags & CTXF_MAIN) != 0; }
780 inline bool multiline() const { return (ctxflags & CTXF_MULTI) != 0; }
781 inline bool force_code() const { return (ctxflags & CTXF_CODE) != 0; }
782 inline bool stack_view() const { return (ctxflags & CTXF_STACK) != 0; }
783 inline bool display_voids() const { return (ctxflags & CTXF_VOIDS) != 0; }
784 inline bool display_hidden() const { return (ctxflags & CTXF_UNHIDE) != 0; }
785 inline void set_gen_xrefs(bool on=true) { setflag(ctxflags, CTXF_GEN_XREFS, on); }
786 inline int get_xrefgen_state() const { return ctxflags & CTXF_XREF_STATE; }
787 inline void set_gen_cmt(bool on=true) { setflag(ctxflags, CTXF_GEN_CMT, on); }
788 inline int get_cmtgen_state() const { return ctxflags & CTXF_CMT_STATE; }
789 inline int get_binop_state() const { return ctxflags & CTXF_BINOP_STATE; }
790 inline void clr_gen_label(void) { ctxflags &= ~(CTXF_NORMAL_LABEL|CTXF_DEMANGLED_LABEL); }
791 inline void set_gen_label(void) { ctxflags |= CTXF_NORMAL_LABEL; }
792 inline void set_gen_demangled_label(void) { ctxflags |= CTXF_DEMANGLED_LABEL; ctxflags &= ~CTXF_NORMAL_LABEL; }
793 inline void set_comment_addr(ea_t ea) { cmt_ea = ea; }
794 inline void set_dlbind_opnd(void) { ctxflags |= CTXF_DBLIND_OPND; }
795 inline bool print_label_now() const
796 {
797 return (ctxflags & (CTXF_LABEL_OK|CTXF_MAIN)) == 0 // label not ready
798 && (ctxflags & (CTXF_NORMAL_LABEL|CTXF_DEMANGLED_LABEL)) != 0; // requested it
799 }
801 { // temporarily forbid printing of xrefs, label, cmt
802 int bits = CTXF_GEN_XREFS|CTXF_NORMAL_LABEL|CTXF_DEMANGLED_LABEL|CTXF_GEN_CMT;
803 int saved_flags = ctxflags & bits;
804 ctxflags &= ~bits;
805 return saved_flags;
806 }
807 void restore_ctxflags(int saved_flags)
808 {
809 ctxflags |= saved_flags;
810 }
811
812 outctx_base_t(ea_t ea, flags64_t flags, int _suspop=0);
814 virtual ~outctx_base_t(void);
815
818
821 AS_PRINTF(2, 3) size_t out_printf(const char *format, ...)
822 {
823 va_list va;
825 size_t len = out_vprintf(format, va);
827 return len;
828 }
829
830 GCC_DIAG_OFF(format-nonliteral);
831 size_t nowarn_out_printf(const char *format, ...)
832 {
833 va_list va;
835 size_t len = out_vprintf(format, va);
836 va_end(va);
837 return len;
838 }
839 GCC_DIAG_ON(format-nonliteral);
840
841 virtual AS_PRINTF(2, 0) size_t idaapi out_vprintf(const char *format, va_list va);
842
852 virtual flags64_t idaapi out_value(const op_t &x, int outf=0);
853
858#define OOF_SIGNMASK 0x0003
859#define OOFS_IFSIGN 0x0000
860#define OOFS_NOSIGN 0x0001
861#define OOFS_NEEDSIGN 0x0002
862#define OOF_SIGNED 0x0004
863#define OOF_NUMBER 0x0008
864#define OOF_WIDTHMASK 0x0070
865#define OOFW_IMM 0x0000
866#define OOFW_8 0x0010
867#define OOFW_16 0x0020
868#define OOFW_24 0x0030
869#define OOFW_32 0x0040
870#define OOFW_64 0x0050
871#define OOF_ADDR 0x0080
873#define OOF_OUTER 0x0100
874#define OOF_ZSTROFF 0x0200
879#define OOF_NOBNOT 0x0400
880#define OOF_SPACES 0x0800
882#define OOF_ANYSERIAL 0x1000
883#define OOF_LZEROES 0x2000
884#define OOF_NO_LZEROES 0x4000
888
890 virtual void idaapi out_symbol(char c);
891
893 virtual void idaapi out_chars(char c, int n);
894
897 virtual void idaapi add_spaces(qstring *buf, ssize_t len);
898
900 virtual void idaapi out_line(const char *str, color_t color=0);
901
903 inline void out_keyword(const char *str)
904 {
906 }
907
909 inline void out_register(const char *str)
910 {
911 out_line(str, COLOR_REG);
912 }
913
915 inline void out_lvar(const char *name, int width=-1)
916 {
917 out_line(name, COLOR_LOCNAME);
918 if ( width != -1 && name != nullptr )
919 {
920 size_t len = ::qstrlen(name);
921 if ( len < width )
922 out_chars(' ', width - len);
923 }
924 }
925
927 virtual void idaapi out_tagon(color_t tag);
928
930 virtual void idaapi out_tagoff(color_t tag);
931
933 virtual void idaapi out_addr_tag(ea_t ea);
934
938 virtual void idaapi out_colored_register_line(const char *str);
939
943 virtual void idaapi out_char(char c) { outbuf.append(c); }
944
948 virtual void idaapi out_btoa(uval_t Word, char radix=0);
949
965 virtual void idaapi out_long(sval_t v, char radix);
966
975 virtual bool idaapi out_name_expr(
976 const op_t &x,
977 ea_t ea,
978 adiff_t off=BADADDR);
979
980 // Generate the closing comment if if it required by the assembler
981
982 inline void close_comment(void) { out_line(closing_comment()); }
983
986
990 virtual bool idaapi flush_outbuf(int indent=-1);
991
994 virtual bool idaapi flush_buf(const char *buf, int indent=-1);
995
998 virtual int idaapi term_outctx(const char *prefix=nullptr);
999
1001 virtual AS_PRINTF(3, 0) bool idaapi gen_vprintf(
1002 int indent,
1003 const char *format,
1004 va_list va);
1005
1019
1020 AS_PRINTF(3, 4) inline bool gen_printf(int indent, const char *format, ...)
1021 {
1022 va_list va;
1024 bool code = gen_vprintf(indent, format, va);
1026 return code;
1027 }
1028#define DEFAULT_INDENT 0xFFFF
1029
1033
1034 virtual bool idaapi gen_empty_line(void);
1035
1036
1041
1042 virtual bool idaapi gen_border_line(bool solid=false);
1043
1045 virtual AS_PRINTF(3, 0) bool idaapi gen_colored_cmt_line_v(
1046 color_t color,
1047 const char *format,
1048 va_list va);
1049
1051
1052 AS_PRINTF(2, 0) inline bool gen_cmt_line_v(const char *format, va_list va)
1053 {
1054 return gen_colored_cmt_line_v(COLOR_AUTOCMT, format, va);
1055 }
1056
1061
1062 AS_PRINTF(2, 3) inline bool gen_cmt_line(const char *format, ...)
1063 {
1064 va_list va;
1066 bool code = gen_cmt_line_v(format, va);
1068 return code;
1069 }
1070
1075
1076 AS_PRINTF(2, 3) inline bool gen_collapsed_line(const char *format, ...)
1077 {
1078 va_list va;
1080 bool answer = gen_colored_cmt_line_v(COLOR_COLLAPSED, format, va);
1082 return answer;
1083 }
1084
1090
1091 virtual bool idaapi gen_block_cmt(const char *cmt, color_t color);
1092
1093 //-------------------------------------------------------------------------
1095 virtual void idaapi setup_outctx(const char *prefix, int makeline_flags);
1096#define MAKELINE_NONE 0x00
1097#define MAKELINE_BINPREF 0x01
1098#define MAKELINE_VOID 0x02
1099#define MAKELINE_STACK 0x04
1100
1101 virtual ssize_t idaapi retrieve_cmt(void) { return -1; }
1102 virtual ssize_t idaapi retrieve_name(qstring *, color_t *) { return -1; }
1103 virtual bool idaapi gen_xref_lines(void) { return false; }
1104
1105 virtual void idaapi init_lines_array(qstrvec_t *answers, int maxsize);
1106
1107 virtual ssize_t idaapi get_stkvar(const op_t &x, uval_t v, sval_t *vv, int *is_sp_based, tinfo_t *_frame);
1108
1110 {
1111 int saved_flags = forbid_annotations();
1113 restore_ctxflags(saved_flags);
1114 }
1115
1116 inline flags64_t getF() const;
1117
1118
1119protected:
1120 virtual bool idaapi flush_and_reinit(void);
1121 virtual void idaapi append_user_prefix(const char *, int) {}
1122 virtual void idaapi add_aux_prefix(const char *, int) {}
1123 virtual void idaapi out_label_addr_tag(void) {}
1124 virtual void idaapi out_aux_cmts(void) {}
1125};
1126
1127//--------------------------------------------------------------------------
1128// This class is used to print instructions and data items
1130{
1131 // kernel only data:
1132 ea_t bin_ea; // Current binary format EA
1133 char bin_state; // =0 not generated,1-in process,2-finished
1134 int gl_bpsize = 0; // binary line prefix size
1135 int bin_width = 0;
1136
1137 // instruction to display:
1138 insn_t insn; // valid only when ph.out_insn() is called
1139
1140 // colorized and demangled label of the current address
1142
1143 // opinfo_t to use for out_value()
1145
1146 // processor module and its description
1150
1151 // out_value() saves the printed values here
1152 uval_t saved_immvals[UA_MAXOP] = { 0 };
1153
1154 ea_t prefix_ea = BADADDR;
1155 ea_t next_line_ea = BADADDR; // EA of next line (for prefix)
1157
1159 procmod_t *p,
1160 processor_t &ph,
1161 asm_t &ash,
1162 ea_t ea,
1163 flags64_t flags=0,
1164 int _suspop=0,
1165 const printop_t *_wif=nullptr);
1167 {
1168 }
1169 virtual void idaapi setup_outctx(const char *prefix, int flags) override;
1170 virtual int idaapi term_outctx(const char *prefix=nullptr) override;
1171 virtual ssize_t idaapi retrieve_cmt(void) override;
1172 virtual ssize_t idaapi retrieve_name(qstring *, color_t *) override;
1173 virtual bool idaapi gen_xref_lines(void) override;
1174 virtual void idaapi out_btoa(uval_t Word, char radix=0) override;
1175
1176 void set_bin_state(int value)
1177 {
1178 bin_state = value;
1179 ctxflags &= ~CTXF_BINOP_STATE;
1180 ctxflags |= value == 0 ? BINOPSTATE_NONE
1181 : value == 1 ? BINOPSTATE_GO
1182 : BINOPSTATE_DONE;
1183 }
1184
1194 virtual void idaapi out_mnem(int width=8, const char *postfix=nullptr) newapi;
1195
1204 virtual void idaapi out_custom_mnem(
1205 const char *mnem,
1206 int width=8,
1207 const char *postfix=nullptr) newapi;
1208
1213 virtual void idaapi out_mnemonic(void) newapi;
1214
1223 virtual bool idaapi out_one_operand(int n) newapi;
1224
1230 virtual size_t idaapi get_immvals(uval_t *out, int i) newapi;
1231
1236 virtual void idaapi out_immchar_cmts(void) newapi;
1237
1238 virtual void idaapi gen_func_header(func_t *pfn) newapi;
1239 virtual void idaapi gen_func_footer(const func_t *pfn) newapi;
1240
1241 // display data items and undefined bytes.
1242 virtual void idaapi out_data(bool analyze_only) newapi;
1243
1244 // generate declaration for item in a special segment
1245 // return: 0-ok, 1-overflow
1246 virtual bool idaapi out_specea(uchar segtype) newapi;
1247
1248 // convenience functions for processor modules
1249 // print lines from ash.header
1250 virtual void idaapi gen_header_extra() newapi;
1251
1252 // flags for gen_header()
1253#define GH_PRINT_PROC (1 << 0)
1254#define GH_PRINT_ASM (1 << 1)
1255#define GH_PRINT_BYTESEX (1 << 2)
1256#define GH_PRINT_HEADER (1 << 3)
1257#define GH_BYTESEX_HAS_HIGHBYTE (1 << 4)
1258#define GH_PRINT_PROC_AND_ASM (GH_PRINT_PROC | GH_PRINT_ASM)
1259#define GH_PRINT_PROC_ASM_AND_BYTESEX (GH_PRINT_PROC_AND_ASM | GH_PRINT_BYTESEX)
1260#define GH_PRINT_ALL (GH_PRINT_PROC_ASM_AND_BYTESEX | GH_PRINT_HEADER)
1261#define GH_PRINT_ALL_BUT_BYTESEX (GH_PRINT_PROC_AND_ASM | GH_PRINT_HEADER)
1262 virtual void idaapi gen_header(
1263 int flags = GH_PRINT_PROC_AND_ASM,
1264 const char *proc_name = nullptr,
1265 const char *proc_flavour = nullptr) newapi;
1266
1272 virtual void idaapi out_fcref_names() newapi;
1273};
1274
1275//-------------------------------------------------------------------------
1277{
1278 return (ctxflags & CTXF_OUTCTX_T) != 0 ? ((outctx_t *) this)->F : F32;
1279}
1280
1281//--------------------------------------------------------------------------
1284
1285idaman outctx_base_t *ida_export create_outctx(ea_t ea, flags64_t F=0, int suspop=0);
1286
1287
1292
1293idaman bool ida_export print_insn_mnem(qstring *out, ea_t ea);
1294
1295
1299#define FCBF_CONT 0x00000001
1300#define FCBF_ERR_REPL 0x00000002
1302
1303#define FCBF_FF_LIT 0x00000004
1306
1307#define FCBF_DELIM 0x00000008
1311
1312
1341
1342idaman bool ida_export format_charlit(
1343 qstring *out,
1344 const uchar **ptr,
1345 size_t size,
1346 uint32 flags=0,
1347 int encidx=0);
1348
1349
1358
1359idaman bool ida_export print_fpval(char *buf, size_t bufsize, const void *v, int size);
1360
1361
1362//--------------------------------------------------------------------------
1363// I D P H E L P E R F U N C T I O N S - E M U L A T O R
1364//--------------------------------------------------------------------------
1366idaman flags64_t ida_export get_dtype_flag(op_dtype_t dtype);
1368idaman size_t ida_export get_dtype_size(op_dtype_t dtype);
1371
1374{
1375 return dtype == dt_float
1376 || dtype == dt_double
1377 || dtype == dt_tbyte
1378 || dtype == dt_ldbl
1379 || dtype == dt_half;
1380}
1381
1382
1383//--------------------------------------------------------------------------
1384// K E R N E L I N T E R F A C E T O I D P F U N C T I O N S
1385//--------------------------------------------------------------------------
1394idaman int ida_export create_insn(ea_t ea, insn_t *out=nullptr);
1395
1396
1404
1405idaman int ida_export decode_insn(insn_t *out, ea_t ea);
1406
1410
1411inline bool can_decode(ea_t ea) { insn_t insn; return decode_insn(&insn, ea) > 0; }
1412
1413
1424
1425idaman bool ida_export print_operand(
1426 qstring *out,
1427 ea_t ea,
1428 int n,
1429 int getn_flags=0,
1430 struct printop_t *newtype=nullptr);
1431
1432
1433//--------------------------------------------------------------------------
1434// Helper functions for the processor emulator/analyzer
1435//--------------------------------------------------------------------------
1436
1441
1442idaman ea_t ida_export decode_prev_insn(insn_t *out, ea_t ea);
1443
1444
1451
1452idaman ea_t ida_export decode_preceding_insn(insn_t *out, ea_t ea, bool *p_farref=nullptr);
1453
1454
1457{
1458 size_t reserved = 0;
1459
1461
1480 inline bool construct_macro(insn_t *insn, bool enable);
1481
1496 virtual bool idaapi build_macro(insn_t *insn, bool may_go_forward) = 0;
1497};
1498
1499// Do not directly call this function, use macro_constructor_t
1500idaman bool ida_export construct_macro(
1501 macro_constructor_t *_this,
1502 insn_t *insn,
1503 bool enable);
1504
1505inline bool macro_constructor_t::construct_macro(insn_t *insn, bool enable)
1506{
1507 return ::construct_macro(this, insn, enable);
1508}
1509
1510
1518
1519idaman int ida_export get_spoiled_reg(const insn_t &insn, const uint32 *regs, size_t n);
1520
1521
1522#endif // _UA_HPP
Contains functions that deal with individual byte characteristics.
A function is a set of continuous ranges of addresses with characteristics.
Definition funcs.hpp:85
Operand of an instruction.
Definition ua.hpp:170
uint16 low
IBM PC: segment register number (o_mem,o_far,o_near)
Definition ua.hpp:282
uchar n
Number of operand (0,1,2).
Definition ua.hpp:175
bool is_reg(int r) const
Is register operand?
Definition ua.hpp:263
op_t()
Definition ua.hpp:329
struct op_t::@355145044314106136163341364327273110212111274006::@105003236016226244000346201374354173104334320270 addr_shorts
This structure is defined for your convenience only.
char offo
Same as offb (some operands have 2 numeric values used to form an operand).
Definition ua.hpp:195
uint16 reg
number of register (o_reg)
Definition ua.hpp:256
uint16 phrase
number of register phrase (o_phrase,o_displ).
Definition ua.hpp:257
bool is_imm(uval_t v) const
Is immediate operand?
Definition ua.hpp:288
uint16 high
IBM PC: segment selector value (o_mem,o_far,o_near)
Definition ua.hpp:283
uval_t value
operand value (o_imm) or outer displacement (o_displ+OF_OUTER_DISP).
Definition ua.hpp:270
optype_t type
Type of operand (see Operand types)
Definition ua.hpp:178
op_dtype_t dtype
Type of operand value (see Operand value types).
Definition ua.hpp:225
void set_shown()
Set operand to be shown.
Definition ua.hpp:216
char offb
Offset of operand value from the instruction start (0 means unknown).
Definition ua.hpp:189
struct op_t::@314264034300125366226121250377171170106022317216::@067003166240224161210217156357235221062015160112 specval_shorts
This structure is defined for your convenience only.
ea_t addr
virtual address pointed or used by the operand.
Definition ua.hpp:293
char specflag4
Definition ua.hpp:326
void clr_shown()
Set operand to hidden.
Definition ua.hpp:218
bool shown() const
Is operand set to be shown?
Definition ua.hpp:220
uchar flags
Operand flags
Definition ua.hpp:197
char specflag3
Definition ua.hpp:325
char specflag1
Definition ua.hpp:323
struct op_t::@140153357217061121023364357273245161007012105054::@172011301334131030205016047004346361350234062301 value_shorts
This structure is defined for your convenience only.
char specflag2
Definition ua.hpp:324
ea_t specval
This field may be used as you want.
Definition ua.hpp:308
Primary mechanism for managing type information.
Definition typeinf.hpp:3046
const color_t COLOR_AUTOCMT
Automatic comment.
Definition lines.hpp:102
const color_t COLOR_COLLAPSED
Collapsed line.
Definition lines.hpp:137
const color_t COLOR_REG
Register name.
Definition lines.hpp:131
const color_t COLOR_KEYWORD
Keywords.
Definition lines.hpp:130
const color_t COLOR_LOCNAME
Local variable name.
Definition lines.hpp:123
uchar color_t
see <lines.hpp>
Definition kernwin.hpp:26
const optype_t o_mem
A direct memory reference to a data item.
Definition ua.hpp:84
const optype_t o_idpspec1
processor specific type.
Definition ua.hpp:96
const optype_t o_idpspec3
processor specific type.
Definition ua.hpp:98
const optype_t o_reg
General Register (al,ax,es,ds...).
Definition ua.hpp:83
const optype_t o_idpspec5
processor specific type.
Definition ua.hpp:100
const optype_t o_far
An immediate far code reference (inter-segment)
Definition ua.hpp:93
const optype_t o_idpspec2
processor specific type.
Definition ua.hpp:97
const optype_t o_phrase
An indirect memory reference that uses a register: [reg] There can be several registers but no displa...
Definition ua.hpp:87
const optype_t o_displ
An indirect memory reference that uses a register and has an immediate constant added to it: [reg+N] ...
Definition ua.hpp:89
const optype_t o_imm
An immediate Value (constant).
Definition ua.hpp:92
const optype_t o_idpspec4
processor specific type.
Definition ua.hpp:99
const optype_t o_idpspec0
processor specific type.
Definition ua.hpp:95
const optype_t o_near
An immediate near code reference (intra-segment)
Definition ua.hpp:94
const optype_t o_void
No Operand.
Definition ua.hpp:82
idaman size_t n
Definition pro.h:997
idaman uchar ida_export segtype(ea_t ea)
Get segment type.
cref_t
CODE xref types.
Definition xref.hpp:49
dref_t
DATA xref types.
Definition xref.hpp:67
const tinfo_t & type
Definition hexrays.hpp:7301
ea_t idaapi to_ea(sel_t reg_cs, uval_t reg_ip)
Convert (sel,off) value to a linear address.
Definition ida.hpp:1136
Defines the interface between the kernel and the UI.
uval_t uval_t
Definition kernwin.hpp:1878
asize_t size
Definition kernwin.hpp:6339
High level functions that deal with the generation of the disassembled text lines.
unsigned __int64 uint64
Definition llong.hpp:13
THREAD_SAFE size_t idaapi qstrlen(const char *s)
Definition pro.h:2998
unsigned short uint16
unsigned 16 bit value
Definition pro.h:346
int bool
Definition pro.h:329
unsigned int uint32
unsigned 32 bit value
Definition pro.h:348
uint64 asize_t
Definition pro.h:423
uint8 op_dtype_t
Definition pro.h:460
adiff_t sval_t
signed value used by the processor.
Definition pro.h:446
short int16
signed 16 bit value
Definition pro.h:345
int64 adiff_t
Definition pro.h:424
uint64 ea_t
Definition pro.h:421
uint32 flags_t
32-bit flags for each address
Definition pro.h:5008
unsigned char uchar
unsigned 8 bit value
Definition pro.h:337
idaman size_t bufsize
Definition pro.h:600
uint64 flags64_t
64-bit flags for each address
Definition pro.h:5009
ptrdiff_t ssize_t
Signed size_t - used to check for size overflows when the counter becomes negative.
Definition pro.h:381
void idaapi setflag(T &where, U bit, bool cnd)
Set a 'bit' in 'where' if 'value' if not zero.
Definition pro.h:1527
unsigned char uint8
unsigned 8 bit value
Definition pro.h:344
_qstring< char > qstring
regular string
Definition pro.h:3694
qvector< qstring > qstrvec_t
vector of strings
Definition pro.h:3697
Describes the target assembler.
Definition idp.hpp:176
helper class to support 32bit addresses in ida64
Definition ida.hpp:1145
Helper class for processor modules to build macro instructions.
Definition ua.hpp:1457
size_t reserved
Definition ua.hpp:1458
bool construct_macro(insn_t *insn, bool enable)
Construct a macro instruction.
Definition ua.hpp:1505
virtual ~macro_constructor_t()
Definition ua.hpp:1460
virtual bool idaapi build_macro(insn_t *insn, bool may_go_forward)=0
Try to extend the instruction.
Definition ua.hpp:720
virtual flags64_t idaapi out_value(const op_t &x, int outf=0)
Output immediate value.
flags64_t getF() const
Definition ua.hpp:1276
GCC_DIAG_ON(format-nonliteral)
int get_cmtgen_state() const
Definition ua.hpp:788
bool multiline() const
Definition ua.hpp:780
virtual const char * format
Definition ua.hpp:1003
virtual void idaapi out_char(char c)
Output one character.
Definition ua.hpp:943
virtual void idaapi setup_outctx(const char *prefix, int makeline_flags)
Initialization; normally used only by the kernel.
qstring line_prefix
usually segname:offset
Definition ua.hpp:739
qstring cmtbuf
indented comment
Definition ua.hpp:775
virtual ssize_t idaapi retrieve_cmt(void)
Definition ua.hpp:1101
void out_register(const char *str)
Output a character with COLOR_REG color.
Definition ua.hpp:909
ssize_t regname_idx
to rename registers
Definition ua.hpp:726
void set_comment_addr(ea_t ea)
Definition ua.hpp:793
virtual bool idaapi gen_empty_line(void)
Generate empty line.
void clr_gen_label(void)
Definition ua.hpp:790
virtual int idaapi term_outctx(const char *prefix=nullptr)
Finalize the output context.
virtual void idaapi out_tagoff(color_t tag)
Output "turn color off" escape sequence.
void out_lvar(const char *name, int width=-1)
Output local variable name with COLOR_LOCNAME color.
Definition ua.hpp:915
int outvalue_getn_flags
additional flags for print_operand()
Definition ua.hpp:730
void set_gen_demangled_label(void)
Definition ua.hpp:792
virtual void idaapi out_line(const char *str, color_t color=0)
Output a string with the specified color.
color_t cmtcolor
comment color
Definition ua.hpp:777
void close_comment(void)
Definition ua.hpp:982
ssize_t prefix_len
visible length of line_prefix
Definition ua.hpp:740
bool only_main_line() const
Definition ua.hpp:779
virtual void idaapi append_user_prefix(const char *, int)
Definition ua.hpp:1121
virtual void idaapi out_tagon(color_t tag)
Output "turn color on" escape sequence.
virtual void idaapi add_spaces(qstring *buf, ssize_t len)
virtual void idaapi out_symbol(char c)
Output a character with COLOR_SYMBOL color.
const char va_start(va, format)
virtual bool idaapi flush_outbuf(int indent=-1)
Move the contents of the output buffer to the line array (outbuf->lnar) The kernel augments the outbu...
bool display_hidden() const
Definition ua.hpp:784
ea_t cmt_ea
indirectly referenced address (used to generate cmt)
Definition ua.hpp:774
int get_binop_state() const
Definition ua.hpp:789
virtual bool idaapi flush_buf(const char *buf, int indent=-1)
Append contents of 'buf' to the line array.
virtual bool idaapi gen_block_cmt(const char *cmt, color_t color)
Generate big non-indented comment lines.
virtual va_list va
Definition ua.hpp:841
ea_helper_t & _eah
Definition ua.hpp:721
virtual ssize_t idaapi get_stkvar(const op_t &x, uval_t v, sval_t *vv, int *is_sp_based, tinfo_t *_frame)
size_t nowarn_out_printf(const char *format,...)
Definition ua.hpp:831
AS_PRINTF(2, 3) inline bool gen_cmt_line(const char *format
Generate one non-indented comment line, colored with COLOR_AUTOCMT.
void out_spaces(ssize_t len)
Appends spaces to outbuf until its tag_strlen becomes 'len'.
Definition ua.hpp:896
GCC_DIAG_OFF(format-nonliteral)
void * kern_data
internal info used by the kernel
Definition ua.hpp:732
bool display_voids() const
Definition ua.hpp:783
void set_gen_xrefs(bool on=true)
Definition ua.hpp:785
virtual bool idaapi gen_border_line(bool solid=false)
Generate thin border line.
void set_gen_cmt(bool on=true)
Definition ua.hpp:787
virtual void idaapi out_aux_cmts(void)
Definition ua.hpp:1124
bool answer
Definition ua.hpp:1080
virtual void idaapi out_colored_register_line(const char *str)
Output a colored line with register names in it.
virtual AS_PRINTF(3, 0) bool idaapi gen_vprintf(int indent
See gen_printf()
void * user_data
pointer to be used by the processor module for any purpose
Definition ua.hpp:731
qstring outbuf
buffer for the current output line once ready, it is moved to lnar
Definition ua.hpp:724
virtual bool idaapi flush_and_reinit(void)
virtual bool idaapi out_name_expr(const op_t &x, ea_t ea, adiff_t off=BADADDR)
Output a name expression.
int ctxflags
various bits
Definition ua.hpp:741
virtual AS_PRINTF(3, 0) bool idaapi gen_colored_cmt_line_v(color_t color
See gen_cmt_line()
int default_lnnum
index of the most important line in lnar
Definition ua.hpp:737
virtual AS_PRINTF(2, 0) size_t idaapi out_vprintf(const char *format
int lnar_maxsize
max permitted size of lnar
Definition ua.hpp:736
flags_t F32
please use outctx_t::F instead
Definition ua.hpp:728
void set_dlbind_opnd(void)
Definition ua.hpp:794
virtual void idaapi out_addr_tag(ea_t ea)
Output "address" escape sequence.
outctx_base_t & operator=(const outctx_base_t &)=delete
virtual ~outctx_base_t(void)
virtual void idaapi out_long(sval_t v, char radix)
Output a number with appropriate color.
void out_keyword(const char *str)
Output a string with COLOR_KEYWORD color.
Definition ua.hpp:903
virtual void idaapi out_label_addr_tag(void)
Definition ua.hpp:1123
bool code
Definition ua.hpp:1024
virtual void idaapi out_chars(char c, int n)
Append a character multiple times.
qstrvec_t * lnar
vector of output lines
Definition ua.hpp:735
virtual void idaapi init_lines_array(qstrvec_t *answers, int maxsize)
void gen_empty_line_without_annotations(void)
Definition ua.hpp:1109
void set_gen_label(void)
Definition ua.hpp:791
va_start(va, format)
size_t len
Definition ua.hpp:825
virtual ssize_t idaapi retrieve_name(qstring *, color_t *)
Definition ua.hpp:1102
virtual bool idaapi gen_xref_lines(void)
Definition ua.hpp:1103
int suspop
controls color for out_long()
Definition ua.hpp:727
uval_t * outvalues
at least 2*UA_MAXOP elements
Definition ua.hpp:729
const char * cmtptr
rest of indented comment
Definition ua.hpp:776
virtual void idaapi out_btoa(uval_t Word, char radix=0)
Output a number with the specified base (binary, octal, decimal, hex) The number is output without co...
void restore_ctxflags(int saved_flags)
Definition ua.hpp:807
AS_PRINTF(2, 3) size_t out_printf(const char *format
Append a formatted string to the output string.
ea_t insn_ea
Definition ua.hpp:723
AS_PRINTF(2, 3) inline bool gen_collapsed_line(const char *format
Generate one non-indented comment line, colored with COLOR_COLLAPSED.
bool print_label_now() const
Definition ua.hpp:795
outctx_base_t(ea_t ea, flags64_t flags, int _suspop=0)
bool force_code() const
Definition ua.hpp:781
bool stack_view() const
Definition ua.hpp:782
int ind0
Definition ua.hpp:773
int forbid_annotations()
Definition ua.hpp:800
int get_xrefgen_state() const
Definition ua.hpp:786
virtual void idaapi add_aux_prefix(const char *, int)
Definition ua.hpp:1122
Definition ua.hpp:1130
int bin_width
Definition ua.hpp:1135
int gl_bpsize
Definition ua.hpp:1134
ea_t bin_ea
Definition ua.hpp:1132
qstring curlabel
Definition ua.hpp:1141
virtual void idaapi out_mnemonic(void) new api
Output instruction mnemonic using information in 'insn'.
virtual void idaapi gen_header(int flags=GH_PRINT_PROC_AND_ASM, const char *proc_name=nullptr, const char *proc_flavour=nullptr) new api
virtual void idaapi gen_func_footer(const func_t *pfn) new api
procmod_t * procmod
Definition ua.hpp:1147
void set_bin_state(int value)
Definition ua.hpp:1176
uval_t saved_immvals[UA_MAXOP]
Definition ua.hpp:1152
virtual void idaapi out_fcref_names() new api
Print addresses referenced from the specified address as commented symbolic names.
virtual bool idaapi out_one_operand(int n) new api
Use this function to output an operand of an instruction.
virtual void idaapi out_immchar_cmts(void) new api
Print all operand values as commented character constants.
virtual void idaapi setup_outctx(const char *prefix, int flags) override
Initialization; normally used only by the kernel.
virtual ssize_t idaapi retrieve_cmt(void) override
flags64_t F
Definition ua.hpp:1156
virtual void idaapi out_btoa(uval_t Word, char radix=0) override
Output a number with the specified base (binary, octal, decimal, hex) The number is output without co...
processor_t & ph
Definition ua.hpp:1148
~outctx_t(void)
Definition ua.hpp:1166
outctx_t(procmod_t *p, processor_t &ph, asm_t &ash, ea_t ea, flags64_t flags=0, int _suspop=0, const printop_t *_wif=nullptr)
virtual int idaapi term_outctx(const char *prefix=nullptr) override
Finalize the output context.
char bin_state
Definition ua.hpp:1133
insn_t insn
Definition ua.hpp:1138
virtual ssize_t idaapi retrieve_name(qstring *, color_t *) override
virtual void idaapi out_data(bool analyze_only) new api
ea_t prefix_ea
Definition ua.hpp:1154
const printop_t * wif
Definition ua.hpp:1144
virtual bool idaapi out_specea(uchar segtype) new api
virtual size_t idaapi get_immvals(uval_t *out, int i) new api
Get the immediate values used at the specified address.
virtual void idaapi gen_func_header(func_t *pfn) new api
ea_t next_line_ea
Definition ua.hpp:1155
virtual void idaapi gen_header_extra() new api
virtual bool idaapi gen_xref_lines(void) override
asm_t & ash
Definition ua.hpp:1149
virtual void idaapi out_custom_mnem(const char *mnem, int width=8, const char *postfix=nullptr) new api
Output custom mnemonic for 'insn'.
virtual void idaapi out_mnem(int width=8, const char *postfix=nullptr) new api
Output instruction mnemonic for 'insn' using information in 'ph.instruc' array.
Definition nalt.hpp:1259
Describes a processor module (IDP).
Definition idp.hpp:613
Definition idp.hpp:2085
Definition ua.hpp:588
uint64 low
Definition ua.hpp:588
uint64 high
Definition ua.hpp:588
Definition ua.hpp:586
uint32 low
Definition ua.hpp:586
uint32 high
Definition ua.hpp:586
Definition ua.hpp:587
uint32 low
Definition ua.hpp:587
uint16 upper
Definition ua.hpp:587
uint32 high
Definition ua.hpp:587
idaman int ida_export get_spoiled_reg(const insn_t &insn, const uint32 *regs, size_t n)
Does the instruction spoil any register from 'regs'?
idaman int ida_export get_lookback(void)
Number of instructions to look back.
idaman bool ida_export print_fpval(char *buf, size_t bufsize, const void *v, int size)
Print a floating point value.
idaman outctx_base_t *ida_export create_outctx(ea_t ea, flags64_t F=0, int suspop=0)
Create a new output context.
idaman ea_t ida_export map_code_ea(const insn_t &insn, ea_t addr, int opnum)
Map a code address.
idaman ea_t ida_export decode_preceding_insn(insn_t *out, ea_t ea, bool *p_farref=nullptr)
Decode preceding instruction in the execution flow.
idaman bool ida_export print_insn_mnem(qstring *out, ea_t ea)
Print instruction mnemonics.
idaman size_t ida_export get_immvals(uval_t *out, ea_t ea, int n, flags64_t F, insn_t *cache=nullptr)
Get immediate values at the specified address.
idaman flags64_t ida_export get_dtype_flag(op_dtype_t dtype)
Get flags for op_t::dtype field.
size_t get_printable_immvals(uval_t *out, ea_t ea, int n, flags64_t F, insn_t *cache=nullptr)
Get immediate ready-to-print values at the specified address.
Definition ua.hpp:629
idaman int ida_export create_insn(ea_t ea, insn_t *out=nullptr)
Create an instruction at the specified address.
idaman ea_t ida_export calc_dataseg(const insn_t &insn, int n=-1, int rgnum=-1)
Get data segment for the instruction operand.
idaman bool ida_export format_charlit(qstring *out, const uchar **ptr, size_t size, uint32 flags=0, int encidx=0)
Format character literal.
idaman ea_t ida_export decode_prev_insn(insn_t *out, ea_t ea)
Decode previous instruction if it exists, fill 'out'.
uchar optype_t
see Operand types
Definition ua.hpp:66
bool is_floating_dtype(op_dtype_t dtype)
Is a floating type operand?
Definition ua.hpp:1373
ea_t map_ea(const insn_t &insn, const op_t &op, bool iscode)
Definition ua.hpp:704
idaman bool ida_export print_operand(qstring *out, ea_t ea, int n, int getn_flags=0, struct printop_t *newtype=nullptr)
Generate text representation for operand n.
idaman op_dtype_t ida_export get_dtype_by_size(asize_t size)
Get op_t::dtype from size.
CASSERT(sizeof(insn_t)==360)
idaman bool ida_export construct_macro(macro_constructor_t *_this, insn_t *insn, bool enable)
idaman size_t ida_export get_dtype_size(op_dtype_t dtype)
Get size of opt_::dtype field.
ea_t map_data_ea(const insn_t &insn, ea_t addr, int opnum=-1)
Map a data address.
Definition ua.hpp:681
bool can_decode(ea_t ea)
Can the bytes at address 'ea' be decoded as instruction?
Definition ua.hpp:1411
idaman int ida_export decode_insn(insn_t *out, ea_t ea)
Analyze the specified address and fill 'out'.
This union is used to pass byte values to various helper functions.
Definition ua.hpp:580
uval_t v_uval
Definition ua.hpp:585
uint32 v_long
Definition ua.hpp:583
struct value_union_t::d128_t d128
uint64 v_int64
Definition ua.hpp:584
struct value_union_t::dq_t _dq
uint16 v_short
Definition ua.hpp:582
struct value_union_t::dt_t dt
uint8 byte16[16]
Definition ua.hpp:589
uint8 v_char
Definition ua.hpp:581
Functions that deal with cross-references (xrefs).
idaman bool ida_export add_dref(ea_t from, ea_t to, dref_t type)
Create a data cross-reference.
idaman bool ida_export add_cref(ea_t from, ea_t to, cref_t type)
Create a code cross-reference.