diff 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
line wrap: on
line diff
--- a/decode-mixed-mode.c	Sat Jan 24 15:10:05 2026 -0500
+++ b/decode-mixed-mode.c	Sat Mar 07 18:04:10 2026 -0500
@@ -2,6 +2,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <inttypes.h>
+#include <string.h>
 
 static void decode_size(unsigned long x)
 {
@@ -10,16 +11,31 @@
     printf("k%sByteCode", lut[x & 3]);
 }
 
-int main(int argc, char *argv[])
+static void func_header(unsigned long x, unsigned long off)
 {
-    unsigned long x;
+	unsigned long i;
+	int ret;
+
+	static const char *lut[] = {"void", "OMS_uint8", "OMS_uint16", "OMS_uint32"};
+
+	/* dont care */
+	x >>= 4;
 
-    if (argc < 2) {
-        fprintf(stderr, "usage: decrypt-mixed-call <param>\n");
-        return 1;
-    }
+	printf("%s OMS_Unknown0x%02lX(", lut[x & 3], off);
+	ret = !!(x & 3);
+	x >>= 2;
+
+	for (i = 1; x; i++, x >>= 2)
+		printf("%s%s p%ld", (i == 1) ? "" : ", ", lut[x & 3], i);
 
-    x = strtoul(argv[1], NULL, 0);
+	printf(")\n{\n\t");
+	if (ret) printf("return ");
+	printf("CallUniversalProc(OMS_InternalFuncTable[0x%02lX],\n\t\t", off);
+}
+
+static void gen(unsigned long x)
+{
+    unsigned long i;
 
     switch (x & 15) {
     case 0:
@@ -30,7 +46,7 @@
         break;
     case 2:
         printf("I'm too lazy for this!");
-        return 1;
+	break;
     case 5:
         printf("kThinkCStackBased");
         break;
@@ -47,8 +63,7 @@
         printf("kStackDispatchedPascalStackBased");
         break;
     default:
-        /* Invalid */
-        return 1;
+        return;
     }
 
     x >>= 4;
@@ -61,11 +76,56 @@
     x >>= 2;
 
     /* hopefully we're using stack, since that's the ONLY thing i'm handling */
-    for (uint32_t i = 1; i < 13 && x; i++, x >>= 2) {
-        printf(" | STACK_ROUTINE_PARAMETER(%" PRIu32 ", ", i);
+    for (i = 1; x; i++, x >>= 2) {
+        printf(" | STACK_ROUTINE_PARAMETER(%lu, ", i);
         decode_size(x);
         printf(")");
     }
+}
+
+void func_footer(unsigned long x)
+{
+	unsigned long i;
+
+	x >>= 6;
+
+	printf("\n\t");
+
+	for (i = 1; x; i++, x >>= 2)
+		printf(", p%lu", i);
+
+	printf(");\n}");
+}
+
+int main(int argc, char *argv[])
+{
+    unsigned long x;
+    int stubs;
+    int inarg;
+    unsigned long off;
+
+    if (argc < 2) {
+        fprintf(stderr, "usage: decrypt-mixed-call <param>\n");
+        return 1;
+    }
+
+    stubs = (argc > 2 && !strcmp(argv[1], "-gen-stub"));
+
+    if (stubs) {
+        inarg = 3;
+        off = strtoul(argv[2], NULL, 0);
+    } else
+        inarg = 1;
+
+    x = strtoul(argv[inarg], NULL, 0);
+
+    if (stubs) {
+        func_header(x, off);
+    }
+    gen(x);
+    if (stubs) {
+	func_footer(x);        
+    }
 
     puts("");