 | Patching XBE (Xbox Executable) |  |
Simply put...what patching an xbe does, it convert a debug xbox executable (.xbe) to a retail xbe, that can be run on a standard retail xbox..
First things first....we have 2 identical files...but one is patched and the other isn't....we'll create a short program to see what in essence patching an xbe changes...which offsets.
Size's are identical...e.g if one is 10.01kb, then the other is 10.01kb as well.
Anyhow, I wrote two programs so you could see what is actually happening, it will one improve your coding skills and two help you two see how simple it is to create an xbe patch program.
The first program below, will open two xbe files, called 'pcode.xbe' (e.g. patched xbe) and a non-patched xbe file called 'ncode.xbe'. It first checks the file sizes, and writes the file size of both file to a text file called info.txt...which will be created in the same directory as the main.exe program.
Following that, we'll compare byte by byte of each program and write out any differences and there location to the same text file.
// File: main.cpp // Author: bkenwright@xbdev.net // compare patched and non-patched xbe's #include <stdio.h> void debug(char *str) { FILE *fp; fp=fopen("info.txt", "a+"); fprintf(fp, "%s\n", str); fclose(fp); } // patched xbe is "pcode.xbe" // non-patched xbe is "ncode.xbe" #include <windows.h> #pragma comment(lib, "Kernel32.lib") int __stdcall WinMain(HINSTANCE, HINSTANCE, char*, int) { //------These few lines just confirm that the two files are identical sizes----- HANDLE h; DWORD dwSize1, dwSize2; h=CreateFile( "ncode.xbe", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0 ); dwSize1 = GetFileSize( h, NULL); CloseHandle(h); h=NULL; h=CreateFile( "pcode.xbe", GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, 0 ); dwSize2 = GetFileSize( h, NULL); CloseHandle(h); char sz1[400]; sprintf(sz1, "FileSize ncode.xbe: %u \t FileSize pcode.xbe: %u", dwSize1, dwSize2); debug(sz1); //-----Compare both files and show where they differ----- FILE *fp1 = fopen( "ncode.xbe", "rb" ); FILE *fp2 = fopen( "pcode.xbe", "rb" ); int e = 1; unsigned char buf1, buf2; unsigned int offset = 0; debug("\n"); debug("offset\t non-patched\t patched\n"); while (e) { e = fread(&buf1, 1, 1, fp1); e = fread(&buf2, 1, 1, fp2); offset++; if( buf1 != buf2) { char sz2[200]; // offset before after sprintf(sz2, "0x%.4X\t 0x%.4X\t 0x%.4X", offset, buf1, buf2); debug(sz2); } }
fclose(fp1); fclose(fp2); }
Output text file: (info.txt)
|