Author Topic: kof98 decrypt/encrypt tool  (Read 36693 times)

Offline bankbank

  • Newbies
  • *
  • Posts: 32
  • Karma: +3/-0
kof98 decrypt/encrypt tool
« on: September 03, 2021, 04:11:10 AM »
I'm looking to implement a ratio hack into kof98 (mvs)

as you can see in mame's neogeo.cpp, it's encrypted:
Quote
ROM_START( kof98 ) /* encrypted code + protection */ /* MVS VERSION */

I found code from gngeo emulator for decryption:
https://raw.githubusercontent.com/ColumPaget/gngeo-cjp/master/src/neocrypt.c

Code: [Select]
/* Kof98 uses an early encryption, quite different from the others */
void kof98_decrypt_68k(running_machine *machine)
{
UINT8 *src = memory_region(machine, "maincpu");
UINT8 *dst = alloc_array_or_die(UINT8, 0x200000);
int i, j, k;
static const UINT32 sec[]={0x000000,0x100000,0x000004,0x100004,0x10000a,0x00000a,0x10000e,0x00000e};
static const UINT32 pos[]={0x000,0x004,0x00a,0x00e};

memcpy( dst, src, 0x200000);
for( i=0x800; i<0x100000; i+=0x200 )
{
for( j=0; j<0x100; j+=0x10 )
{
for( k=0; k<16; k+=2)
{
memcpy( &src[i+j+k],       &dst[ i+j+sec[k/2]+0x100 ], 2 );
memcpy( &src[i+j+k+0x100], &dst[ i+j+sec[k/2] ],       2 );
}
if( i >= 0x080000 && i < 0x0c0000)
{
for( k=0; k<4; k++ )
{
memcpy( &src[i+j+pos[k]],       &dst[i+j+pos[k]],       2 );
memcpy( &src[i+j+pos[k]+0x100], &dst[i+j+pos[k]+0x100], 2 );
}
}
else if( i >= 0x0c0000 )
{
for( k=0; k<4; k++ )
{
memcpy( &src[i+j+pos[k]],       &dst[i+j+pos[k]+0x100], 2 );
memcpy( &src[i+j+pos[k]+0x100], &dst[i+j+pos[k]],       2 );
}
}
}
memcpy( &src[i+0x000000], &dst[i+0x000000], 2 );
memcpy( &src[i+0x000002], &dst[i+0x100000], 2 );
memcpy( &src[i+0x000100], &dst[i+0x000100], 2 );
memcpy( &src[i+0x000102], &dst[i+0x100100], 2 );
}
memcpy( &src[0x100000], &src[0x200000], 0x400000 );

free(dst);
}

but I'm not good enough in C to implement this as a program.

is there anyone who can transform this into C code for me to compile? I need both to encrypt and decrypt.

I know iq_132 has a similar tool named 'p_dec but it is only for decrypting a few specific games, kof98 not included.

thank you!

edit: seems that AES version kof98h is unencrypted, so I can at least start there with ghidra and MAME debugger until I have the encrypt/decrypt tools necessary for kof98
« Last Edit: September 03, 2021, 06:33:49 AM by bankbank »