/src/libqxp/src/lib/QXP4Deobfuscator.cpp
Line | Count | Source |
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 "QXP4Deobfuscator.h" |
11 | | |
12 | | namespace libqxp |
13 | | { |
14 | | |
15 | | namespace |
16 | | { |
17 | | |
18 | | uint16_t fill(uint16_t value, uint16_t shift, uint16_t mask) |
19 | 75.2k | { |
20 | 75.2k | uint16_t r = shift; |
21 | 75.2k | uint16_t v = value; |
22 | 84.3k | while ((v & 1) == 0 && r > 0) |
23 | 9.13k | { |
24 | 9.13k | v >>= 1; |
25 | 9.13k | r--; |
26 | 9.13k | } |
27 | 75.2k | const uint16_t s = shift - r; |
28 | 75.2k | const uint16_t m = (0xffff >> s) << s; |
29 | 75.2k | return (value | m) & mask; |
30 | 75.2k | } |
31 | | |
32 | | uint16_t shift(uint16_t value, uint16_t count) |
33 | 75.2k | { |
34 | 75.2k | const uint16_t mask = 0xffff >> (16 - count); |
35 | 75.2k | const uint16_t highinit = value & mask; |
36 | 75.2k | const uint16_t high = fill(highinit | (value >> 15), count, mask) << (16 - count); |
37 | 75.2k | return high | (value >> count); |
38 | 75.2k | } |
39 | | |
40 | | } |
41 | | |
42 | | QXP4Deobfuscator::QXP4Deobfuscator(uint16_t seed, uint16_t increment) |
43 | 4.14k | : QXPDeobfuscator(seed) |
44 | 4.14k | , m_increment(increment) |
45 | 4.14k | { |
46 | 4.14k | } |
47 | | |
48 | | void QXP4Deobfuscator::next(uint16_t block) |
49 | 37.0k | { |
50 | 37.0k | m_seed += m_increment; |
51 | 37.0k | m_increment = shift(m_increment, block & 0xf); |
52 | 37.0k | } |
53 | | |
54 | | void QXP4Deobfuscator::nextRev() |
55 | 4.94k | { |
56 | 4.94k | m_seed += 0xffff - m_increment; |
57 | 4.94k | } |
58 | | |
59 | | void QXP4Deobfuscator::nextShift(uint16_t count) |
60 | 38.1k | { |
61 | 38.1k | m_seed = shift(m_seed, count & 0xf); |
62 | 38.1k | } |
63 | | |
64 | | } |
65 | | |
66 | | /* vim:set shiftwidth=2 softtabstop=2 expandtab: */ |