ROSE 0.11.145.192
RelativeVirtualAddress.h
1#ifndef ROSE_BinaryAnalysis_RelativeVirtualAddress_H
2#define ROSE_BinaryAnalysis_RelativeVirtualAddress_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_BINARY_ANALYSIS
5#include <Rose/BinaryAnalysis/Address.h>
6
7#include <ROSE_DEPRECATED.h>
8#include <Cxx_GrammarDeclarations.h>
9
10#include <Sawyer/Optional.h>
11
12namespace Rose {
13namespace BinaryAnalysis {
14
23 // Offset relative to a section's preferred mapping address (if `section_` is not null) or relative to a file's base address (if
24 // `section_` is null). The offset is treated as a signed quantity by virtue of unsigned 64-bit overflow.
25 rose_addr_t rva_ = 0;
26
27 // Optional base section. If present, then it must have a preferred mapping address, and the `rva_` is an offset to the
28 // section's preferred address.
29 SgAsmGenericSection *section_ = nullptr;
30
31#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
32private:
33 friend class boost::serialization::access;
34
35 template<class S>
36 void serialize(S &s, const unsigned /*version*/) {
37 s & BOOST_SERIALIZATION_NVP(rva_);
38 s & BOOST_SERIALIZATION_NVP(section_);
39 }
40#endif
41
42public:
45
50 RelativeVirtualAddress(const rose_addr_t rva, SgAsmGenericSection* = nullptr); //implicit
51
54
57
62 static RelativeVirtualAddress sectionRelative(SgAsmGenericSection*, rose_addr_t sectionOffset);
63
65 bool isBound() const;
66
71 rose_addr_t rva() const;
72
77
80
86
92
97
102
106 rose_addr_t offsetFrom(SgAsmGenericSection*) const;
107
109 void increment(rose_addr_t amount);
110
115 std::string toString() const;
116
117 // [Robb Matzke 2024-02-05]: deprecated
118public:
119 static RelativeVirtualAddress section_relative(SgAsmGenericSection*, rose_addr_t) ROSE_DEPRECATED("use sectionRelative instead");
120 bool is_bound() const ROSE_DEPRECATED("use isBound instead");
121 rose_addr_t get_rva() const ROSE_DEPRECATED("use rva instead");
122 RelativeVirtualAddress& set_rva(rose_addr_t rva) ROSE_DEPRECATED("use rva instead");
123 SgAsmGenericSection *get_section() const ROSE_DEPRECATED("use boundSection instead");
124 RelativeVirtualAddress& set_section(SgAsmGenericSection*) ROSE_DEPRECATED("use bindSection instead");
125 RelativeVirtualAddress& bind(SgAsmGenericHeader*) ROSE_DEPRECATED("use bindBestSection instead");
126 rose_addr_t get_va() const ROSE_DEPRECATED("use va instead");
127 rose_addr_t get_rel() const ROSE_DEPRECATED("use boundOffset instead");
128 rose_addr_t get_rel(SgAsmGenericSection*) ROSE_DEPRECATED("use offsetFrom instead");
129 std::string to_string() const ROSE_DEPRECATED("use toString instead");
130};
131
132} // namespace
133} // namespace
134
135// Old name used from 2008-2024
136using rose_rva_t = Rose::BinaryAnalysis::RelativeVirtualAddress;
137
138std::ostream &operator<<(std::ostream&, const Rose::BinaryAnalysis::RelativeVirtualAddress&);
139
140rose_addr_t operator-(const Rose::BinaryAnalysis::RelativeVirtualAddress &a1,
141 const Rose::BinaryAnalysis::RelativeVirtualAddress &a2);
142rose_addr_t operator+(const Rose::BinaryAnalysis::RelativeVirtualAddress &a1,
143 const Rose::BinaryAnalysis::RelativeVirtualAddress &a2);
144
145bool operator< (const Rose::BinaryAnalysis::RelativeVirtualAddress &a1, const Rose::BinaryAnalysis::RelativeVirtualAddress &a2);
146bool operator<=(const Rose::BinaryAnalysis::RelativeVirtualAddress &a1, const Rose::BinaryAnalysis::RelativeVirtualAddress &a2);
147bool operator> (const Rose::BinaryAnalysis::RelativeVirtualAddress &a1, const Rose::BinaryAnalysis::RelativeVirtualAddress &a2);
148bool operator>=(const Rose::BinaryAnalysis::RelativeVirtualAddress &a1, const Rose::BinaryAnalysis::RelativeVirtualAddress &a2);
149bool operator==(const Rose::BinaryAnalysis::RelativeVirtualAddress &a1, const Rose::BinaryAnalysis::RelativeVirtualAddress &a2);
150bool operator!=(const Rose::BinaryAnalysis::RelativeVirtualAddress &a1, const Rose::BinaryAnalysis::RelativeVirtualAddress &a2);
151
152#endif
153#endif
Optionally bound relative virtual address.
RelativeVirtualAddress(const RelativeVirtualAddress &)
Copy constructor.
std::string toString() const
Convert to a string representation.
RelativeVirtualAddress & rva(rose_addr_t rva)
Assign a new RVA without adjusting the bound section.
RelativeVirtualAddress(const rose_addr_t rva, SgAsmGenericSection *=nullptr)
Conversion from numeric RVA.
Sawyer::Optional< rose_addr_t > boundOffset() const
Returns an offset from the currently bound section.
Sawyer::Optional< rose_addr_t > va() const
Return the absolute address if known.
RelativeVirtualAddress & bindBestSection(SgAsmGenericHeader *)
Binds this RVA to the best available section from the specified file header.
bool isBound() const
Determines whether this instance is associated with a file section.
RelativeVirtualAddress & bindSection(SgAsmGenericSection *)
Changes the section binding.
RelativeVirtualAddress()
Create a zero RVA not linked to any section.
rose_addr_t rva() const
Returns the offset.
static RelativeVirtualAddress sectionRelative(SgAsmGenericSection *, rose_addr_t sectionOffset)
Constructs a new instance from a section and offset.
rose_addr_t offsetFrom(SgAsmGenericSection *) const
Returns an offset relative to the specified section.
RelativeVirtualAddress operator=(const RelativeVirtualAddress &)
Assignment operator.
void increment(rose_addr_t amount)
Increment the address by the specified amount, keeping it attached to the same (if any) section.
SgAsmGenericSection * boundSection() const
Returns the section to which this RVA is bound.
Holds a value or nothing.
Definition Optional.h:56
Base class for container file headers.
Contiguous region of a file.
The ROSE library.