IDA C++ SDK 9.2
Loading...
Searching...
No Matches
lines.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 _LINES_HPP
9#define _LINES_HPP
10
11#include <ida.hpp>
12
23
24struct range_t;
25
26//---------------------------------------------------------------------------
27// C O L O R D E F I N I T I O N S
28//---------------------------------------------------------------------------
29
70
74#define COLOR_ON '\1'
76#define COLOR_OFF '\2'
78#define COLOR_ESC '\3'
81#define COLOR_INV '\4'
84
85#define SCOLOR_ON "\1"
86#define SCOLOR_OFF "\2"
87#define SCOLOR_ESC "\3"
88#define SCOLOR_INV "\4"
89
91inline THREAD_SAFE bool requires_color_esc(char c) { return c >= COLOR_ON && c <= COLOR_INV; }
93
94typedef uchar color_t;
98const color_t
103 COLOR_INSN = 0x05,
105 COLOR_DNAME = 0x07,
108 COLOR_CHAR = 0x0A,
112 COLOR_CREF = 0x0E,
113 COLOR_DREF = 0x0F,
116 COLOR_ERROR = 0x12,
119 COLOR_EXTRA = 0x15,
120 COLOR_ALTOP = 0x16,
126 COLOR_MACRO = 0x1C,
127 COLOR_DSTR = 0x1D,
128 COLOR_DCHAR = 0x1E,
129 COLOR_DNUM = 0x1F,
131 COLOR_REG = 0x21,
135 COLOR_CNAME = 0x25,
136 COLOR_UNAME = 0x26,
139
140 // Fictive colors
141
146
155
156
160
162#define COLOR_ADDR_SIZE (sizeof(ea_t)*2)
163
167#define SCOLOR_DEFAULT "\x01"
168#define SCOLOR_REGCMT "\x02"
169#define SCOLOR_RPTCMT "\x03"
170#define SCOLOR_AUTOCMT "\x04"
171#define SCOLOR_INSN "\x05"
172#define SCOLOR_DATNAME "\x06"
173#define SCOLOR_DNAME "\x07"
174#define SCOLOR_DEMNAME "\x08"
175#define SCOLOR_SYMBOL "\x09"
176#define SCOLOR_CHAR "\x0A"
177#define SCOLOR_STRING "\x0B"
178#define SCOLOR_NUMBER "\x0C"
179#define SCOLOR_VOIDOP "\x0D"
180#define SCOLOR_CREF "\x0E"
181#define SCOLOR_DREF "\x0F"
182#define SCOLOR_CREFTAIL "\x10"
183#define SCOLOR_DREFTAIL "\x11"
184#define SCOLOR_ERROR "\x12"
185#define SCOLOR_PREFIX "\x13"
186#define SCOLOR_BINPREF "\x14"
187#define SCOLOR_EXTRA "\x15"
188#define SCOLOR_ALTOP "\x16"
189#define SCOLOR_HIDNAME "\x17"
190#define SCOLOR_LIBNAME "\x18"
191#define SCOLOR_LOCNAME "\x19"
192#define SCOLOR_CODNAME "\x1A"
193#define SCOLOR_ASMDIR "\x1B"
194#define SCOLOR_MACRO "\x1C"
195#define SCOLOR_DSTR "\x1D"
196#define SCOLOR_DCHAR "\x1E"
197#define SCOLOR_DNUM "\x1F"
198#define SCOLOR_KEYWORD "\x20"
199#define SCOLOR_REG "\x21"
200#define SCOLOR_IMPNAME "\x22"
201#define SCOLOR_SEGNAME "\x23"
202#define SCOLOR_UNKNAME "\x24"
203#define SCOLOR_CNAME "\x25"
204#define SCOLOR_UNAME "\x26"
205#define SCOLOR_COLLAPSED "\x27"
206#define SCOLOR_ADDR "\x28"
208
209//----------------- Line prefix colors --------------------------------------
213#define COLOR_DEFAULT 0x01
214#define COLOR_SELECTED 0x02
215#define COLOR_LIBFUNC 0x03
216#define COLOR_REGFUNC 0x04
217#define COLOR_CODE 0x05
218#define COLOR_DATA 0x06
219#define COLOR_UNKNOWN 0x07
220#define COLOR_EXTERN 0x08
221#define COLOR_CURITEM 0x09
222#define COLOR_CURLINE 0x0A
223#define COLOR_HIDLINE 0x0B
224#define COLOR_LUMFUNC 0x0C
225#define COLOR_BG_MAX 0x0D
226
227#define PALETTE_SIZE (COLOR_FG_MAX+COLOR_BG_MAX)
229
230
234#define COLSTR(str,tag) SCOLOR_ON tag str SCOLOR_OFF tag
235
236
237//------------------------------------------------------------------------
238
244
249
250idaman THREAD_SAFE void ida_export tag_addr(qstring *buf, ea_t ea, bool ins=false);
251
252
258
259idaman THREAD_SAFE const char *ida_export tag_advance(const char *line, int cnt);
260
261
265
266idaman THREAD_SAFE const char *ida_export tag_skipcodes(const char *line);
267
268
276
277idaman THREAD_SAFE const char *ida_export tag_skipcode(const char *line);
278
279
283
284idaman THREAD_SAFE ssize_t ida_export tag_strlen(const char *line);
285
286
292
293idaman THREAD_SAFE ssize_t ida_export tag_remove(qstring *buf, const char *str, int init_level=0);
294
295inline THREAD_SAFE ssize_t idaapi tag_remove(qstring *buf, const qstring &str, int init_level=0)
296{
297 return tag_remove(buf, str.c_str(), init_level);
298}
299
300inline THREAD_SAFE ssize_t idaapi tag_remove(qstring *buf, int init_level=0)
301{
302 if ( buf->empty() )
303 return 0;
304 return tag_remove(buf, buf->begin(), init_level);
305}
306
308
310
311
314idaman color_t ida_export calc_prefix_color(ea_t ea);
315
318idaman bgcolor_t ida_export calc_bg_color(ea_t ea);
319
320
321//------------------------------------------------------------------------
322// S O U R C E F I L E S
323//------------------------------------------------------------------------
324
330
338
339idaman bool ida_export add_sourcefile(ea_t ea1, ea_t ea2, const char *filename);
340
341
348
349idaman const char *ida_export get_sourcefile(ea_t ea, range_t *bounds=nullptr);
350
351
355
356idaman bool ida_export del_sourcefile(ea_t ea);
358
359//------------------------------------------------------------------------
360// G E N E R A T I O N O F D I S A S S E M B L E D T E X T
361//------------------------------------------------------------------------
362
365
375idaman bool ida_export install_user_defined_prefix(
376 size_t prefix_len,
377 struct user_defined_prefix_t *udp,
378 const void *owner);
379
382{
384 user_defined_prefix_t(size_t prefix_len, const void *owner)
385 {
386 install_user_defined_prefix(prefix_len, this, owner);
387 }
388
390 virtual idaapi ~user_defined_prefix_t()
391 {
392 install_user_defined_prefix(0, this, nullptr);
393 }
394
395 // Get a user-defined prefix.
409 virtual void idaapi get_user_defined_prefix(
410 qstring *vout,
411 ea_t ea,
412 const class insn_t &insn,
413 int lnnum,
414 int indent,
415 const char *line) = 0;
416};
417
419
420//------------------------------------------------------------------------
421// A N T E R I O R / P O S T E R I O R L I N E S
422//------------------------------------------------------------------------
423
426
428
429idaman AS_PRINTF(3, 0) bool ida_export vadd_extra_line(
430 ea_t ea,
431 int vel_flags, // see VEL_...
432 const char *format,
433 va_list va);
434
435#define VEL_POST 0x01
436#define VEL_CMT 0x02
437
438
444
445AS_PRINTF(3, 4) inline bool add_extra_line(ea_t ea, bool isprev, const char *format, ...)
446{
447 va_list va;
449 int vel_flags = (isprev ? 0 : VEL_POST);
450 bool ok = vadd_extra_line(ea, vel_flags, format, va);
452 return ok;
453}
454
455
463
464AS_PRINTF(3, 4) inline bool add_extra_cmt(ea_t ea, bool isprev, const char *format, ...)
465{
466 va_list va;
468 int vel_flags = (isprev ? 0 : VEL_POST) | VEL_CMT;
469 bool ok = vadd_extra_line(ea, vel_flags, format, va);
470 va_end(va);
471 return ok;
472}
473
474
480
481AS_PRINTF(1, 2) inline bool add_pgm_cmt(const char *format, ...)
482{
483 va_list va;
485 bool ok = vadd_extra_line(inf_get_min_ea(), VEL_CMT, format, va);
486 va_end(va);
487 return ok;
488}
489
491
494
495// Generate disassembly (many lines) and put them into a buffer
496// Returns number of generated lines
497idaman int ida_export generate_disassembly(
498 qstrvec_t *out, // buffer to hold generated lines
499 int *lnnum, // number of "the most interesting" line
500 ea_t ea, // address to generate disassembly for
501 int maxsize, // maximum number of lines
502 int flags = 0);
503
504#define GDISMF_AS_STACK (1 << 0)
505#define GDISMF_ADDR_TAG (1 << 1)
506#define GDISMF_REMOVE_TAGS (1 << 2)
507#define GDISMF_UNHIDE (1 << 3)
508
509// Generate one line of disassembly
510// This function discards all "non-interesting" lines
511// It is designed to generate one-line descriptions
512// of addresses for lists, etc.
513idaman bool ida_export generate_disasm_line(
514 qstring *buf, // output buffer
515 ea_t ea, // address to generate disassembly for
516 int flags=0);
517#define GENDSM_FORCE_CODE (1 << 0)
519#define GENDSM_MULTI_LINE (1 << 1)
521#define GENDSM_REMOVE_TAGS (1 << 2)
522#define GENDSM_UNHIDE (1 << 3)
523
525
526idaman int ida_export get_last_pfxlen();
527
528
529// Get pointer to the sequence of characters denoting 'close comment'
530// empty string means no comment (the current assembler has no open-comment close-comment pairs)
531// This function uses ash.cmnt2
532
533idaman const char *ida_export closing_comment();
534
535
536// Every anterior/posterior line has its number.
537// Anterior lines have numbers from E_PREV
538// Posterior lines have numbers from E_NEXT
539
540const int E_PREV = 1000;
541const int E_NEXT = 2000;
542
543idaman int ida_export get_first_free_extra_cmtidx(ea_t ea, int start);
544idaman bool ida_export update_extra_cmt(ea_t ea, int what, const char *str);
545idaman bool ida_export del_extra_cmt(ea_t ea, int what);
546idaman ssize_t ida_export get_extra_cmt(qstring *buf, ea_t ea, int what);
547idaman void ida_export delete_extra_cmts(ea_t ea, int what);
548
549idaman ea_t ida_export align_down_to_stack(ea_t newea);
550idaman ea_t ida_export align_up_to_stack(ea_t ea1, ea_t ea2=BADADDR);
551
552// A helper class, to encode from UTF-8, -> into the target encoding.
553// This is typically used when generating listings (or any kind of
554// output file.)
555struct encoder_t
556{
557 // whether or not a message should be printed, letting the
558 // user know that some text couldn't be recoded properly
559 enum notify_recerr_t
560 {
561 nr_none,
562 nr_once,
563 };
564
565 virtual ~encoder_t() {}
566 virtual bool idaapi get_bom(bytevec_t *out) const = 0;
567 // returns true if conversion was entirely successful, false otherwise.
568 // codepoints that couldn't be converted, will be output as C
569 // literal-escaped UTF-8 sequences (e.g., "\xC3\xD9"), and if
570 // 'nr_once' was passed at creation-time, a one-time notification
571 // well be output in the messages window.
572 virtual bool idaapi encode(qstring *s) const = 0;
573 // encode()s the UTF-8 string composed by format + args, and
574 // returns true if all the resulting bytes could be written to
575 // the output file.
576 AS_PRINTF(3, 4) virtual bool idaapi print(FILE *out, const char *format, ...) const = 0;
577 // should a file be opened as binary, or should it rather be opened
578 // in text mode? This will have an importance in how '\n' characters
579 // are possibly converted into '\x0A\x0D' on windows, which is most
580 // inappropriate when output'ing e.g., UTF-16, UTF-32..
581 virtual bool idaapi requires_binary_mode() const = 0;
582};
583
584// Create the encoder with the given target encoding. If -1 is passed
585// then the effective target encoding will be computed like so:
586// if ( encidx < 0 )
587// {
588// encidx = get_outfile_encoding_idx();
589// if ( encidx == STRENC_DEFAULT )
590// encidx = get_default_encoding_idx(BPU_1B);
591// }
592idaman encoder_t *ida_export create_encoding_helper(
593 int encidx=-1,
594 encoder_t::notify_recerr_t nr=encoder_t::nr_once);
595
598typedef int idaapi html_header_cb_t(FILE *fp);
599typedef int idaapi html_footer_cb_t(FILE *fp);
600typedef int idaapi html_line_cb_t(
601 FILE *fp,
602 const qstring &line,
603 bgcolor_t prefix_color,
604 bgcolor_t bg_color);
605#define gen_outline_t html_line_cb_t
607
609
610
611#endif
bool empty(void) const
Does the qstring have 0 non-null elements?
Definition pro.h:3168
iterator begin(void)
Get a pointer to the beginning of the qstring.
Definition pro.h:3177
const qchar * c_str(void) const
Convert the qstring to a char *.
Definition pro.h:3170
const color_t COLOR_OPND4
Instruction operand 4.
Definition lines.hpp:150
const color_t COLOR_MACRO
Macro.
Definition lines.hpp:126
const color_t COLOR_OPND2
Instruction operand 2.
Definition lines.hpp:148
const color_t COLOR_AUTOCMT
Automatic comment.
Definition lines.hpp:102
const color_t COLOR_CODNAME
Dummy code name.
Definition lines.hpp:124
const color_t COLOR_DNAME
Regular Data Name.
Definition lines.hpp:105
const color_t COLOR_RESERVED1
This tag is reserved for internal IDA use.
Definition lines.hpp:157
const color_t COLOR_REGCMT
Regular comment.
Definition lines.hpp:100
const color_t COLOR_DEMNAME
Demangled Name.
Definition lines.hpp:106
const color_t COLOR_IMPNAME
Imported name.
Definition lines.hpp:132
const color_t COLOR_NUMBER
Numeric constant in instruction.
Definition lines.hpp:110
const color_t COLOR_FG_MAX
Max color number.
Definition lines.hpp:138
const color_t COLOR_BINPREF
Binary line prefix bytes.
Definition lines.hpp:118
const color_t COLOR_RPTCMT
Repeatable comment (comment defined somewhere else)
Definition lines.hpp:101
const color_t COLOR_COLLAPSED
Collapsed line.
Definition lines.hpp:137
const color_t COLOR_DATNAME
Dummy Data Name.
Definition lines.hpp:104
const color_t COLOR_OPND3
Instruction operand 3.
Definition lines.hpp:149
const color_t COLOR_CREFTAIL
Code reference to tail byte.
Definition lines.hpp:114
const color_t COLOR_ASMDIR
Assembler directive.
Definition lines.hpp:125
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_UNKNAME
Dummy unknown name.
Definition lines.hpp:134
const color_t COLOR_STRING
String constant in instruction.
Definition lines.hpp:109
const color_t COLOR_LIBNAME
Library function name.
Definition lines.hpp:122
const color_t COLOR_EXTRA
Extra line.
Definition lines.hpp:119
const color_t COLOR_OPND8
Instruction operand 8.
Definition lines.hpp:154
const color_t COLOR_CHAR
Char constant in instruction.
Definition lines.hpp:108
const color_t COLOR_PREFIX
Line prefix.
Definition lines.hpp:117
const color_t COLOR_LOCNAME
Local variable name.
Definition lines.hpp:123
const color_t COLOR_VOIDOP
Void operand.
Definition lines.hpp:111
const color_t COLOR_DREF
Data reference.
Definition lines.hpp:113
const color_t COLOR_SEGNAME
Segment name.
Definition lines.hpp:133
const color_t COLOR_DSTR
String constant in data directive.
Definition lines.hpp:127
const color_t COLOR_DCHAR
Char constant in data directive.
Definition lines.hpp:128
const color_t COLOR_OPND7
Instruction operand 7.
Definition lines.hpp:153
const color_t COLOR_OPND6
Instruction operand 6.
Definition lines.hpp:152
const color_t COLOR_CREF
Code reference.
Definition lines.hpp:112
const color_t COLOR_HIDNAME
Hidden name.
Definition lines.hpp:121
const color_t COLOR_CNAME
Regular code name.
Definition lines.hpp:135
const color_t COLOR_ALTOP
Alternative operand.
Definition lines.hpp:120
const color_t COLOR_UNAME
Regular unknown name.
Definition lines.hpp:136
const color_t COLOR_DREFTAIL
Data reference to tail byte.
Definition lines.hpp:115
const color_t COLOR_ADDR
Hidden address marks.
Definition lines.hpp:142
const color_t COLOR_OPND1
Instruction operand 1.
Definition lines.hpp:147
const color_t COLOR_DEFAULT
Default.
Definition lines.hpp:99
const color_t COLOR_OPND5
Instruction operand 5.
Definition lines.hpp:151
const color_t COLOR_SYMBOL
Punctuation.
Definition lines.hpp:107
const color_t COLOR_INSN
Instruction.
Definition lines.hpp:103
const color_t COLOR_ERROR
Error or problem.
Definition lines.hpp:116
const color_t COLOR_DNUM
Numeric constant in data directive.
Definition lines.hpp:129
const color_t COLOR_LUMINA
Lumina-related, only for the navigation band.
Definition lines.hpp:158
idaman THREAD_SAFE ssize_t ida_export tag_strlen(const char *line)
Calculate length of a colored string This function computes the length in unicode codepoints of a lin...
idaman THREAD_SAFE ssize_t ida_export tag_remove(qstring *buf, const char *str, int init_level=0)
Remove color escape sequences from a string.
idaman THREAD_SAFE void ida_export tag_addr(qstring *buf, ea_t ea, bool ins=false)
Insert an address mark into a string.
idaman THREAD_SAFE const char *ida_export tag_skipcode(const char *line)
Skip one color code.
idaman THREAD_SAFE const char *ida_export tag_advance(const char *line, int cnt)
Move pointer to a 'line' to 'cnt' positions right.
idaman THREAD_SAFE const char *ida_export tag_skipcodes(const char *line)
Move the pointer past all color codes.
uchar color_t
see <lines.hpp>
Definition kernwin.hpp:26
THREAD_SAFE bool requires_color_esc(char c)
Is the given char a color escape character?
Definition lines.hpp:91
idaman THREAD_SAFE va_list va
See qsscanf()
Definition err.h:21
idaman THREAD_SAFE const char * format
Definition fpro.h:78
idaman THREAD_SAFE AS_PRINTF(1, 0) void ida_export vqperror(const char *format
Print error message to stderr (analog of perror)
Contains the inf structure definition and some functions common to the whole IDA project.
ea_t inf_get_min_ea()
Definition ida.hpp:794
bool ok
Definition kernwin.hpp:7006
bool const char va_start(va, format)
idaman const char *ida_export get_sourcefile(ea_t ea, range_t *bounds=nullptr)
Get name of source file occupying the given address.
idaman AS_PRINTF(3, 0) bool ida_export vadd_extra_line(ea_t ea
See higher level functions below.
idaman int vel_flags
Definition lines.hpp:431
va_end(va)
idaman bool ida_export add_sourcefile(ea_t ea1, ea_t ea2, const char *filename)
Mark a range of address as belonging to a source file.
bool isprev
Definition lines.hpp:445
idaman color_t ida_export calc_prefix_color(ea_t ea)
Get prefix color for line at 'ea'.
idaman bool ida_export install_user_defined_prefix(size_t prefix_len, struct user_defined_prefix_t *udp, const void *owner)
User-defined line-prefixes are displayed just after the autogenerated line prefixes in the disassembl...
idaman bgcolor_t ida_export calc_bg_color(ea_t ea)
Get background color for line at 'ea'.
idaman bool ida_export del_sourcefile(ea_t ea)
Delete information about the source file.
int bool
Definition pro.h:329
uint32 bgcolor_t
background color in RGB
Definition pro.h:5012
uint64 ea_t
Definition pro.h:421
struct bytevec_tag bytevec_t
Definition pro.h:4665
unsigned char uchar
unsigned 8 bit value
Definition pro.h:337
ptrdiff_t ssize_t
Signed size_t - used to check for size overflows when the counter becomes negative.
Definition pro.h:381
_qstring< char > qstring
regular string
Definition pro.h:3694
qvector< qstring > qstrvec_t
vector of strings
Definition pro.h:3697
Base class for an range.
Definition range.hpp:35
Class to generate user-defined prefixes in the disassembly listing.
Definition lines.hpp:382
virtual idaapi ~user_defined_prefix_t()
Destroying a user-defined prefix object uninstalls it.
Definition lines.hpp:390
virtual void idaapi get_user_defined_prefix(qstring *vout, ea_t ea, const class insn_t &insn, int lnnum, int indent, const char *line)=0
This callback must be overridden by the derived class.
user_defined_prefix_t(size_t prefix_len, const void *owner)
Creating a user-defined prefix object installs it.
Definition lines.hpp:384