google-site-verification: googlebaca44933768a824.html compile time things - Old Royal Hack Forum

Announcement

Collapse
No announcement yet.

compile time things

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    compile time things

    Code:
    #ifndef __COMPILE_TIME_RNG__
    #define __COMPILE_TIME_RNG__
    
    //////////////////////////////////////////////////////////////////////////
    //
    //
    //
    //  https://www.gamedeception.net/threads/19561-C%28-%29-compile-time-string-encryption-library-no-custom-build-step-needed
    //
    //
    //  http://stackoverflow.com/questions/4132558/compile-time-container-of-functors-for-controlling-an-algorithm
    //
    //
    //  http://stackoverflow.com/questions/1032602/template-ing-a-for-loop-in-c
    //
    //
    // error :
    //         too many segments in object file
    //         http://msdn.microsoft.com/en-us/library/ms173499%28VS.80%29.aspx
    //         project option -> c++ -> advanced option (commandline) -> /bigobj
    //
    //
    //////////////////////////////////////////////////////////////////////////
    
    #pragma pack(push,1)
    template <uint64 N, uint64 Seed, uint64 Modulo>
    struct ctn
    {
      scuint64 value_impl = ctn<N - 1,Seed^Modulo,MAXDWORD>::val % MAXLONGLONG;
      scuint64        val = ( ( 1 ^ ( (CNT + 1) + Seed ) ) + value_impl ) % Modulo;
    };
    template <uint64 Seed, uint64 Modulo>
    struct ctn<CNT, Seed, Modulo>
    {
      scuint64 value_impl = ( ( 1 + ( Seed ^ Modulo ) ) );
      scuint64        val = ( ( 1 ^ ( (CNT + 1) * Modulo ) ) + value_impl ) % Modulo;
    };
    #pragma pack(pop)
    
    #endif  __COMPILE_TIME_RNG__
    CNT=__COUNTER__

    Code:
    #ifndef __COMPILE_TIME_STRINGS__
    #define __COMPILE_TIME_STRINGS__
    
    //////////////////////////////////////////////////////////////////////////
    //
    //
    //
    //  https://www.gamedeception.net/threads/19561-C%28-%29-compile-time-string-encryption-library-no-custom-build-step-needed
    //
    //
    //  http://stackoverflow.com/questions/4132558/compile-time-container-of-functors-for-controlling-an-algorithm
    //
    //
    //  http://stackoverflow.com/questions/1032602/template-ing-a-for-loop-in-c
    //
    //
    // error :
    //         too many segments in object file
    //         http://msdn.microsoft.com/en-us/library/ms173499%28VS.80%29.aspx
    //         project option -> c++ -> advanced option (commandline) -> /bigobj
    //
    //
    //////////////////////////////////////////////////////////////////////////
    
    // past here
    //           all needs /Ob2
    
    #pragma pack(push,1)
    
    template < typename  cast >
    static __forceinline cast c_rand( cast _min, cast _max, uint64 key0, uint64 key1, uint64 pos ) {
      return cast( _min + ((((key0-1) ^ (key1+1)) * (++pos ^ (1+_max))) % 0xFFFFFFFFFFFFFFFFULL) % _max );
    }
    
    struct halp
    {
      static __forceinline void _R _conv( uint8 _a, uint16 & _w )
      {
        // ansii to unicode
        uint8 _c [4] = {
          _a  , 0x00,
          0x00, 0x00
        };
        _w = puint16(_c)[0];
      }
      static __forceinline void _R _code( uint8 _o, uint64 i, uint64 _ink, uint64 _inK, uint8& _c )
      {
        // en/decode
        _c = uint8(_o ^ c_rand<uint8>( 1,   8, (9+_ink)^(i+1), (9+_inK)^(i+5), i ) );
        _c = uint8(_c ^ c_rand<uint8>( 1,  16, (8+_ink)^(i+2), (8+_inK)^(i+4), i ) );
        _c = uint8(_c ^ c_rand<uint8>( 1,  32, (7+_ink)^(i+3), (7+_inK)^(i+3), i ) );
        _c = uint8(_c ^ c_rand<uint8>( 1,  64, (6+_ink)^(i+4), (6+_inK)^(i+2), i ) );
        _c = uint8(_c ^ c_rand<uint8>( 1, 128, (5+_ink)^(i+5), (5+_inK)^(i+1), i ) );
      }
    };
    
    //////////////////////////////////////////////////////////////////////////
    // clear to mess and mess to clear
    template< const __int32 i, const __int32 end >
    struct static_loop
    {
      static __forceinline void _R _enc( char o[], uint8 n[], uint64 _ink, uint64 _inK )
      {
        // enc/dec
        halp::_code( o[i], i, _ink, _inK, n[i] );
    
        // next
        static_loop<i + 1,end>::_enc(o,n,_ink,_inK);
      };
    };
    
    template< const __int32 end >
    struct static_loop< end,end >
    {
      static __forceinline void _R _enc( char o[], uint8 n[], uint64 _ink, uint64 _inK )
      {
        // double null term = triple null term k
        n[ end - 1 ] = 0;
        n[ end - 0 ] = 0;
      };
    };
    //////////////////////////////////////////////////////////////////////////
    #pragma pack(pop)
    #ifndef encrypt_line
    # define encrypt_line( os, ns ) class VT0 es_##ns {                        \
      /*   */protected:                                                        \
      /*     */uint8  _c[ ARRAYSIZE( os ) + 1 ];                               \
      /*     */uint8  _a[ ARRAYSIZE( os ) + 1 ];                               \
      /*     */uint16 _w[ ARRAYSIZE( os ) + 1 ];                               \
      /*   */public:                                                           \
      /*     */explicit es_##ns( void ) { static uint8 _h = 0x0;               \
      /*       */if ( _h == 33 )        { return; };   _h = 33;                \
      /*       */scuint64 _sk = _rand(_rand(0x1,0xFF),0xFFFFFFFF00073200ULL);  \
      /*       */scuint64 _tk = _rand(_rand(0x1,0xFF),0x12000000FFFFFFFFULL);  \
      /*       */static_loop<0,sizeof( _c )>::_enc( os, _c, _sk, _tk );        \
      /*       */for ( uint32 i = 0; i < ARRAYSIZE( _c ); i++ ) {              \
      /*           */halp::_code( _c[ i ], i, _sk, _tk, _a[ i ] );             \
      /*           */halp::_conv( _a[ i ], _w[ i ] );                          \
      /*       */};                                                            \
      /*       */_c[ ARRAYSIZE( os ) - 1 ] =  '\0';                            \
      /*       */_a[ ARRAYSIZE( os ) - 1 ] =  '\0';                            \
      /*       */_w[ ARRAYSIZE( os ) - 1 ] = L'\0';                            \
      /*     */};                                                              \
      /*   */public:                                                           \
      /*     */operator   pchar() { return   pchar(_a); };                     \
      /*     */operator  pwchar() { return  pwchar(_w); };                     \
      /*   */public:                                                           \
      /*     */operator  cpchar() { return  cpchar( operator  pchar() ); };    \
      /*     */operator cpwchar() { return cpwchar( operator pwchar() ); };    \
      /**/};   static es_##ns ns;
    #endif encrypt_line
    
    #ifndef encrypt_number
    # define encrypt_number( os, ns ) class VT0 es_##ns {                      \
      /*   */public:                                                           \
      /*     */uint64 _tk,_nk,_sk;                                             \
      /*   */public:                                                           \
      /*     */explicit es_##ns( void ) { static uint8 _h = 0x0;               \
      /*       */if ( _h == 33 )        { return; };   _h = 33;                \
      /*     */_sk = _rand(_rand(0x1,0xFF),0xFFFFFFFF00093600ULL);             \
      /*     */_tk = _rand(_rand(0x1,0xFF),0x13000000FFFFFFFFULL);             \
      /*     */_nk = ((os ^ _tk) ^ _sk);                                       \
      /*     */};                                                              \
      /*   */public:                                                           \
      /*     */operator uint64() { return ((_nk ^ _tk) ^ _sk); };              \
      /*     */operator uint32() { return operator uint64(); };                \
      /*     */operator uint16() { return operator uint32(); };                \
      /*     */operator uint8 () { return operator uint16(); };                \
      /*   */public:                                                           \
      /*     */operator dword()     { return dword(operator uint32()); };      \
      /*   */public:                                                           \
      /*     */operator __int8()  { return __int8( operator uint8( )); };      \
      /*     */operator __int16() { return __int16(operator uint16()); };      \
      /*     */operator __int32() { return __int32(operator uint32()); };      \
      /*     */operator __int64() { return __int64(operator uint64()); };      \
      /**/};   static es_##ns ns;
    #endif encrypt_number
    
    #ifndef encrypt_speak
    #define encrypt_speak( os, ns , ... )        \
      /*    */encrypt_line( os, ns ); if( true ){ \
      /*    */tools::speak( ns, __VA_ARGS__ );  }
    #endif  encrypt_speak
    
    #endif  __COMPILE_TIME_STRINGS__
    _C=__cdecl
    _R=__regcall
    VT0=__declspec(novtable)
    scuint64=static const uint64
    _rand(seed,maxval) = ctn<CNT,seed,maxval>::val

    Code:
          encrypt_line("some bullshit text",szCMD);
          printf(szCMD);
          wprintf(szCMD);
    
    
      encrypt_number( 1999, number_test1 );
      encrypt_number( 0xDEAD, number_test2 );
      encrypt_speak("number_test %i %x\0",hi,
        __int32(number_test1),
        dword(number_test2) );
    not tested ever without intel compiler 11/12/13 (vs default one might fails idk)

    text thing looks like:
    Code:
    int __thiscall es_szwintrust::es_szwintrust(int this)
    {
      int result; // eax@2
      signed __int64 v2; // kr00_8@5
      __int64 v3; // ST98_8@5
      int v4; // STA4_4@5
      signed __int64 v5; // kr08_8@5
      int v6; // ebx@5
      signed __int64 v7; // kr10_8@5
      int v8; // ebx@5
      unsigned int v9; // [sp+A0h] [bp-30h]@4
    
      if ( byte_F68930 == 33 )
      {
        result = this;
      }
      else
      {
        byte_F68930 = 33;
        v9 = 0;
        *(_BYTE *)this = 118;
        *(_BYTE *)(this + 1) = 125;
        *(_BYTE *)(this + 2) = 109;
        *(_BYTE *)(this + 3) = 106;
        *(_BYTE *)(this + 4) = 87;
        *(_BYTE *)(this + 5) = 117;
        *(_BYTE *)(this + 6) = 4;
        *(_BYTE *)(this + 7) = 86;
        *(_BYTE *)(this + 8) = 111;
        *(_BYTE *)(this + 9) = 16;
        *(_BYTE *)(this + 10) = 127;
        *(_BYTE *)(this + 11) = 2;
        *(_BYTE *)(this + 12) = 37;
        *(_BYTE *)(this + 13) = 0;
        *(_BYTE *)(this + 14) = 0;
        do
        {
          v2 = ((v9 + 2) ^ 0xFFF8CE3C) - 1i64;
          HIDWORD(v3) = HIDWORD(v2) - 1;
          LODWORD(v3) = (((v9 + 4) ^ 0x9A0000E7) + 1) ^ v2;
          v4 = ((((v9 + 1) ^ 0x11ui64) * v3 % 0xFFFFFFFFFFFFFFFFui64 & 0xF) + 1) ^ ((((v9 + 1) ^ 9i64)
                                                                                   * ((((v9 + 5) ^ 0x9A0000E8) + 1) ^ __PAIR__((((unsigned __int64)((v9 + 1) ^ 0xFFF8CE3D) - 1) >> 32) - 1, ((v9 + 1) ^ 0xFFF8CE3D) - 1))
                                                                                   % 0xFFFFFFFFFFFFFFFFui64 & 7)
                                                                                  + 1) ^ *(_BYTE *)(v9 + this);
          v5 = ((v9 + 3) ^ 0xFFF8CE3B) - 1i64;
          HIDWORD(v3) = HIDWORD(v5) - 1;
          LODWORD(v3) = (((v9 + 3) ^ 0x9A0000E6) + 1) ^ v5;
          v6 = ((((v9 + 1) ^ 0x21ui64) * v3 % 0xFFFFFFFFFFFFFFFFui64 & 0x1F) + 1) ^ v4;
          v7 = ((v9 + 4) ^ 0xFFF8CE3A) - 1i64;
          HIDWORD(v3) = HIDWORD(v7) - 1;
          LODWORD(v3) = (((v9 + 2) ^ 0x9A0000E5) + 1) ^ v7;
          v8 = ((((v9 + 1) ^ 0x81)
               * __PAIR__(
                   (((unsigned __int64)((v9 + 5) ^ 0xFFF8CE39) - 1) >> 32) - 1,
                   (((v9 + 1) ^ 0x9A0000E4) + 1) ^ (((v9 + 5) ^ 0xFFF8CE39) - 1))
               % 0xFFFFFFFFFFFFFFFFui64 & 0x7F)
              + 1) ^ ((((v9 + 1) ^ 0x41ui64) * v3 % 0xFFFFFFFFFFFFFFFFui64 & 0x3F) + 1) ^ v6;
          *(_BYTE *)(v9 + this + 14) = v8;
          *(_WORD *)(this + 2 * v9++ + 28) = (unsigned __int8)v8;
        }
        while ( v9 < 0xE );
        result = this;
        *(_BYTE *)(this + 12) = 0;
        *(_BYTE *)(this + 26) = 0;
        *(_WORD *)(this + 52) = 0;
      }
      return result;
    }
    char *__thiscall es_szwintrust::operator_pchar()
    {
      int v0; // ecx@0
    
      return (char *)(v0 + 14);
    }
    number thing looks like:
    Code:
    int __thiscall es_number_test1::es_number_test1(int this)
    {
      if ( byte_F69024 != 33 )
      {
        byte_F69024 = 33;
        *(_DWORD *)(this + 16) = -603626;
        *(_DWORD *)(this + 20) = 0;
        *(_DWORD *)this = 1124073574;
        *(_DWORD *)(this + 4) = 0;
        *(_DWORD *)(this + 8) = -1124676161;
        *(_DWORD *)(this + 12) = 0;
      }
      return this;
    }
    unsigned __int64 __thiscall es_number_test1::operator_uint64()
    {
      int v0; // ecx@0
    
      return *(_QWORD *)(v0 + 16) ^ *(_QWORD *)v0 ^ *(_QWORD *)(v0 + 8);
    }
    each of them gets their own keys.


    hoping nones understands
    :facepalm:






    gibs coins @
    1KatP9B8KG7mvcoFhdLGua1isG88nYZE8C


    #2
    Re: compile time things

    I had somehow missed this thread, I remember reading that thread on GD and noticed you started figuring it out there, GJ

    Code:
    // double null term = triple null term k
    rifk
    lolmaoman: Germans are born with a lifetime x22 login engraved into their birth certificates. True story.
    I DONT HAVE TEAMVIEWER AND IM NOT GOING TO GIVE ANY 24/7 ONLINE SUPPORT VIA STEAM, XFIRE OR OTHER IM PROGRAMS SO DONT BOTHER ASKING. THANKS.

    Comment


      #3
      Re: compile time things

      changed a bit since then but yeah(i dont rly liked the macro way with static size+vs that could not go very deep&internal errored),
      (for sub)updates in rhc_src\e_krnl






      gibs coins @
      1KatP9B8KG7mvcoFhdLGua1isG88nYZE8C

      Comment

      Working...
      X