IDA C++ SDK 9.2
Loading...
Searching...
No Matches
registry.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 __REGISTRY_HPP
9#define __REGISTRY_HPP
10
23
24// Unix systems use a file in the user directory (usually $HOME/.idapro/ida.reg)
25#if !defined(LOCAL_REGISTRY) && !defined(__NT__)
26# define LOCAL_REGISTRY
27#endif
28//#define LOCAL_REGISTRY // for testing local registry on windows, uncomment
29
30//---------------------------------------------------------------------------
31// Each application has its own registry file
32#ifdef LOCAL_REGISTRY
33# define IDA_REGISTRY_NAME "ida"
34#else
35# define IDA_REGISTRY_NAME "IDA"
36#endif
37#define HVUI_REGISTRY_NAME "hvui"
38
39// note: root_name[] in register.cpp
43#define ROOT_KEY_NAME "Software\\Hex-Rays\\IDA"
44
46// Low level functions. DO NOT USE THEM. See the wrappers below.
47// 'mode' is:
48// - 0: data is a raw buffer, and its datalen must be able to hold the entire binary contents
49// - 1: data is a raw buffer, and its datalen doesn't need to be able to hold the entire binary contents
50// - 2: data is a ::bytevec_t*, datalen is ignored.
51idaman THREAD_SAFE bool ida_export reg_bin_op(
52 const char *name,
53 bool save,
54 void *data,
55 size_t datalen,
56 const char *subkey,
57 int mode = 0);
58idaman THREAD_SAFE bool ida_export reg_str_get(qstring *buf, const char *name, const char *subkey);
59idaman THREAD_SAFE void ida_export reg_str_set(const char *name, const char *subkey, const char *buf);
60idaman THREAD_SAFE int ida_export reg_int_op(
61 const char *name,
62 bool save,
63 int value,
64 const char *subkey = nullptr);
66
75
76
78idaman THREAD_SAFE bool ida_export reg_delete_subkey(const char *name);
79
81idaman THREAD_SAFE bool ida_export reg_delete_tree(const char *name);
82
87
88idaman THREAD_SAFE bool ida_export reg_delete(const char *name, const char *subkey = nullptr);
89
90
92
93idaman THREAD_SAFE bool ida_export reg_subkey_exists(const char *name);
94
95
99
100idaman THREAD_SAFE bool ida_export reg_exists(const char *name, const char *subkey = nullptr);
101
102
108
109idaman THREAD_SAFE bool ida_export reg_subkey_children(qstrvec_t *out, const char *name, bool subkeys);
110
111
117
118idaman THREAD_SAFE bool ida_export reg_data_type(regval_type_t *out, const char *name, const char *subkey = nullptr);
119
120
123
124idaman THREAD_SAFE void ida_export reg_read_strlist(qstrvec_t *list, const char *subkey);
125
126
129
130idaman THREAD_SAFE void ida_export reg_write_strlist(const qstrvec_t &in, const char *subkey);
131
132
139
140idaman THREAD_SAFE void ida_export reg_update_strlist(
141 const char *subkey,
142 const char *add,
143 size_t maxrecs,
144 const char *rem = nullptr,
145 bool ignorecase = false);
146
147
153
154inline THREAD_SAFE void reg_write_binary(
155 const char *name,
156 const void *data,
157 size_t datalen,
158 const char *subkey = nullptr)
159{
160 reg_bin_op(name, true, CONST_CAST(void *)(data), datalen, subkey);
161}
162
163
168inline THREAD_SAFE void reg_write_binary(
169 const char *name,
170 const bytevec_t &data,
171 const char *subkey = nullptr)
172{
173 return reg_write_binary(name, data.begin(), data.size(), subkey);
174}
175
176
184
185inline THREAD_SAFE bool reg_read_binary(
186 const char *name,
187 void *data,
188 size_t datalen,
189 const char *subkey = nullptr)
190{
191 return reg_bin_op(name, false, data, datalen, subkey);
192}
193
194
202
203inline THREAD_SAFE bool reg_read_binary_part(
204 const char *name,
205 void *data,
206 size_t datalen,
207 const char *subkey = nullptr)
208{
209 return reg_bin_op(name, false, data, datalen, subkey, 1);
210}
211
212
218
219inline THREAD_SAFE bool reg_read_binary(
220 const char *name,
221 bytevec_t *data,
222 const char *subkey = nullptr)
223{
224 return reg_bin_op(name, false, data, 0, subkey, 2);
225}
226
227
232
233inline THREAD_SAFE void reg_write_string(
234 const char *name,
235 const char *utf8,
236 const char *subkey = nullptr)
237{
238 reg_str_set(name, subkey, utf8);
239}
240
241
247
248inline THREAD_SAFE bool reg_read_string(
249 qstring *utf8,
250 const char *name,
251 const char *subkey = nullptr)
252{
253 return reg_str_get(utf8, name, subkey);
254}
255
256
262
263inline THREAD_SAFE int reg_read_int(const char *name, int defval, const char *subkey = nullptr)
264{
265 return reg_int_op(name, false, defval, subkey);
266}
267
268
273
274inline THREAD_SAFE void reg_write_int(const char *name, int value, const char *subkey = nullptr)
275{
276 reg_int_op(name, true, value, subkey);
277}
278
279
285
286inline THREAD_SAFE bool reg_read_bool(const char *name, bool defval, const char *subkey = nullptr)
287{
288 return reg_int_op(name, false, int(defval), subkey) != 0;
289}
290
291
296
297inline THREAD_SAFE void reg_write_bool(const char *name, int value, const char *subkey = nullptr)
298{
299 reg_int_op(name, true, value != 0, subkey);
300}
301
302
304
305inline THREAD_SAFE bool reg_subkey_subkeys(qstrvec_t *out, const char *name)
306{
307 return reg_subkey_children(out, name, true);
308}
309
310
312
313inline THREAD_SAFE bool reg_subkey_values(qstrvec_t *out, const char *name)
314{
315 return reg_subkey_children(out, name, false);
316}
317
318
322
323inline THREAD_SAFE void reg_update_filestrlist(
324 const char *subkey,
325 const char *add,
326 size_t maxrecs,
327 const char *rem = nullptr)
328{
330 subkey, add, maxrecs, rem,
331 #ifdef __NT__ // Ignore case in Windows
332 true
333 #else
334 false
335 #endif
336 );
337}
338
339//-----------------------------------------------------------------------------
340// INTERNALS
341
343#define _RVN_(f) regname_ ## f
344
345#ifndef __DEFINE_REG_NAMES__
346#define REG_VAL_NAME(n,s) \
347 extern const char _RVN_(n)[]
348#else
349#define REG_VAL_NAME(n,s) \
350 extern const char _RVN_(n)[]; \
351 const char _RVN_(n)[] = s
352#endif
353
354#define REG_BOOL_FUNC(func, valname) \
355REG_VAL_NAME(func, valname); \
356inline THREAD_SAFE void regset_ ## func(bool value) \
357 { reg_write_bool(_RVN_(func), value); } \
358inline THREAD_SAFE bool regget_ ## func(bool def) \
359 { return reg_read_bool(_RVN_(func), def); }
360
361#define REG_INT_FUNC(func, valname) \
362REG_VAL_NAME(func,valname); \
363inline THREAD_SAFE void regset_ ## func(int value) \
364{ \
365 reg_int_op(_RVN_(func), true, value); \
366} \
367inline THREAD_SAFE int regget_ ## func(int def=0) \
368{ \
369 return reg_int_op(_RVN_(func), false, def); \
370}
371
375idaman THREAD_SAFE bool ida_export set_registry_name(const char *name);
376
377// if using history functions below, you have to define the following two variables
378extern const char regkey_history[];
379extern int max_history_files; // max number of files in the file menu
380 // and in the welcome box
381#define MAX_HISTORY_FILES_DEF 10 // default value
382
383inline THREAD_SAFE void regget_history(qstrvec_t *list)
384{
385 reg_read_strlist(list, regkey_history);
386}
387
388inline THREAD_SAFE void reg_update_history(const char *addfile, const char *removefile = nullptr)
389{
390 // On Windows avoid duplicate upper/lower-case entries
391 // by using reg_update_filestrlist() which takes care of case sensitivity
392 reg_update_filestrlist(regkey_history, addfile, max_history_files, removefile);
393}
394
395inline THREAD_SAFE void reg_history_size_truncate(void)
396{
397 reg_update_strlist(regkey_history, nullptr, max_history_files, nullptr);
398}
400
401
402#endif // __REGISTRY_HPP
Vector of bytes (use for dynamic memory)
Definition pro.h:3773
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
size_t const char * defval
Definition kernwin.hpp:7959
_qstring< char > qstring
regular string
Definition pro.h:3694
qvector< qstring > qstrvec_t
vector of strings
Definition pro.h:3697
THREAD_SAFE bool reg_subkey_subkeys(qstrvec_t *out, const char *name)
Get all subkey names of given key.
Definition registry.hpp:305
idaman THREAD_SAFE bool ida_export reg_subkey_exists(const char *name)
Is there already a key with the given name?
THREAD_SAFE bool reg_read_bool(const char *name, bool defval, const char *subkey=nullptr)
Read boolean value from the registry.
Definition registry.hpp:286
THREAD_SAFE bool reg_read_binary_part(const char *name, void *data, size_t datalen, const char *subkey=nullptr)
Read a chunk of binary data from the registry.
Definition registry.hpp:203
idaman THREAD_SAFE bool ida_export reg_exists(const char *name, const char *subkey=nullptr)
Is there already a value with the given name?
idaman THREAD_SAFE void ida_export reg_read_strlist(qstrvec_t *list, const char *subkey)
Retrieve all string values associated with the given key.
idaman THREAD_SAFE void ida_export reg_write_strlist(const qstrvec_t &in, const char *subkey)
Write string values associated with the given key.
idaman THREAD_SAFE bool ida_export reg_data_type(regval_type_t *out, const char *name, const char *subkey=nullptr)
Get data type of a given value.
THREAD_SAFE int reg_read_int(const char *name, int defval, const char *subkey=nullptr)
Read integer value from the registry.
Definition registry.hpp:263
idaman THREAD_SAFE bool ida_export reg_delete_subkey(const char *name)
Delete a key from the registry.
THREAD_SAFE bool reg_read_binary(const char *name, void *data, size_t datalen, const char *subkey=nullptr)
Read binary data from the registry.
Definition registry.hpp:185
idaman THREAD_SAFE bool ida_export reg_delete_tree(const char *name)
Delete a subtree from the registry.
THREAD_SAFE void reg_write_bool(const char *name, int value, const char *subkey=nullptr)
Write boolean value to the registry.
Definition registry.hpp:297
THREAD_SAFE void reg_write_binary(const char *name, const void *data, size_t datalen, const char *subkey=nullptr)
Write binary data to the registry.
Definition registry.hpp:154
regval_type_t
Types of values stored in the registry.
Definition registry.hpp:69
@ reg_binary
binary data
Definition registry.hpp:72
@ reg_dword
32-bit number
Definition registry.hpp:73
@ reg_sz
utf8 string
Definition registry.hpp:71
@ reg_unknown
unknown
Definition registry.hpp:70
THREAD_SAFE void reg_update_filestrlist(const char *subkey, const char *add, size_t maxrecs, const char *rem=nullptr)
Update registry with a file list.
Definition registry.hpp:323
idaman THREAD_SAFE bool ida_export reg_subkey_children(qstrvec_t *out, const char *name, bool subkeys)
Retrieve the child names of the given key.
idaman THREAD_SAFE void ida_export reg_update_strlist(const char *subkey, const char *add, size_t maxrecs, const char *rem=nullptr, bool ignorecase=false)
Update list of strings associated with given key.
THREAD_SAFE void reg_write_string(const char *name, const char *utf8, const char *subkey=nullptr)
Write a string to the registry.
Definition registry.hpp:233
THREAD_SAFE bool reg_read_string(qstring *utf8, const char *name, const char *subkey=nullptr)
Read a string from the registry.
Definition registry.hpp:248
THREAD_SAFE void reg_write_int(const char *name, int value, const char *subkey=nullptr)
Write integer value to the registry.
Definition registry.hpp:274
THREAD_SAFE bool reg_subkey_values(qstrvec_t *out, const char *name)
Get all value names under given key.
Definition registry.hpp:313
idaman THREAD_SAFE bool ida_export reg_delete(const char *name, const char *subkey=nullptr)
Delete a value from the registry.