IDA C++ SDK 9.2
Loading...
Searching...
No Matches
cvt64.hpp
Go to the documentation of this file.
1/*
2 * Interactive disassembler (IDA).
3 * Copyright (c) 2005-2025 Hex-Rays SA <support@hex-rays.com>
4 * ALL RIGHTS RESERVED.
5 *
6 * Convert 'idb' file to 'i64' file.
7 *
8 * Conversion is performed by IDA64 in the special conversion mode.
9 * To convert data we need to read it in the 32-bit format from the idb file,
10 * convert it to the 64-bit format and write it to the i64 file.
11 *
12 * This file contains the conversion helpers functions for plugins.
13 *
14 * Also see the following events:
15 * * processor_t::ev_cvt64_supval
16 * * processor_t::ev_cvt64_hashval
17 *
18 * For more information check the cvt64.md file.
19 */
20
21#pragma once
22
23//-------------------------------------------------------------------------
24// Conversion of 32-bit databases to 64-bit is performed by ida64,
25// only in IDA Pro and IDA Teams
26#if !defined(IDAFREE) && !defined(IDAHOME)
27# if defined(__EA64__)
28# define CVT64
29# else
30# define UPG32 // enable the logic to upgrade 32-bit databases
31# endif
32#endif
33
34//------------------------------------------------------------------------
35// This class keeps 32-bit addresses regardless of IDA bitness
37{
40
42 range32_t(ea_t ea1, ea_t ea2) : start_ea(ea1), end_ea(ea2) {}
43};
44
45//------------------------------------------------------------------------
52THREAD_SAFE inline ea_t mmdsr_unpack_ea(memory_deserializer_t &mmdsr, ea_t base = 0)
53{
54#ifdef CVT64
55 if ( is_cvt64() )
56 {
57 ea_t ea = ea32_t(mmdsr.unpack_dd()+base);
58 return ea == BADADDR32 ? BADADDR : ea;
59 }
60#endif
61 return mmdsr.unpack_ea()+base;
62}
63
64//------------------------------------------------------------------------
66THREAD_SAFE inline ea_t mmdsr_unpack_ea_neg(memory_deserializer_t &mmdsr, ea_t base)
67{
68#ifdef CVT64
69 if ( is_cvt64() )
70 {
71 ea_t ea = ea32_t(base - mmdsr.unpack_dd());
72 return ea == BADADDR32 ? BADADDR : ea;
73 }
74#endif
75 return base - mmdsr.unpack_ea();
76}
77
78//------------------------------------------------------------------------
81{
82 nodeidx_t ndx = mmdsr_unpack_ea(mmdsr);
83 return node2ea(ndx);
84}
85
86//------------------------------------------------------------------------
88THREAD_SAFE inline sval_t mmdsr_unpack_sval(memory_deserializer_t &mmdsr, sval_t base=0)
89{
90#ifdef CVT64
91 if ( is_cvt64() )
92 return (int32)(mmdsr.unpack_dd() + base);
93#endif
94 return mmdsr.unpack_ea() + base;
95}
96
97//------------------------------------------------------------------------
99THREAD_SAFE inline void mmdsr_unpack_eavec(
100 eavec_t *vec,
102 ea_t ea)
103{
104#ifdef CVT64
105 if ( is_cvt64() )
106 {
107 ea_t old = ea;
108 int n = mmdsr.unpack_dw();
109 vec->resize_noinit(n);
110 for ( int i=0; i < n; ++i )
111 {
112 old = mmdsr_unpack_ea(mmdsr, old);
113 vec->at(i) = old;
114 }
115 return;
116 }
117#endif
118 return mmdsr.unpack_eavec(vec, ea);
119}
120
121//------------------------------------------------------------------------
123THREAD_SAFE inline ea_t mmdsr_read_ea(memory_deserializer_t &mmdsr)
124{
125#ifdef CVT64
126 if ( is_cvt64() )
127 {
128 ea32_t ea32 = BADADDR32;
129 mmdsr.read(&ea32, sizeof(ea32));
130 return ea32;
131 }
132#endif
133 ea_t ea = BADADDR;
134 mmdsr.read(&ea, sizeof(ea));
135 return ea;
136}
137
138//------------------------------------------------------------------------
145inline int cvt64_blob(netnode node, nodeidx_t start, uchar tag)
146{
147 bytevec_t buf;
148 if ( node.getblob(&buf, start, tag) > 0 )
149 {
150 node.setblob(buf.begin(), buf.size(), start, tag);
151 return 1;
152 }
153 return 0;
154}
155
156#ifdef CVT64
157//------------------------------------------------------------------------
164{
167
181#define CVT64_ZERO_IDX 0x00800000
182 int tag;
183
191};
192
193// Descriptors for popular database values
194#define CVT64_NODE_DEVICE { helper, stag, nodeidx_t(-1) }
195#define CVT64_NODE_IDP_FLAGS { helper, atag|NETMAP_VAL, nodeidx_t(-1) }
196
206
207idaman int ida_export cvt64_node_supval_for_event(
208 va_list va,
209 const cvt64_node_tag_t *node_info,
210 size_t node_info_qty);
211
212#endif // CVT64
Vector of bytes (use for dynamic memory)
Definition pro.h:3773
Definition of the IDA database node.
Definition netnode.hpp:241
bool setblob(const void *buf, size_t size, nodeidx_t _start, uchar tag)
Store a blob in a netnode.
Definition netnode.hpp:1012
void * getblob(void *buf, size_t *bufsize, nodeidx_t _start, uchar tag)
Get blob from a netnode.
Definition netnode.hpp:952
void resize_noinit(size_t _newsize)
Definition pro.h:2504
const T & at(size_t _idx) const
Get element at index '_idx'.
Definition pro.h:2427
iterator begin(void)
Get an iterator that points to the first element in the qvector.
Definition pro.h:2609
size_t size(void) const
Get the number of elements in the qvector.
Definition pro.h:2423
THREAD_SAFE ea_t mmdsr_unpack_node2ea(memory_deserializer_t &mmdsr)
Unpack a netnode index.
Definition cvt64.hpp:80
THREAD_SAFE sval_t mmdsr_unpack_sval(memory_deserializer_t &mmdsr, sval_t base=0)
Unpack as a signed value.
Definition cvt64.hpp:88
THREAD_SAFE ea_t mmdsr_unpack_ea(memory_deserializer_t &mmdsr, ea_t base=0)
Unpack an address.
Definition cvt64.hpp:52
idaman int ida_export cvt64_node_supval_for_event(va_list va, const cvt64_node_tag_t *node_info, size_t node_info_qty)
Helper for the processor_t::ev_cvt64_supval event.
THREAD_SAFE ea_t mmdsr_read_ea(memory_deserializer_t &mmdsr)
Read a stored (without packing) address.
Definition cvt64.hpp:123
THREAD_SAFE ea_t mmdsr_unpack_ea_neg(memory_deserializer_t &mmdsr, ea_t base)
Unpack an address relative to the specified base address.
Definition cvt64.hpp:66
int cvt64_blob(netnode node, nodeidx_t start, uchar tag)
Convert a blob whose content does not depend on the IDA bitness.
Definition cvt64.hpp:145
THREAD_SAFE void mmdsr_unpack_eavec(eavec_t *vec, memory_deserializer_t &mmdsr, ea_t ea)
Unpack vector of addresses.
Definition cvt64.hpp:99
idaman THREAD_SAFE va_list va
See qsscanf()
Definition err.h:21
idaman size_t n
Definition pro.h:997
idaman ea_t ida_export node2ea(nodeidx_t ndx)
nodeidx64_t nodeidx_t
Definition netnode.hpp:114
uint32 ea32_t
32-bit address, regardless of IDA bitness.
Definition pro.h:450
adiff_t sval_t
signed value used by the processor.
Definition pro.h:446
uint64 ea_t
Definition pro.h:421
int int32
signed 32 bit value
Definition pro.h:347
unsigned char uchar
unsigned 8 bit value
Definition pro.h:337
idaman bool ida_export is_cvt64()
is IDA converting IDB into I64?
qvector< ea_t > eavec_t
vector of addresses
Definition pro.h:2764
Descriptor of information stored in a netnode.
Definition cvt64.hpp:164
int tag
Definition cvt64.hpp:182
nodeidx_t node
netnode id
Definition cvt64.hpp:166
nodeidx_t exact_alt
The index described by the descriptor.
Definition cvt64.hpp:190
Definition pro.h:4382
ea_t unpack_ea()
Definition pro.h:4397
ssize_t read(void *obj, size_t objsize)
Definition pro.h:4453
void unpack_eavec(eavec_t *vec, ea_t ea)
Definition pro.h:4428
uint16 unpack_dw()
Definition pro.h:4394
uint32 unpack_dd()
Definition pro.h:4395
ea32_t start_ea
Definition cvt64.hpp:38
range32_t(ea_t ea1, ea_t ea2)
Definition cvt64.hpp:42
range32_t()
Definition cvt64.hpp:41
ea32_t end_ea
Definition cvt64.hpp:39