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-2026 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>
13struct kdata_t;
14
21
22//--------------------------------------------------------------------------
24
33#define FIXUP_OFF8 13
34#define FIXUP_OFF16 1
35#define FIXUP_SEG16 2
36#define FIXUP_PTR16 3
38#define FIXUP_OFF32 4
39#define FIXUP_PTR32 5
40#define FIXUP_HI8 6
41#define FIXUP_HI16 7
42#define FIXUP_LOW8 8
43#define FIXUP_LOW16 9
44#define V695_FIXUP_VHIGH 10
45#define V695_FIXUP_VLOW 11
46#define FIXUP_OFF64 12
47#define FIXUP_OFF8S 14
48#define FIXUP_OFF16S 15
49#define FIXUP_OFF32S 16
50//#define FIXUP_ 0xE
51#define FIXUP_CUSTOM 0x8000
53
55inline THREAD_SAFE bool is_fixup_custom(fixup_type_t type)
56{
57 return (type & FIXUP_CUSTOM) != 0;
58}
59
63
66#define FIXUPF_REL 0x0001
70#define FIXUPF_EXTDEF 0x0002
74#define FIXUPF_UNUSED 0x0004
76#define FIXUPF_CREATED 0x0008
79#define FIXUPF_LOADER_MASK 0xF0000000
81
82struct fixup_handler_t;
84{
85protected:
86 fixup_type_t type = 0; // fixup type
87 uint32 flags = 0; // FIXUPF_... bits
88 uval_t base = 0; // base for relative fixups
89
90public:
91 sel_t sel = BADSEL;
94
95 ea_t off = 0;
98
100
101public:
104 : type(type_),
105 flags(flags_) {}
106
108 fixup_type_t get_type(void) const { return type; }
109 void set_type(fixup_type_t type_) { type = type_; }
110 void set_type_and_flags(fixup_type_t type_, uint32 flags_ = 0)
111 {
112 type = type_;
113 flags = flags_;
114 }
115
116 bool is_custom(void) const;
117
119 uint32 get_flags() const { return flags; }
120
121 bool is_extdef(void) const { return (flags & FIXUPF_EXTDEF) != 0; }
122 void set_extdef(void) { flags |= FIXUPF_EXTDEF; }
123 void clr_extdef(void) { flags &= ~FIXUPF_EXTDEF; }
124
125 bool is_unused(void) const { return (flags & FIXUPF_UNUSED) != 0; }
126 void set_unused(void) { flags |= FIXUPF_UNUSED; }
127 void clr_unused(void) { flags &= ~FIXUPF_UNUSED; }
128
130 bool has_base(void) const { return (flags & FIXUPF_REL) != 0; }
131
133 bool was_created(void) const { return (flags & FIXUPF_CREATED) != 0; }
134
139 {
140 return has_base() ? base : sel != BADSEL ? sel2ea(sel) : 0;
141 }
142
145 void set_base(ea_t new_base)
146 {
147 ea_t target = get_base() + off;
148 flags |= FIXUPF_REL;
149 base = new_base;
150 off = target - base;
151 }
152
153 void set_sel(sel_t _sel)
154 {
155 sel = _sel;
156 }
157
159 DEPRECATED void set_sel(const segment_t *seg)
160 {
161 set_sel(seg == nullptr ? BADSEL : seg->sel);
162 }
163
167 {
168 ea_t target = get_base() + off;
169 segment_info_t seg;
170 if ( get_segment_info(&seg, target) )
171 set_sel(seg.get_sel());
172 else
173 set_sel(BADSEL);
174 flags &= ~FIXUPF_REL;
175 base = 0; // just in case
176 off = target - get_base();
177 }
178
179 void set(ea_t source) const;
180 bool get(ea_t source);
181
183 const fixup_handler_t *get_handler() const;
184
186 const char *get_desc(qstring *buf, ea_t source) const;
187
188 // TODO rewrite to the inline implementation which uses
189 // fixup_handler_t::size
190 int calc_size() const;
191 uval_t get_value(ea_t ea) const;
192 bool patch_value(ea_t ea) const;
193
194#ifndef SWIG
195 friend kdata_t;
197 friend size_t pack_fixup(uchar *buf, size_t bufsize, const fixup_data_t &fd);
198 friend void convert_fixups_to_700(dbctx_t &db);
199 fixup_data_t(const fixup_data_t &) = default;
201 bool operator==(const fixup_data_t &r) const
202 {
203 return type == r.type
204 && flags == r.flags
205 && base == r.base
206 && sel == r.sel
207 && off == r.off
209 }
210#endif // SWIG
211};
212
214
215idaman bool ida_export get_fixup(fixup_data_t *fd, ea_t source);
216
217
219
220inline bool exists_fixup(ea_t source)
221{
222 return get_fixup(nullptr, source);
223}
224
225
231
232idaman void ida_export set_fixup(ea_t source, const fixup_data_t &fd);
233
234
236
237idaman void ida_export del_fixup(ea_t source);
238
239
245idaman ea_t ida_export get_first_fixup_ea(void);
246
251idaman ea_t ida_export get_next_fixup_ea(ea_t ea);
252
257idaman ea_t ida_export get_prev_fixup_ea(ea_t ea);
259
260
262
264
265
277
278idaman bool ida_export apply_fixup(ea_t item_ea, ea_t fixup_ea, int n, bool is_macro);
279
280
294
296
297
310
311idaman bool ida_export patch_fixup_value(ea_t ea, const fixup_data_t &fd);
312
313
315
316idaman const char *ida_export get_fixup_desc(
317 qstring *buf,
318 ea_t source,
319 const fixup_data_t &fd);
320
321
324
325idaman int ida_export calc_fixup_size(fixup_type_t type);
326
327
328//--------------------------------------------------------------------------
329// inline implementation
330inline bool fixup_data_t::is_custom(void) const
331{
332 return is_fixup_custom(type);
333}
334inline void fixup_data_t::set(ea_t source) const
335{
336 set_fixup(source, *this);
337}
338
339inline bool fixup_data_t::get(ea_t source)
340{
341 return get_fixup(this, source);
342}
343
344inline const char *fixup_data_t::get_desc(qstring *buf, ea_t source) const
345{
346 return get_fixup_desc(buf, source, *this);
347}
348
349inline int fixup_data_t::calc_size() const
350{
351 return calc_fixup_size(type);
352}
353
355{
356 return get_fixup_value(ea, type);
357}
358
359inline bool fixup_data_t::patch_value(ea_t ea) const
360{
361 return patch_fixup_value(ea, *this);
362}
363
365{
366 return get_fixup_handler(type);
367}
368
369
376
377//--------------------------------------------------------------------------
380{
382 const char *name;
387#define FHF_VERIFY 0x0001
390#define FHF_CODE 0x0002
392#define FHF_FORCE_CODE 0x0004
395#define FHF_ABS_OPVAL 0x0008
398#define FHF_SIGNED 0x0010
403 bool is_signed() const { return (props & FHF_SIGNED) != 0; }
404
414 uint8 rsrv4; // reserved
415
419
424 bool (idaapi *apply)(
425 const fixup_handler_t *fh,
428 int opnum,
431
436 uval_t (idaapi *get_value)(const fixup_handler_t *fh, ea_t ea);
437
445 bool (idaapi *patch_value)(
446 const fixup_handler_t *fh,
447 ea_t ea,
449
450#ifndef SWIG
452#endif
453};
454
455
459
491
509
510
518
520 const fixup_handler_t *cfh);
521
522
525
527
528
532
533idaman fixup_type_t ida_export find_custom_fixup(const char *name);
534
536
537
538//--------------------------------------------------------------------------
542
550
551idaman bool ida_export get_fixups(fixups_t *out, ea_t ea, asize_t size);
552
553
555
557{
558 return get_fixups(nullptr, ea, size);
559}
560
561
568
569idaman void ida_export gen_fix_fixups(ea_t from, ea_t to, asize_t size);
570
571
585
586idaman bool ida_export handle_fixups_in_macro(
587 refinfo_t *ri,
588 ea_t ea,
589 fixup_type_t other,
590 uint32 macro_reft_and_flags);
591
592
593#endif // FIXUP_HPP
Reimplementation of vector class from STL.
Definition pro.h:2262
Describes a program segment.
Definition segment.hpp:408
sel_t sel
segment selector - should be unique.
Definition segment.hpp:492
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:549
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:556
THREAD_SAFE bool is_fixup_custom(fixup_type_t type)
Is fixup processed by processor module?
Definition fixup.hpp:55
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:220
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:25
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:414
uint32 reftype
reference info type and flags, std_apply() produces an offset of this type
Definition fixup.hpp:416
uint8 shift
number of bits to shift right before patching.
Definition fixup.hpp:411
uint8 size
The examples below show how these options work.
Definition fixup.hpp:409
uint8 width
number of significant bits before shifting
Definition fixup.hpp:410
idaman size_t n
Definition pro.h:1000
idaman bool ida_export get_segment_info(segment_info_t *out, ea_t ea, int flags=0)
Fill segment_info_t structure for segment at the specified address.
ea_t idaapi sel2ea(sel_t selector)
Get mapping of a selector as a linear address.
Definition segment.hpp:719
const tinfo_t & type
Definition hexrays.hpp:7698
uval_t uval_t
Definition kernwin.hpp:1926
asize_t size
Definition kernwin.hpp:6701
Definitions of various information kept in netnodes.
unsigned short uint16
unsigned 16 bit value
Definition pro.h:350
unsigned int uint32
unsigned 32 bit value
Definition pro.h:352
uint64 asize_t
Definition pro.h:427
int64 adiff_t
Definition pro.h:428
uint64 ea_t
Definition pro.h:425
int int32
signed 32 bit value
Definition pro.h:351
unsigned char uchar
unsigned 8 bit value
Definition pro.h:341
idaman size_t bufsize
Definition pro.h:604
uint64 sel_t
Definition pro.h:426
unsigned char uint8
unsigned 8 bit value
Definition pro.h:348
_qstring< char > qstring
regular string
Definition pro.h:3771
Functions that deal with segments.
Definition fixup.hpp:84
uval_t base
Definition fixup.hpp:88
const fixup_handler_t * get_handler() const
get_fixup_handler()
Definition fixup.hpp:364
void set_type_and_flags(fixup_type_t type_, uint32 flags_=0)
Definition fixup.hpp:110
ea_t off
target offset
Definition fixup.hpp:95
friend void unpack_fixup_ub(fixup_data_t *fd, memory_deserializer_t &mmdsr)
bool has_base(void) const
Is fixup relative?
Definition fixup.hpp:130
fixup_type_t type
Definition fixup.hpp:86
DEPRECATED void set_sel(const segment_t *seg)
Definition fixup.hpp:159
friend void convert_fixups_to_700(dbctx_t &db)
sel_t sel
selector of the target segment.
Definition fixup.hpp:91
bool is_unused(void) const
Definition fixup.hpp:125
bool patch_value(ea_t ea) const
patch_fixup_value()
Definition fixup.hpp:359
fixup_data_t(fixup_type_t type_, uint32 flags_=0)
Definition fixup.hpp:103
bool was_created(void) const
Is fixup artificial?
Definition fixup.hpp:133
void set_base(ea_t new_base)
Set base of fixup.
Definition fixup.hpp:145
friend kdata_t
Definition fixup.hpp:195
fixup_type_t get_type(void) const
Fixup type Types of fixups.
Definition fixup.hpp:108
void set_sel(sel_t _sel)
Definition fixup.hpp:153
bool is_extdef(void) const
Definition fixup.hpp:121
bool is_custom(void) const
is_fixup_custom()
Definition fixup.hpp:330
uval_t get_value(ea_t ea) const
get_fixup_value()
Definition fixup.hpp:354
void clr_unused(void)
Definition fixup.hpp:127
fixup_data_t & operator=(const fixup_data_t &)=default
fixup_data_t(const fixup_data_t &)=default
uint32 flags
Definition fixup.hpp:87
void set_extdef(void)
Definition fixup.hpp:122
bool get(ea_t source)
get_fixup()
Definition fixup.hpp:339
uint32 get_flags() const
Fixup flags Fixup flags.
Definition fixup.hpp:119
const char * get_desc(qstring *buf, ea_t source) const
get_fixup_desc()
Definition fixup.hpp:344
bool operator==(const fixup_data_t &r) const
Definition fixup.hpp:201
friend size_t pack_fixup(uchar *buf, size_t bufsize, const fixup_data_t &fd)
adiff_t displacement
displacement (offset from the target)
Definition fixup.hpp:99
int calc_size() const
calc_fixup_size()
Definition fixup.hpp:349
void set_unused(void)
Definition fixup.hpp:126
fixup_data_t()
Definition fixup.hpp:102
void clr_extdef(void)
Definition fixup.hpp:123
void set_target_sel()
Set selector of fixup to the target.
Definition fixup.hpp:166
void set_type(fixup_type_t type_)
Definition fixup.hpp:109
ea_t get_base() const
Get base of fixup.
Definition fixup.hpp:138
void set(ea_t source) const
set_fixup()
Definition fixup.hpp:334
Implements the core behavior of a custom fixup.
Definition fixup.hpp:380
ea_t ea_t int bool is_macro
Definition fixup.hpp:429
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:430
ea_t ea_t int opnum
Definition fixup.hpp:428
DECLARE_COMPARISONS(fixup_handler_t)
int32 cbsize
size of this structure
Definition fixup.hpp:381
ea_t item_ea
Definition fixup.hpp:426
ea_t ea
Definition fixup.hpp:436
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:427
const char * name
Format name, must be unique.
Definition fixup.hpp:382
bool is_signed() const
Is the operand value signed?
Definition fixup.hpp:403
uint32 props
Fixup handler properties
Definition fixup.hpp:383
Collect fixup records for the specified range.
Definition fixup.hpp:544
ea_t ea
Definition fixup.hpp:545
fixup_data_t fd
Definition fixup.hpp:546
Definition pro.h:4475
Information about a reference.
Definition nalt.hpp:1001