Tuesday, March 24, 2015

Freedom Fighter PIF Board

I've been working on improving the VP-931 code for Dexter (used by Firefox) so this was a good time for me to take a look at Freedom Fighter also.  I've reversed engineered the schematics for the PIF prototype board and also written a little utility to "decrypt" the PIF ROM.


Here's the utility:

// Freedom Fighter PIF board has the ROM data lines scrambled, presumably to try to prevent reverse engineering.
// Here is how the ROM data lines match up to the CPU's data lines (verified using multimeter):

// CPU data line ROM data line
// 0 2
// 1 6
// 2 5
// 3 4
// 4 3
// 5 7
// 6 1
// 7 0

#include <stdio.h>
#include <stdexcept>

using namespace std;

int main(int argc, char **argv)
{
if (argc != 3)
{
fprintf(stderr, "Usage: %s [src scrambled rom file] [destination unscrambled rom file]\n");
return 1;
}

try
{
unsigned char u8 = 0;
FILE *F = fopen(argv[1], "rb");

if (!F)
{
throw runtime_error("Cannot open src file");
}
FILE *G = fopen(argv[2], "wb");

if (!G)
{
throw runtime_error("Cannot open destination file");
}

for (;;)
{
int i = fgetc(F);

// EOF ?
if (i == EOF)
{
break;
}

// do bit manipulation
u8 = 0;
u8 |= (((i >> 7) << 0) & (1 << 0));
u8 |= (((i >> 6) << 1) & (1 << 1));
u8 |= (((i >> 0) << 2) & (1 << 2));
u8 |= (((i >> 4) << 3) & (1 << 3));
u8 |= (((i >> 3) << 4) & (1 << 4));
u8 |= (((i >> 2) << 5) & (1 << 5));
u8 |= (((i >> 1) << 6) & (1 << 6));
u8 |= (((i >> 5) << 7) & (1 << 7));

fputc(u8, G);
}

fclose(G);
fclose(F);

return 0;
}
catch (std::exception &ex)
{
fprintf(stderr, "%s\n", ex.what());
return 1;
}
}

No comments:

Post a Comment