bool loadCODE0Segment() { boost::scoped_ptr<DataPair> code0(resourceFork.getResource(kCodeTag, 0)); if (!code0) { // XXX error message return false; } const uint32_t sizeAboveA5 = readUint32BE(code0->data + 0); const uint32_t globalsSize = readUint32BE(code0->data + 4); const uint32_t jumpTableSize = readUint32BE(code0->data + 8); const uint32_t jumpTableOffset = readUint32BE(code0->data + 12); if (sizeAboveA5 < jumpTableOffset + jumpTableSize) { // XXX error message return false; } const uint32_t realJumpTableSize = sizeAboveA5 - jumpTableOffset; if (realJumpTableSize > jumpTableSize && jumpTableSize != 8) { // XXX error message return false; } Memory::allocateGlobals(globalsSize); Memory::allocateAboveA5(sizeAboveA5); Memory::initializeParameters(jumpTableOffset); Memory::initializeJumpTable(jumpTableOffset, realJumpTableSize, jumpTableSize, code0->data + 16); return true; }
bool ScummFile::openSubFile(const Common::String &filename) { assert(isOpen()); // Disable the XOR encryption and reset any current subfile range setEnc(0); resetSubfile(); // Read in the filename table and look for the specified file unsigned long file_off, file_len; char file_name[0x20+1]; unsigned long i; // Get the length of the data file to use for consistency checks const uint32 data_file_len = size(); // Read offset and length to the file records */ const uint32 file_record_off = readUint32BE(); const uint32 file_record_len = readUint32BE(); // Do a quick check to make sure the offset and length are good if (file_record_off + file_record_len > data_file_len) { return false; } // Do a little consistancy check on file_record_length if (file_record_len % 0x28) { return false; } // Scan through the files for (i = 0; i < file_record_len; i += 0x28) { // read a file record seek(file_record_off + i, SEEK_SET); file_off = readUint32BE(); file_len = readUint32BE(); read(file_name, 0x20); file_name[0x20] = 0; assert(file_name[0]); //debug(7, " extracting \'%s\'", file_name); // Consistency check. make sure the file data is in the file if (file_off + file_len > data_file_len) { return false; } if (scumm_stricmp(file_name, filename.c_str()) == 0) { // We got a match! setSubfileRange(file_off, file_len); return true; } } return false; }
void readFileList(std::ifstream &stream, std::list<FileInfo> &files, uint32 count) { int startOffset = count * 20 + 4; while (count-- > 0) { FileInfo file; readFixedString(stream, file.name, 12); file.size = readUint32BE(stream); file.offset = readUint32BE(stream) + startOffset; files.push_back(file); } }
bool Nicookie::safariFindPage(QIODevice &device) { qint64 begin_pos = device.pos(); // Page Header quint32 page_header = readUint32BE(device); if (page_header != 0x00000100) { setError(Nicookie::InvalidDataFormtaError); return false; } // No. of cookies quint32 cookie_num = readUint32LE(device); if (cookie_num == 0) { // エラーじゃ無い? return false; } // Cookie N offset QList<quint32> cookie_offset_list; for (quint32 i = 0; i < cookie_num; i++) { cookie_offset_list.append(readUint32LE(device)); } // Cookie N for (auto &cookie_offset: cookie_offset_list) { device.seek(begin_pos + cookie_offset); if (safariFindCookie(device)) return true; } return false; }
int main(int argc, char **argv) { if (argc < 2) { printHelp(argv[0]); return -1; } std::ifstream pgfFile; pgfFile.open(argv[1]); if (!pgfFile.is_open()) { printf("Error opening file \"%s\"\n", argv[1]); return -1; } uint32 fileCount = readUint32BE(pgfFile); printf("Number of file: %d\n", fileCount); std::list<FileInfo> files; readFileList(pgfFile, files, fileCount); extractFiles(pgfFile, files); files.clear(); pgfFile.close(); return 0; }
static void readIso(FILE *fp, int block, int flags) { if (block < 0) { uint8_t buf[128]; fread(buf, sizeof(buf), 1, fp); if (buf[0] == 1 && memcmp(buf + 40, "CD-ROM", 6) == 0) { const int offset = readUint32BE(buf + 100); readIso(fp, offset, 0); } } else { uint32_t attr = 0; do { fseek(fp, block * BLOCK_SIZE + 20, SEEK_SET); do { uint8_t buf[72]; fread(buf, sizeof(buf), 1, fp); attr = readUint32BE(buf); const char *name = (const char *)buf + 32; const uint32_t count = readUint32BE(buf + 64); const uint32_t offset = readUint32BE(buf + 68); fseek(fp, count * 4, SEEK_CUR); switch (attr & 255) { case 2: if (flags & 1) { const int pos = ftell(fp); dumpGameData(name, fp, offset * BLOCK_SIZE, readUint32BE(buf + 16)); fseek(fp, pos, SEEK_SET); } break; case 7: if (strcmp(name, GAMEDATA_DIRECTORY) == 0) { readIso(fp, offset, 1); } break; } } while (attr < 256); ++block; } while ((attr >> 24) == 0x40); } }
bool Nicookie::safariFindFile(QIODevice &device) { // Signature QByteArray headr_signature("cook", 4); if (headr_signature != device.read(4)) { setError(Nicookie::InvalidDataFormtaError); return false; } // No. of pages quint32 page_num = readUint32BE(device); if (page_num == 0) { setError(Nicookie::NotFoundDataError); return false; } // Page N Size QList<quint32> page_size_list; for (quint32 i = 0; i < page_num; ++i) { page_size_list.append(readUint32BE(device)); } if (device.atEnd()) { setError(Nicookie::InvalidDataFormtaError); return false; } // Page N for (auto &page_size: page_size_list) { qint64 pos = device.pos(); if (safariFindPage(device)) return true; device.seek(pos + page_size); } if (!hasError()) { setError(Nicookie::NotFoundDataError); } return false; }