Debian Codegraph @

terps/unp64/scanners/abuze_crunch.cpp

raw symbols SCIP
1 /* This is a cut-down version of UNP64 with only the bare minimum
2 * needed to decompress a number of Commodore 64 adventure games.
3 * It is distributed under the zlib License by kind permission of
4 * the original authors Magnus Lind and iAN CooG.
5 */
6
7 /*
8 UNP64 - generic Commodore 64 prg unpacker
9 (C) 2008-2022 iAN CooG/HVSC Crew^C64Intros
10 original source and idea: testrun.c, taken from exo20b7
11
12 Follows original disclaimer
13 */
14
15 /*
16 * Copyright (c) 2002 - 2023 Magnus Lind.
17 *
18 *
19 * This software is provided 'as-is', without any express or implied
20 * warranty. In no event will the authors be held liable for any damages
21 * arising from the use of this software.
22 *
23 * Permission is granted to anyone to use this software for any purpose,
24 * including commercial applications, and to alter it and redistribute it
25 * freely, subject to the following restrictions:
26 *
27 * 1. The origin of this software must not be misrepresented; you must not
28 * claim that you wrote the original software. If you use this software
29 * in a product, an acknowledgment in the product documentation would be
30 * appreciated but is not required.
31 * 2. Altered source versions must be plainly marked as such, and must not be
32 * misrepresented as being the original software.
33 * 3. This notice may not be removed or altered from any source distribution.
34 *
35 */
36
37 /*
38 C++ version based on code adapted to ScummVM by Avijeet Maurya
39 */
40
41 #include "exo_util.h"
42 #include "types.h"
43 #include "unp64.h"
44
45 namespace Unp64 {
46
47 /* AbuzeCrunch */
48 void scnAbuzeCrunch(UnpStr *unp) {
49 unsigned char *mem;
50 int q, p = 0;
51 if (unp->_idFlag)
52 return;
53 mem = unp->_mem;
54 if (unp->_depAdr == 0) {
55 for (q = 0x80b; q < 0x820; q++) {
56 if (u32eq(mem + q, 0x1BA200A0) &&
57 u32eq(mem + q + 0x13, 0x10CAA095) &&
58 u16eq(mem + q + 0x20, 0x4CF7)) {
59 p = READ_LE_UINT16(&mem[q + 0xc]);
60 if (u32eq(mem + p + 0x25, 0xFFA9FE91) ||
61 u32eq(mem + p + 0x25, 0xFeA5FE91)) {
62 unp->_depAdr = READ_LE_UINT16(&mem[q + 0x22]);
63 break;
64 }
65 }
66 }
67 if (unp->_depAdr) {
68 unp->_endAdr = READ_LE_UINT16(&mem[p + 0x4]);
69 unp->_endAdr++;
70 unp->_forced = q;
71 if (mem[p + 0x2f] == 0xa5)
72 unp->_retAdr = READ_LE_UINT16(&mem[p + 0x3f]);
73 if (mem[p + 0x2f] == 0xa9)
74 unp->_retAdr = READ_LE_UINT16(&mem[p + 0x3d]);
75 unp->_fStrAf = 0xfe;
76 unp->_idFlag = 1;
77 return;
78 }
79 }
80 if (unp->_depAdr == 0) {
81 for (q = 0x80b; q < 0x820; q++) {
82 if (u32eq(mem + q, 0xA27800A0) &&
83 u32eq(mem + q + 4, 0xBAA59AFF) &&
84 u16eq(mem + q + 0x2c, 0x4CF7)) {
85 p = READ_LE_UINT16(&mem[q + 0x12]);
86 if (u32eq(mem + p + 0x25, 0xFeA5FE91)) {
87 unp->_depAdr = READ_LE_UINT16(&mem[q + 0x2e]);
88 break;
89 }
90 }
91 }
92 if (unp->_depAdr) {
93 unp->_endAdr = READ_LE_UINT16(&mem[p + 0x4]);
94 unp->_endAdr++;
95 unp->_forced = q;
96 unp->_retAdr = READ_LE_UINT16(&mem[p + 0x42]);
97 unp->_fStrAf = 0xfe;
98 unp->_idFlag = 1;
99 return;
100 }
101 }
102 /* Abuze 5.0/FLT */
103 if (unp->_depAdr == 0) {
104 if (u32eq(mem + 0x80b, 0x1BA200A0) &&
105 u32eq(mem + 0x813, 0x10CAA095) &&
106 u32eq(mem + 0x822, 0x011F4C01)) {
107 p = READ_LE_UINT16(&mem[0x819]);
108 if (u32eq(mem + p + 0x06, 0x9101E520)) {
109 unp->_depAdr = 0x11f;
110 if (unp->_info->_run == -1)
111 unp->_forced = 0x80b;
112 unp->_retAdr = READ_LE_UINT16(&mem[p + 0x23]);
113 unp->_endAdr = READ_LE_UINT16(&mem[p + 0x4]);
114 unp->_endAdr++;
115 unp->_fStrAf = 0xfe;
116 unp->_idFlag = 1;
117 return;
118 }
119 }
120 }
121 }
122
123 } // End of namespace Unp64