void CHaruotoFD::DecodeData(void* pvTarget, DWORD dwSize) { BYTE* pbtTarget = (BYTE*)pvTarget; DWORD* pdwTable = GetTable(); DWORD dwValue1; DWORD dwValue2; for (DWORD i = 0; i < dwSize; i += 8) { dwValue1 = *(DWORD*)&pbtTarget[i] ^ pdwTable[17]; dwValue2 = DecodeValueByTable(dwValue1, pdwTable) ^ *(DWORD*)&pbtTarget[i + 4] ^ pdwTable[16]; for (DWORD j = 15; j > 1; j -= 2) { dwValue1 ^= DecodeValueByTable(dwValue2, pdwTable) ^ pdwTable[j - 0]; dwValue2 ^= DecodeValueByTable(dwValue1, pdwTable) ^ pdwTable[j - 1]; } dwValue1 ^= DecodeValueByTable(dwValue2, pdwTable); *(DWORD*)&pbtTarget[i + 0] = pdwTable[0] ^ dwValue2; *(DWORD*)&pbtTarget[i + 4] = pdwTable[1] ^ dwValue1; } }
/// Decode Data /// /// @param target Data to be decoded /// @param size Decoding size /// void CHaruotoFD::DecodeData(u8* target, size_t size) { const u32* table = GetTable(); for (size_t i = 0; i < size; i += 8) { u32 value1 = *reinterpret_cast<const u32*>(&target[i]) ^ table[17]; u32 value2 = DecodeValueByTable(value1, table) ^ *reinterpret_cast<const u32*>(&target[i + 4]) ^ table[16]; for (size_t j = 15; j > 1; j -= 2) { value1 ^= DecodeValueByTable(value2, table) ^ table[j - 0]; value2 ^= DecodeValueByTable(value1, table) ^ table[j - 1]; } value1 ^= DecodeValueByTable(value2, table); *reinterpret_cast<u32*>(&target[i + 0]) = table[0] ^ value2; *reinterpret_cast<u32*>(&target[i + 4]) = table[1] ^ value1; } }
/// Decode Value /// /// @param value1 Target data 1 /// @param value2 Target data 2 /// @param table Table /// void CPaz::DecodeValue(u32* value1, u32* value2, const u32* table) { u32 work1 = *value1; u32 work2 = *value2; for (size_t i = 0; i < 16; i++) { const u32 value = work1 ^ table[i]; work1 = DecodeValueByTable(value, table) ^ work2; work2 = value; } *value1 = table[17] ^ work2; *value2 = table[16] ^ work1; }
/// Decode Value /// /// @param pdwValue1 - Target data 1 /// @param pdwValue2 - Target data 2 /// @param pvTable - Table /// void CPaz::DecodeValue(DWORD* pdwValue1, DWORD* pdwValue2, void* pvTable) { DWORD* pdwTable = (DWORD*)pvTable; DWORD dwWork1 = *pdwValue1; DWORD dwWork2 = *pdwValue2; for (DWORD i = 0; i < 16; i++) { DWORD dwValue = dwWork1 ^ pdwTable[i]; dwWork1 = DecodeValueByTable(dwValue, pdwTable) ^ dwWork2; dwWork2 = dwValue; } *pdwValue1 = pdwTable[17] ^ dwWork2; *pdwValue2 = pdwTable[16] ^ dwWork1; }
/// Decode Data /// /// @param target Data to be decoded /// @param size Decoding size /// void CPaz::DecodeData(u8* target, size_t size) { const u32* table = GetTable(); for (size_t i = 0; i < size; i += 8) { u32 value1 = *reinterpret_cast<const u32*>(&target[i + 0]); u32 value2 = *reinterpret_cast<const u32*>(&target[i + 4]); for (size_t j = 17; j > 1; j--) { const u32 work = value1 ^ table[j]; value1 = DecodeValueByTable(work, table) ^ value2; value2 = work; } *reinterpret_cast<u32*>(&target[i + 0]) = table[0] ^ value2; *reinterpret_cast<u32*>(&target[i + 4]) = table[1] ^ value1; } }
/// Decode Data /// /// @param pvTarget Data to be decoded /// @param dwSize Decoding size /// void CPaz::DecodeData(void* pvTarget, DWORD dwSize) { BYTE* pbtTarget = (BYTE*)pvTarget; DWORD* pdwTable = GetTable(); for (DWORD i = 0; i < dwSize; i += 8) { DWORD dwValue1 = *(DWORD*)&pbtTarget[i + 0]; DWORD dwValue2 = *(DWORD*)&pbtTarget[i + 4]; for (DWORD j = 17; j > 1; j--) { DWORD dwWork; dwWork = dwValue1 ^ pdwTable[j]; dwValue1 = DecodeValueByTable(dwWork, pdwTable) ^ dwValue2; dwValue2 = dwWork; } *(DWORD*)&pbtTarget[i + 0] = pdwTable[0] ^ dwValue2; *(DWORD*)&pbtTarget[i + 4] = pdwTable[1] ^ dwValue1; } }
/// Decode Table 2 void CHaruotoFD::DecodeTable2() { u32* table = GetTable(); // Decrypt 72 byte table u32 value1 = 0; u32 value2 = 0; u32 value3 = 0; u32 value4 = 0; for (size_t i = 0; i < 18; i += 2) { value1 ^= table[0]; value4 = DecodeValueByTable(value1, table) ^ value2 ^ table[1]; value3 = DecodeValueByTable(value4, table) ^ value1 ^ table[2]; value2 = DecodeValueByTable(value3, table) ^ value4 ^ table[3]; for (size_t j = 4; j < 16; j += 3) { value1 = DecodeValueByTable(value2, table) ^ value3 ^ table[j + 0]; value3 = DecodeValueByTable(value1, table) ^ value2 ^ table[j + 1]; value2 = DecodeValueByTable(value3, table) ^ value1 ^ table[j + 2]; } value1 = value2 ^ table[17]; value2 = DecodeValueByTable(value2, table) ^ value3 ^ table[16]; table[i + 0] = value1; table[i + 1] = value2; } // Decrypt 4096 byte table size_t table_ptr = 18; for (size_t i = 0; i < 512; i++) { value1 ^= table[0]; for (size_t j = 1; j < 16; j += 3) { value3 = DecodeValueByTable(value1, table) ^ value2 ^ table[j + 0]; value2 = DecodeValueByTable(value3, table) ^ value1 ^ table[j + 1]; value1 = DecodeValueByTable(value2, table) ^ value3 ^ table[j + 2]; } value2 = DecodeValueByTable(value1, table) ^ value2 ^ table[16]; value1 ^= table[17]; table[table_ptr++] = value1; table[table_ptr++] = value2; } }
void CHaruotoFD::DecodeTable2() { DWORD* pdwTable = GetTable(); // Decrypt 72 byte table DWORD dwValue1 = 0; DWORD dwValue2 = 0; DWORD dwValue3 = 0; DWORD dwValue4 = 0; for (DWORD i = 0; i < 18; i += 2) { dwValue1 ^= pdwTable[0]; dwValue4 = DecodeValueByTable(dwValue1, pdwTable) ^ dwValue2 ^ pdwTable[1]; dwValue3 = DecodeValueByTable(dwValue4, pdwTable) ^ dwValue1 ^ pdwTable[2]; dwValue2 = DecodeValueByTable(dwValue3, pdwTable) ^ dwValue4 ^ pdwTable[3]; for (DWORD j = 4; j < 16; j += 3) { dwValue1 = DecodeValueByTable(dwValue2, pdwTable) ^ dwValue3 ^ pdwTable[j + 0]; dwValue3 = DecodeValueByTable(dwValue1, pdwTable) ^ dwValue2 ^ pdwTable[j + 1]; dwValue2 = DecodeValueByTable(dwValue3, pdwTable) ^ dwValue1 ^ pdwTable[j + 2]; } dwValue1 = dwValue2 ^ pdwTable[17]; dwValue2 = DecodeValueByTable(dwValue2, pdwTable) ^ dwValue3 ^ pdwTable[16]; pdwTable[i + 0] = dwValue1; pdwTable[i + 1] = dwValue2; } // Decrypt 4096 byte table DWORD dwTablePtr = 18; for (DWORD i = 0; i < 512; i++) { dwValue1 ^= pdwTable[0]; for (DWORD j = 1; j < 16; j += 3) { dwValue3 = DecodeValueByTable(dwValue1, pdwTable) ^ dwValue2 ^ pdwTable[j + 0]; dwValue2 = DecodeValueByTable(dwValue3, pdwTable) ^ dwValue1 ^ pdwTable[j + 1]; dwValue1 = DecodeValueByTable(dwValue2, pdwTable) ^ dwValue3 ^ pdwTable[j + 2]; } dwValue2 = DecodeValueByTable(dwValue1, pdwTable) ^ dwValue2 ^ pdwTable[16]; dwValue1 ^= pdwTable[17]; pdwTable[dwTablePtr++] = dwValue1; pdwTable[dwTablePtr++] = dwValue2; } }