From 33be3da057f9c62f04751f9d44e4303840a27728 Mon Sep 17 00:00:00 2001 From: Kingcom Date: Mon, 2 Sep 2013 01:49:15 +0200 Subject: [PATCH] Try to detect if someone tries to open a PSX ISO --- Core/Loaders.cpp | 37 +++++++++++++++++++++++++++++++------ Core/Loaders.h | 1 + 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/Core/Loaders.cpp b/Core/Loaders.cpp index b85789fa58..305b1af9fc 100644 --- a/Core/Loaders.cpp +++ b/Core/Loaders.cpp @@ -35,9 +35,35 @@ IdentifiedFileType Identify_File(std::string &filename) return FILETYPE_ERROR; } + FileInfo info; + if (!getFileInfo(filename.c_str(), &info)) { + return FILETYPE_ERROR; + } + std::string extension = filename.size() >= 5 ? filename.substr(filename.size() - 4) : ""; if (!strcasecmp(extension.c_str(),".iso")) { + // may be a psx iso, they have 2352 byte sectors. You never know what some people try to open + if ((info.size % 2352) == 0) + { + FILE *f = File::OpenCFile(filename.c_str(), "rb"); + if (!f) { + // File does not exists + return FILETYPE_ERROR; + } + + unsigned char sync[12]; + fread(sync,1,12,f); + fclose(f); + + // each sector in a mode2 image starts with these 12 bytes + if (memcmp(sync,"\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\x00",12) == 0) + { + return FILETYPE_ISO_MODE2; + } + + // maybe it also just happened to have that size, + } return FILETYPE_PSP_ISO; } else if (!strcasecmp(extension.c_str(),".cso")) @@ -45,13 +71,8 @@ IdentifiedFileType Identify_File(std::string &filename) return FILETYPE_PSP_ISO; } - // First, check if it's a directory with an EBOOT.PBP in it. - FileInfo info; - if (!getFileInfo(filename.c_str(), &info)) { - return FILETYPE_ERROR; - } - if (info.isDirectory) { + // First, check if it's a directory with an EBOOT.PBP in it. if (info.isDirectory) { if (filename.size() > 4) { FileInfo ebootInfo; // Check for existence of EBOOT.PBP, as required for "Directory games". @@ -218,6 +239,10 @@ bool LoadFile(std::string &filename, std::string *error_string) { #endif break; + case FILETYPE_ISO_MODE2: + *error_string = "File is a MODE2 image. Are you trying to open a PSX game?"; + break; + case FILETYPE_NORMAL_DIRECTORY: ERROR_LOG(LOADER, "Just a directory."); *error_string = "Just a directory."; diff --git a/Core/Loaders.h b/Core/Loaders.h index b8f018bbe3..d08b96cf1a 100644 --- a/Core/Loaders.h +++ b/Core/Loaders.h @@ -36,6 +36,7 @@ enum IdentifiedFileType { FILETYPE_ARCHIVE_RAR, FILETYPE_ARCHIVE_ZIP, FILETYPE_PSP_PS1_PBP, + FILETYPE_ISO_MODE2, FILETYPE_NORMAL_DIRECTORY,