IDA C++ SDK 9.2
Loading...
Searching...
No Matches
fixup.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 FIXUP_HPP
9#define FIXUP_HPP
10
11#include <nalt.hpp>
12#include <segment.hpp>
13
20
21//--------------------------------------------------------------------------
23
32#define FIXUP_OFF8 13
33#define FIXUP_OFF16 1
34#define FIXUP_SEG16 2
35#define FIXUP_PTR16 3
37#define FIXUP_OFF32 4
38#define FIXUP_PTR32 5
39#define FIXUP_HI8 6
40#define FIXUP_HI16 7
41#define FIXUP_LOW8 8
42#define FIXUP_LOW16 9
43#define V695_FIXUP_VHIGH 10
44#define V695_FIXUP_VLOW 11
45#define FIXUP_OFF64 12
46#define FIXUP_OFF8S 14
47#define FIXUP_OFF16S 15
48#define FIXUP_OFF32S 16
49//#define FIXUP_ 0xE
50#define FIXUP_CUSTOM 0x8000
52
54inline THREAD_SAFE bool is_fixup_custom(fixup_type_t type)
55{
56 return (type & FIXUP_CUSTOM) != 0;
57}
58
62
65#define FIXUPF_REL 0x0001
69#define FIXUPF_EXTDEF 0x0002
73#define FIXUPF_UNUSED 0x0004
75#define FIXUPF_CREATED 0x0008
78#define FIXUPF_LOADER_MASK 0xF0000000
80
81struct fixup_handler_t;
83{
84protected:
85 fixup_type_t type; // fixup type
86 uint32 flags; // FIXUPF_... bits
87 uval_t base; // base for relative fixups
88
89public:
93
97
99
100public:
102 : type(0),
103 flags(0),
104 base(0),
105 sel(BADSEL),
106 off(0),
107 displacement(0) {}
109 : type(type_),
110 flags(flags_),
111 base(0),
112 sel(BADSEL),
113 off(0),
114 displacement(0) {}
115
117 fixup_type_t get_type(void) const { return type; }
118 void set_type(fixup_type_t type_) { type = type_; }
119 void set_type_and_flags(fixup_type_t type_, uint32 flags_ = 0)
120 {
121 type = type_;
122 flags = flags_;
123 }
124
125 bool is_custom(void) const;
126
128 uint32 get_flags() const { return flags; }
129
130 bool is_extdef(void) const { return (flags & FIXUPF_EXTDEF) != 0; }
131 void set_extdef(void) { flags |= FIXUPF_EXTDEF; }
132 void clr_extdef(void) { flags &= ~FIXUPF_EXTDEF; }
133
134 bool is_unused(void) const { return (flags & FIXUPF_UNUSED) != 0; }
135 void set_unused(void) { flags |= FIXUPF_UNUSED; }
136 void clr_unused(void) { flags &= ~FIXUPF_UNUSED; }
137
139 bool has_base(void) const { return (flags & FIXUPF_REL) != 0; }
140
142 bool was_created(void) const { return (flags & FIXUPF_CREATED) != 0; }
143
148 {
149 return has_base() ? base : sel != BADSEL ? sel2ea(sel) : 0;
150 }
151
154 void set_base(ea_t new_base)
155 {
156 ea_t target = get_base() + off;
157 flags |= FIXUPF_REL;
158 base = new_base;
159 off = target - base;
160 }
161
162 void set_sel(const segment_t *seg)
163 {
164 sel = seg == nullptr ? BADSEL : seg->sel;
165 }
166
170 {
171 ea_t target = get_base() + off;
172 set_sel(getseg(target));
173 flags &= ~FIXUPF_REL;
174 base = 0; // just in case
175 off = target - get_base();
176 }
177
178 void set(ea_t source) const;
179 bool get(ea_t source);
180
182 const fixup_handler_t *get_handler() const;
183
185 const char *get_desc(qstring *buf, ea_t source) const;
186
187 // TODO rewrite to the inline implementation which uses
188 // fixup_handler_t::size
189 int calc_size() const;
190 uval_t get_value(ea_t ea) const;
191 bool patch_value(ea_t ea) const;
192
193};
194
196
197idaman bool ida_export get_fixup(fixup_data_t *fd, ea_t source);
198
199
201
202inline bool exists_fixup(ea_t source)
203{
204 return get_fixup(nullptr, source);
205}
206
207
213
214idaman void ida_export set_fixup(ea_t source, const fixup_data_t &fd);
215
216
218
219idaman void ida_export del_fixup(ea_t source);
220
221
227idaman ea_t ida_export get_first_fixup_ea(void);
228
233idaman ea_t ida_export get_next_fixup_ea(ea_t ea);
234
239idaman ea_t ida_export get_prev_fixup_ea(ea_t ea);
241
242
244
246
247
259
260idaman bool ida_export apply_fixup(ea_t item_ea, ea_t fixup_ea, int n, bool is_macro);
261
262
276
278
279
292
293idaman bool ida_export patch_fixup_value(ea_t ea, const fixup_data_t &fd);
294
295
297
298idaman const char *ida_export get_fixup_desc(
299 qstring *buf,
300 ea_t source,
301 const fixup_data_t &fd);
302
303
306
307idaman int ida_export calc_fixup_size(fixup_type_t type);
308
309
310//--------------------------------------------------------------------------
311// inline implementation
312inline bool fixup_data_t::is_custom(void) const
313{
314 return is_fixup_custom(type);
315}
316inline void fixup_data_t::set(ea_t source) const
317{
318 set_fixup(source, *this);
319}
320
321inline bool fixup_data_t::get(ea_t source)
322{
323 return get_fixup(this, source);
324}
325
326inline const char *fixup_data_t::get_desc(qstring *buf, ea_t source) const
327{
328 return get_fixup_desc(buf, source, *this);
329}
330
331inline int fixup_data_t::calc_size() const
332{
333 return calc_fixup_size(type);
334}
335
337{
338 return get_fixup_value(ea, type);
339}
340
341inline bool fixup_data_t::patch_value(ea_t ea) const
342{
343 return patch_fixup_value(ea, *this);
344}
345
347{
348 return get_fixup_handler(type);
349}
350
351
358
359//--------------------------------------------------------------------------
362{
364 const char *name;
369#define FHF_VERIFY 0x0001
372#define FHF_CODE 0x0002
374#define FHF_FORCE_CODE 0x0004
377#define FHF_ABS_OPVAL 0x0008
380#define FHF_SIGNED 0x0010
385 bool is_signed() const { return (props & FHF_SIGNED) != 0; }
386
396 uint8 rsrv4; // reserved
397
401
406 bool (idaapi *apply)(
407 const fixup_handler_t *fh,
410 int opnum,
413
418 uval_t (idaapi *get_value)(const fixup_handler_t *fh, ea_t ea);
419
427 bool (idaapi *patch_value)(
428 const fixup_handler_t *fh,
429 ea_t ea,
431
432#ifndef SWIG
434#endif
435};
436
437
441
473
491
492
500
502 const fixup_handler_t *cfh);
503
504
507
509
510
514
515idaman fixup_type_t ida_export find_custom_fixup(const char *name);
516
518
519
520//--------------------------------------------------------------------------
524
532
533idaman bool ida_export get_fixups(fixups_t *out, ea_t ea, asize_t size);
534
535
537
539{
540 return get_fixups(nullptr, ea, size);
541}
542
543
550
551idaman void ida_export gen_fix_fixups(ea_t from, ea_t to, asize_t size);
552
553
567
568idaman bool ida_export handle_fixups_in_macro(
569 refinfo_t *ri,
570 ea_t ea,
571 fixup_type_t other,
572 uint32 macro_reft_and_flags);
573
574
575#endif // FIXUP_HPP
Reimplementation of vector class from STL.
Definition pro.h:2250
Describes a program segment.
Definition segment.hpp:69
sel_t sel
segment selector - should be unique.
Definition segment.hpp:242
idaman fixup_type_t ida_export find_custom_fixup(const char *name)
Get id of a custom fixup handler.
idaman ea_t ida_export get_next_fixup_ea(ea_t ea)
Find next address with fixup information.
idaman void ida_export set_fixup(ea_t source, const fixup_data_t &fd)
Set fixup information.
idaman void ida_export del_fixup(ea_t source)
Delete fixup information.
idaman const fixup_handler_t *ida_export get_fixup_handler(fixup_type_t type)
Get handler of standard or custom fixup.
qvector< fixup_info_t > fixups_t
Definition fixup.hpp:531
idaman bool ida_export patch_fixup_value(ea_t ea, const fixup_data_t &fd)
Patch the fixup bytes.
idaman void ida_export gen_fix_fixups(ea_t from, ea_t to, asize_t size)
Relocate the bytes with fixup information once more (generic function).
idaman bool ida_export unregister_custom_fixup(fixup_type_t type)
Unregister a new custom fixup format.
idaman ea_t ida_export get_prev_fixup_ea(ea_t ea)
Find previous address with fixup information.
bool contains_fixups(ea_t ea, asize_t size)
Does the specified address range contain any fixup information?
Definition fixup.hpp:538
THREAD_SAFE bool is_fixup_custom(fixup_type_t type)
Is fixup processed by processor module?
Definition fixup.hpp:54
idaman bool ida_export handle_fixups_in_macro(refinfo_t *ri, ea_t ea, fixup_type_t other, uint32 macro_reft_and_flags)
Handle two fixups in a macro.
bool exists_fixup(ea_t source)
Check that a fixup exists at the given address.
Definition fixup.hpp:202
idaman fixup_type_t ida_export register_custom_fixup(const fixup_handler_t *cfh)
Register a new custom fixup.
DECLARE_TYPE_AS_MOVABLE(fixup_info_t)
idaman bool ida_export get_fixup(fixup_data_t *fd, ea_t source)
Get fixup information.
idaman int ida_export calc_fixup_size(fixup_type_t type)
Calculate size of fixup in bytes (the number of bytes the fixup patches)
idaman bool ida_export apply_fixup(ea_t item_ea, ea_t fixup_ea, int n, bool is_macro)
Use fixup information for an address.
uint16 fixup_type_t
Fixup information structure.
Definition fixup.hpp:24
idaman bool ida_export get_fixups(fixups_t *out, ea_t ea, asize_t size)
idaman ea_t ida_export get_first_fixup_ea(void)
idaman const char *ida_export get_fixup_desc(qstring *buf, ea_t source, const fixup_data_t &fd)
Get FIXUP description comment.
idaman uval_t ida_export get_fixup_value(ea_t ea, fixup_type_t type)
Get the operand value.
uint8 rsrv4
Definition fixup.hpp:396
uint32 reftype
reference info type and flags, std_apply() produces an offset of this type
Definition fixup.hpp:398
uint8 shift
number of bits to shift right before patching.
Definition fixup.hpp:393
uint8 size
The examples below show how these options work.
Definition fixup.hpp:391
uint8 width
number of significant bits before shifting
Definition fixup.hpp:392
idaman size_t n
Definition pro.h:997
idaman segment_t *ida_export getseg(ea_t ea)
Get pointer to segment by linear address.
ea_t idaapi sel2ea(sel_t selector)
Get mapping of a selector as a linear address.
Definition segment.hpp:459
const tinfo_t & type
Definition hexrays.hpp:7301
uval_t uval_t
Definition kernwin.hpp:1878
asize_t size
Definition kernwin.hpp:6339
Definitions of various information kept in netnodes.
unsigned short uint16
unsigned 16 bit value
Definition pro.h:346
unsigned int uint32
unsigned 32 bit value
Definition pro.h:348
uint64 asize_t
Definition pro.h:423
int64 adiff_t
Definition pro.h:424
uint64 ea_t
Definition pro.h:421
int int32
signed 32 bit value
Definition pro.h:347
uint64 sel_t
Definition pro.h:422
unsigned char uint8
unsigned 8 bit value
Definition pro.h:344
_qstring< char > qstring
regular string
Definition pro.h:3694
Functions that deal with segments.
Definition fixup.hpp:83
uval_t base
Definition fixup.hpp:87
const fixup_handler_t * get_handler() const
get_fixup_handler()
Definition fixup.hpp:346
void set_type_and_flags(fixup_type_t type_, uint32 flags_=0)
Definition fixup.hpp:119
ea_t off
target offset
Definition fixup.hpp:94
bool has_base(void) const
Is fixup relative?
Definition fixup.hpp:139
fixup_type_t type
Definition fixup.hpp:85
sel_t sel
selector of the target segment.
Definition fixup.hpp:90
bool is_unused(void) const
Definition fixup.hpp:134
bool patch_value(ea_t ea) const
patch_fixup_value()
Definition fixup.hpp:341
fixup_data_t(fixup_type_t type_, uint32 flags_=0)
Definition fixup.hpp:108
bool was_created(void) const
Is fixup artificial?
Definition fixup.hpp:142
void set_base(ea_t new_base)
Set base of fixup.
Definition fixup.hpp:154
fixup_type_t get_type(void) const
Fixup type Types of fixups.
Definition fixup.hpp:117
bool is_extdef(void) const
Definition fixup.hpp:130
bool is_custom(void) const
is_fixup_custom()
Definition fixup.hpp:312
uval_t get_value(ea_t ea) const
get_fixup_value()
Definition fixup.hpp:336
void clr_unused(void)
Definition fixup.hpp:136
uint32 flags
Definition fixup.hpp:86
void set_extdef(void)
Definition fixup.hpp:131
bool get(ea_t source)
get_fixup()
Definition fixup.hpp:321
uint32 get_flags() const
Fixup flags Fixup flags.
Definition fixup.hpp:128
const char * get_desc(qstring *buf, ea_t source) const
get_fixup_desc()
Definition fixup.hpp:326
adiff_t displacement
displacement (offset from the target)
Definition fixup.hpp:98
int calc_size() const
calc_fixup_size()
Definition fixup.hpp:331
void set_unused(void)
Definition fixup.hpp:135
void set_sel(const segment_t *seg)
Definition fixup.hpp:162
fixup_data_t()
Definition fixup.hpp:101
void clr_extdef(void)
Definition fixup.hpp:132
void set_target_sel()
Set selector of fixup to the target.
Definition fixup.hpp:169
void set_type(fixup_type_t type_)
Definition fixup.hpp:118
ea_t get_base() const
Get base of fixup.
Definition fixup.hpp:147
void set(ea_t source) const
set_fixup()
Definition fixup.hpp:316
Implements the core behavior of a custom fixup.
Definition fixup.hpp:362
ea_t ea_t int bool is_macro
Definition fixup.hpp:411
bool(idaapi *patch_value)(const fixup_handler_t *fh
Patch the fixup bytes.
ea_t ea_t int bool const fixup_data_t & fd
Definition fixup.hpp:412
ea_t ea_t int opnum
Definition fixup.hpp:410
DECLARE_COMPARISONS(fixup_handler_t)
int32 cbsize
size of this structure
Definition fixup.hpp:363
ea_t item_ea
Definition fixup.hpp:408
ea_t ea
Definition fixup.hpp:418
bool(idaapi *apply)(const fixup_handler_t *fh
Apply a fixup: take it into account while analyzing the file.
ea_t ea_t fixup_ea
Definition fixup.hpp:409
const char * name
Format name, must be unique.
Definition fixup.hpp:364
bool is_signed() const
Is the operand value signed?
Definition fixup.hpp:385
uint32 props
Fixup handler properties
Definition fixup.hpp:365
Collect fixup records for the specified range.
Definition fixup.hpp:526
ea_t ea
Definition fixup.hpp:527
fixup_data_t fd
Definition fixup.hpp:528
Information about a reference.
Definition nalt.hpp:1010