Welcome! Log In Create A New Profile

Advanced

Re-encrypting setting.txt on windows

Posted by Darkmystery 
Re-encrypting setting.txt on windows
October 25, 2009 12:18PM
Hi guise,

So, I bricked my wii a while ago to test bootmii by removing the complete system menu, which included the setting.txt (and wii serial number).
I fixed this by just putting a new setting.txt back on my wii by just modifying some of tona's tools. (setting_replace, anyregion changer) and used via bootmii->HBC.

But now, my consoleID has also changed. Which is annoying the crap out of me. (just personal issues :p)

Now my idea to fix this was just by decrypting my setting.txt (on windows), changing my consoleID manually, and then re-encrypting it to put it back on my wii.

Now, I just grabbed some code from tona's anyregion changer, compiled it with VC++08 and it successfully decrypted my setting.txt! But the problem is the reencrypting. The result I'm getting is not OK, it's only reencrypting the first 2 bytes, which has to do with the __SYSCONF_EndOfTextOffset() function and linebreaking on windows I guess..

But since I'm a horrible C coder, I'm unable to fix it. So I'm asking for your help here.

Here's my (90% tona's) current code, almost a 1:1 copy from anyregion changer's sysconf.c:

#include "stdafx.h"
#include "stdlib.h"
#include "memory.h"

static int __sysconf_buffer_txt_decrypted = 0; // When 0, perfect decryption, when 1, 2 byte reencryption.
static char __sysconf_txt_buffer[0x101];

int __SYSCONF_EndOfTextOffset(void){
	int i;
	int offset = 0;
	
	for (i = 0; i < 0x100; i++)
		if (!memcmp(__sysconf_txt_buffer+i, "\r\n", 2)) // searching for wrong line break?
			offset = i;
		
	offset += 2; //Only 2 bytes that the function returns.
	return offset;
}

void __SYSCONF_DecryptEncryptTextBuffer(void)
{
	unsigned long key = 0x73B5DBFA; // Magic stuffz here zomg
	int i;
	char *end = (char*)__sysconf_txt_buffer;
	
	if (__sysconf_buffer_txt_decrypted)
		end += __SYSCONF_EndOfTextOffset();
	
	for(i=0; i<0x100; i++) {
		printf("Decrypting.. %d", __sysconf_txt_buffer);
		__sysconf_txt_buffer ^= key & 0xff;
		key = (key<<1) | (key>>31);
		printf(" -> %d\n", __sysconf_txt_buffer);
	}
	
	__sysconf_buffer_txt_decrypted = !__sysconf_buffer_txt_decrypted;
	
	if (__sysconf_buffer_txt_decrypted)
		end += __SYSCONF_EndOfTextOffset();
	
	
	memset(end, 0, (__sysconf_txt_buffer+0x100)-end);
	
}

int main(int argc, char* argv[])
{
  FILE * pFile;
 
  pFile = fopen ("setting.txt" , "r");
  if (pFile==NULL) 
  {
	  fputs ("File error (setting.txt not found)\n",stderr); 
	  system("pause");
	  exit (1);
  }

  fread (__sysconf_txt_buffer,1,0x100,pFile);

__SYSCONF_DecryptEncryptTextBuffer();

  fclose (pFile);
  pFile = fopen ("setting_decrypted.txt" , "wb" );
  fwrite (__sysconf_txt_buffer, 1 , 0x100 , pFile);
  fclose (pFile);
  printf("Finished!\n");
  system("pause");
  exit (1);
  return 0;

}

I hope someone can help me out. Thanks in advance.



Edited 1 time(s). Last edit at 10/25/2009 12:19PM by Darkmystery.
Re: Re-encrypting setting.txt on windows
November 06, 2009 03:59PM
Anyone?
Re: Re-encrypting setting.txt on windows
November 08, 2009 11:00PM
Maybe "\r\n" returns unicode (4 bytes) so memcmp comparison doesn't work... Try compiling the program with no unicode support compilation option...



Alternatively you can use a char array with contents { 0x0d, 0x0a }



Edited 1 time(s). Last edit at 11/08/2009 11:01PM by I.R.on.
Re: Re-encrypting setting.txt on windows
November 17, 2009 01:09PM
Thanks, got it working. :)
Re: Re-encrypting setting.txt on windows
February 07, 2010 02:58AM
Sorry, for dragging up an old thread. But now SNEEK is out this becomes interesting again :)

I'm finding the same as the OP, this code can decrypt, but only encodes the first two bytes. I tried I.R.on's suggestion about the encoding, but to no avail. I don't know how to try the array suggestion.

Any help would be appreciated. Here's a VC++08 project for this: [www.mediafire.com]

Thanks.
Re: Re-encrypting setting.txt on windows
February 08, 2010 09:29AM
Open the original file (setting.txt) in binary mode to prevent windows translating end-of-line characters.
Sorry, only registered users may post in this forum.

Click here to login