view 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 source

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <string.h>

static void decode_size(unsigned long x)
{
    const char *lut[] = {"No", "One", "Two", "Four"};

    printf("k%sByteCode", lut[x & 3]);
}

static void func_header(unsigned long x, unsigned long off)
{
	unsigned long i;
	int ret;

	static const char *lut[] = {"void", "OMS_uint8", "OMS_uint16", "OMS_uint32"};

	/* dont care */
	x >>= 4;

	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);

	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:
        printf("kPascalStackBased");
        break;
    case 1:
        printf("kCStackBased");
        break;
    case 2:
        printf("I'm too lazy for this!");
	break;
    case 5:
        printf("kThinkCStackBased");
        break;
    case 8:
        printf("kD0DispatchedPascalStackBased");
        break;
    case 9:
        printf("kD0DispatchedCStackBased");
        break;
    case 12:
        printf("kD1DispatchedPascalStackBased");
        break;
    case 14:
        printf("kStackDispatchedPascalStackBased");
        break;
    default:
        return;
    }

    x >>= 4;

    printf(" | RESULT_SIZE(");
    decode_size(x);
    printf(")");

    /* trim the fat */
    x >>= 2;

    /* hopefully we're using stack, since that's the ONLY thing i'm handling */
    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("");

    return 0;
}