Spaces:
Running
Running
Commit
·
8853681
1
Parent(s):
f2561b7
Update defs.h to newer version
Browse files- Dockerfile +2 -0
- defs.h +442 -0
Dockerfile
CHANGED
@@ -9,6 +9,8 @@ RUN chmod -R og+rX /root/miniconda3
|
|
9 |
|
10 |
RUN git clone https://github.com/lt-asset/resym /home/ReSym
|
11 |
|
|
|
|
|
12 |
WORKDIR /code
|
13 |
|
14 |
# Set up a new user named "user" with user ID 1000
|
|
|
9 |
|
10 |
RUN git clone https://github.com/lt-asset/resym /home/ReSym
|
11 |
|
12 |
+
COPY ./defs.h /home/ReSym/clang-parser/defs.hh
|
13 |
+
|
14 |
WORKDIR /code
|
15 |
|
16 |
# Set up a new user named "user" with user ID 1000
|
defs.h
ADDED
@@ -0,0 +1,442 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
|
3 |
+
This file contains definitions used in the Hex-Rays decompiler output.
|
4 |
+
It has type definitions and convenience macros to make the
|
5 |
+
output more readable.
|
6 |
+
|
7 |
+
Copyright (c) 2007-2024 Hex-Rays
|
8 |
+
|
9 |
+
*/
|
10 |
+
|
11 |
+
#ifndef HEXRAYS_DEFS_H
|
12 |
+
#define HEXRAYS_DEFS_H
|
13 |
+
|
14 |
+
#if defined(__GNUC__)
|
15 |
+
typedef long long ll;
|
16 |
+
typedef unsigned long long ull;
|
17 |
+
#define __int64 long long
|
18 |
+
#define __int32 int
|
19 |
+
#define __int16 short
|
20 |
+
#define __int8 char
|
21 |
+
#define MAKELL(num) num ## LL
|
22 |
+
#define FMT_64 "ll"
|
23 |
+
#elif defined(_MSC_VER)
|
24 |
+
typedef __int64 ll;
|
25 |
+
typedef unsigned __int64 ull;
|
26 |
+
#define MAKELL(num) num ## i64
|
27 |
+
#define FMT_64 "I64"
|
28 |
+
#elif defined (__BORLANDC__)
|
29 |
+
typedef __int64 ll;
|
30 |
+
typedef unsigned __int64 ull;
|
31 |
+
#define MAKELL(num) num ## i64
|
32 |
+
#define FMT_64 "L"
|
33 |
+
#else
|
34 |
+
#error "unknown compiler"
|
35 |
+
#endif
|
36 |
+
typedef unsigned int uint;
|
37 |
+
typedef unsigned char uchar;
|
38 |
+
typedef unsigned short ushort;
|
39 |
+
typedef unsigned long ulong;
|
40 |
+
|
41 |
+
typedef char int8;
|
42 |
+
typedef signed char sint8;
|
43 |
+
typedef unsigned char uint8;
|
44 |
+
typedef short int16;
|
45 |
+
typedef signed short sint16;
|
46 |
+
typedef unsigned short uint16;
|
47 |
+
typedef int int32;
|
48 |
+
typedef signed int sint32;
|
49 |
+
typedef unsigned int uint32;
|
50 |
+
typedef ll int64;
|
51 |
+
typedef ll sint64;
|
52 |
+
typedef ull uint64;
|
53 |
+
|
54 |
+
// Partially defined types. They are used when the decompiler does not know
|
55 |
+
// anything about the type except its size.
|
56 |
+
#define _BYTE uint8
|
57 |
+
#define _WORD uint16
|
58 |
+
#define _DWORD uint32
|
59 |
+
#define _QWORD uint64
|
60 |
+
#if !defined(_MSC_VER)
|
61 |
+
#define _LONGLONG __int128
|
62 |
+
#endif
|
63 |
+
|
64 |
+
// Non-standard boolean types. They are used when the decompiler cannot use
|
65 |
+
// the standard "bool" type because of the size mistmatch but the possible
|
66 |
+
// values are only 0 and 1. See also 'BOOL' type below.
|
67 |
+
typedef int8 _BOOL1;
|
68 |
+
typedef int16 _BOOL2;
|
69 |
+
typedef int32 _BOOL4;
|
70 |
+
typedef int64 _BOOL8;
|
71 |
+
|
72 |
+
#ifndef _WINDOWS_
|
73 |
+
typedef int8 BYTE;
|
74 |
+
typedef int16 WORD;
|
75 |
+
typedef int32 DWORD;
|
76 |
+
typedef int32 LONG;
|
77 |
+
typedef int BOOL; // uppercase BOOL is usually 4 bytes
|
78 |
+
#endif
|
79 |
+
typedef int64 QWORD;
|
80 |
+
#ifndef __cplusplus
|
81 |
+
typedef int bool; // we want to use bool in our C programs
|
82 |
+
#endif
|
83 |
+
|
84 |
+
#define __pure // pure function:
|
85 |
+
// when given the same arguments, always returns the same value
|
86 |
+
// has no side effects
|
87 |
+
|
88 |
+
// Non-returning function
|
89 |
+
#if defined(__GNUC__)
|
90 |
+
#define __noreturn __attribute__((noreturn))
|
91 |
+
#else
|
92 |
+
#define __noreturn __declspec(noreturn)
|
93 |
+
#endif
|
94 |
+
|
95 |
+
|
96 |
+
#ifndef NULL
|
97 |
+
#define NULL 0
|
98 |
+
#endif
|
99 |
+
|
100 |
+
// Some convenience macros to make partial accesses nicer
|
101 |
+
#define LAST_IND(x,part_type) (sizeof(x)/sizeof(part_type) - 1)
|
102 |
+
#if defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN
|
103 |
+
# define LOW_IND(x,part_type) LAST_IND(x,part_type)
|
104 |
+
# define HIGH_IND(x,part_type) 0
|
105 |
+
#else
|
106 |
+
# define HIGH_IND(x,part_type) LAST_IND(x,part_type)
|
107 |
+
# define LOW_IND(x,part_type) 0
|
108 |
+
#endif
|
109 |
+
// first unsigned macros:
|
110 |
+
#define BYTEn(x, n) (*((_BYTE*)&(x)+n))
|
111 |
+
#define WORDn(x, n) (*((_WORD*)&(x)+n))
|
112 |
+
#define DWORDn(x, n) (*((_DWORD*)&(x)+n))
|
113 |
+
|
114 |
+
#define LOBYTE(x) BYTEn(x,LOW_IND(x,_BYTE))
|
115 |
+
#define LOWORD(x) WORDn(x,LOW_IND(x,_WORD))
|
116 |
+
#define LODWORD(x) DWORDn(x,LOW_IND(x,_DWORD))
|
117 |
+
#define HIBYTE(x) BYTEn(x,HIGH_IND(x,_BYTE))
|
118 |
+
#define HIWORD(x) WORDn(x,HIGH_IND(x,_WORD))
|
119 |
+
#define HIDWORD(x) DWORDn(x,HIGH_IND(x,_DWORD))
|
120 |
+
#define BYTE1(x) BYTEn(x, 1) // byte 1 (counting from 0)
|
121 |
+
#define BYTE2(x) BYTEn(x, 2)
|
122 |
+
#define BYTE3(x) BYTEn(x, 3)
|
123 |
+
#define BYTE4(x) BYTEn(x, 4)
|
124 |
+
#define BYTE5(x) BYTEn(x, 5)
|
125 |
+
#define BYTE6(x) BYTEn(x, 6)
|
126 |
+
#define BYTE7(x) BYTEn(x, 7)
|
127 |
+
#define BYTE8(x) BYTEn(x, 8)
|
128 |
+
#define BYTE9(x) BYTEn(x, 9)
|
129 |
+
#define BYTE10(x) BYTEn(x, 10)
|
130 |
+
#define BYTE11(x) BYTEn(x, 11)
|
131 |
+
#define BYTE12(x) BYTEn(x, 12)
|
132 |
+
#define BYTE13(x) BYTEn(x, 13)
|
133 |
+
#define BYTE14(x) BYTEn(x, 14)
|
134 |
+
#define BYTE15(x) BYTEn(x, 15)
|
135 |
+
#define WORD1(x) WORDn(x, 1)
|
136 |
+
#define WORD2(x) WORDn(x, 2) // third word of the object, unsigned
|
137 |
+
#define WORD3(x) WORDn(x, 3)
|
138 |
+
#define WORD4(x) WORDn(x, 4)
|
139 |
+
#define WORD5(x) WORDn(x, 5)
|
140 |
+
#define WORD6(x) WORDn(x, 6)
|
141 |
+
#define WORD7(x) WORDn(x, 7)
|
142 |
+
|
143 |
+
// now signed macros (the same but with sign extension)
|
144 |
+
#define SBYTEn(x, n) (*((int8*)&(x)+n))
|
145 |
+
#define SWORDn(x, n) (*((int16*)&(x)+n))
|
146 |
+
#define SDWORDn(x, n) (*((int32*)&(x)+n))
|
147 |
+
|
148 |
+
#define SLOBYTE(x) SBYTEn(x,LOW_IND(x,int8))
|
149 |
+
#define SLOWORD(x) SWORDn(x,LOW_IND(x,int16))
|
150 |
+
#define SLODWORD(x) SDWORDn(x,LOW_IND(x,int32))
|
151 |
+
#define SHIBYTE(x) SBYTEn(x,HIGH_IND(x,int8))
|
152 |
+
#define SHIWORD(x) SWORDn(x,HIGH_IND(x,int16))
|
153 |
+
#define SHIDWORD(x) SDWORDn(x,HIGH_IND(x,int32))
|
154 |
+
#define SBYTE1(x) SBYTEn(x, 1)
|
155 |
+
#define SBYTE2(x) SBYTEn(x, 2)
|
156 |
+
#define SBYTE3(x) SBYTEn(x, 3)
|
157 |
+
#define SBYTE4(x) SBYTEn(x, 4)
|
158 |
+
#define SBYTE5(x) SBYTEn(x, 5)
|
159 |
+
#define SBYTE6(x) SBYTEn(x, 6)
|
160 |
+
#define SBYTE7(x) SBYTEn(x, 7)
|
161 |
+
#define SBYTE8(x) SBYTEn(x, 8)
|
162 |
+
#define SBYTE9(x) SBYTEn(x, 9)
|
163 |
+
#define SBYTE10(x) SBYTEn(x, 10)
|
164 |
+
#define SBYTE11(x) SBYTEn(x, 11)
|
165 |
+
#define SBYTE12(x) SBYTEn(x, 12)
|
166 |
+
#define SBYTE13(x) SBYTEn(x, 13)
|
167 |
+
#define SBYTE14(x) SBYTEn(x, 14)
|
168 |
+
#define SBYTE15(x) SBYTEn(x, 15)
|
169 |
+
#define SWORD1(x) SWORDn(x, 1)
|
170 |
+
#define SWORD2(x) SWORDn(x, 2)
|
171 |
+
#define SWORD3(x) SWORDn(x, 3)
|
172 |
+
#define SWORD4(x) SWORDn(x, 4)
|
173 |
+
#define SWORD5(x) SWORDn(x, 5)
|
174 |
+
#define SWORD6(x) SWORDn(x, 6)
|
175 |
+
#define SWORD7(x) SWORDn(x, 7)
|
176 |
+
|
177 |
+
// Generate a pair of operands. S stands for 'signed'
|
178 |
+
#define __SPAIR16__(high, low) (((int16) (high) << 8) | (uint8) (low))
|
179 |
+
#define __SPAIR32__(high, low) (((int32) (high) << 16) | (uint16)(low))
|
180 |
+
#define __SPAIR64__(high, low) (((int64) (high) << 32) | (uint32)(low))
|
181 |
+
#define __SPAIR128__(high, low) (((int128) (high) << 64) | (uint64)(low))
|
182 |
+
#define __PAIR16__(high, low) (((uint16) (high) << 8) | (uint8) (low))
|
183 |
+
#define __PAIR32__(high, low) (((uint32) (high) << 16) | (uint16)(low))
|
184 |
+
#define __PAIR64__(high, low) (((uint64) (high) << 32) | (uint32)(low))
|
185 |
+
#define __PAIR128__(high, low) (((uint128)(high) << 64) | (uint64)(low))
|
186 |
+
|
187 |
+
// Helper functions to represent some assembly instructions.
|
188 |
+
|
189 |
+
#ifdef __cplusplus
|
190 |
+
|
191 |
+
// compile time assertion
|
192 |
+
#define __CASSERT_N0__(l) COMPILE_TIME_ASSERT_ ## l
|
193 |
+
#define __CASSERT_N1__(l) __CASSERT_N0__(l)
|
194 |
+
#define CASSERT(cnd) typedef char __CASSERT_N1__(__LINE__) [(cnd) ? 1 : -1]
|
195 |
+
|
196 |
+
// check that unsigned multiplication does not overflow
|
197 |
+
template<class T> bool is_mul_ok(T count, T elsize)
|
198 |
+
{
|
199 |
+
CASSERT(T(-1) > 0); // make sure T is unsigned
|
200 |
+
if ( elsize == 0 || count == 0 )
|
201 |
+
return true;
|
202 |
+
return count <= T(-1) / elsize;
|
203 |
+
}
|
204 |
+
|
205 |
+
// multiplication that saturates (yields the biggest value) instead of overflowing
|
206 |
+
// such a construct is useful in "operator new[]"
|
207 |
+
template<class T> bool saturated_mul(T count, T elsize)
|
208 |
+
{
|
209 |
+
return is_mul_ok(count, elsize) ? count * elsize : T(-1);
|
210 |
+
}
|
211 |
+
|
212 |
+
#include <stddef.h> // for size_t
|
213 |
+
|
214 |
+
// memcpy() with determined behavoir: it always copies
|
215 |
+
// from the start to the end of the buffer
|
216 |
+
// note: it copies byte by byte, so it is not equivalent to, for example, rep movsd
|
217 |
+
inline void *qmemcpy(void *dst, const void *src, size_t cnt)
|
218 |
+
{
|
219 |
+
char *out = (char *)dst;
|
220 |
+
const char *in = (const char *)src;
|
221 |
+
while ( cnt > 0 )
|
222 |
+
{
|
223 |
+
*out++ = *in++;
|
224 |
+
--cnt;
|
225 |
+
}
|
226 |
+
return dst;
|
227 |
+
}
|
228 |
+
|
229 |
+
// rotate left
|
230 |
+
template<class T> T __ROL__(T value, int count)
|
231 |
+
{
|
232 |
+
const uint nbits = sizeof(T) * 8;
|
233 |
+
|
234 |
+
if ( count > 0 )
|
235 |
+
{
|
236 |
+
count %= nbits;
|
237 |
+
T high = value >> (nbits - count);
|
238 |
+
if ( T(-1) < 0 ) // signed value
|
239 |
+
high &= ~((T(-1) << count));
|
240 |
+
value <<= count;
|
241 |
+
value |= high;
|
242 |
+
}
|
243 |
+
else
|
244 |
+
{
|
245 |
+
count = -count % nbits;
|
246 |
+
T low = value << (nbits - count);
|
247 |
+
value >>= count;
|
248 |
+
value |= low;
|
249 |
+
}
|
250 |
+
return value;
|
251 |
+
}
|
252 |
+
|
253 |
+
inline uint8 __ROL1__(uint8 value, int count) { return __ROL__((uint8)value, count); }
|
254 |
+
inline uint16 __ROL2__(uint16 value, int count) { return __ROL__((uint16)value, count); }
|
255 |
+
inline uint32 __ROL4__(uint32 value, int count) { return __ROL__((uint32)value, count); }
|
256 |
+
inline uint64 __ROL8__(uint64 value, int count) { return __ROL__((uint64)value, count); }
|
257 |
+
inline uint8 __ROR1__(uint8 value, int count) { return __ROL__((uint8)value, -count); }
|
258 |
+
inline uint16 __ROR2__(uint16 value, int count) { return __ROL__((uint16)value, -count); }
|
259 |
+
inline uint32 __ROR4__(uint32 value, int count) { return __ROL__((uint32)value, -count); }
|
260 |
+
inline uint64 __ROR8__(uint64 value, int count) { return __ROL__((uint64)value, -count); }
|
261 |
+
|
262 |
+
// sign flag
|
263 |
+
template<class T> int8 __SETS__(T x)
|
264 |
+
{
|
265 |
+
if ( sizeof(T) == 1 )
|
266 |
+
return int8(x) < 0;
|
267 |
+
if ( sizeof(T) == 2 )
|
268 |
+
return int16(x) < 0;
|
269 |
+
if ( sizeof(T) == 4 )
|
270 |
+
return int32(x) < 0;
|
271 |
+
return int64(x) < 0;
|
272 |
+
}
|
273 |
+
|
274 |
+
// overflow flag of subtraction (x-y)
|
275 |
+
template<class T, class U> int8 __OFSUB__(T x, U y)
|
276 |
+
{
|
277 |
+
if ( sizeof(T) < sizeof(U) )
|
278 |
+
{
|
279 |
+
U x2 = x;
|
280 |
+
int8 sx = __SETS__(x2);
|
281 |
+
return (sx ^ __SETS__(y)) & (sx ^ __SETS__(U(x2-y)));
|
282 |
+
}
|
283 |
+
else
|
284 |
+
{
|
285 |
+
T y2 = y;
|
286 |
+
int8 sx = __SETS__(x);
|
287 |
+
return (sx ^ __SETS__(y2)) & (sx ^ __SETS__(T(x-y2)));
|
288 |
+
}
|
289 |
+
}
|
290 |
+
|
291 |
+
// overflow flag of addition (x+y)
|
292 |
+
template<class T, class U> int8 __OFADD__(T x, U y)
|
293 |
+
{
|
294 |
+
if ( sizeof(T) < sizeof(U) )
|
295 |
+
{
|
296 |
+
U x2 = x;
|
297 |
+
int8 sx = __SETS__(x2);
|
298 |
+
return ((1 ^ sx) ^ __SETS__(y)) & (sx ^ __SETS__(U(x2+y)));
|
299 |
+
}
|
300 |
+
else
|
301 |
+
{
|
302 |
+
T y2 = y;
|
303 |
+
int8 sx = __SETS__(x);
|
304 |
+
return ((1 ^ sx) ^ __SETS__(y2)) & (sx ^ __SETS__(T(x+y2)));
|
305 |
+
}
|
306 |
+
}
|
307 |
+
|
308 |
+
// https://en.wikipedia.org/wiki/Carry_flag#Carry_flag_vs._borrow_flag
|
309 |
+
#if defined(__ARM__) || defined(__PPC__)
|
310 |
+
#define SUB_WITH_CARRY 1
|
311 |
+
#else
|
312 |
+
#define SUB_WITH_CARRY 0
|
313 |
+
#endif
|
314 |
+
|
315 |
+
// carry flag of subtraction (x-y)
|
316 |
+
template<class T, class U> int8 __CFSUB__(T x, U y)
|
317 |
+
{
|
318 |
+
int size = sizeof(T) > sizeof(U) ? sizeof(T) : sizeof(U);
|
319 |
+
bool res;
|
320 |
+
if ( size == 1 )
|
321 |
+
res = uint8(x) < uint8(y);
|
322 |
+
else if ( size == 2 )
|
323 |
+
res = uint16(x) < uint16(y);
|
324 |
+
else if ( size == 4 )
|
325 |
+
res = uint32(x) < uint32(y);
|
326 |
+
else
|
327 |
+
res = uint64(x) < uint64(y);
|
328 |
+
#if SUB_WITH_CARRY
|
329 |
+
res = !res;
|
330 |
+
#endif
|
331 |
+
return res;
|
332 |
+
}
|
333 |
+
|
334 |
+
// carry flag of addition (x+y)
|
335 |
+
template<class T, class U> int8 __CFADD__(T x, U y)
|
336 |
+
{
|
337 |
+
int size = sizeof(T) > sizeof(U) ? sizeof(T) : sizeof(U);
|
338 |
+
if ( size == 1 )
|
339 |
+
return uint8(x) > uint8(x+y);
|
340 |
+
if ( size == 2 )
|
341 |
+
return uint16(x) > uint16(x+y);
|
342 |
+
if ( size == 4 )
|
343 |
+
return uint32(x) > uint32(x+y);
|
344 |
+
return uint64(x) > uint64(x+y);
|
345 |
+
}
|
346 |
+
|
347 |
+
// carry flag of subtraction with carry
|
348 |
+
template<class T, class U> int8 __CFSUB__(T x, U y, int8 cf)
|
349 |
+
{
|
350 |
+
#if SUB_WITH_CARRY
|
351 |
+
cf = !cf;
|
352 |
+
#endif
|
353 |
+
return __CFADD__(y, cf) ^ __CFSUB(x, y + cf);
|
354 |
+
}
|
355 |
+
|
356 |
+
// overflow flag of subtraction with carry
|
357 |
+
template<class T, class U> int8 __OFSUB__(T x, U y, int8 cf)
|
358 |
+
{
|
359 |
+
#if SUB_WITH_CARRY
|
360 |
+
cf = !cf;
|
361 |
+
#endif
|
362 |
+
return __OFADD__(y, cf) ^ __OFSUB(x, y + cf);
|
363 |
+
}
|
364 |
+
|
365 |
+
inline uint8 abs8(int8 x) { return x >= 0 ? x : -x; }
|
366 |
+
inline uint16 abs16(int16 x) { return x >= 0 ? x : -x; }
|
367 |
+
inline uint32 abs32(int32 x) { return x >= 0 ? x : -x; }
|
368 |
+
inline uint64 abs64(int64 x) { return x >= 0 ? x : -x; }
|
369 |
+
//inline uint128 abs128(int128 x) { return x >= 0 ? x : -x; }
|
370 |
+
|
371 |
+
#include <string.h> // for memcpy
|
372 |
+
#include <type_traits> // for enable_if
|
373 |
+
|
374 |
+
template <typename T, typename F>
|
375 |
+
inline typename std::enable_if<sizeof(T) <= sizeof(F), T>::type __coerce(F f)
|
376 |
+
{
|
377 |
+
T t;
|
378 |
+
memcpy(&t, &f, sizeof(T));
|
379 |
+
return t;
|
380 |
+
}
|
381 |
+
#define COERCE_FLOAT(v) __coerce<float>(v)
|
382 |
+
#define COERCE_DOUBLE(v) __coerce<double>(v)
|
383 |
+
#define COERCE_LONG_DOUBLE(v) __coerce<long double>(v)
|
384 |
+
#define COERCE_UNSIGNED_INT(v) __coerce<unsigned int>(v)
|
385 |
+
#define COERCE_UNSIGNED_INT64(v) __coerce<uint64>(v)
|
386 |
+
|
387 |
+
#else // C++
|
388 |
+
// For C, we just provide macros, they are not quite correct.
|
389 |
+
#define __ROL__(x, y) __rotl__(x, y) // Rotate left
|
390 |
+
#define __ROR__(x, y) __rotr__(x, y) // Rotate right
|
391 |
+
#define __CFSHL__(x, y) invalid_operation // Generate carry flag for (x<<y)
|
392 |
+
#define __CFSHR__(x, y) invalid_operation // Generate carry flag for (x>>y)
|
393 |
+
#define __CFADD__(x, y) invalid_operation // Generate carry flag for (x+y)
|
394 |
+
#define __CFSUB__(x, y) invalid_operation // Generate carry flag for (x-y)
|
395 |
+
#define __OFADD__(x, y) invalid_operation // Generate overflow flag for (x+y)
|
396 |
+
#define __OFSUB__(x, y) invalid_operation // Generate overflow flag for (x-y)
|
397 |
+
|
398 |
+
#define abs8(x) (int8) ((int8) (x) >= 0 ? (x) : -(x))
|
399 |
+
#define abs16(x) (int16) ((int16) (x) >= 0 ? (x) : -(x))
|
400 |
+
#define abs32(x) (int32) ((int32) (x) >= 0 ? (x) : -(x))
|
401 |
+
#define abs64(x) (int64) ((int64) (x) >= 0 ? (x) : -(x))
|
402 |
+
#define abs128(x) (int128)((int128)(x) >= 0 ? (x) : -(x))
|
403 |
+
|
404 |
+
#endif // C++
|
405 |
+
|
406 |
+
#if defined(__MIPS__)
|
407 |
+
// traps for MIPS arithmetic operation
|
408 |
+
void __noreturn __integer_oveflow(void); // SIGFPE/FPE_INTOVF
|
409 |
+
void __noreturn __divide_by_zero(void); // SIGFPE/FPE_INTDIV
|
410 |
+
void __noreturn __trap(uint16 trapcode); // SIGTRAP
|
411 |
+
void __noreturn __break(uint16 code, uint16 subcode);
|
412 |
+
#endif
|
413 |
+
|
414 |
+
#define __SETP__(x, y) invalid_operation // Generate parity flag for (x-y)
|
415 |
+
|
416 |
+
// In the decompilation listing there are some objects declared as _UNKNOWN
|
417 |
+
// because we could not determine their types. Since the C compiler does not
|
418 |
+
// accept void item declarations, we replace them by anything of our choice,
|
419 |
+
// for example a char:
|
420 |
+
|
421 |
+
#define _UNKNOWN char
|
422 |
+
|
423 |
+
#ifdef _MSC_VER
|
424 |
+
#define snprintf _snprintf
|
425 |
+
#define vsnprintf _vsnprintf
|
426 |
+
#endif
|
427 |
+
|
428 |
+
// The ADJ() macro is used for shifted pointers.
|
429 |
+
// While compilers do not understand it, it makes the code more readable.
|
430 |
+
// A shifted pointer is declared like this, for example:
|
431 |
+
// char *__shifted(mystruct,8) p;
|
432 |
+
// It means: while 'p' points to 'char', it also points to the middle of 'mystruct'.
|
433 |
+
// More precisely, it is at the offset of 8 bytes from the beginning of 'mystruct'.
|
434 |
+
//
|
435 |
+
// The ADJ() macro performs the necessary adjustment.
|
436 |
+
// The __parentof() and __deltaof() functions are made up, they do not exist.
|
437 |
+
// __parentof() returns the parent structure type.
|
438 |
+
// __deltaof() returns the shift amount.
|
439 |
+
|
440 |
+
#define ADJ(p) (__parentof(p) *)(p-__deltaof(p))
|
441 |
+
|
442 |
+
#endif // HEXRAYS_DEFS_H
|