|
129
|
1 #include <stdint.h>
|
|
|
2 #include <stdio.h>
|
|
|
3 #include <stdlib.h>
|
|
|
4 #include <inttypes.h>
|
|
136
|
5 #include <string.h>
|
|
129
|
6
|
|
|
7 static void decode_size(unsigned long x)
|
|
|
8 {
|
|
|
9 const char *lut[] = {"No", "One", "Two", "Four"};
|
|
|
10
|
|
|
11 printf("k%sByteCode", lut[x & 3]);
|
|
|
12 }
|
|
|
13
|
|
136
|
14 static void func_header(unsigned long x, unsigned long off)
|
|
129
|
15 {
|
|
136
|
16 unsigned long i;
|
|
|
17 int ret;
|
|
|
18
|
|
|
19 static const char *lut[] = {"void", "OMS_uint8", "OMS_uint16", "OMS_uint32"};
|
|
|
20
|
|
|
21 /* dont care */
|
|
|
22 x >>= 4;
|
|
129
|
23
|
|
136
|
24 printf("%s OMS_Unknown0x%02lX(", lut[x & 3], off);
|
|
|
25 ret = !!(x & 3);
|
|
|
26 x >>= 2;
|
|
|
27
|
|
|
28 for (i = 1; x; i++, x >>= 2)
|
|
|
29 printf("%s%s p%ld", (i == 1) ? "" : ", ", lut[x & 3], i);
|
|
129
|
30
|
|
136
|
31 printf(")\n{\n\t");
|
|
|
32 if (ret) printf("return ");
|
|
|
33 printf("CallUniversalProc(OMS_InternalFuncTable[0x%02lX],\n\t\t", off);
|
|
|
34 }
|
|
|
35
|
|
|
36 static void gen(unsigned long x)
|
|
|
37 {
|
|
|
38 unsigned long i;
|
|
129
|
39
|
|
|
40 switch (x & 15) {
|
|
|
41 case 0:
|
|
|
42 printf("kPascalStackBased");
|
|
|
43 break;
|
|
|
44 case 1:
|
|
|
45 printf("kCStackBased");
|
|
|
46 break;
|
|
|
47 case 2:
|
|
|
48 printf("I'm too lazy for this!");
|
|
136
|
49 break;
|
|
129
|
50 case 5:
|
|
|
51 printf("kThinkCStackBased");
|
|
|
52 break;
|
|
|
53 case 8:
|
|
|
54 printf("kD0DispatchedPascalStackBased");
|
|
|
55 break;
|
|
|
56 case 9:
|
|
|
57 printf("kD0DispatchedCStackBased");
|
|
|
58 break;
|
|
|
59 case 12:
|
|
|
60 printf("kD1DispatchedPascalStackBased");
|
|
|
61 break;
|
|
|
62 case 14:
|
|
|
63 printf("kStackDispatchedPascalStackBased");
|
|
|
64 break;
|
|
|
65 default:
|
|
136
|
66 return;
|
|
129
|
67 }
|
|
|
68
|
|
|
69 x >>= 4;
|
|
|
70
|
|
|
71 printf(" | RESULT_SIZE(");
|
|
|
72 decode_size(x);
|
|
|
73 printf(")");
|
|
|
74
|
|
|
75 /* trim the fat */
|
|
|
76 x >>= 2;
|
|
|
77
|
|
|
78 /* hopefully we're using stack, since that's the ONLY thing i'm handling */
|
|
136
|
79 for (i = 1; x; i++, x >>= 2) {
|
|
|
80 printf(" | STACK_ROUTINE_PARAMETER(%lu, ", i);
|
|
129
|
81 decode_size(x);
|
|
|
82 printf(")");
|
|
|
83 }
|
|
136
|
84 }
|
|
|
85
|
|
|
86 void func_footer(unsigned long x)
|
|
|
87 {
|
|
|
88 unsigned long i;
|
|
|
89
|
|
|
90 x >>= 6;
|
|
|
91
|
|
|
92 printf("\n\t");
|
|
|
93
|
|
|
94 for (i = 1; x; i++, x >>= 2)
|
|
|
95 printf(", p%lu", i);
|
|
|
96
|
|
|
97 printf(");\n}");
|
|
|
98 }
|
|
|
99
|
|
|
100 int main(int argc, char *argv[])
|
|
|
101 {
|
|
|
102 unsigned long x;
|
|
|
103 int stubs;
|
|
|
104 int inarg;
|
|
|
105 unsigned long off;
|
|
|
106
|
|
|
107 if (argc < 2) {
|
|
|
108 fprintf(stderr, "usage: decrypt-mixed-call <param>\n");
|
|
|
109 return 1;
|
|
|
110 }
|
|
|
111
|
|
|
112 stubs = (argc > 2 && !strcmp(argv[1], "-gen-stub"));
|
|
|
113
|
|
|
114 if (stubs) {
|
|
|
115 inarg = 3;
|
|
|
116 off = strtoul(argv[2], NULL, 0);
|
|
|
117 } else
|
|
|
118 inarg = 1;
|
|
|
119
|
|
|
120 x = strtoul(argv[inarg], NULL, 0);
|
|
|
121
|
|
|
122 if (stubs) {
|
|
|
123 func_header(x, off);
|
|
|
124 }
|
|
|
125 gen(x);
|
|
|
126 if (stubs) {
|
|
|
127 func_footer(x);
|
|
|
128 }
|
|
129
|
129
|
|
|
130 puts("");
|
|
|
131
|
|
|
132 return 0;
|
|
|
133 }
|