hi all i was wondering if anyone could update this bit of code so i can use it in future vb.net projects.thank you so much in advance
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void usage(char *str)
{
printf("Usage (descramble): %s -d [input module] [output scramble]\nUsage (scramble): %s -s [input scramble] [output/input module]\n", str, str);
}
void rescramble(FILE *fp, FILE *out, char *str)
{
int i;
int code = 0, mtc1 = 0, ori = 0, lui = 0, patch = 0, addr_patched = 0;
printf("Scrambling %s... ", str);
fseek(out, 0, SEEK_END);
int size = ftell(out);
size = (size - (size % 4)) / 4;
for (i = size - 1; i > -1; i--)
{
fseek(out, i * sizeof(int), SEEK_SET);
fread(&code, sizeof(int), 1, out);
fseek(out, i * sizeof(int), SEEK_SET);
if ((code >> 16) == 0x4481)
{
mtc1 = 1;
fseek(fp, sizeof(int) * addr_patched, SEEK_SET);
fread(&patch, sizeof(int), 1, fp);
}
else if (mtc1 && ((code >> 16) == 0x3421))
{
ori = 0x34210000 | (patch & 0xFFFF);
if (ori != code)
{
fwrite(&ori, sizeof(int), 1, out);
}
}
else if (mtc1 && ((code >> 16) == 0x3C01))
{
lui = 0x3C010000 | ((patch >> 16) & 0xFFFF);
if (lui != code)
{
fwrite(&lui, sizeof(int), 1, out);
}
ori = 0;
mtc1 = 0;
lui = 0;
addr_patched++;
}
}
fclose(out);
fclose(fp);
printf("OK\n");
}
void descramble(FILE *fp, FILE *out, char *str)
{
int i;
int code = 0, mtc1 = 0, ori = 0, lui = 0;
printf("Descrambling %s... ", str);
fseek(fp, 0, SEEK_END);
int size = ftell(fp);
size = (size - (size % 4)) / 4;
for (i = size - 1; i > -1; i--)
{
fseek(fp, i * sizeof(int), SEEK_SET);
fread(&code, sizeof(int), 1, fp);
if ((code >> 16) == 0x4481)
{
mtc1 = 1;
}
else if (mtc1 && ((code >> 16) == 0x3421))
{
ori = code & 0xFFFF;
}
else if (mtc1 && ((code >> 16) == 0x3C01))
{
lui = (code & 0xFFFF) << 16;
if (ori)
{
lui |= ori;
}
fwrite(&lui, sizeof(int), 1, out);
ori = 0;
mtc1 = 0;
lui = 0;
}
}
fclose(fp);
fclose(out);
printf("OK\n");
}
int main(int argc, char *argv[])
{
printf("Descrambler");
if (argc != 4)
{
usage(argv[0]);
return -1;
}
FILE *fp = fopen(argv[2], "rb");
if (!fp)
{
printf("Error opening input!\n");
return -2;
}
FILE *out = fopen(argv[3], (strcmp(argv[1], "-s") == 0) ? "rb+" : "wb");
if (!out)
{
printf("Error opening output!\n");
return -3;
}
if (strcmp(argv[1], "-d") == 0)
{
descramble(fp, out, argv[2]);
}
else if (strcmp(argv[1], "-s") == 0)
{
rescramble(fp, out, argv[3]);
}
else
{
usage(argv[0]);
return -1;
}
return 0;
}