| 1 |
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
| 2 |
/* |
| 3 |
* This file is part of the libqxp project. |
| 4 |
* |
| 5 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 6 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 |
*/ |
| 9 |
|
| 10 |
#include <cppunit/TestFixture.h> |
| 11 |
#include <cppunit/extensions/HelperMacros.h> |
| 12 |
|
| 13 |
#include "libqxp_utils.h" |
| 14 |
#include "QXP33Deobfuscator.h" |
| 15 |
#include "QXP4Deobfuscator.h" |
| 16 |
|
| 17 |
namespace test |
| 18 |
{ |
| 19 |
|
| 20 |
using libqxp::QXP33Deobfuscator; |
| 21 |
using libqxp::QXP4Deobfuscator; |
| 22 |
|
| 23 |
class QXPDeobfuscatorTest : public CPPUNIT_NS::TestFixture |
| 24 |
{ |
| 25 |
public: |
| 26 |
virtual void setUp() override; |
| 27 |
virtual void tearDown() override; |
| 28 |
|
| 29 |
private: |
| 30 |
CPPUNIT_TEST_SUITE(QXPDeobfuscatorTest); |
| 31 |
CPPUNIT_TEST(test33Deobfuscation); |
| 32 |
CPPUNIT_TEST(test4Deobfuscation); |
| 33 |
CPPUNIT_TEST_SUITE_END(); |
| 34 |
|
| 35 |
private: |
| 36 |
void test33Deobfuscation(); |
| 37 |
void test4Deobfuscation(); |
| 38 |
}; |
| 39 |
|
| 40 |
void QXPDeobfuscatorTest::setUp() |
| 41 |
{ |
| 42 |
} |
| 43 |
|
| 44 |
void QXPDeobfuscatorTest::tearDown() |
| 45 |
{ |
| 46 |
} |
| 47 |
|
| 48 |
void QXPDeobfuscatorTest::test33Deobfuscation() |
| 49 |
{ |
| 50 |
QXP33Deobfuscator deobfuscate(0x337c, 0x3797); |
| 51 |
|
| 52 |
uint8_t type = 0x7f; |
| 53 |
uint16_t content = 0x337c; |
| 54 |
CPPUNIT_ASSERT_EQUAL(uint8_t(3), deobfuscate(type)); |
| 55 |
CPPUNIT_ASSERT_EQUAL(uint16_t(0), deobfuscate(content)); |
| 56 |
deobfuscate.next(); |
| 57 |
|
| 58 |
type = 0x10; |
| 59 |
content = 0x6b03; |
| 60 |
CPPUNIT_ASSERT_EQUAL(uint8_t(3), deobfuscate(type)); |
| 61 |
CPPUNIT_ASSERT_EQUAL(uint16_t(0x10), deobfuscate(content)); |
| 62 |
deobfuscate.next(); |
| 63 |
|
| 64 |
type = 0xa7; |
| 65 |
content = 0xa2aa; |
| 66 |
CPPUNIT_ASSERT_EQUAL(uint8_t(13), deobfuscate(type)); |
| 67 |
CPPUNIT_ASSERT_EQUAL(uint16_t(0), deobfuscate(content)); |
| 68 |
deobfuscate.next(); |
| 69 |
|
| 70 |
type = 0x42; |
| 71 |
content = 0xda41; |
| 72 |
CPPUNIT_ASSERT_EQUAL(uint8_t(3), deobfuscate(type)); |
| 73 |
CPPUNIT_ASSERT_EQUAL(uint16_t(0), deobfuscate(content)); |
| 74 |
deobfuscate.next(); |
| 75 |
|
| 76 |
type = 0xdb; |
| 77 |
content = 0x11ca; |
| 78 |
CPPUNIT_ASSERT_EQUAL(uint8_t(3), deobfuscate(type)); |
| 79 |
CPPUNIT_ASSERT_EQUAL(uint16_t(0x12), deobfuscate(content)); |
| 80 |
deobfuscate.next(); |
| 81 |
|
| 82 |
type = 0x6c; |
| 83 |
content = 0x496f; |
| 84 |
CPPUNIT_ASSERT_EQUAL(uint8_t(3), deobfuscate(type)); |
| 85 |
CPPUNIT_ASSERT_EQUAL(uint16_t(0), deobfuscate(content)); |
| 86 |
deobfuscate.next(); |
| 87 |
} |
| 88 |
|
| 89 |
void QXPDeobfuscatorTest::test4Deobfuscation() |
| 90 |
{ |
| 91 |
QXP4Deobfuscator deobfuscate(0x3c3e, 0xb3b7); |
| 92 |
|
| 93 |
uint16_t objectsCount = 0x3c3e; |
| 94 |
CPPUNIT_ASSERT_EQUAL(uint16_t(0), deobfuscate(objectsCount)); |
| 95 |
deobfuscate.nextRev(); |
| 96 |
|
| 97 |
objectsCount = 0x8886; |
| 98 |
CPPUNIT_ASSERT_EQUAL(uint16_t(0), deobfuscate(objectsCount)); |
| 99 |
deobfuscate.nextRev(); |
| 100 |
|
| 101 |
objectsCount = 0xd4cf; |
| 102 |
CPPUNIT_ASSERT_EQUAL(uint16_t(1), deobfuscate(objectsCount)); |
| 103 |
deobfuscate.nextRev(); |
| 104 |
|
| 105 |
uint8_t contentType = 0x15; |
| 106 |
uint16_t content = 0xc422; |
| 107 |
uint8_t shapeType = 0x27; |
| 108 |
contentType = deobfuscate(contentType); |
| 109 |
CPPUNIT_ASSERT_EQUAL(uint8_t(3), contentType); |
| 110 |
deobfuscate.nextShift(contentType); |
| 111 |
content = deobfuscate(content); |
| 112 |
CPPUNIT_ASSERT_EQUAL(uint16_t(0), content); |
| 113 |
CPPUNIT_ASSERT_EQUAL(uint8_t(5), deobfuscate(shapeType)); |
| 114 |
deobfuscate.next(content); |
| 115 |
|
| 116 |
objectsCount = 0x77da; |
| 117 |
CPPUNIT_ASSERT_EQUAL(uint16_t(3), deobfuscate(objectsCount)); |
| 118 |
deobfuscate.nextRev(); |
| 119 |
|
| 120 |
contentType = 0x22; |
| 121 |
content = 0xf8c0; |
| 122 |
shapeType = 0x8c; |
| 123 |
contentType = deobfuscate(contentType); |
| 124 |
CPPUNIT_ASSERT_EQUAL(uint8_t(3), contentType); |
| 125 |
deobfuscate.nextShift(contentType); |
| 126 |
content = deobfuscate(content); |
| 127 |
CPPUNIT_ASSERT_EQUAL(uint16_t(0x44), content); |
| 128 |
CPPUNIT_ASSERT_EQUAL(uint8_t(8), deobfuscate(shapeType)); |
| 129 |
deobfuscate.next(content); |
| 130 |
|
| 131 |
contentType = 0x38; |
| 132 |
content = 0xf5c1; |
| 133 |
shapeType = 0x8f; |
| 134 |
contentType = deobfuscate(contentType); |
| 135 |
CPPUNIT_ASSERT_EQUAL(uint8_t(3), contentType); |
| 136 |
deobfuscate.nextShift(contentType); |
| 137 |
content = deobfuscate(content); |
| 138 |
CPPUNIT_ASSERT_EQUAL(uint16_t(0x46), content); |
| 139 |
CPPUNIT_ASSERT_EQUAL(uint8_t(8), deobfuscate(shapeType)); |
| 140 |
deobfuscate.next(content); |
| 141 |
|
| 142 |
contentType = 0xc1; |
| 143 |
content = 0xfe50; |
| 144 |
shapeType = 0x1d; |
| 145 |
contentType = deobfuscate(contentType); |
| 146 |
CPPUNIT_ASSERT_EQUAL(uint8_t(3), contentType); |
| 147 |
deobfuscate.nextShift(contentType); |
| 148 |
content = deobfuscate(content); |
| 149 |
CPPUNIT_ASSERT_EQUAL(uint16_t(0x48), content); |
| 150 |
CPPUNIT_ASSERT_EQUAL(uint8_t(5), deobfuscate(shapeType)); |
| 151 |
deobfuscate.next(content); |
| 152 |
|
| 153 |
objectsCount = 0xfe00; |
| 154 |
CPPUNIT_ASSERT_EQUAL(uint16_t(4), deobfuscate(objectsCount)); |
| 155 |
deobfuscate.nextRev(); |
| 156 |
|
| 157 |
contentType = 0x04; |
| 158 |
content = 0xfe04; |
| 159 |
shapeType = 0x06; |
| 160 |
contentType = deobfuscate(contentType); |
| 161 |
CPPUNIT_ASSERT_EQUAL(uint8_t(0), contentType); |
| 162 |
deobfuscate.nextShift(contentType); |
| 163 |
content = deobfuscate(content); |
| 164 |
CPPUNIT_ASSERT_EQUAL(uint16_t(0), content); |
| 165 |
CPPUNIT_ASSERT_EQUAL(uint8_t(2), deobfuscate(shapeType)); |
| 166 |
deobfuscate.next(content); |
| 167 |
|
| 168 |
contentType = 0x07; |
| 169 |
content = 0xffe0; |
| 170 |
shapeType = 0xe6; |
| 171 |
contentType = deobfuscate(contentType); |
| 172 |
CPPUNIT_ASSERT_EQUAL(uint8_t(4), contentType); |
| 173 |
deobfuscate.nextShift(contentType); |
| 174 |
content = deobfuscate(content); |
| 175 |
CPPUNIT_ASSERT_EQUAL(uint16_t(0), content); |
| 176 |
CPPUNIT_ASSERT_EQUAL(uint8_t(6), deobfuscate(shapeType)); |
| 177 |
deobfuscate.next(content); |
| 178 |
|
| 179 |
contentType = 0xdc; |
| 180 |
content = 0xfffb; |
| 181 |
shapeType = 0xf3; |
| 182 |
contentType = deobfuscate(contentType); |
| 183 |
CPPUNIT_ASSERT_EQUAL(uint8_t(3), contentType); |
| 184 |
deobfuscate.nextShift(contentType); |
| 185 |
content = deobfuscate(content); |
| 186 |
CPPUNIT_ASSERT_EQUAL(uint16_t(0), content); |
| 187 |
CPPUNIT_ASSERT_EQUAL(uint8_t(8), deobfuscate(shapeType)); |
| 188 |
deobfuscate.next(content); |
| 189 |
|
| 190 |
contentType = 0xf9; |
| 191 |
content = 0xffff; |
| 192 |
shapeType = 0xfa; |
| 193 |
contentType = deobfuscate(contentType); |
| 194 |
CPPUNIT_ASSERT_EQUAL(uint8_t(3), contentType); |
| 195 |
deobfuscate.nextShift(contentType); |
| 196 |
content = deobfuscate(content); |
| 197 |
CPPUNIT_ASSERT_EQUAL(uint16_t(0), content); |
| 198 |
CPPUNIT_ASSERT_EQUAL(uint8_t(5), deobfuscate(shapeType)); |
| 199 |
deobfuscate.next(content); |
| 200 |
} |
| 201 |
|
| 202 |
CPPUNIT_TEST_SUITE_REGISTRATION(QXPDeobfuscatorTest); |
| 203 |
|
| 204 |
} |
| 205 |
|
| 206 |
/* vim:set shiftwidth=2 softtabstop=2 expandtab: */ |