IDA C++ SDK 9.2
Loading...
Searching...
No Matches
segment.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 _SEGMENT_HPP
9#define _SEGMENT_HPP
10
11#include <functional>
12#include <ida.hpp>
13#include <range.hpp> // segments are range of addresses
14 // with characteristics
15
51
54
55
57#define SREG_NUM 16
58
59
60//-------------------------------------------------------------------------
61// D E F I N I T O N O F S E G M E N T S T R U C T U R E
62//-------------------------------------------------------------------------
68
74#define SFL_COMORG 0x01
76#define SFL_OBOK 0x02
78#define SFL_HIDDEN 0x04
81#define SFL_DEBUG 0x08
83#define SFL_LOADER 0x10
85#define SFL_HIDETYPE 0x20
87#define SFL_HEADER 0x40
89
94#define SEG_NORM 0
95#define SEG_XTRN 1
97#define SEG_CODE 2
98#define SEG_DATA 3
99#define SEG_IMP 4
100#define SEG_GRP 6
101#define SEG_NULL 7
102#define SEG_UNDF 8
103#define SEG_BSS 9
104#define SEG_ABSSYM 10
105#define SEG_COMM 11
106#define SEG_IMEM 12
107#define SEG_MAX_SEGTYPE_CODE SEG_IMEM
109
114#define SEGPERM_EXEC 1
115#define SEGPERM_WRITE 2
116#define SEGPERM_READ 4
117#define SEGPERM_MAXVAL (SEGPERM_EXEC + SEGPERM_WRITE + SEGPERM_READ)
119
124#define saAbs 0
125#define saRelByte 1
126#define saRelWord 2
127#define saRelPara 3
128#define saRelPage 4
129#define saRelDble 5
131#define saRel4K 6
133#define saGroup 7
134#define saRel32Bytes 8
135#define saRel64Bytes 9
136#define saRelQword 10
137#define saRel128Bytes 11
138#define saRel512Bytes 12
139#define saRel1024Bytes 13
140#define saRel2048Bytes 14
141#define saRel_MAX_ALIGN_CODE saRel2048Bytes
143
148#define scPriv 0
150#define scGroup 1
151#define scPub 2
153#define scPub2 4
154#define scStack 5
156#define scCommon 6
157#define scPub3 7
158#define sc_MAX_COMB_CODE scPub3
160
161#define SEG_MAX_BITNESS_CODE 2
162
164class segment_info_t;
165#define DECLARE_SEGMENT_HELPERS(decl)\
166decl bool ida_export segment_info_t__visible_name(const segment_info_t *_this, qstring *); \
167
168DECLARE_SEGMENT_HELPERS(idaman)
169
170
172class segment_info_t : public range_t
173{
174public:
176 segment_info_t() { memset(defsr_, -1, sizeof(defsr_)); }
177
179 bool is_valid() const { return !empty(); }
180
184 bool has(int gsi_flags) const { return (filled_ & gsi_flags) == gsi_flags; }
185
190 const char *get_name() const { return qname_.c_str(); }
191 bool visible_name(qstring *out) const { return segment_info_t__visible_name(this, out); }
192 void set_name(const char *v) { qname_ = v; updated_ |= SI_NAME; }
193
203 const char *get_sclass() const { return qsclass_.c_str(); }
204 void set_sclass(const char *v) { qsclass_ = v; updated_ |= SI_SCLASS; }
205
208 uval_t get_orgbase() const { return orgbase_; }
209 void set_orgbase(uval_t v) { orgbase_ = v; updated_ |= SI_ORGBASE; }
210
212 uchar get_align() const { return align_; }
213 void set_align(uchar v) { align_ = v; updated_ |= SI_ALIGN; }
214
216 uchar get_comb() const { return comb_; }
217 void set_comb(uchar v) { comb_ = v; updated_ |= SI_COMB; }
218
220 uchar get_perm() const { return perm_; }
221 void set_perm(uchar v) { perm_ = v; updated_ |= SI_PERM; }
222
224 uchar get_bitness() const { return bitness_; }
225 void set_bitness(uchar v) { bitness_ = v; updated_ |= SI_BITNESS; }
226
228 bool is_16bit() const { return bitness_ == 0; }
230 bool is_32bit() const { return bitness_ == 1; }
232 bool is_64bit() const { return bitness_ == 2; }
234 int abits() const { return 1 << (bitness_ + 4); }
236 int abytes() const { return abits() / 8; }
237
239 ushort get_flags() const { return flags_; }
240 void set_flags(ushort v) { flags_ = v; updated_ |= SI_FLAGS; }
241
245 bool comorg() const { return (flags_ & SFL_COMORG) != 0; }
246 void set_comorg(bool v=true) { setflag(flags_, SFL_COMORG, v); updated_ |= SI_FLAGS; }
248
252 bool ob_ok() const { return (flags_ & SFL_OBOK) != 0; }
253 void set_ob_ok(bool v=true) { setflag(flags_, SFL_OBOK, v); updated_ |= SI_FLAGS; }
255
259 bool is_visible_segm() const { return (flags_ & SFL_HIDDEN) == 0; }
260 bool is_finally_visible_segm() const { return (inf_get_cmtflg() & SCF_SHHID_SEGM) != 0 || is_visible_segm(); }
261 void set_visible_segm(bool visible=true) { setflag(flags_, SFL_HIDDEN, !visible); updated_ |= SI_FLAGS; }
263
267 bool is_debugger_segm() const { return (flags_ & SFL_DEBUG) != 0; }
268 void set_debugger_segm(bool debseg=true) { setflag(flags_, SFL_DEBUG, debseg); updated_ |= SI_FLAGS; }
270
274 bool is_loader_segm() const { return (flags_ & SFL_LOADER) != 0; }
275 void set_loader_segm(bool ldrseg=true) { setflag(flags_, SFL_LOADER, ldrseg); updated_ |= SI_FLAGS; }
277
281 bool is_hidden_segtype() const { return (flags_ & SFL_HIDETYPE) != 0; }
282 void set_hidden_segtype(bool hide=true) { setflag(flags_, SFL_HIDETYPE, hide); updated_ |= SI_FLAGS; }
284
288 bool is_header_segm() const { return (flags_ & SFL_HEADER) != 0; }
289 void set_header_segm(bool on=true) { setflag(flags_, SFL_HEADER, on); updated_ |= SI_FLAGS; }
291
296 bool is_ephemeral_segm() const
297 { return (flags_ & (SFL_DEBUG|SFL_LOADER)) == SFL_DEBUG; }
298
305 sel_t get_sel() const { return sel_; }
306 void set_sel(sel_t v) { sel_ = v; updated_ |= SI_SEL; }
307
309 inline ea_t para() const;
310
312 ea_t base() const { return to_ea(para(), 0); }
313
319 sel_t get_defsr(int sr_idx) const { return (sr_idx >= 0 && sr_idx < SREG_NUM) ? defsr_[sr_idx] : BADSEL; }
320 void set_defsr(int sr_idx, sel_t v) { if ( sr_idx >= 0 && sr_idx < SREG_NUM ) { defsr_[sr_idx] = v; updated_ |= si_defsr(sr_idx); } }
321
327 uchar get_type() const { return type_; }
328 void set_type(uchar v) { type_ = v; updated_ |= SI_TYPE; }
329
331 bgcolor_t get_color() const { return color_; }
332 void set_color(bgcolor_t v) { color_ = v; updated_ |= SI_COLOR; }
333
336 const char *get_cmt_reg() const { return cmt_reg_.c_str(); }
337 void set_cmt_reg(const char *v) { cmt_reg_ = v; updated_ |= SI_CMT_REG; }
338
341 const char *get_cmt_rpt() const { return cmt_rpt_.c_str(); }
342 void set_cmt_rpt(const char *v) { cmt_rpt_ = v; updated_ |= SI_CMT_RPT; }
344
345private:
346 static constexpr int SI_VERSION = 1;
347
348 uint64 updated_ = 0;
349 int filled_ = 0;
350 qstring qname_;
351 qstring qsclass_;
352 qstring cmt_reg_;
353 qstring cmt_rpt_;
354 uval_t orgbase_ = 0;
355 uchar align_ = 0;
356 uchar comb_ = 0;
357 uchar perm_ = 0;
358 uchar bitness_ = 0;
359 ushort flags_ = 0;
360 sel_t sel_ = 0;
361 sel_t defsr_[SREG_NUM];
362 uchar type_ = SEG_NORM;
363 bgcolor_t color_ = DEFCOLOR;
364 uchar version_ = SI_VERSION;
365
366 DECLARE_SEGMENT_HELPERS(friend)
367 friend struct kdata_t;
368
372 enum
373 {
374 SI_SEL = 0x00000001,
375 SI_ORGBASE = 0x00000002,
376 SI_FLAGS = 0x00000004,
377 SI_TYPE = 0x00000008,
378 SI_PERM = 0x00000010,
379 SI_BITNESS = 0x00000020,
380 SI_ALIGN = 0x00000040,
381 SI_COMB = 0x00000080,
382 SI_COLOR = 0x00000100,
383 SI_NAME = 0x00000200,
384 SI_SCLASS = 0x00000400,
385 SI_CMT_REG = 0x00000800,
386 SI_CMT_RPT = 0x00001000,
387 SI_DEFSR_FIRST= 0x00002000,
388 SI_ALL_FIELDS = 0x00001FFF,
389 SI_ALL_DEFSR = 0x1FFFE000,
390 SI_ALL = 0x1FFFFFFF,
391 };
393 static uint64 si_defsr(int rg) { return SI_DEFSR_FIRST << rg; }
395};
396
398
399//-------------------------------------------------------------------------
400// INTERNAL
405
407class segment_t : public range_t
408{
409public:
415
424 bool is_16bit() const { return bitness == 0; }
426 bool is_32bit() const { return bitness == 1; }
428 bool is_64bit() const { return bitness == 2; }
430 int abits() const { return 1<<(bitness+4); }
432 int abytes() const { return abits() / 8; }
433
437
442 bool comorg() const { return (flags & SFL_COMORG) != 0; }
443 void set_comorg() { flags |= SFL_COMORG; }
444 void clr_comorg() { flags &= ~SFL_COMORG; }
449 bool ob_ok() const { return (flags & SFL_OBOK) != 0; }
450 void set_ob_ok() { flags |= SFL_OBOK; }
451 void clr_ob_ok() { flags &= ~SFL_OBOK; }
456 bool is_visible_segm() const { return (flags & SFL_HIDDEN) == 0; }
457 void set_visible_segm(bool visible) { setflag(flags, SFL_HIDDEN, !visible); }
462 bool is_debugger_segm() const { return (flags & SFL_DEBUG) != 0; }
463 // use ::change_segment_status() to change the segment state during debugging
464 void set_debugger_segm(bool debseg) { setflag(flags, SFL_DEBUG, debseg); }
469 bool is_loader_segm() const { return (flags & SFL_LOADER) != 0; }
470 void set_loader_segm(bool ldrseg) { setflag(flags, SFL_LOADER, ldrseg); }
475 bool is_hidden_segtype() const { return (flags & SFL_HIDETYPE) != 0; }
476 void set_hidden_segtype(bool hide) { setflag(flags, SFL_HIDETYPE, hide); }
481 bool is_header_segm() const { return (flags & SFL_HEADER) != 0; }
482 void set_header_segm(bool on) { setflag(flags, SFL_HEADER, on); }
484
489 bool is_ephemeral_segm() const
490 { return (flags & (SFL_DEBUG|SFL_LOADER)) == SFL_DEBUG; }
491
492 sel_t sel = 0;
498
499 sel_t defsr[SREG_NUM];
502
503 uchar type = SEG_NORM;
508
509 bgcolor_t color = DEFCOLOR;
510
515 inline bool update();
516
519 {
520 memset(defsr, -1, sizeof(defsr)); // BADSEL
521 }
522
523#ifndef SWIG
525#endif
526}; // total 192 bytes
527
528#ifdef __EA64__
529CASSERT(sizeof(segment_t) == 192);
530#endif
531
533inline bool is_visible_segm(segment_t *s) { return s != nullptr && s->is_visible_segm(); }
536{
537 return (inf_get_cmtflg() & SCF_SHHID_SEGM) != 0 || is_visible_segm(s);
538}
539
541idaman DEPRECATED void ida_export set_visible_segm(segment_t *s, bool visible);
542
546
547idaman void ida_export set_visible_segment(ea_t ea, bool visible);
548
549
552
553idaman bool ida_export is_spec_segm(uchar seg_type);
554
555
559
560idaman bool ida_export is_spec_ea(ea_t ea);
561
562
567
568idaman DEPRECATED void ida_export lock_segm(const segment_t *segm, bool lock);
569
574
575idaman void ida_export lock_segment_by_ea(ea_t ea, bool lock);
576
579class DEPRECATED lock_segment
580{
581 ea_t ea = BADADDR;
582public:
584 {
585 if ( segm != nullptr )
586 {
587 ea = segm->start_ea;
588 lock_segment_by_ea(ea, true);
589 }
590 }
592 {
593 if ( ea != BADADDR )
594 lock_segment_by_ea(ea, false);
595 }
596};
597
600{
601 ea_t seg_ea;
602public:
603 lock_segment_ea(ea_t ea) : seg_ea(ea)
604 {
605 lock_segment_by_ea(seg_ea, true);
606 }
608 {
609 lock_segment_by_ea(seg_ea, false);
610 }
611};
612
615idaman DEPRECATED bool ida_export is_segm_locked(const segment_t *segm);
616
620
621idaman bool ida_export is_segment_locked(ea_t ea);
622
624
625//-------------------------------------------------------------------------
626// S E G M E N T S E L E C T O R S
627//
640//-------------------------------------------------------------------------
641
643
644idaman bool ida_export getn_selector(sel_t *sel, ea_t *base, int n);
645
646
648
649idaman size_t ida_export get_selector_qty();
650
651
661
662idaman sel_t ida_export setup_selector(ea_t segbase);
663
664
673
674idaman sel_t ida_export allocate_selector(ea_t segbase);
675
676
679
680idaman sel_t ida_export find_free_selector();
681
682
694
695idaman int ida_export set_selector(sel_t selector, ea_t paragraph);
696
697
702
703idaman void ida_export del_selector(sel_t selector);
704
705
710
711idaman ea_t ida_export sel2para(sel_t selector);
712
713
718
719inline ea_t idaapi sel2ea(sel_t selector)
720{
721 if ( selector == BADSEL )
722 return BADADDR;
723 return to_ea(sel2para(selector), 0);
724}
725
726
730
731idaman sel_t ida_export find_selector(ea_t base);
732
733
742
743idaman int ida_export enumerate_selectors(int (idaapi *func)(sel_t sel,ea_t para));
744
745
761
762idaman DEPRECATED ea_t ida_export enumerate_segments_with_selector(
763 sel_t selector,
764 ea_t (idaapi *func)(segment_t *s, void *ud),
765 void *ud=nullptr);
766
767
772typedef std::function<ea_t(ea_t seg_start_ea)> segment_selector_visitor_t;
773
774
785
787 sel_t selector,
788 const segment_selector_visitor_t &visitor);
789
790
797
798idaman DEPRECATED segment_t *ida_export get_segm_by_sel(sel_t selector);
799
805
806idaman ea_t ida_export get_segment_ea_by_sel(sel_t selector);
807
809
810//-------------------------------------------------------------------------
811// S E G M E N T M A N I P U L A T I O N F U N C T I O N S
812//-------------------------------------------------------------------------
817
845
846idaman DEPRECATED bool ida_export add_segm_ex(
847 segment_t *NONNULL s,
848 const char *name,
849 const char *sclass,
850 int flags);
851
878
879idaman bool ida_export add_segment_ex(segment_info_t *si, int flags);
880
884#define ADDSEG_NOSREG 0x0001
886#define ADDSEG_OR_DIE 0x0002
887#define ADDSEG_NOTRUNC 0x0004
889#define ADDSEG_QUIET 0x0008
890#define ADDSEG_FILLGAP 0x0010
897#define ADDSEG_SPARSE 0x0020
902#define ADDSEG_NOAA 0x0040
903#define ADDSEG_IDBENC 0x0080
905#define ADDSEG_KEEP_TYPE 0x0100
907
908
946
947idaman bool ida_export add_segm(
948 ea_t para,
949 ea_t start,
950 ea_t end,
951 const char *name,
952 const char *sclass,
953 int flags=0);
954
955
961
962idaman bool ida_export del_segm(ea_t ea, int flags);
963
967#define SEGMOD_KILL 0x0001
968#define SEGMOD_KEEP 0x0002
969#define SEGMOD_SILENT 0x0004
970#define SEGMOD_KEEP0 0x0008
971#define SEGMOD_KEEPSEL 0x0010
972#define SEGMOD_NOMOVE 0x0020
974#define SEGMOD_SPARSE 0x0040
977
978
980
981idaman int ida_export get_segm_qty();
982
983
988
989idaman DEPRECATED segment_t *ida_export getseg(ea_t ea);
990
995#define GSI_NAME 0x0001
996#define GSI_SCLASS 0x0002
997#define GSI_CMT_REG 0x0004
998#define GSI_CMT_RPT 0x0008
999#define GSI_COMMENTS (GSI_CMT_REG|GSI_CMT_RPT)
1000#define GSI_ALL (GSI_NAME|GSI_SCLASS|GSI_COMMENTS)
1001#define GSI_UPDATED 0x0100
1003
1011
1012idaman bool ida_export get_segment_info(segment_info_t *out, ea_t ea, int flags=0);
1013
1014
1020
1021idaman bool ida_export set_segment_info(segment_info_t *si, int flags=0);
1022
1023
1027
1028idaman ea_t ida_export get_segment_ea(ea_t ea);
1029
1030
1037
1038idaman DEPRECATED segment_t *ida_export getnseg(int n);
1039
1047
1048idaman bool ida_export get_segment_info_by_num(segment_info_t *out, int n, int flags=0);
1049
1050
1055
1056idaman ea_t ida_export get_segment_ea_by_num(int n);
1057
1058
1063idaman int ida_export get_segm_num(ea_t ea);
1064
1065
1068idaman DEPRECATED segment_t *ida_export get_next_seg(ea_t ea);
1069
1073
1074idaman ea_t ida_export get_next_segment_ea(ea_t seg_ea);
1075
1076
1079idaman DEPRECATED segment_t *ida_export get_prev_seg(ea_t ea);
1080
1084
1085idaman ea_t ida_export get_prev_segment_ea(ea_t seg_ea);
1086
1087
1090idaman DEPRECATED segment_t *ida_export get_first_seg();
1091
1095
1096idaman ea_t ida_export get_first_segment_ea();
1097
1098
1101idaman DEPRECATED segment_t *ida_export get_last_seg();
1102
1105
1106idaman ea_t ida_export get_last_segment_ea();
1107
1108
1114
1115idaman DEPRECATED segment_t *ida_export get_segm_by_name(const char *name);
1116
1121
1122idaman ea_t ida_export get_segment_ea_by_name(const char *name);
1123
1125
1126//-------------------------------------------------------------------------
1130
1141
1142idaman bool ida_export set_segm_end(ea_t ea, ea_t newend, int flags);
1143
1144
1157
1158idaman bool ida_export set_segm_start(ea_t ea, ea_t newstart, int flags);
1159
1160
1185
1186idaman bool ida_export move_segm_start(ea_t ea, ea_t newstart, int mode);
1187
1188
1207
1208
1209
1211idaman const char *ida_export move_segm_strerror(move_segm_code_t code);
1212
1213
1224
1225idaman DEPRECATED move_segm_code_t ida_export move_segm(segment_t *s, ea_t to, int flags=0);
1226
1236
1237idaman move_segm_code_t ida_export move_segment(ea_t seg_ea, ea_t to, int flags=0);
1238
1242#define MSF_SILENT 0x0001
1243#define MSF_NOFIX 0x0002
1244#define MSF_LDKEEP 0x0004
1245#define MSF_FIXONCE 0x0008
1247#define MSF_PRIORITY 0x0020
1249#define MSF_NETNODES 0x0080
1252
1259
1260idaman move_segm_code_t ida_export rebase_program(adiff_t delta, int flags);
1261
1262
1270
1271idaman DEPRECATED int ida_export change_segment_status(segment_t *s, bool is_deb_segm);
1272
1279
1280idaman int ida_export change_segment_status_by_ea(ea_t ea, bool is_deb_segm);
1281
1285#define CSS_OK 0
1286#define CSS_NODBG -1
1287#define CSS_NORANGE -2
1288#define CSS_NOMEM -3
1290#define CSS_BREAK -4
1292
1293
1298#define SNAP_ALL_SEG 0
1299#define SNAP_LOAD_SEG 1
1300#define SNAP_CUR_SEG 2
1302
1306
1307idaman bool ida_export take_memory_snapshot(int type);
1308
1312
1313idaman bool ida_export is_miniidb();
1314
1315
1318
1319idaman DEPRECATED bool ida_export set_segm_base(segment_t *s, ea_t newbase);
1320
1326
1327idaman bool ida_export set_segment_base_ea(ea_t seg_ea, ea_t newbase);
1328
1330
1331//-------------------------------------------------------------------------
1332// S E G M E N T G R O U P S
1333//-------------------------------------------------------------------------
1337
1338
1350
1351idaman int ida_export set_group_selector(sel_t grp, sel_t sel);
1352
1353#define MAX_GROUPS 8
1354
1355
1359
1360idaman sel_t ida_export get_group_selector(sel_t grpsel);
1361
1363
1364//-------------------------------------------------------------------------
1365// S E G M E N T T R A N S L A T I O N S
1405//-------------------------------------------------------------------------
1406
1412
1413idaman bool ida_export add_segment_translation(ea_t segstart, ea_t mappedseg);
1414
1415#define MAX_SEGM_TRANSLATIONS 64
1416
1417
1424
1425idaman bool ida_export set_segment_translations(ea_t segstart, const eavec_t &transmap);
1426
1427
1430
1431idaman void ida_export del_segment_translations(ea_t segstart);
1432
1433
1439
1440idaman ssize_t ida_export get_segment_translations(eavec_t *transmap, ea_t segstart);
1442
1443//-------------------------------------------------------------------------
1444// S E G M E N T C O M M E N T S
1445//
1464//-------------------------------------------------------------------------
1465
1473
1474idaman DEPRECATED ssize_t ida_export get_segment_cmt(qstring *buf, const segment_t *s, bool repeatable);
1475
1482
1483idaman ssize_t ida_export get_segment_cmt_by_ea(qstring *buf, ea_t ea, bool repeatable);
1484
1485
1495
1496idaman DEPRECATED void ida_export set_segment_cmt(const segment_t *s, const char *cmt, bool repeatable);
1497
1505
1506idaman void ida_export set_segment_cmt_by_ea(ea_t ea, const char *cmt, bool repeatable);
1507
1508
1513
1514idaman DEPRECATED void ida_export std_out_segm_footer(struct outctx_t &ctx, segment_t *seg);
1515
1521
1522idaman void ida_export std_out_segment_footer(struct outctx_t &ctx, ea_t seg_ea);
1523
1525
1526//-------------------------------------------------------------------------
1527// S E G M E N T N A M E S
1528//-------------------------------------------------------------------------
1533
1544
1545idaman DEPRECATED int ida_export set_segm_name(
1546 segment_t *s,
1547 const char *name,
1548 int flags=0);
1549
1559
1560idaman int ida_export set_segment_name(ea_t ea, const char *name, int flags=0);
1561
1562
1570
1571idaman DEPRECATED ssize_t ida_export get_segm_name(qstring *buf, const segment_t *s, int flags=0);
1572
1579
1580idaman ssize_t ida_export get_segment_name(qstring *buf, ea_t ea, int flags=0);
1581
1582
1588
1589DEPRECATED inline ssize_t idaapi get_visible_segm_name(qstring *buf, const segment_t *s)
1590{
1591 return s != nullptr ? get_segment_name(buf, s->start_ea, 1) : -1;
1592}
1593
1594
1603
1605
1607
1608//-------------------------------------------------------------------------
1609// S E G M E N T C L A S S E S A N D T Y P E S
1610//-------------------------------------------------------------------------
1615
1622
1623idaman DEPRECATED ssize_t ida_export get_segm_class(qstring *buf, const segment_t *s);
1624
1630
1631idaman ssize_t ida_export get_segment_class(qstring *buf, ea_t ea);
1632
1633
1648
1649idaman DEPRECATED int ida_export set_segm_class(segment_t *s, const char *sclass, int flags=0);
1650
1664
1665idaman int ida_export set_segment_class(ea_t ea, const char *sclass, int flags=0);
1666
1667
1671
1672idaman uchar ida_export segtype(ea_t ea);
1673
1675
1676//-------------------------------------------------------------------------
1677// S E G M E N T A L I G N M E N T A N D C O M B I N A T I O N
1678//-------------------------------------------------------------------------
1682
1685
1686idaman const char *ida_export get_segment_alignment(uchar align);
1687
1688
1691
1692idaman const char *ida_export get_segment_combination(uchar comb);
1693
1695
1696//-------------------------------------------------------------------------
1697// S E G M E N T A D D R E S S I N G
1698//-------------------------------------------------------------------------
1702
1711
1712idaman DEPRECATED ea_t ida_export get_segm_para(const segment_t *s);
1713
1719
1720idaman ea_t ida_export get_segment_para(ea_t ea);
1721
1722
1731
1732idaman DEPRECATED ea_t ida_export get_segm_base(const segment_t *s);
1733
1740
1741idaman ea_t ida_export get_segment_base(ea_t ea);
1742
1743
1755
1756idaman DEPRECATED bool ida_export set_segm_addressing(segment_t *s, size_t bitness);
1757
1768
1769idaman bool ida_export set_segment_addressing(ea_t ea, size_t bitness);
1770
1771
1777
1778idaman bool ida_export is_same_segment(ea_t ea1, ea_t ea2);
1779
1780
1781ea_t segment_info_t::para() const { return sel2para(sel_); }
1783
1784//-----------------------------------------------------------------------
1785
1787
1788inline bool is_debugger_segm(ea_t ea)
1789{
1790 segment_info_t si;
1791 return get_segment_info(&si, ea) && si.is_debugger_segm();
1792}
1793
1795
1797{
1798 segment_info_t si;
1799 return get_segment_info(&si, ea) && si.is_ephemeral_segm();
1800}
1801
1802//-------------------------------------------------------------------------
1803idaman ea_t ida_export correct_address(ea_t ea, ea_t from, ea_t to, ea_t size, bool skip_check=false);
1804
1805//-------------------------------------------------------------------------
1806idaman bool ida_export update_segm(segment_t *s);
1807
1809{
1810 return update_segm(this);
1811}
1812
1815idaman DEPRECATED adiff_t ida_export segm_adjust_diff(const segment_t *s, adiff_t delta);
1816
1821idaman adiff_t ida_export adjust_segment_diff(ea_t seg_ea, adiff_t delta);
1822
1825idaman DEPRECATED ea_t ida_export segm_adjust_ea(const segment_t *s, ea_t ea);
1826
1831idaman ea_t ida_export adjust_segment_ea(ea_t seg_ea, ea_t ea);
1832
1833#endif // _SEGMENT_HPP
flags64_t idaapi get_flags(ea_t ea)
Get flags value for address 'ea'.
Definition bytes.hpp:282
~lock_segment_ea()
Definition segment.hpp:607
lock_segment_ea(ea_t ea)
Definition segment.hpp:603
lock_segment(const segment_t *segm)
Definition segment.hpp:583
~lock_segment()
Definition segment.hpp:591
Describes a program segment.
Definition segment.hpp:408
uchar comb
Segment combination codes
Definition segment.hpp:417
uchar align
Segment alignment codes
Definition segment.hpp:416
bool is_header_segm() const
Definition segment.hpp:481
void set_header_segm(bool on)
Definition segment.hpp:482
uchar type
segment type (see Segment types).
Definition segment.hpp:503
bool update()
Update segment information.
Definition segment.hpp:1808
sel_t defsr[SREG_NUM]
default segment register values.
Definition segment.hpp:499
DECLARE_COMPARISONS(segment_t)
void clr_ob_ok()
Definition segment.hpp:451
int abits() const
Get number of address bits.
Definition segment.hpp:430
bool is_ephemeral_segm() const
Ephemeral segments are not analyzed automatically (no flirt, no functions unless required,...
Definition segment.hpp:489
uval_t name
use get/set_segm_name() functions
Definition segment.hpp:410
uchar bitness
Number of bits in the segment addressing.
Definition segment.hpp:419
void set_loader_segm(bool ldrseg)
Definition segment.hpp:470
bool is_loader_segm() const
Definition segment.hpp:469
void set_debugger_segm(bool debseg)
Definition segment.hpp:464
uchar perm
Segment permissions (0 means no information)
Definition segment.hpp:418
bool is_debugger_segm() const
Definition segment.hpp:462
void set_ob_ok()
Definition segment.hpp:450
bool is_hidden_segtype() const
Definition segment.hpp:475
int abytes() const
Get number of address bytes.
Definition segment.hpp:432
bool is_32bit() const
Is a 32-bit segment?
Definition segment.hpp:426
uval_t orgbase
this field is IDP dependent.
Definition segment.hpp:412
bool is_visible_segm() const
Definition segment.hpp:456
bool comorg() const
Definition segment.hpp:442
void set_visible_segm(bool visible)
Definition segment.hpp:457
bool ob_ok() const
Definition segment.hpp:449
uval_t sclass
use get/set_segm_class() functions
Definition segment.hpp:411
bgcolor_t color
the segment color
Definition segment.hpp:509
sel_t sel
segment selector - should be unique.
Definition segment.hpp:492
ushort flags
Segment flags
Definition segment.hpp:438
void set_hidden_segtype(bool hide)
Definition segment.hpp:476
bool is_16bit() const
Is a 16-bit segment?
Definition segment.hpp:424
void clr_comorg()
Definition segment.hpp:444
bool is_64bit() const
Is a 64-bit segment?
Definition segment.hpp:428
segment_t()
Constructor.
Definition segment.hpp:518
void set_comorg()
Definition segment.hpp:443
move_segm_code_t
Definition segment.hpp:1193
@ MOVE_SEGM_MAPPING
Memory mapping ranges of addresses hinder segment movement.
Definition segment.hpp:1204
@ MOVE_SEGM_LOADER
The segment has been moved but the loader complained.
Definition segment.hpp:1199
@ MOVE_SEGM_ROOM
Not enough free room at the target address.
Definition segment.hpp:1196
@ MOVE_SEGM_PARAM
The specified segment does not exist.
Definition segment.hpp:1195
@ MOVE_SEGM_OK
all ok
Definition segment.hpp:1194
@ MOVE_SEGM_ORPHAN
Orphan bytes hinder segment movement.
Definition segment.hpp:1201
@ MOVE_SEGM_IDP
IDP module forbids moving the segment.
Definition segment.hpp:1197
@ MOVE_SEGM_INVAL
Invalid argument (delta/target does not fit the address space)
Definition segment.hpp:1205
@ MOVE_SEGM_CHUNK
Too many chunks are defined, can't move.
Definition segment.hpp:1198
@ MOVE_SEGM_ODD
Cannot move segments by an odd number of bytes.
Definition segment.hpp:1200
@ MOVE_SEGM_SOURCEFILES
Source files ranges of addresses hinder segment movement.
Definition segment.hpp:1203
@ MOVE_SEGM_DEBUG
Debugger segments cannot be moved.
Definition segment.hpp:1202
idaman const char * end
Definition pro.h:1004
int code
Definition fpro.h:88
idaman size_t n
Definition pro.h:1000
idaman ea_t ida_export get_segment_para(ea_t ea)
Get segment base paragraph by address.
idaman ea_t ida_export get_segment_base(ea_t ea)
Get segment base linear address by address.
idaman DEPRECATED bool ida_export set_segm_addressing(segment_t *s, size_t bitness)
Change segment addressing mode (16, 32, 64 bits).
idaman DEPRECATED ea_t ida_export get_segm_para(const segment_t *s)
Get segment base paragraph.
idaman bool ida_export set_segment_addressing(ea_t ea, size_t bitness)
Change segment addressing mode (16, 32, 64 bits) by address.
idaman DEPRECATED ea_t ida_export get_segm_base(const segment_t *s)
Get segment base linear address.
idaman bool ida_export is_same_segment(ea_t ea1, ea_t ea2)
Check two addresses belong to one segment.
idaman const char *ida_export get_segment_combination(uchar comb)
Get text representation of segment combination code.
idaman const char *ida_export get_segment_alignment(uchar align)
Get text representation of segment alignment code.
idaman void ida_export std_out_segment_footer(struct outctx_t &ctx, ea_t seg_ea)
Generate segment footer line as a comment line by address.
idaman ssize_t ida_export get_segment_cmt_by_ea(qstring *buf, ea_t ea, bool repeatable)
Get segment comment by address.
idaman DEPRECATED ssize_t ida_export get_segment_cmt(qstring *buf, const segment_t *s, bool repeatable)
Get segment comment.
idaman DEPRECATED void ida_export std_out_segm_footer(struct outctx_t &ctx, segment_t *seg)
Generate segment footer line as a comment line.
idaman DEPRECATED void ida_export set_segment_cmt(const segment_t *s, const char *cmt, bool repeatable)
Set segment comment.
idaman void ida_export set_segment_cmt_by_ea(ea_t ea, const char *cmt, bool repeatable)
Set segment comment by address.
idaman sel_t ida_export get_group_selector(sel_t grpsel)
Get common selector for a group of segments.
idaman int ida_export set_group_selector(sel_t grp, sel_t sel)
Create a new group of segments (used OMF files).
idaman ea_t ida_export get_first_segment_ea()
Get start address of the first segment.
idaman DEPRECATED segment_t *ida_export get_next_seg(ea_t ea)
Get pointer to the next segment.
idaman ea_t ida_export get_last_segment_ea()
Get start address of the last segment.
idaman bool ida_export add_segment_ex(segment_info_t *si, int flags)
Add a new segment using segment_info_t.
idaman DEPRECATED segment_t *ida_export get_segm_by_name(const char *name)
Get pointer to segment by its name.
idaman ea_t ida_export get_segment_ea_by_name(const char *name)
Get segment start address by its name.
idaman bool ida_export set_segment_info(segment_info_t *si, int flags=0)
Apply segment_info_t modifications to the database.
idaman DEPRECATED bool ida_export add_segm_ex(segment_t *NONNULL s, const char *name, const char *sclass, int flags)
Add a new segment.
idaman ea_t ida_export get_segment_ea(ea_t ea)
Get segment start address.
idaman ea_t ida_export get_prev_segment_ea(ea_t seg_ea)
Get start address of the previous segment.
idaman bool ida_export add_segm(ea_t para, ea_t start, ea_t end, const char *name, const char *sclass, int flags=0)
Add a new segment, second form.
idaman DEPRECATED segment_t *ida_export get_last_seg()
Get pointer to the last segment.
idaman DEPRECATED segment_t *ida_export getnseg(int n)
Get pointer to segment by its number.
idaman bool ida_export get_segment_info_by_num(segment_info_t *out, int n, int flags=0)
Fill segment_info_t structure for segment by its number.
idaman DEPRECATED segment_t *ida_export get_first_seg()
Get pointer to the first segment.
idaman ea_t ida_export get_segment_ea_by_num(int n)
Get segment start address by its number.
idaman int ida_export get_segm_num(ea_t ea)
Get number of segment by address.
idaman bool ida_export del_segm(ea_t ea, int flags)
Delete a segment.
idaman int ida_export get_segm_qty()
Get number of segments.
idaman DEPRECATED segment_t *ida_export get_prev_seg(ea_t ea)
Get pointer to the previous segment.
idaman ea_t ida_export get_next_segment_ea(ea_t seg_ea)
Get start address of the next segment.
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.
idaman DEPRECATED segment_t *ida_export getseg(ea_t ea)
Get pointer to segment by linear address.
idaman int ida_export change_segment_status_by_ea(ea_t ea, bool is_deb_segm)
Convert a debugger segment to a regular segment and vice versa by address.
idaman DEPRECATED move_segm_code_t ida_export move_segm(segment_t *s, ea_t to, int flags=0)
This function moves all information to the new address.
idaman bool ida_export is_miniidb()
Is the database a miniidb created by the debugger?
idaman const char *ida_export move_segm_strerror(move_segm_code_t code)
Return string describing error MOVE_SEGM_... code.
idaman DEPRECATED bool ida_export set_segm_base(segment_t *s, ea_t newbase)
Internal function.
idaman bool ida_export set_segment_base_ea(ea_t seg_ea, ea_t newbase)
Set segment base.
idaman move_segm_code_t ida_export move_segment(ea_t seg_ea, ea_t to, int flags=0)
Move segment to a new address.
idaman bool ida_export move_segm_start(ea_t ea, ea_t newstart, int mode)
Move segment start.
idaman bool ida_export take_memory_snapshot(int type)
Take a memory snapshot of the running process.
idaman bool ida_export set_segm_end(ea_t ea, ea_t newend, int flags)
Set segment end address.
idaman DEPRECATED int ida_export change_segment_status(segment_t *s, bool is_deb_segm)
Convert a debugger segment to a regular segment and vice versa.
idaman move_segm_code_t ida_export rebase_program(adiff_t delta, int flags)
Rebase the whole program by 'delta' bytes.
idaman bool ida_export set_segm_start(ea_t ea, ea_t newstart, int flags)
Set segment start address.
idaman DEPRECATED int ida_export set_segm_name(segment_t *s, const char *name, int flags=0)
Rename segment.
idaman ssize_t ida_export get_segment_name(qstring *buf, ea_t ea, int flags=0)
Get segment name by address.
DEPRECATED ssize_t idaapi get_visible_segm_name(qstring *buf, const segment_t *s)
Get segment name by pointer to segment.
Definition segment.hpp:1589
idaman DEPRECATED ssize_t ida_export get_segm_name(qstring *buf, const segment_t *s, int flags=0)
Get true segment name by pointer to segment.
idaman int ida_export set_segment_name(ea_t ea, const char *name, int flags=0)
Rename segment by address.
ssize_t get_segm_expr(qstring *buf, ea_t from, sel_t sel)
Get colored segment name expression in the form (segname + displacement).
idaman sel_t ida_export allocate_selector(ea_t segbase)
Allocate a selector for a segment unconditionally.
ea_t idaapi sel2ea(sel_t selector)
Get mapping of a selector as a linear address.
Definition segment.hpp:719
idaman DEPRECATED segment_t *ida_export get_segm_by_sel(sel_t selector)
Get pointer to segment structure.
idaman void ida_export del_selector(sel_t selector)
Delete mapping of a selector.
idaman size_t ida_export get_selector_qty()
Get number of defined selectors.
idaman ea_t ida_export enumerate_segments_with_selector_ea(sel_t selector, const segment_selector_visitor_t &visitor)
Enumerate all segments with the specified selector.
idaman sel_t ida_export find_free_selector()
Find first unused selector.
idaman DEPRECATED ea_t ida_export enumerate_segments_with_selector(sel_t selector, ea_t(idaapi *func)(segment_t *s, void *ud), void *ud=nullptr)
Enumerate all segments with the specified selector.
idaman int ida_export enumerate_selectors(int(idaapi *func)(sel_t sel, ea_t para))
Enumerate all selectors from the translation table.
idaman ea_t ida_export sel2para(sel_t selector)
Get mapping of a selector.
idaman sel_t ida_export setup_selector(ea_t segbase)
Allocate a selector for a segment if necessary.
std::function< ea_t(ea_t seg_start_ea)> segment_selector_visitor_t
Callback type for enumerate_segments_with_selector_ea().
Definition segment.hpp:772
idaman ea_t ida_export get_segment_ea_by_sel(sel_t selector)
Get segment start address by its selector.
idaman bool ida_export getn_selector(sel_t *sel, ea_t *base, int n)
Get description of selector (0..get_selector_qty()-1)
idaman int ida_export set_selector(sel_t selector, ea_t paragraph)
Set mapping of selector to a paragraph.
idaman sel_t ida_export find_selector(ea_t base)
Find a selector that has mapping to the specified paragraph.
idaman void ida_export lock_segment_by_ea(ea_t ea, bool lock)
Lock segment by address.
bool is_finally_visible_segm(segment_t *s)
See SFL_HIDDEN, SCF_SHHID_SEGM.
Definition segment.hpp:535
idaman DEPRECATED bool ida_export is_segm_locked(const segment_t *segm)
Is a segment pointer locked?
idaman bool ida_export is_spec_ea(ea_t ea)
Does the address belong to a segment with a special type?
idaman void ida_export set_visible_segment(ea_t ea, bool visible)
Set segment visibility by address.
idaman bool ida_export is_segment_locked(ea_t ea)
Is segment locked by address?
idaman bool ida_export is_spec_segm(uchar seg_type)
Has segment a special type?
bool is_visible_segm(segment_t *s)
See SFL_HIDDEN.
Definition segment.hpp:533
CASSERT(sizeof(segment_t)==192)
idaman DEPRECATED void ida_export lock_segm(const segment_t *segm, bool lock)
Lock segment pointer.
idaman DEPRECATED void ida_export set_visible_segm(segment_t *s, bool visible)
See SFL_HIDDEN.
idaman bool ida_export add_segment_translation(ea_t segstart, ea_t mappedseg)
Add segment translation.
idaman void ida_export del_segment_translations(ea_t segstart)
Delete the translation list.
idaman ssize_t ida_export get_segment_translations(eavec_t *transmap, ea_t segstart)
Get segment translation list.
idaman bool ida_export set_segment_translations(ea_t segstart, const eavec_t &transmap)
Set new translation list.
idaman int ida_export set_segment_class(ea_t ea, const char *sclass, int flags=0)
Set segment class by address.
idaman uchar ida_export segtype(ea_t ea)
Get segment type.
idaman ssize_t ida_export get_segment_class(qstring *buf, ea_t ea)
Get segment class by address.
idaman DEPRECATED int ida_export set_segm_class(segment_t *s, const char *sclass, int flags=0)
Set segment class.
idaman DEPRECATED ssize_t ida_export get_segm_class(qstring *buf, const segment_t *s)
Get segment class.
bool hexapi get_type(uval_t id, tinfo_t *tif, type_source_t guess)
Get a global type.
Definition hexrays.hpp:11257
bool hexapi set_type(uval_t id, const tinfo_t &tif, type_source_t source, bool force=false)
Set a global type.
Definition hexrays.hpp:11263
const tinfo_t & type
Definition hexrays.hpp:7698
Contains the inf structure definition and some functions common to the whole IDA project.
ea_t idaapi to_ea(sel_t reg_cs, uval_t reg_ip)
Convert (sel,off) value to a linear address.
Definition ida.hpp:1152
uchar inf_get_cmtflg()
Definition ida.hpp:905
uval_t uval_t
Definition kernwin.hpp:1926
asize_t size
Definition kernwin.hpp:6701
unsigned __int64 uint64
Definition llong.hpp:13
ssize_t get_name(qstring *out, ea_t ea, int gtn_flags=0)
Definition name.hpp:352
idaman bool ida_export set_name(ea_t ea, const char *name, int flags=0)
Set or delete name of an item at the specified address.
uint32 bgcolor_t
background color in RGB
Definition pro.h:5109
int64 adiff_t
Definition pro.h:428
uint64 ea_t
Definition pro.h:425
unsigned char uchar
unsigned 8 bit value
Definition pro.h:341
uint64 sel_t
Definition pro.h:426
qvector< ea_t > eavec_t
vector of addresses
Definition pro.h:2838
ptrdiff_t ssize_t
Signed size_t - used to check for size overflows when the counter becomes negative.
Definition pro.h:385
unsigned short ushort
unsigned 16 bit value
Definition pro.h:342
void idaapi setflag(T &where, U bit, bool cnd)
Set a 'bit' in 'where' if 'value' is not zero.
Definition pro.h:1530
_qstring< char > qstring
regular string
Definition pro.h:3771
Contains the definition of range_t.
idaman ea_t ida_export correct_address(ea_t ea, ea_t from, ea_t to, ea_t size, bool skip_check=false)
idaman DEPRECATED ea_t ida_export segm_adjust_ea(const segment_t *s, ea_t ea)
Truncate an address depending on the segment.
bool is_ephemeral_segm(ea_t ea)
Does the address belong to an ephemeral segment?
Definition segment.hpp:1796
idaman adiff_t ida_export adjust_segment_diff(ea_t seg_ea, adiff_t delta)
Truncate and sign extend a delta depending on the segment by address.
idaman bool ida_export update_segm(segment_t *s)
idaman DEPRECATED adiff_t ida_export segm_adjust_diff(const segment_t *s, adiff_t delta)
Truncate and sign extend a delta depending on the segment.
bool is_debugger_segm(ea_t ea)
Does the address belong to a debug segment?
Definition segment.hpp:1788
idaman ea_t ida_export adjust_segment_ea(ea_t seg_ea, ea_t ea)
Truncate an address depending on the segment by address.
Definition ua.hpp:1119
Base class for an range.
Definition range.hpp:35
bool empty() const
Is the size of the range_t <= 0?
Definition range.hpp:60
ea_t start_ea
start_ea included
Definition range.hpp:37
range_t(ea_t ea1=0, ea_t ea2=0)
Definition range.hpp:39