daily pastebin goal
62%
SHARE
TWEET

Untitled

a guest May 16th, 2018 96 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "Decryptor.h"
  2. using namespace Decryptor_space;
  3. //extern uint64_t g_base_addr;
  4.  
  5. #define _WORD  uint16_t
  6. #define _DWORD  uint32_t
  7. #define _BYTE  char
  8.  
  9. // roll functions
  10. #pragma region roll
  11. static uint8_t rol1(uint8_t x, unsigned int count) {
  12.     count %= 8;
  13.     return (x << count) | (x >> (8 - count));
  14. }
  15.  
  16. static uint16_t rol2(uint16_t x, unsigned int count) {
  17.     count %= 16;
  18.     return (x << count) | (x >> (16 - count));
  19. }
  20.  
  21. static uint32_t rol4(uint32_t x, unsigned int count) {
  22.     count %= 32;
  23.     return (x << count) | (x >> (32 - count));
  24. }
  25.  
  26. static uint64_t rol8(uint64_t x, unsigned int count) {
  27.     count %= 64;
  28.     return (x << count) | (x >> (64 - count));
  29. }
  30.  
  31. static uint8_t ror1(uint8_t x, unsigned int count) {
  32.     count %= 8;
  33.     return (x << (8 - count)) | (x >> count);
  34. }
  35.  
  36. static uint16_t ror2(uint16_t x, unsigned int count) {
  37.     count %= 16;
  38.     return (x << (16 - count)) | (x >> count);
  39. }
  40.  
  41. static uint32_t ror4(uint32_t x, unsigned int count) {
  42.     count %= 32;
  43.     return (x << (32 - count)) | (x >> count);
  44. }
  45.  
  46. static uint64_t ror8(uint64_t x, unsigned int count) {
  47.     count %= 64;
  48.     return (x << (64 - count)) | (x >> count);
  49. }
  50. #pragma endregion
  51.  
  52. // public functions
  53. #pragma region public
  54. int Decryptor::tsl_init(uint64_t base, uint64_t table) {
  55.     tsl = new Tsl();
  56.     tsl->func = (decrypt_func)VirtualAlloc(NULL, 0x200, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
  57.     if (tsl->func == NULL) {
  58.         return 0;
  59.     }
  60.     g_base_addr = base;
  61.     TABLE = table;
  62.     return 1;
  63. }
  64.  
  65. void Decryptor::tsl_finit() {
  66.     if (tsl && tsl->func != NULL) {
  67.         VirtualFree(tsl->func, 0, MEM_RELEASE);
  68.         tsl->func = NULL;
  69.         delete tsl;
  70.     }
  71. }
  72.  
  73. uint64_t Decryptor::tsl_decrypt_actor(uint64_t actor) {
  74.  
  75.     struct uint128_t xmm;
  76.     if (!READ(actor, &xmm, 16)) {
  77.         return 0;
  78.     }
  79.     uint32_t key = (uint32_t)xmm.low;
  80.  
  81.     int v7 = ((unsigned __int16)~((~IDA_HIWORD(key) - 15) ^ 0xF) + 43467) ^ (unsigned __int16)ror2(IDA_LOWORD(key) - 27, 8);
  82.  
  83.  
  84.     uint64_t func = READ64(GET_ADDR(TABLE) + (8 * (((unsigned __int8)(((~((~(_BYTE)IDA_HIWORD(key) - 15) ^ 0xF) - 53) ^ ror2(IDA_LOWORD(key) - 27, 8))
  85.         - 115) ^ ((unsigned __int8)(BYTE1(v7) - 93) + 170))
  86.         % 128)));
  87.  
  88.     return ror8(decrypt(func, (key ^ rol8(xmm.high - key, 8 * (IDA_LOWORD(key) & 7u)))), -97);
  89. }
  90.  
  91. uint64_t Decryptor::tsl_decrypt_prop(uint64_t prop)
  92. {
  93.     struct uint128_t xmm;
  94.     if (!READ(prop, &xmm, 16)) {
  95.         return 0;
  96.     }
  97.  
  98.     uint32_t key = (uint32_t)xmm.low;
  99.  
  100.     uint64_t func = READ64(GET_ADDR(TABLE) + (8 * ((((unsigned __int8)(((unsigned __int16)(~((~IDA_LOWORD(key) - 74) ^ 0x4A) ^ (IDA_HIWORD(key) + 12108)) >> 8) + 58)
  101.         + 172) ^ (unsigned __int8)~((~(~((~(_BYTE)IDA_LOWORD(key) - 74) ^ 0x4A) ^ (IDA_HIWORD(key) + 76)) + 102) ^ 0x9A))
  102.         % 128)));
  103.  
  104.     return ror8(decrypt(func, (key + rol8(key + xmm.high, 8 * (IDA_LOWORD(key) & 7u)))), 66);
  105.  
  106. }
  107.  
  108. camera_cache_entry Decryptor::getCameraCacheEntry(uint64_t cce_address) {
  109.     struct camera_cache_entry cce;
  110.     READ(cce_address, &cce, sizeof(struct camera_cache_entry));
  111.     return cce;
  112. }
  113.  
  114. #pragma endregion
  115.  
  116. // private funcitons
  117. #pragma region privatee
  118.  
  119. uint64_t Decryptor::GET_ADDR(uint64_t addr) {
  120.     return g_base_addr + addr;
  121. }
  122.  
  123. static int find_call(const uint8_t *buf, uint32_t size, struct rel_addr *ret) {
  124.     uint32_t offset = 0;
  125.     while (offset < (size - 5)) {
  126.         if (buf[offset] == 0xe8) {
  127.             uint32_t addr = *(uint32_t *)(buf + (offset + 1));
  128.             if (addr < 0x1FFFF) {
  129.                 ret->offset = offset + 5;
  130.                 ret->addr = addr;
  131.                 return 1;
  132.             }
  133.         }
  134.         offset++;
  135.     }
  136.     return 0;
  137. }
  138.  
  139. static uint32_t get_func_len(const uint8_t *buf, uint32_t size, uint8_t start, uint32_t end) {
  140.     if (*buf == start) {
  141.         uint32_t offset = 0;
  142.         while (offset < (size - sizeof(end))) {
  143.             if (*(uint32_t *)(buf + offset) == end) {
  144.                 return offset;
  145.             }
  146.             offset++;
  147.         }
  148.     }
  149.     return 0;
  150. }
  151.  
  152. uint64_t Decryptor::decrypt(uint64_t func, uint64_t arg) {
  153.     uint8_t buf_0x100[0x100];
  154.     if (!READ(func, buf_0x100, 0x100)) {
  155.         return 0;
  156.     }
  157.     struct rel_addr rel_addr;
  158.     if (!find_call(buf_0x100, 0x100, &rel_addr)) {
  159.         return 0;
  160.     }
  161.     uint64_t abs_addr = func + (rel_addr.offset + rel_addr.addr);
  162.     uint8_t buf_0x20[0x20];
  163.     if (!READ(abs_addr, buf_0x20, 0x20)) {
  164.         return 0;
  165.     }
  166.     uint32_t len = get_func_len(buf_0x20, 0x20, 0x48, 0xccccccc3);
  167.     if (!len || len > 0xf) {
  168.         return 0;
  169.     }
  170.     uint32_t temp = rel_addr.offset - 5;
  171.     memcpy(tsl->func, buf_0x100, temp);
  172.     memcpy((char *)tsl->func + temp, buf_0x20, len);
  173.     memcpy((char *)tsl->func + (temp + len), buf_0x100 + rel_addr.offset, 0x100 - rel_addr.offset);
  174.     uint64_t ret = tsl->func(arg);
  175.     memset(tsl->func, 0, 0x200);
  176.     return ret;
  177. }
  178.  
  179. uint64_t Decryptor::tsl_decrypt_world(uint64_t world) {
  180.     return 0;
  181. }
  182.  
  183. #pragma endregion
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top