/*
This file contains definitions used by the Hex-Rays decompiler output.
It has type definitions and convenience macros to make the
output more readable.
Copyright (c) 2007-2017 Hex-Rays
*/#ifndefHEXRAYS_DEFS_H#defineHEXRAYS_DEFS_H#ifdefined(__GNUC__)typedeflonglong ll;typedefunsignedlonglong ull;#define__int64longlong#define__int32int#define__int16short#define__int8char#defineMAKELL(num) num ##LL#defineFMT_64"ll"#elifdefined(_MSC_VER)typedef __int64 ll;typedefunsigned __int64 ull;#defineMAKELL(num) num ##i64#defineFMT_64"I64"#elifdefined(__BORLANDC__)typedef __int64 ll;typedefunsigned __int64 ull;#defineMAKELL(num) num ##i64#defineFMT_64"L"#else#error"unknown compiler"#endiftypedefunsignedint uint;typedefunsignedchar uchar;typedefunsignedshort ushort;typedefunsignedlong ulong;typedefchar int8;typedefsignedchar sint8;typedefunsignedchar uint8;typedefshort int16;typedefsignedshort sint16;typedefunsignedshort uint16;typedefint int32;typedefsignedint sint32;typedefunsignedint uint32;typedef ll int64;typedef ll sint64;typedef ull uint64;// Partially defined types. They are used when the decompiler does not know// anything about the type except its size.#define_BYTEuint8#define_WORDuint16#define_DWORDuint32#define_QWORDuint64#if!defined(_MSC_VER)#define_LONGLONG__int128#endif// Non-standard boolean types. They are used when the decompiler can not use// the standard "bool" type because of the size mistmatch but the possible// values are only 0 and 1. See also 'BOOL' type below.typedef int8 _BOOL1;typedef int16 _BOOL2;typedef int32 _BOOL4;#ifndef_WINDOWS_typedef int8 BYTE;typedef int16 WORD;typedef int32 DWORD;typedef int32 LONG;typedefint BOOL;// uppercase BOOL is usually 4 bytes#endiftypedef int64 QWORD;#ifndef__cplusplustypedefintbool;// we want to use bool in our C programs#endif#define__pure// pure function: always returns the same value, has no// side effects// Non-returning function#ifdefined(__GNUC__)#define__noreturn__attribute__((noreturn))#else#define__noreturn__declspec(noreturn)#endif#ifndefNULL#defineNULL0#endif// Some convenience macros to make partial accesses nicer#defineLAST_IND(x,part_type)(sizeof(x)/sizeof(part_type)-1)#ifdefined(__BYTE_ORDER)&& __BYTE_ORDER == __BIG_ENDIAN#defineLOW_IND(x,part_type)LAST_IND(x,part_type)#defineHIGH_IND(x,part_type)0#else#defineHIGH_IND(x,part_type)LAST_IND(x,part_type)#defineLOW_IND(x,part_type)0#endif// first unsigned macros:#defineBYTEn(x, n)(*((_BYTE*)&(x)+n))#defineWORDn(x, n)(*((_WORD*)&(x)+n))#defineDWORDn(x, n)(*((_DWORD*)&(x)+n))#defineLOBYTE(x)BYTEn(x,LOW_IND(x,_BYTE))#defineLOWORD(x)WORDn(x,LOW_IND(x,_WORD))#defineLODWORD(x)DWORDn(x,LOW_IND(x,_DWORD))#defineHIBYTE(x)BYTEn(x,HIGH_IND(x,_BYTE))#defineHIWORD(x)WORDn(x,HIGH_IND(x,_WORD))#defineHIDWORD(x)DWORDn(x,HIGH_IND(x,_DWORD))#defineBYTE1(x)BYTEn(x,1)// byte 1 (counting from 0)#defineBYTE2(x)BYTEn(x,2)#defineBYTE3(x)BYTEn(x,3)#defineBYTE4(x)BYTEn(x,4)#defineBYTE5(x)BYTEn(x,5)#defineBYTE6(x)BYTEn(x,6)#defineBYTE7(x)BYTEn(x,7)#defineBYTE8(x)BYTEn(x,8)#defineBYTE9(x)BYTEn(x,9)#defineBYTE10(x)BYTEn(x,10)#defineBYTE11(x)BYTEn(x,11)#defineBYTE12(x)BYTEn(x,12)#defineBYTE13(x)BYTEn(x,13)#defineBYTE14(x)BYTEn(x,14)#defineBYTE15(x)BYTEn(x,15)#defineWORD1(x)WORDn(x,1)#defineWORD2(x)WORDn(x,2)// third word of the object, unsigned#defineWORD3(x)WORDn(x,3)#defineWORD4(x)WORDn(x,4)#defineWORD5(x)WORDn(x,5)#defineWORD6(x)WORDn(x,6)#defineWORD7(x)WORDn(x,7)// now signed macros (the same but with sign extension)#defineSBYTEn(x, n)(*((int8*)&(x)+n))#defineSWORDn(x, n)(*((int16*)&(x)+n))#defineSDWORDn(x, n)(*((int32*)&(x)+n))#defineSLOBYTE(x)SBYTEn(x,LOW_IND(x,int8))#defineSLOWORD(x)SWORDn(x,LOW_IND(x,int16))#defineSLODWORD(x)SDWORDn(x,LOW_IND(x,int32))#defineSHIBYTE(x)SBYTEn(x,HIGH_IND(x,int8))#defineSHIWORD(x)SWORDn(x,HIGH_IND(x,int16))#defineSHIDWORD(x)SDWORDn(x,HIGH_IND(x,int32))#defineSBYTE1(x)SBYTEn(x,1)#defineSBYTE2(x)SBYTEn(x,2)#defineSBYTE3(x)SBYTEn(x,3)#defineSBYTE4(x)SBYTEn(x,4)#defineSBYTE5(x)SBYTEn(x,5)#defineSBYTE6(x)SBYTEn(x,6)#defineSBYTE7(x)SBYTEn(x,7)#defineSBYTE8(x)SBYTEn(x,8)#defineSBYTE9(x)SBYTEn(x,9)#defineSBYTE10(x)SBYTEn(x,10)#defineSBYTE11(x)SBYTEn(x,11)#defineSBYTE12(x)SBYTEn(x,12)#defineSBYTE13(x)SBYTEn(x,13)#defineSBYTE14(x)SBYTEn(x,14)#defineSBYTE15(x)SBYTEn(x,15)#defineSWORD1(x)SWORDn(x,1)#defineSWORD2(x)SWORDn(x,2)#defineSWORD3(x)SWORDn(x,3)#defineSWORD4(x)SWORDn(x,4)#defineSWORD5(x)SWORDn(x,5)#defineSWORD6(x)SWORDn(x,6)#defineSWORD7(x)SWORDn(x,7)// Helper functions to represent some assembly instructions.#ifdef__cplusplus// compile time assertion#define__CASSERT_N0__(l) COMPILE_TIME_ASSERT_ ##l#define__CASSERT_N1__(l)__CASSERT_N0__(l)#defineCASSERT(cnd)typedefchar__CASSERT_N1__(__LINE__)[(cnd)?1:-1]// check that unsigned multiplication does not overflowtemplate<classT>boolis_mul_ok(T count, T elsize){CASSERT((T)(-1)>0);// make sure T is unsignedif( elsize ==0|| count ==0)returntrue;return count <=((T)(-1))/ elsize;}// multiplication that saturates (yields the biggest value) instead of overflowing// such a construct is useful in "operator new[]"template<classT>boolsaturated_mul(T count, T elsize){returnis_mul_ok(count, elsize)? count * elsize :T(-1);}#include<stddef.h>// for size_t// memcpy() with determined behavoir: it always copies// from the start to the end of the buffer// note: it copies byte by byte, so it is not equivalent to, for example, rep movsdinlinevoid*qmemcpy(void*dst,constvoid*src, size_t cnt){char*out =(char*)dst;constchar*in =(constchar*)src;while( cnt >0){*out++=*in++;--cnt;}return dst;}// Generate a reference to pair of operandstemplate<classT> int16 __PAIR__( int8 high, T low){return((( int16)high)<<sizeof(high)*8)|uint8(low);}template<classT> int32 __PAIR__( int16 high, T low){return((( int32)high)<<sizeof(high)*8)|uint16(low);}template<classT> int64 __PAIR__( int32 high, T low){return((( int64)high)<<sizeof(high)*8)|uint32(low);}template<classT> uint16 __PAIR__(uint8 high, T low){return(((uint16)high)<<sizeof(high)*8)|uint8(low);}template<classT> uint32 __PAIR__(uint16 high, T low){return(((uint32)high)<<sizeof(high)*8)|uint16(low);}template<classT> uint64 __PAIR__(uint32 high, T low){return(((uint64)high)<<sizeof(high)*8)|uint32(low);}// rotate lefttemplate<classT> 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)// signed value
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);}// carry flag of left shifttemplate<classT> int8 __MKCSHL__(T value, uint count){const uint nbits =sizeof(T)*8;
count %= nbits;return(value >>(nbits-count))&1;}// carry flag of right shifttemplate<classT> int8 __MKCSHR__(T value, uint count){return(value >>(count-1))&1;}// sign flagtemplate<classT> int8 __SETS__(T x){if(sizeof(T)==1)returnint8(x)<0;if(sizeof(T)==2)returnint16(x)<0;if(sizeof(T)==4)returnint32(x)<0;returnint64(x)<0;}// overflow flag of subtraction (x-y)template<classT,classU> int8 __OFSUB__(T x, U y){if(sizeof(T)<sizeof(U)){
U x2 = x;
int8 sx =__SETS__(x2);return(sx ^__SETS__(y))&(sx ^__SETS__(x2-y));}else{
T y2 = y;
int8 sx =__SETS__(x);return(sx ^__SETS__(y2))&(sx ^__SETS__(x-y2));}}// overflow flag of addition (x+y)template<classT,classU> 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__(x2+y));}else{
T y2 = y;
int8 sx =__SETS__(x);return((1^ sx)^__SETS__(y2))&(sx ^__SETS__(x+y2));}}// carry flag of subtraction (x-y)template<classT,classU> int8 __CFSUB__(T x, U y){int size =sizeof(T)>sizeof(U)?sizeof(T):sizeof(U);if( size ==1)returnuint8(x)<uint8(y);if( size ==2)returnuint16(x)<uint16(y);if( size ==4)returnuint32(x)<uint32(y);returnuint64(x)<uint64(y);}// carry flag of addition (x+y)template<classT,classU> int8 __CFADD__(T x, U y){int size =sizeof(T)>sizeof(U)?sizeof(T):sizeof(U);if( size ==1)returnuint8(x)>uint8(x+y);if( size ==2)returnuint16(x)>uint16(x+y);if( size ==4)returnuint32(x)>uint32(x+y);returnuint64(x)>uint64(x+y);}#else// The following definition is not quite correct because it always returns// uint64. The above C++ functions are good, though.#define__PAIR__(high, low)(((uint64)(high)<<sizeof(high)*8)| low)// For C, we just provide macros, they are not quite correct.#define__ROL__(x, y)__rotl__(x, y)// Rotate left#define__ROR__(x, y)__rotr__(x, y)// Rotate right#define__CFSHL__(x, y) invalid_operation // Generate carry flag for (x<<y)#define__CFSHR__(x, y) invalid_operation // Generate carry flag for (x>>y)#define__CFADD__(x, y) invalid_operation // Generate carry flag for (x+y)#define__CFSUB__(x, y) invalid_operation // Generate carry flag for (x-y)#define__OFADD__(x, y) invalid_operation // Generate overflow flag for (x+y)#define__OFSUB__(x, y) invalid_operation // Generate overflow flag for (x-y)#endif// No definition for rcl/rcr because the carry flag is unknown#define__RCL__(x, y) invalid_operation // Rotate left thru carry#define__RCR__(x, y) invalid_operation // Rotate right thru carry#define__MKCRCL__(x, y) invalid_operation // Generate carry flag for a RCL#define__MKCRCR__(x, y) invalid_operation // Generate carry flag for a RCR#define__SETP__(x, y) invalid_operation // Generate parity flag for (x-y)// In the decompilation listing there are some objects declarared as _UNKNOWN// because we could not determine their types. Since the C compiler does not// accept void item declarations, we replace them by anything of our choice,// for example a char:#define_UNKNOWNchar#ifdef_MSC_VER#definesnprintf_snprintf#definevsnprintf_vsnprintf#endif#endif// HEXRAYS_DEFS_H