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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443
|
#ifndef HEXRAYS_DEFS_H #define HEXRAYS_DEFS_H
#if defined(__GNUC__) typedef long long ll; typedef unsigned long long ull; #define __int64 long long #define __int32 int #define __int16 short #define __int8 char #define MAKELL(num) num ## LL #define FMT_64 "ll" #elif defined(_MSC_VER) typedef __int64 ll; typedef unsigned __int64 ull; #define MAKELL(num) num ## i64 #define FMT_64 "I64" #elif defined (__BORLANDC__) typedef __int64 ll; typedef unsigned __int64 ull; #define MAKELL(num) num ## i64 #define FMT_64 "L" #else #error "unknown compiler" #endif typedef unsigned int uint; typedef unsigned char uchar; typedef unsigned short ushort; typedef unsigned long ulong;
typedef char int8; typedef signed char sint8; typedef unsigned char uint8; typedef short int16; typedef signed short sint16; typedef unsigned short uint16; typedef int int32; typedef signed int sint32; typedef unsigned int uint32; typedef ll int64; typedef ll sint64; typedef ull uint64;
#define _BYTE uint8 #define _WORD uint16 #define _DWORD uint32 #define _QWORD uint64 #if !defined(_MSC_VER) #define _LONGLONG __int128 #endif
typedef int8 _BOOL1; typedef int16 _BOOL2; typedef int32 _BOOL4; typedef int64 _BOOL8;
#ifndef _WINDOWS_ typedef int8 BYTE; typedef int16 WORD; typedef int32 DWORD; typedef int32 LONG; typedef int BOOL; #endif typedef int64 QWORD; #ifndef __cplusplus typedef int bool; #endif
#define __pure
#if defined(__GNUC__) #define __noreturn __attribute__((noreturn)) #else #define __noreturn __declspec(noreturn) #endif
#ifndef NULL #define NULL 0 #endif
#define LAST_IND(x,part_type) (sizeof(x)/sizeof(part_type) - 1) #if defined(__BYTE_ORDER) && __BYTE_ORDER == __BIG_ENDIAN # define LOW_IND(x,part_type) LAST_IND(x,part_type) # define HIGH_IND(x,part_type) 0 #else # define HIGH_IND(x,part_type) LAST_IND(x,part_type) # define LOW_IND(x,part_type) 0 #endif
#define BYTEn(x, n) (*((_BYTE*)&(x)+n)) #define WORDn(x, n) (*((_WORD*)&(x)+n)) #define DWORDn(x, n) (*((_DWORD*)&(x)+n))
#define LOBYTE(x) BYTEn(x,LOW_IND(x,_BYTE)) #define LOWORD(x) WORDn(x,LOW_IND(x,_WORD)) #define LODWORD(x) DWORDn(x,LOW_IND(x,_DWORD)) #define HIBYTE(x) BYTEn(x,HIGH_IND(x,_BYTE)) #define HIWORD(x) WORDn(x,HIGH_IND(x,_WORD)) #define HIDWORD(x) DWORDn(x,HIGH_IND(x,_DWORD)) #define BYTE1(x) BYTEn(x, 1) #define BYTE2(x) BYTEn(x, 2) #define BYTE3(x) BYTEn(x, 3) #define BYTE4(x) BYTEn(x, 4) #define BYTE5(x) BYTEn(x, 5) #define BYTE6(x) BYTEn(x, 6) #define BYTE7(x) BYTEn(x, 7) #define BYTE8(x) BYTEn(x, 8) #define BYTE9(x) BYTEn(x, 9) #define BYTE10(x) BYTEn(x, 10) #define BYTE11(x) BYTEn(x, 11) #define BYTE12(x) BYTEn(x, 12) #define BYTE13(x) BYTEn(x, 13) #define BYTE14(x) BYTEn(x, 14) #define BYTE15(x) BYTEn(x, 15) #define WORD1(x) WORDn(x, 1) #define WORD2(x) WORDn(x, 2) #define WORD3(x) WORDn(x, 3) #define WORD4(x) WORDn(x, 4) #define WORD5(x) WORDn(x, 5) #define WORD6(x) WORDn(x, 6) #define WORD7(x) WORDn(x, 7)
#define SBYTEn(x, n) (*((int8*)&(x)+n)) #define SWORDn(x, n) (*((int16*)&(x)+n)) #define SDWORDn(x, n) (*((int32*)&(x)+n))
#define SLOBYTE(x) SBYTEn(x,LOW_IND(x,int8)) #define SLOWORD(x) SWORDn(x,LOW_IND(x,int16)) #define SLODWORD(x) SDWORDn(x,LOW_IND(x,int32)) #define SHIBYTE(x) SBYTEn(x,HIGH_IND(x,int8)) #define SHIWORD(x) SWORDn(x,HIGH_IND(x,int16)) #define SHIDWORD(x) SDWORDn(x,HIGH_IND(x,int32)) #define SBYTE1(x) SBYTEn(x, 1) #define SBYTE2(x) SBYTEn(x, 2) #define SBYTE3(x) SBYTEn(x, 3) #define SBYTE4(x) SBYTEn(x, 4) #define SBYTE5(x) SBYTEn(x, 5) #define SBYTE6(x) SBYTEn(x, 6) #define SBYTE7(x) SBYTEn(x, 7) #define SBYTE8(x) SBYTEn(x, 8) #define SBYTE9(x) SBYTEn(x, 9) #define SBYTE10(x) SBYTEn(x, 10) #define SBYTE11(x) SBYTEn(x, 11) #define SBYTE12(x) SBYTEn(x, 12) #define SBYTE13(x) SBYTEn(x, 13) #define SBYTE14(x) SBYTEn(x, 14) #define SBYTE15(x) SBYTEn(x, 15) #define SWORD1(x) SWORDn(x, 1) #define SWORD2(x) SWORDn(x, 2) #define SWORD3(x) SWORDn(x, 3) #define SWORD4(x) SWORDn(x, 4) #define SWORD5(x) SWORDn(x, 5) #define SWORD6(x) SWORDn(x, 6) #define SWORD7(x) SWORDn(x, 7)
#define __SPAIR16__(high, low) (((int16) (high) << 8) | (uint8) (low)) #define __SPAIR32__(high, low) (((int32) (high) << 16) | (uint16)(low)) #define __SPAIR64__(high, low) (((int64) (high) << 32) | (uint32)(low)) #define __SPAIR128__(high, low) (((int128) (high) << 64) | (uint64)(low)) #define __PAIR16__(high, low) (((uint16) (high) << 8) | (uint8) (low)) #define __PAIR32__(high, low) (((uint32) (high) << 16) | (uint16)(low)) #define __PAIR64__(high, low) (((uint64) (high) << 32) | (uint32)(low)) #define __PAIR128__(high, low) (((uint128)(high) << 64) | (uint64)(low))
#ifdef __cplusplus
#define __CASSERT_N0__(l) COMPILE_TIME_ASSERT_ ## l #define __CASSERT_N1__(l) __CASSERT_N0__(l) #define CASSERT(cnd) typedef char __CASSERT_N1__(__LINE__) [(cnd) ? 1 : -1]
template<class T> bool is_mul_ok(T count, T elsize) { CASSERT(T(-1) > 0); if ( elsize == 0 || count == 0 ) return true; return count <= T(-1) / elsize; }
template<class T> bool saturated_mul(T count, T elsize) { return is_mul_ok(count, elsize) ? count * elsize : T(-1); }
#include <stddef.h>
inline void *qmemcpy(void *dst, const void *src, size_t cnt) { char *out = (char *)dst; const char *in = (const char *)src; while ( cnt > 0 ) { *out++ = *in++; --cnt; } return dst; }
template<class T> T __ROL__(T value, int count) { const uint nbits = sizeof(T) * 8;
if ( count > 0 ) { count %= nbits; T high = value >> (nbits - count); if ( T(-1) < 0 ) high &= ~((T(-1) << count)); value <<= count; value |= high; } else { count = -count % nbits; T low = value << (nbits - count); value >>= count; value |= low; } return value; }
inline uint8 __ROL1__(uint8 value, int count) { return __ROL__((uint8)value, count); } inline uint16 __ROL2__(uint16 value, int count) { return __ROL__((uint16)value, count); } inline uint32 __ROL4__(uint32 value, int count) { return __ROL__((uint32)value, count); } inline uint64 __ROL8__(uint64 value, int count) { return __ROL__((uint64)value, count); } inline uint8 __ROR1__(uint8 value, int count) { return __ROL__((uint8)value, -count); } inline uint16 __ROR2__(uint16 value, int count) { return __ROL__((uint16)value, -count); } inline uint32 __ROR4__(uint32 value, int count) { return __ROL__((uint32)value, -count); } inline uint64 __ROR8__(uint64 value, int count) { return __ROL__((uint64)value, -count); }
template<class T> int8 __SETS__(T x) { if ( sizeof(T) == 1 ) return int8(x) < 0; if ( sizeof(T) == 2 ) return int16(x) < 0; if ( sizeof(T) == 4 ) return int32(x) < 0; return int64(x) < 0; }
template<class T, class U> int8 __OFSUB__(T x, U y) { if ( sizeof(T) < sizeof(U) ) { U x2 = x; int8 sx = __SETS__(x2); return (sx ^ __SETS__(y)) & (sx ^ __SETS__(U(x2-y))); } else { T y2 = y; int8 sx = __SETS__(x); return (sx ^ __SETS__(y2)) & (sx ^ __SETS__(T(x-y2))); } }
template<class T, class U> int8 __OFADD__(T x, U y) { if ( sizeof(T) < sizeof(U) ) { U x2 = x; int8 sx = __SETS__(x2); return ((1 ^ sx) ^ __SETS__(y)) & (sx ^ __SETS__(U(x2+y))); } else { T y2 = y; int8 sx = __SETS__(x); return ((1 ^ sx) ^ __SETS__(y2)) & (sx ^ __SETS__(T(x+y2))); } }
#if defined(__ARM__) || defined(__PPC__) #define SUB_WITH_CARRY 1 #else #define SUB_WITH_CARRY 0 #endif
template<class T, class U> int8 __CFSUB__(T x, U y) { int size = sizeof(T) > sizeof(U) ? sizeof(T) : sizeof(U); bool res; if ( size == 1 ) res = uint8(x) < uint8(y); else if ( size == 2 ) res = uint16(x) < uint16(y); else if ( size == 4 ) res = uint32(x) < uint32(y); else res = uint64(x) < uint64(y); #if SUB_WITH_CARRY res = !res; #endif return res; }
template<class T, class U> int8 __CFADD__(T x, U y) { int size = sizeof(T) > sizeof(U) ? sizeof(T) : sizeof(U); if ( size == 1 ) return uint8(x) > uint8(x+y); if ( size == 2 ) return uint16(x) > uint16(x+y); if ( size == 4 ) return uint32(x) > uint32(x+y); return uint64(x) > uint64(x+y); }
template<class T, class U> int8 __CFSUB__(T x, U y, int8 cf) { #if SUB_WITH_CARRY cf = !cf; #endif return __CFADD__(y, cf) ^ __CFSUB(x, y + cf); }
template<class T, class U> int8 __OFSUB__(T x, U y, int8 cf) { #if SUB_WITH_CARRY cf = !cf; #endif return __OFADD__(y, cf) ^ __OFSUB(x, y + cf); }
inline uint8 abs8(int8 x) { return x >= 0 ? x : -x; } inline uint16 abs16(int16 x) { return x >= 0 ? x : -x; } inline uint32 abs32(int32 x) { return x >= 0 ? x : -x; } inline uint64 abs64(int64 x) { return x >= 0 ? x : -x; }
#include <string.h> #include <type_traits>
template <typename T, typename F> inline typename std::enable_if<sizeof(T) <= sizeof(F), T>::type __coerce(F f) { T t; memcpy(&t, &f, sizeof(T)); return t; } #define COERCE_FLOAT(v) __coerce<float>(v) #define COERCE_DOUBLE(v) __coerce<double>(v) #define COERCE_LONG_DOUBLE(v) __coerce<long double>(v) #define COERCE_UNSIGNED_INT(v) __coerce<unsigned int>(v) #define COERCE_UNSIGNED_INT64(v) __coerce<uint64>(v)
#else
#define __ROL__(x, y) __rotl__(x, y) #define __ROR__(x, y) __rotr__(x, y) #define __CFSHL__(x, y) invalid_operation #define __CFSHR__(x, y) invalid_operation #define __CFADD__(x, y) invalid_operation #define __CFSUB__(x, y) invalid_operation #define __OFADD__(x, y) invalid_operation #define __OFSUB__(x, y) invalid_operation
#define abs8(x) (int8) ((int8) (x) >= 0 ? (x) : -(x)) #define abs16(x) (int16) ((int16) (x) >= 0 ? (x) : -(x)) #define abs32(x) (int32) ((int32) (x) >= 0 ? (x) : -(x)) #define abs64(x) (int64) ((int64) (x) >= 0 ? (x) : -(x)) #define abs128(x) (int128)((int128)(x) >= 0 ? (x) : -(x))
#endif
#if defined(__MIPS__)
void __noreturn __integer_oveflow(void); void __noreturn __divide_by_zero(void); void __noreturn __trap(uint16 trapcode); void __noreturn __break(uint16 code, uint16 subcode); #endif
#define __SETP__(x, y) invalid_operation
#define _UNKNOWN char
#ifdef _MSC_VER #define snprintf _snprintf #define vsnprintf _vsnprintf #endif
#define ADJ(p) (__parentof(p) *)(p-__deltaof(p))
#endif
|