|
From: Nicolas B. <ar...@us...> - 2005-10-19 21:00:45
|
Update of /cvsroot/nbftools/TyphoonNbfTool In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24438 Modified Files: DlgHeader.cpp DlgMain.cpp DlgMain.h NbfFile.cpp RUUHeader.cpp RUUHeader.h Log Message: Tornado ROM format support - bump to 0.4. Thanks to I-Mate for their contribution :p Index: RUUHeader.h =================================================================== RCS file: /cvsroot/nbftools/TyphoonNbfTool/RUUHeader.h,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- RUUHeader.h 7 May 2005 14:04:29 -0000 1.7 +++ RUUHeader.h 19 Oct 2005 21:00:36 -0000 1.8 @@ -27,6 +27,7 @@ char * GetVersion2(); char * GetOperatorID(); char GetNumSections(); + bool isTornado(); CRUUHeader(); virtual ~CRUUHeader(); @@ -34,6 +35,7 @@ unsigned static char Key[64]; unsigned char * pDecryptedHeader; unsigned char * pEncryptedHeader; + bool tornado; }; #endif \ No newline at end of file Index: DlgMain.cpp =================================================================== RCS file: /cvsroot/nbftools/TyphoonNbfTool/DlgMain.cpp,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- DlgMain.cpp 7 May 2005 14:16:28 -0000 1.16 +++ DlgMain.cpp 19 Oct 2005 21:00:36 -0000 1.17 @@ -516,7 +516,7 @@ EndDialog(hwndDlg, LOWORD(wParam)); return TRUE; case ID_HELP_ABOUT: - MessageBox(hwndDlg, TEXT("Typhoon NBF Tools\r\n\r\nTyphoon/Feeler ROM manipulation tool\r\n\r\nVersion " VERSION "\r\n\r\nhttp://www.spv-developers.com"), TEXT("Typhoon NBF Tools"), MB_OK); + MessageBox(hwndDlg, TEXT("Typhoon NBF Tools\r\n\r\nTyphoon/Feeler/Tornado ROM manipulation tool\r\n\r\nVersion " VERSION "\r\n\r\nhttp://www.spv-developers.com"), TEXT("Typhoon NBF Tools"), MB_OK); break; default: break; Index: DlgMain.h =================================================================== RCS file: /cvsroot/nbftools/TyphoonNbfTool/DlgMain.h,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- DlgMain.h 7 May 2005 14:04:18 -0000 1.7 +++ DlgMain.h 19 Oct 2005 21:00:36 -0000 1.8 @@ -15,7 +15,7 @@ #include "dlgheader.h" #include "Splash.h" -#define VERSION "0.3" +#define VERSION "0.4" class CDlgMain { Index: NbfFile.cpp =================================================================== RCS file: /cvsroot/nbftools/TyphoonNbfTool/NbfFile.cpp,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- NbfFile.cpp 7 May 2005 14:15:45 -0000 1.9 +++ NbfFile.cpp 19 Oct 2005 21:00:36 -0000 1.10 @@ -47,8 +47,8 @@ while(pRUUSections->m_pHead) pRUUSections->DelHead(); //Clear Sections List int i; - DWORD nOffset = 0x50; - DWORD nNBFOst = 0x200; + DWORD nOffset = (!pRUUHeader->isTornado() ? 0x50 : 0x204); + DWORD nNBFOst = (!pRUUHeader->isTornado() ? 0x200 : 0x400); CRUUSection * pSection; for(i=0;i<pRUUHeader->GetNumSections();i++) { @@ -108,6 +108,9 @@ ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST; // Display the Open dialog box. + + if (hFile) + CloseHandle(hFile); if (GetOpenFileName(&ofn)==TRUE) { hFile = CreateFile(ofn.lpstrFile, GENERIC_READ, @@ -122,7 +125,7 @@ DWORD nFSize = GetFileSize(hFile, NULL); DWORD nRead; unsigned char* pMemory; - pMemory = (unsigned char*)LocalAlloc(0, 0x200); + pMemory = (unsigned char*)LocalAlloc(0, 0x400); if(!pMemory) { MessageBox(CGlobals::hWndMainDlg, TEXT("Error") , TEXT("Failed allocating memory for NBF file"), MB_OK); @@ -130,9 +133,9 @@ return FALSE; } - ReadFile(hFile, pMemory, 0x200, &nRead, NULL); + ReadFile(hFile, pMemory, 0x400, &nRead, NULL); - if (nRead != 0x200) { + if (nRead != 0x400) { MessageBox(CGlobals::hWndMainDlg, TEXT("Error") , TEXT("Failed reading file"), MB_OK); LocalFree(pMemory); CloseHandle(hFile); Index: DlgHeader.cpp =================================================================== RCS file: /cvsroot/nbftools/TyphoonNbfTool/DlgHeader.cpp,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- DlgHeader.cpp 6 May 2005 00:11:04 -0000 1.4 +++ DlgHeader.cpp 19 Oct 2005 21:00:36 -0000 1.5 @@ -40,7 +40,7 @@ switch (LOWORD(wParam)) { case IDOK: - //Clear relevant header fields + //Clear relevant header fields CGlobals::pLoadedNbfFile->header()->Clear(); //Inject data from textboxes into header Index: RUUHeader.cpp =================================================================== RCS file: /cvsroot/nbftools/TyphoonNbfTool/RUUHeader.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- RUUHeader.cpp 6 May 2005 00:11:04 -0000 1.6 +++ RUUHeader.cpp 19 Oct 2005 21:00:36 -0000 1.7 @@ -2,6 +2,9 @@ // ////////////////////////////////////////////////////////////////////// +#include <stdio.h> +#include <stdlib.h> + #include "RUUHeader.h" unsigned char CRUUHeader::Key[64] = { @@ -17,8 +20,9 @@ CRUUHeader::CRUUHeader() { - pEncryptedHeader = (unsigned char *)LocalAlloc(0, 0x200); - pDecryptedHeader = (unsigned char *)LocalAlloc(0, 0x200); + pEncryptedHeader = (unsigned char *)LocalAlloc(0, 0x400); + pDecryptedHeader = (unsigned char *)LocalAlloc(0, 0x400); + tornado = false; if(!pEncryptedHeader || !pDecryptedHeader) { MessageBox(NULL, TEXT("LocalAlloc Error"), TEXT("Failed allocating memory for NBF header"), MB_OK); @@ -29,25 +33,27 @@ { LocalFree(pEncryptedHeader); LocalFree(pDecryptedHeader); -} - -unsigned char* CRUUHeader::decryptedHeader() { - return pDecryptedHeader; -} - -void CRUUHeader::SetEncrypted(unsigned char *data) { - CopyMemory(pEncryptedHeader, data, 0x200); -} - -void CRUUHeader::Clear() { - ZeroMemory(pDecryptedHeader + 0x00, 0x50); - ZeroMemory(pDecryptedHeader + 0x100, 0x10); -} - -bool CRUUHeader::CopyToFile(HANDLE hFile) { - DWORD nWritten; - WriteFile(hFile, pEncryptedHeader, 0x200, &nWritten, NULL); - return (nWritten == 0x200); +} + +unsigned char* CRUUHeader::decryptedHeader() { + return pDecryptedHeader; +} + +void CRUUHeader::SetEncrypted(unsigned char *data) { + tornado = false; + CopyMemory(pEncryptedHeader, data, 0x400); +} + +void CRUUHeader::Clear() { + // FIXME Tornado + ZeroMemory(pDecryptedHeader + 0x00, 0x50); + ZeroMemory(pDecryptedHeader + 0x100, 0x10); +} + +bool CRUUHeader::CopyToFile(HANDLE hFile) { + DWORD nWritten; + WriteFile(hFile, pEncryptedHeader, (!tornado ? 0x200 : 0x400), &nWritten, NULL); + return (nWritten == (!tornado ? 0x200 : 0x400)); } void CRUUHeader::Decrypt() @@ -55,13 +61,19 @@ unsigned char c=0; unsigned int i; - for(i=0;i<0x200;i++) { + for(i=0;i<0x400;i++) { pDecryptedHeader[i] = (pEncryptedHeader[i]-(unsigned char)i)^Key[c]; if(++c == 64) c=0; } + if (pDecryptedHeader[0xF8] > 8) + tornado = true; + //The CRC checksum at the end isn't encrypted. - *(DWORD*)(pDecryptedHeader+0x1FC) = *(DWORD*)(pEncryptedHeader+0x1FC); + if (!tornado) + *(DWORD*)(pDecryptedHeader+0x1FC) = *(DWORD*)(pEncryptedHeader+0x1FC); + else + *(DWORD*)(pDecryptedHeader+0x3FC) = *(DWORD*)(pEncryptedHeader+0x3FC); } void CRUUHeader::Encrypt() //Untested @@ -69,13 +81,16 @@ unsigned char c=0; unsigned int i; - for(i=0;i<0x200;i++) { - pEncryptedHeader[i] = (pDecryptedHeader[i]^Key[c])+(unsigned char)i; - if(++c == 64) c=0; + for(i=0;i<(!tornado ? 0x200 : 0x400);i++) { + pEncryptedHeader[i] = (pDecryptedHeader[i]^Key[c])+(unsigned char)i; + if(++c == 64) c=0; } //The CRC checksum at the end isn't encrypted. - *(DWORD*)(pEncryptedHeader+0x1FC) = *(DWORD*)(pDecryptedHeader+0x1FC); + if (!tornado) + *(DWORD*)(pEncryptedHeader+0x1FC) = *(DWORD*)(pDecryptedHeader+0x1FC); + else + *(DWORD*)(pEncryptedHeader+0x3FC) = *(DWORD*)(pDecryptedHeader+0x3FC); } char * CRUUHeader::GetManufacturer() { return (char*)&pDecryptedHeader[0x00]; } @@ -84,8 +99,9 @@ char * CRUUHeader::GetLanguage() { return (char*)&pDecryptedHeader[0x30]; } char * CRUUHeader::GetVersion2() { return (char*)&pDecryptedHeader[0x40]; } char * CRUUHeader::GetOperatorID() { return (char*)&pDecryptedHeader[0x100]; } -char CRUUHeader::GetNumSections() { return pDecryptedHeader[0xF8]; } -DWORD CRUUHeader::GetCRC32() { return *(DWORD*)(pDecryptedHeader + 0x1FC); } +char CRUUHeader::GetNumSections() { return (!tornado ? pDecryptedHeader[0xF8] : pDecryptedHeader[0x200]); } +DWORD CRUUHeader::GetCRC32() { return (!tornado ? *(DWORD*)(pDecryptedHeader + 0x1FC) : *(DWORD*)(pDecryptedHeader + 0x3FC)); } +bool CRUUHeader::isTornado() { return tornado; } void CRUUHeader::UpdateCRC() { @@ -93,12 +109,12 @@ TCHAR szMsg[100]; CCRC32::gen_crc_table(); - nCRC = CCRC32::update_crc(0, (unsigned char*)pDecryptedHeader, 0x1FC); + nCRC = CCRC32::update_crc(0, (unsigned char*)pDecryptedHeader, (!tornado ? 0x1FC : 0x3FC)); wsprintf(szMsg, TEXT("Calculated Header CRC-32: 0x%08X"), nCRC); MessageBox(CGlobals::hWndMainDlg, szMsg, "Calculated Header CRC32", MB_OK); - *(DWORD*)(pDecryptedHeader + 0x1FC) = nCRC; + *(DWORD*)(pDecryptedHeader + (!tornado ? 0x1FC : 0x3FC)) = nCRC; Encrypt(); } |