(winport) fix: #1543 fex identifying ROMs as compressed archives, causing crash (added a method to attempt to ID any kind of NDS rom before even passing it to FEX)
This commit is contained in:
parent
e0f8e5a82a
commit
40d4d80c25
|
@ -26,7 +26,7 @@
|
||||||
//#include "ndstool.h"
|
//#include "ndstool.h"
|
||||||
//#include "banner.h"
|
//#include "banner.h"
|
||||||
//#include "sha1.h"
|
//#include "sha1.h"
|
||||||
//#include "crc.h"
|
#include "crc.h"
|
||||||
//#include "bigint.h"
|
//#include "bigint.h"
|
||||||
//#include "arm7_sha1_homebrew.h"
|
//#include "arm7_sha1_homebrew.h"
|
||||||
//#include "arm7_sha1_nintendo.h"
|
//#include "arm7_sha1_nintendo.h"
|
||||||
|
@ -58,10 +58,22 @@
|
||||||
///*
|
///*
|
||||||
// * CalcLogoCRC
|
// * CalcLogoCRC
|
||||||
// */
|
// */
|
||||||
//unsigned short CalcLogoCRC(Header &header)
|
|
||||||
//{
|
extern unsigned short crc16tab[];
|
||||||
// return CalcCrc16((unsigned char *)&header + 0xC0, 156);
|
static short MyCalcCrc(unsigned char *data, unsigned int length)
|
||||||
//}
|
{
|
||||||
|
short crc = (short)~0;
|
||||||
|
for (unsigned int i=0; i<length; i++)
|
||||||
|
{
|
||||||
|
crc = (crc >> 8) ^ crc16tab[(crc ^ data[i]) & 0xFF];
|
||||||
|
}
|
||||||
|
return crc;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned short CalcLogoCRC(Header &header)
|
||||||
|
{
|
||||||
|
return MyCalcCrc((unsigned char *)&header + 0xC0, 156);
|
||||||
|
}
|
||||||
//
|
//
|
||||||
/*
|
/*
|
||||||
* DetectRomType
|
* DetectRomType
|
||||||
|
@ -656,3 +668,26 @@ int DetectRomType(const Header &header, char *secure)
|
||||||
//
|
//
|
||||||
// fclose(fNDS);
|
// fclose(fNDS);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
bool CheckLogoCRC(void* bytes512)
|
||||||
|
{
|
||||||
|
Header* header = (Header*)bytes512;
|
||||||
|
unsigned short crc = CalcLogoCRC(*header); //this isn't working, don't know why
|
||||||
|
return header->logo_crc == crc;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool DetectAnyRom(void* bytes512)
|
||||||
|
{
|
||||||
|
//if(CheckLogoCRC(bytes512)) return true; //this isn't working
|
||||||
|
|
||||||
|
//use other heuristics
|
||||||
|
Header* header = (Header*)bytes512;
|
||||||
|
//at least we have 5 bytes to ID here, not bad
|
||||||
|
if(header->rom_header_size != 0x4000) return false;
|
||||||
|
if(header->logo[0] != 0x24) return false;
|
||||||
|
if(header->logo_crc != 0xCF56) return false;
|
||||||
|
//if(header->zero[0] != 0) return false; //not sure if some weird demos will be packing data in here
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
|
@ -124,6 +124,9 @@ int HashAndCompareWithList(char *filename, unsigned char sha1[]);
|
||||||
int DetectRomType(const Header& header, char* secure);
|
int DetectRomType(const Header& header, char* secure);
|
||||||
unsigned short CalcSecureAreaCRC(bool encrypt);
|
unsigned short CalcSecureAreaCRC(bool encrypt);
|
||||||
|
|
||||||
|
bool CheckLogoCRC(void* bytes512);
|
||||||
|
bool DetectAnyRom(void* bytes512);
|
||||||
|
|
||||||
#define ROMTYPE_HOMEBREW 0
|
#define ROMTYPE_HOMEBREW 0
|
||||||
#define ROMTYPE_MULTIBOOT 1
|
#define ROMTYPE_MULTIBOOT 1
|
||||||
#define ROMTYPE_NDSDUMPED 2 // decrypted secure area
|
#define ROMTYPE_NDSDUMPED 2 // decrypted secure area
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
|
|
||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
#include "utils/decrypt/header.h"
|
||||||
|
|
||||||
static char Str_Tmp[1024];
|
static char Str_Tmp[1024];
|
||||||
|
|
||||||
|
@ -414,6 +415,15 @@ bool ObtainFile(const char* Name, char *const & LogicalName, char *const & Physi
|
||||||
|
|
||||||
while(true)
|
while(true)
|
||||||
{
|
{
|
||||||
|
//before sending to FEX, see if we're known to be an NDS file
|
||||||
|
//(this will stop games beginning with the name ZOO from being mis-recognized as a zoo file)
|
||||||
|
FILE* inf = fopen(PhysicalName,"rb");
|
||||||
|
u8 bytes512[512];
|
||||||
|
bool got512 = fread(bytes512,1,512,inf)==512;
|
||||||
|
fclose(inf);
|
||||||
|
if(got512 && DetectAnyRom(bytes512))
|
||||||
|
return true;
|
||||||
|
|
||||||
ArchiveFile archive (PhysicalName);
|
ArchiveFile archive (PhysicalName);
|
||||||
if(!archive.IsCompressed())
|
if(!archive.IsCompressed())
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue