1 #ifndef ROSE_BinaryAnalysis_ByteOrder_H
2 #define ROSE_BinaryAnalysis_ByteOrder_H
3 #include <featureTests.h>
4 #ifdef ROSE_ENABLE_BINARY_ANALYSIS
6 #include <Rose/BitOps.h>
7 #include <boost/numeric/conversion/cast.hpp>
10 namespace BinaryAnalysis {
21 Endianness hostOrder();
24 void convert(
void *bytes,
size_t nbytes, Endianness from, Endianness to);
28 typename std::enable_if<std::is_integral<T>::value, T>::type
29 swapBytes(
const T &x) {
35 typename std::enable_if<std::is_integral<T>::value, T>::type
36 leToHost(
const T &x) {
42 typename std::enable_if<std::is_integral<T>::value, T>::type
43 beToHost(
const T &x) {
49 typename std::enable_if<std::is_integral<T>::value, T>::type
50 diskToHost(Endianness sex,
const T &x) {
61 template<
class Source,
class Destination>
63 hostToLe(
const Source &src, Destination *dst ,
64 typename std::enable_if<std::is_integral<Source>::value && std::is_integral<Destination>::value>::type* =
nullptr) {
83 template<
class Source,
class Destination>
85 hostToBe(
const Source &src, Destination *dst,
86 typename std::enable_if<std::is_integral<Source>::value && std::is_integral<Destination>::value>::type* =
nullptr) {
103 template<
class Source,
class Destination>
105 hostToDisk(Endianness sex,
const Source &src, Destination *dst,
106 typename std::enable_if<std::is_integral<Source>::value && std::is_integral<Destination>::value>::type* =
nullptr) {
107 ASSERT_not_null(dst);
108 *dst = ORDER_LSB == sex ?
114 Endianness host_order() ROSE_DEPRECATED("use hostOrder");
115 int8_t swap_bytes(int8_t n) ROSE_DEPRECATED("use swapBytes");
116 uint8_t swap_bytes(uint8_t n) ROSE_DEPRECATED("use swapBytes");
117 int16_t swap_bytes(int16_t n) ROSE_DEPRECATED("use swapBytes");
118 uint16_t swap_bytes(uint16_t n) ROSE_DEPRECATED("use swapBytes");
119 int32_t swap_bytes(int32_t n) ROSE_DEPRECATED("use swapBytes");
120 uint32_t swap_bytes(uint32_t n) ROSE_DEPRECATED("use swapBytes");
121 int64_t swap_bytes(int64_t n) ROSE_DEPRECATED("use swapBytes");
122 uint64_t swap_bytes(uint64_t n) ROSE_DEPRECATED("use swapBytes");
123 int8_t le_to_host(int8_t n) ROSE_DEPRECATED("use leToHost");
124 uint8_t le_to_host(uint8_t n) ROSE_DEPRECATED("use leToHost");
125 int16_t le_to_host(int16_t n) ROSE_DEPRECATED("use leToHost");
126 uint16_t le_to_host(uint16_t n) ROSE_DEPRECATED("use leToHost");
127 int32_t le_to_host(int32_t n) ROSE_DEPRECATED("use leToHost");
128 uint32_t le_to_host(uint32_t n) ROSE_DEPRECATED("use leToHost");
129 int64_t le_to_host(int64_t n) ROSE_DEPRECATED("use leToHost");
130 uint64_t le_to_host(uint64_t n) ROSE_DEPRECATED("use leToHost");
131 void host_to_le(
unsigned h, uint8_t *n) ROSE_DEPRECATED("use hostToLe");
132 void host_to_le(
unsigned h, uint16_t *n) ROSE_DEPRECATED("use hostToLe");
133 void host_to_le(
unsigned h, uint32_t *n) ROSE_DEPRECATED("use hostToLe");
134 void host_to_le(rose_addr_t h, uint64_t *n) ROSE_DEPRECATED("use hostToLe");
135 void host_to_le(
int h, int8_t *n) ROSE_DEPRECATED("use hostToLe");
136 void host_to_le(
int h, int16_t *n) ROSE_DEPRECATED("use hostToLe");
137 void host_to_le(
int h, int32_t *n) ROSE_DEPRECATED("use hostToLe");
138 void host_to_le(int64_t h, int64_t *n) ROSE_DEPRECATED("use hostToLe");
139 void host_to_le(
rose_rva_t h, uint32_t *n) ROSE_DEPRECATED("use hostToLe");
140 void host_to_le(
rose_rva_t h, uint64_t *n) ROSE_DEPRECATED("use hostToLe");
141 uint8_t be_to_host(uint8_t n) ROSE_DEPRECATED("use beToHost");
142 uint16_t be_to_host(uint16_t n) ROSE_DEPRECATED("use beToHost");
143 uint32_t be_to_host(uint32_t n) ROSE_DEPRECATED("use beToHost");
144 uint64_t be_to_host(uint64_t n) ROSE_DEPRECATED("use beToHost");
145 int8_t be_to_host(int8_t n) ROSE_DEPRECATED("use beToHost");
146 int16_t be_to_host(int16_t n) ROSE_DEPRECATED("use beToHost");
147 int32_t be_to_host(int32_t n) ROSE_DEPRECATED("use beToHost");
148 int64_t be_to_host(int64_t n) ROSE_DEPRECATED("use beToHost");
149 void host_to_be(
unsigned h, uint8_t *n) ROSE_DEPRECATED("use hostToBe");
150 void host_to_be(
unsigned h, uint16_t *n) ROSE_DEPRECATED("use hostToBe");
151 void host_to_be(
unsigned h, uint32_t *n) ROSE_DEPRECATED("use hostToBe");
152 void host_to_be(rose_addr_t h, uint64_t *n) ROSE_DEPRECATED("use hostToBe");
153 void host_to_be(
int h, int8_t *n) ROSE_DEPRECATED("use hostToBe");
154 void host_to_be(
int h, int16_t *n) ROSE_DEPRECATED("use hostToBe");
155 void host_to_be(
int h, int32_t *n) ROSE_DEPRECATED("use hostToBe");
156 void host_to_be(int64_t h, int64_t *n) ROSE_DEPRECATED("use hostToBe");
157 void host_to_be(
rose_rva_t h, uint32_t *n) ROSE_DEPRECATED("use hostToBe");
158 void host_to_be(
rose_rva_t h, uint64_t *n) ROSE_DEPRECATED("use hostToBe");
159 uint8_t disk_to_host(Endianness sex, uint8_t n) ROSE_DEPRECATED("use diskToHost");
160 uint16_t disk_to_host(Endianness sex, uint16_t n) ROSE_DEPRECATED("use diskToHost");
161 uint32_t disk_to_host(Endianness sex, uint32_t n) ROSE_DEPRECATED("use diskToHost");
162 uint64_t disk_to_host(Endianness sex, uint64_t n) ROSE_DEPRECATED("use diskToHost");
163 int8_t disk_to_host(Endianness sex, int8_t n) ROSE_DEPRECATED("use diskToHost");
164 int16_t disk_to_host(Endianness sex, int16_t n) ROSE_DEPRECATED("use diskToHost");
165 int32_t disk_to_host(Endianness sex, int32_t n) ROSE_DEPRECATED("use diskToHost");
166 int64_t disk_to_host(Endianness sex, int64_t n) ROSE_DEPRECATED("use diskToHost");
167 void host_to_disk(Endianness sex,
unsigned h, uint8_t *np) ROSE_DEPRECATED("use hostToDisk");
168 void host_to_disk(Endianness sex,
unsigned h, uint16_t *np) ROSE_DEPRECATED("use hostToDisk");
169 void host_to_disk(Endianness sex,
unsigned h, uint32_t *np) ROSE_DEPRECATED("use hostToDisk");
170 void host_to_disk(Endianness sex, rose_addr_t h, uint64_t *np) ROSE_DEPRECATED("use hostToDisk");
171 void host_to_disk(Endianness sex,
rose_rva_t h, uint64_t *np) ROSE_DEPRECATED("use hostToDisk");
172 void host_to_disk(Endianness sex,
int h, int8_t *np) ROSE_DEPRECATED("use hostToDisk");
173 void host_to_disk(Endianness sex,
int h, int16_t *np) ROSE_DEPRECATED("use hostToDisk");
174 void host_to_disk(Endianness sex,
int h, int32_t *np) ROSE_DEPRECATED("use hostToDisk");
175 void host_to_disk(Endianness sex, int64_t h, int64_t *np) ROSE_DEPRECATED("use hostToDisk");
std::enable_if< std::is_integral< T >::value, T >::type fromBigEndian(const T x)
Convert integral value from big endian to host order.
std::enable_if< std::is_integral< T >::value, T >::type fromLittleEndian(const T x)
Convert integral value from little endian to host order.
rose_addr_t get_rva() const
Returns the numeric RVA.
UnsignedTarget convert(UnsignedSource x, bool b=false)
Extend or truncate a value.
std::enable_if< std::is_integral< T >::value, T >::type toLittleEndian(const T x)
Convert integral value from host order to little endian.
Main namespace for the ROSE library.
A relative virtual address optionally associated with a SgAsmSection.
std::enable_if< std::is_integral< T >::value, T >::type toBigEndian(const T x)
Convert integral value from host order to big endian.
std::enable_if< std::is_integral< T >::value, T >::type reverseBytes(const T &x)
Reverse the bytes.