Skip to content

Commit

Permalink
Check for zip/rar header in the extractor.
Browse files Browse the repository at this point in the history
  • Loading branch information
louist103 committed Oct 15, 2023
1 parent 5ddc418 commit 9640206
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
22 changes: 22 additions & 0 deletions soh/soh/Extractor/Extract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ void Extractor::ShowCrcErrorBox() const {
ShowErrorBox("Rom CRC invalid", "Rom CRC did not match the list of known good roms. Please find another.");
}

void Extractor::ShowCompressedErrorBox() const {
ShowErrorBox("File is Compressed", "The selected file appears to be compressed. Please extract before using.");
}

int Extractor::ShowRomPickBox(uint32_t verCrc) const {
std::unique_ptr<char[]> boxBuffer = std::make_unique<char[]>(mCurrentRomPath.size() + 100);
SDL_MessageBoxData boxData = { 0 };
Expand Down Expand Up @@ -328,6 +332,20 @@ bool Extractor::ValidateAndFixRom() {
return false;
}

// The file box will only allow selecting an n64 rom but typing in the file name will allow selecting anything.
bool Extractor::ValidateNotCompressed() const {
// ZIP file header
if (mRomData[0] == 'P' && mRomData[1] == 'K' && mRomData[2] == 0x03 && mRomData[3] == 0x04) {
return 0;
}
// RAR file header. Only the first 4 bytes.
if (mRomData[0] == 'R' && mRomData[1] == 'a' && mRomData[2] == 'r' && mRomData[3] == 0x21) {
return 0;
}

return 1;
}

bool Extractor::ValidateRomSize() const {
if (mCurRomSize != MB32 && mCurRomSize != MB54 && mCurRomSize != MB64) {
return false;
Expand All @@ -336,6 +354,10 @@ bool Extractor::ValidateRomSize() const {
}

bool Extractor::ValidateRom(bool skipCrcTextBox) {
if (!ValidateNotCompressed()) {
ShowCompressedErrorBox();
return false;
}
if (!ValidateRomSize()) {
ShowSizeErrorBox();
return false;
Expand Down
2 changes: 2 additions & 0 deletions soh/soh/Extractor/Extract.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class Extractor {
bool ValidateRomSize() const;

bool ValidateRom(bool skipCrcBox = false);
bool ValidateNotCompressed() const;
const char* GetZapdVerStr() const;

void SetRomInfo(const std::string& path);
Expand All @@ -46,6 +47,7 @@ class Extractor {
void GetRoms(std::vector<std::string>& roms);
void ShowSizeErrorBox() const;
void ShowCrcErrorBox() const;
void ShowCompressedErrorBox() const;
int ShowRomPickBox(uint32_t verCrc) const;
bool ManuallySearchForRom();
bool ManuallySearchForRomMatchingType(RomSearchMode searchMode);
Expand Down

0 comments on commit 9640206

Please sign in to comment.