Skip to content

Instantly share code, notes, and snippets.

@CodeAsm
Created July 4, 2020 10:55
Show Gist options
  • Save CodeAsm/ec596c702a634a8a57f00bc1df36d7ca to your computer and use it in GitHub Desktop.
Save CodeAsm/ec596c702a634a8a57f00bc1df36d7ca to your computer and use it in GitHub Desktop.
Xbox eeprom dump and writer, buggy, donot use if not reading code
#include <hal/debug.h>
#include <hal/video.h>
#include <nxdk/mount.h>
#include <stdio.h>
#include <windows.h>
#include <stdbool.h>
/// Bunnie Huang eeprom
char array[] = {
0xE3, 0x1C, 0x5C, 0x23, 0x6A, 0x58, 0x68, 0x37,
0xB7, 0x12, 0x26, 0x6C, 0x99, 0x11, 0x30, 0xD1,
0xE2, 0x3E, 0x4D, 0x56, 0xF7, 0x73, 0x2B, 0x73,
0x85, 0xFE, 0x7F, 0x0A, 0x08, 0xEF, 0x15, 0x3C,
0x77, 0xEE, 0x6D, 0x4E, 0x93, 0x2F, 0x28, 0xEE,
0xF8, 0x61, 0xF7, 0x94, 0x17, 0x1F, 0xFC, 0x11,
0x0B, 0x84, 0x44, 0xED, 0x31, 0x30, 0x35, 0x35,
0x38, 0x31, 0x31, 0x31, 0x34, 0x30, 0x30, 0x33,
0x00, 0x50, 0xF2, 0x4F, 0x65, 0x52, 0x00, 0x00,
0x0A, 0x1E, 0x35, 0x33, 0x71, 0x85, 0x31, 0x4D,
0x59, 0x12, 0x38, 0x48, 0x1C, 0x91, 0x53, 0x60,
0x00, 0x01, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00,
0x75, 0x61, 0x57, 0xFB, 0x2C, 0x01, 0x00, 0x00,
0x45, 0x53, 0x54, 0x00, 0x45, 0x44, 0x54, 0x02,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x0A, 0x05, 0x00, 0x02, 0x03, 0x05, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xC4, 0xFF, 0xFF, 0xFF,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
int PrintDrive(char Drive){
char *path = "E:\\*.*";
WIN32_FIND_DATA findFileData;
HANDLE hFind;
// Like on Windows, "*.*" and "*" will both list all files,
// no matter whether they contain a dot or not
hFind = FindFirstFile(path, &findFileData);
if (hFind == INVALID_HANDLE_VALUE) {
debugPrint("FindFirstHandle() failed!\n");
Sleep(5000);
return 1;
}
do {
if (findFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
debugPrint("Directory: ");
} else {
debugPrint("File : ");
}
debugPrint("%s\n", findFileData.cFileName);
} while (FindNextFile(hFind, &findFileData) != 0);
debugPrint("\n");
DWORD error = GetLastError();
if (error == ERROR_NO_MORE_FILES) {
debugPrint("===========================.\n");
} else {
debugPrint("error: %x\n", error);
}
FindClose(hFind);
return 0;
}
void readFile(char* path){
unsigned char eeprom_buffer[256];
FILE *file;
file = fopen(path, "r");
int count = fread(&eeprom_buffer, 1, 256, file);
fclose(file);
if (count != 256) {
debugPrint("Something bad happened.\n");
Sleep(1000);
}
for (int i = 0; i < 256; ++i){
array[i] = eeprom_buffer[i];
}
}
void PrintFile(char array[]){
int eeprom_size = 256;
int count = 0;
int row = 0;
debugPrint("%.3X: ", row); // print the first row number
for (int i = 0; i < eeprom_size; ++i){
debugPrint("%.2x", array[i] & 0xff); //print the actual hex value at i
count++;
if(count>=16 ){ //row size 16
debugPrint(" "); //Print the chars human readable
//if(count>=16 && i+1 !=eeprom_size )
for (int x = 15; x > 0; x--){
if(array[i-x] == 0x0 || array[i-x] == 0x0A ){
debugPrint("."); // skip these, they break the print
}else{
debugPrint("%c", array[i-x] & 0xff); // the actual print human read
}
}
row+=16;
count=0;
debugPrint("\n");
if(i+1 !=eeprom_size) // if end of file, then dont do next
debugPrint("%.3X: ", row); // Like the first, print row number
}
}
}
BOOL write_file(const char *name, unsigned char *buffer, size_t buffer_size){
FILE *file;
file = fopen(name, "w");
if (file == NULL) {
debugPrint("Failed opening file to write.\n");
return FALSE;
}
if (fwrite(buffer, 1, buffer_size, file) != buffer_size) {
debugPrint("Failed writing the buffer to disk.\n");
fclose(file);
return FALSE;
}
fclose(file);
PrintFile(buffer);
return TRUE;
}
int main(void)
{
XVideoSetMode(640, 480, 32, REFRESH_DEFAULT);
debugPrint("Xbox Eeprom thingy.\n");
debugPrint("==============================.\n");
if (!nxMountDrive('E', "\\Device\\Harddisk0\\Partition1\\")) {
debugPrint("Failed to mount E: drive!\n");
return 1;
}
if (!nxMountDrive('C', "\\Device\\Harddisk0\\Partition2\\")) {
debugPrint("Failed to mount C: drive!\n");
return 1;
}
PrintDrive('D');
Sleep(2000);
debugPrint("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
debugPrint("Deleting eeprom\n");
const char *eeprom_name = "E:\\eeprom.bin";
DeleteFileA(eeprom_name);
PrintDrive('D');
Sleep(5000);
debugPrint("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
/* write_file(eeprom_name, array, 0x256);
debugPrint("Just wrote standard eeprom\n");
Sleep(2000);
debugPrint("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
PrintDrive('D');
debugPrint("Eeprom file? now print it\n");
Sleep(2000);
debugPrint("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
readFile(eeprom_name);
debugPrint("did write succes?\n");
PrintDrive('D');
debugPrint("show it\n");
Sleep(2000);
debugPrint("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
PrintFile(array);
Sleep(5000);
debugPrint("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
*/
/* debugPrint("empty array..");
for (int i = 0; i <= 255; i++) {
array[i] = ' ';
debugPrint("_");
}
*/
Sleep(2000);
PrintFile(array);
Sleep(2000);
// debugPrint("Now read eeprom from MB\n");
/*UCHAR end = 255;
for (int i = 0; i <= 255; i++) {
ULONG DataValue;
debugPrint("-");
HalReadSMBusValue(0xA8, i, 0, DataValue);
debugPrint("%X ", DataValue);
//debugPrint("%d ", i);
Sleep(1);
}
*/
ULONG bytes_read;
ULONG eeprom_type;
ExQueryNonVolatileSetting(0xFFFF, &eeprom_type, array, (ULONG)256, &bytes_read);
Sleep(2000);
debugPrint("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
debugPrint("Is MB eeprom ");
PrintFile(array);
//debugPrint("Writing eeprom to disk ");
//write_file(eeprom_name, array, 0x256);
//debugPrint("done "); */
Sleep(5000);
for (int i = 0; i < 256; i++) {
HalWriteSMBusValue(0xA8, i, 0, array[i]);
}
debugPrint("writing MB done ");
debugPrint("\n\n\n\n\n\n\n\n\n\n");
ExQueryNonVolatileSetting(0xFFFF, &eeprom_type, array, (ULONG)256, &bytes_read);
Sleep(2000);
PrintFile(array);
debugPrint("Was MB eeprom ");
Sleep(5000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment