Mercurial > codedump
comparison decode-mixed-mode.c @ 136:da4f7200665f default tip
buncha shit
| author | Paper <paper@tflc.us> |
|---|---|
| date | Sat, 07 Mar 2026 18:04:10 -0500 |
| parents | 8c39820da60a |
| children |
comparison
equal
deleted
inserted
replaced
| 135:0c3cd90e91f7 | 136:da4f7200665f |
|---|---|
| 1 #include <stdint.h> | 1 #include <stdint.h> |
| 2 #include <stdio.h> | 2 #include <stdio.h> |
| 3 #include <stdlib.h> | 3 #include <stdlib.h> |
| 4 #include <inttypes.h> | 4 #include <inttypes.h> |
| 5 #include <string.h> | |
| 5 | 6 |
| 6 static void decode_size(unsigned long x) | 7 static void decode_size(unsigned long x) |
| 7 { | 8 { |
| 8 const char *lut[] = {"No", "One", "Two", "Four"}; | 9 const char *lut[] = {"No", "One", "Two", "Four"}; |
| 9 | 10 |
| 10 printf("k%sByteCode", lut[x & 3]); | 11 printf("k%sByteCode", lut[x & 3]); |
| 11 } | 12 } |
| 12 | 13 |
| 13 int main(int argc, char *argv[]) | 14 static void func_header(unsigned long x, unsigned long off) |
| 14 { | 15 { |
| 15 unsigned long x; | 16 unsigned long i; |
| 17 int ret; | |
| 16 | 18 |
| 17 if (argc < 2) { | 19 static const char *lut[] = {"void", "OMS_uint8", "OMS_uint16", "OMS_uint32"}; |
| 18 fprintf(stderr, "usage: decrypt-mixed-call <param>\n"); | |
| 19 return 1; | |
| 20 } | |
| 21 | 20 |
| 22 x = strtoul(argv[1], NULL, 0); | 21 /* dont care */ |
| 22 x >>= 4; | |
| 23 | |
| 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); | |
| 30 | |
| 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; | |
| 23 | 39 |
| 24 switch (x & 15) { | 40 switch (x & 15) { |
| 25 case 0: | 41 case 0: |
| 26 printf("kPascalStackBased"); | 42 printf("kPascalStackBased"); |
| 27 break; | 43 break; |
| 28 case 1: | 44 case 1: |
| 29 printf("kCStackBased"); | 45 printf("kCStackBased"); |
| 30 break; | 46 break; |
| 31 case 2: | 47 case 2: |
| 32 printf("I'm too lazy for this!"); | 48 printf("I'm too lazy for this!"); |
| 33 return 1; | 49 break; |
| 34 case 5: | 50 case 5: |
| 35 printf("kThinkCStackBased"); | 51 printf("kThinkCStackBased"); |
| 36 break; | 52 break; |
| 37 case 8: | 53 case 8: |
| 38 printf("kD0DispatchedPascalStackBased"); | 54 printf("kD0DispatchedPascalStackBased"); |
| 45 break; | 61 break; |
| 46 case 14: | 62 case 14: |
| 47 printf("kStackDispatchedPascalStackBased"); | 63 printf("kStackDispatchedPascalStackBased"); |
| 48 break; | 64 break; |
| 49 default: | 65 default: |
| 50 /* Invalid */ | 66 return; |
| 51 return 1; | |
| 52 } | 67 } |
| 53 | 68 |
| 54 x >>= 4; | 69 x >>= 4; |
| 55 | 70 |
| 56 printf(" | RESULT_SIZE("); | 71 printf(" | RESULT_SIZE("); |
| 59 | 74 |
| 60 /* trim the fat */ | 75 /* trim the fat */ |
| 61 x >>= 2; | 76 x >>= 2; |
| 62 | 77 |
| 63 /* hopefully we're using stack, since that's the ONLY thing i'm handling */ | 78 /* hopefully we're using stack, since that's the ONLY thing i'm handling */ |
| 64 for (uint32_t i = 1; i < 13 && x; i++, x >>= 2) { | 79 for (i = 1; x; i++, x >>= 2) { |
| 65 printf(" | STACK_ROUTINE_PARAMETER(%" PRIu32 ", ", i); | 80 printf(" | STACK_ROUTINE_PARAMETER(%lu, ", i); |
| 66 decode_size(x); | 81 decode_size(x); |
| 67 printf(")"); | 82 printf(")"); |
| 83 } | |
| 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); | |
| 68 } | 128 } |
| 69 | 129 |
| 70 puts(""); | 130 puts(""); |
| 71 | 131 |
| 72 return 0; | 132 return 0; |
