Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

 

#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;
}

Posted
Last time I checked Software Development was a profession.

 

How about you come to my house and fix my door, thank you so much in advance.

 

i dont really understand your comment for there are many people out there that do this in there spare time so would you call them professionals ? and as far as fixing your door id be happy to as thats another thing i can do in my free time.i would maybe suggest you find a hobbie instead of wasting mine and your time being childish.thank you in advance ;)

Posted

For future reference, you'll typically get a better response if you ask for someone to point you in the right direction to either convert the code yourself, or purchas a software package to help you do it.

 

You will always get a better response if you ask for help instead of asking for someone to do your job for you.

~Nate�

___________________________________________

Please use the [vb]/[cs] tags on posted code.

Please post solutions you find somewhere else.

Follow me on Twitter here.

  • Leaders
Posted
Now that we've thoroughly explained Diesel's frustration, is there any particular part of the conversion that is troubling you? Or are all of those wacky curly braces just gibberish to you?
[sIGPIC]e[/sIGPIC]
Posted
Now that we've thoroughly explained Diesel's frustration, is there any particular part of the conversion that is troubling you? Or are all of those wacky curly braces just gibberish to you?

 

i am just going to learn the language so i can just do it myself.like you guys are telling me to do what i already know i have three quarters of it converted and i do kinda see whats what like the open file read it backwards seeking bla bla.i just didnt think it was very much there so it wouldn't be a problem for someone who knows this stuff much better then i.i am sorry to waste your time and if i came on looking like an a-hole that was never my intention.if i ever do post again i will make sure all my ducks are in line.again thank you for your time

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...