forked from K0lb3/UnityPy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathendian.h
More file actions
40 lines (39 loc) · 1.44 KB
/
endian.h
File metadata and controls
40 lines (39 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/*
############################################################################
endianess definitions
############################################################################
*/
// check if the system is little endian
#define IS_LITTLE_ENDIAN (*(unsigned char *)&(unsigned short){1})
// set swap funcions (source: old version of nodejs/src/node_buffer.cc)
#if defined(__GNUC__) || defined(__clang__)
#define bswap16(x) __builtin_bswap16(x)
#define bswap32(x) __builtin_bswap32(x)
#define bswap64(x) __builtin_bswap64(x)
#elif defined(__linux__)
#include <byteswap.h>
#define bswap16(x) bswap_16(x)
#define bswap32(x) bswap_32(x)
#define bswap64(x) bswap_64(x)
#elif defined(_MSC_VER)
#include <intrin.h>
#define bswap16(x) _byteswap_ushort(x)
#define bswap32(x) _byteswap_ulong(x)
#define bswap64(x) _byteswap_uint64(x)
#else
#define bswap16 ((x) << 8) | ((x) >> 8)
#define bswap32 \
(((x)&0xFF) << 24) | \
(((x)&0xFF00) << 8) | \
(((x) >> 8) & 0xFF00) | \
(((x) >> 24) & 0xFF)
#define bswap64 \
(((x)&0xFF00000000000000ull) >> 56) | \
(((x)&0x00FF000000000000ull) >> 40) | \
(((x)&0x0000FF0000000000ull) >> 24) | \
(((x)&0x000000FF00000000ull) >> 8) | \
(((x)&0x00000000FF000000ull) << 8) | \
(((x)&0x0000000000FF0000ull) << 24) | \
(((x)&0x000000000000FF00ull) << 40) | \
(((x)&0x00000000000000FFull) << 56)
#endif