2012-11-01 15:19:01 +00:00
|
|
|
// Copyright (c) 2012- PPSSPP Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
2012-11-04 22:01:49 +00:00
|
|
|
// the Free Software Foundation, version 2.0 or later versions.
|
2012-11-01 15:19:01 +00:00
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official git repository and contact information can be found at
|
|
|
|
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
// Abstractions around read-only blockdevices, such as PSP UMD discs.
|
|
|
|
// CISOFileBlockDevice implements compressed iso images, CISO format.
|
|
|
|
//
|
|
|
|
// The ISOFileSystemReader reads from a BlockDevice, so it automatically works
|
|
|
|
// with CISO images.
|
|
|
|
|
2013-12-30 09:17:11 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2013-04-27 21:16:51 +00:00
|
|
|
#include "Core/ELF/PBPReader.h"
|
|
|
|
|
2014-11-23 21:59:56 +00:00
|
|
|
class FileLoader;
|
|
|
|
|
2012-11-01 15:19:01 +00:00
|
|
|
class BlockDevice
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~BlockDevice() {}
|
|
|
|
virtual bool ReadBlock(int blockNumber, u8 *outPtr) = 0;
|
2014-11-03 05:43:27 +00:00
|
|
|
virtual bool ReadBlocks(u32 minBlock, int count, u8 *outPtr) {
|
2014-11-03 03:50:26 +00:00
|
|
|
for (int b = 0; b < count; ++b) {
|
|
|
|
if (!ReadBlock(minBlock + b, outPtr)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
outPtr += GetBlockSize();
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2012-11-01 15:19:01 +00:00
|
|
|
int GetBlockSize() const { return 2048;} // forced, it cannot be changed by subclasses
|
2013-01-19 21:48:20 +00:00
|
|
|
virtual u32 GetNumBlocks() = 0;
|
2012-11-01 15:19:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class CISOFileBlockDevice : public BlockDevice
|
|
|
|
{
|
2013-01-02 20:00:10 +00:00
|
|
|
public:
|
2014-11-23 21:59:56 +00:00
|
|
|
CISOFileBlockDevice(FileLoader *fileLoader);
|
2013-01-02 20:00:10 +00:00
|
|
|
~CISOFileBlockDevice();
|
2014-11-03 05:43:27 +00:00
|
|
|
bool ReadBlock(int blockNumber, u8 *outPtr) override;
|
|
|
|
bool ReadBlocks(u32 minBlock, int count, u8 *outPtr) override;
|
2014-12-08 20:14:35 +00:00
|
|
|
u32 GetNumBlocks() override { return numBlocks; }
|
2013-01-02 20:00:10 +00:00
|
|
|
|
|
|
|
private:
|
2014-11-23 21:59:56 +00:00
|
|
|
FileLoader *fileLoader_;
|
2012-11-01 15:19:01 +00:00
|
|
|
u32 *index;
|
2014-10-26 04:16:43 +00:00
|
|
|
u8 *readBuffer;
|
|
|
|
u8 *zlibBuffer;
|
|
|
|
u32 zlibBufferFrame;
|
|
|
|
u8 indexShift;
|
|
|
|
u8 blockShift;
|
|
|
|
u32 frameSize;
|
2013-01-19 21:48:20 +00:00
|
|
|
u32 numBlocks;
|
2014-10-26 04:16:43 +00:00
|
|
|
u32 numFrames;
|
2012-11-01 15:19:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class FileBlockDevice : public BlockDevice
|
|
|
|
{
|
|
|
|
public:
|
2014-11-23 21:59:56 +00:00
|
|
|
FileBlockDevice(FileLoader *fileLoader);
|
2012-11-01 15:19:01 +00:00
|
|
|
~FileBlockDevice();
|
2014-10-30 23:14:00 +00:00
|
|
|
bool ReadBlock(int blockNumber, u8 *outPtr) override;
|
2014-11-03 05:43:27 +00:00
|
|
|
bool ReadBlocks(u32 minBlock, int count, u8 *outPtr) override;
|
2014-11-23 21:59:56 +00:00
|
|
|
u32 GetNumBlocks() override {return (u32)(filesize_ / GetBlockSize());}
|
2013-01-02 20:00:10 +00:00
|
|
|
|
|
|
|
private:
|
2014-11-23 21:59:56 +00:00
|
|
|
FileLoader *fileLoader_;
|
|
|
|
u64 filesize_;
|
2012-11-01 15:19:01 +00:00
|
|
|
};
|
2013-03-30 14:44:10 +00:00
|
|
|
|
|
|
|
|
2013-04-27 21:16:51 +00:00
|
|
|
// For encrypted ISOs in PBP files.
|
|
|
|
|
2013-05-08 15:36:57 +00:00
|
|
|
struct table_info {
|
|
|
|
u8 mac[16];
|
|
|
|
u32 offset;
|
|
|
|
int size;
|
|
|
|
int flag;
|
|
|
|
int unk_1c;
|
|
|
|
};
|
|
|
|
|
2013-04-27 21:16:51 +00:00
|
|
|
class NPDRMDemoBlockDevice : public BlockDevice
|
|
|
|
{
|
|
|
|
public:
|
2014-11-23 21:59:56 +00:00
|
|
|
NPDRMDemoBlockDevice(FileLoader *fileLoader);
|
2013-04-27 21:16:51 +00:00
|
|
|
~NPDRMDemoBlockDevice();
|
|
|
|
|
2014-10-30 23:14:00 +00:00
|
|
|
bool ReadBlock(int blockNumber, u8 *outPtr) override;
|
|
|
|
u32 GetNumBlocks() override {return (u32)lbaSize;}
|
2013-04-27 21:16:51 +00:00
|
|
|
|
|
|
|
private:
|
2014-11-23 21:59:56 +00:00
|
|
|
FileLoader *fileLoader_;
|
2013-05-08 15:36:57 +00:00
|
|
|
u32 lbaSize;
|
|
|
|
|
|
|
|
u32 psarOffset;
|
|
|
|
int blockSize;
|
|
|
|
int blockLBAs;
|
|
|
|
u32 numBlocks;
|
|
|
|
|
|
|
|
u8 vkey[16];
|
|
|
|
u8 hkey[16];
|
|
|
|
struct table_info *table;
|
|
|
|
|
|
|
|
int currentBlock;
|
|
|
|
u8 *blockBuf;
|
|
|
|
u8 *tempBuf;
|
2013-04-27 21:16:51 +00:00
|
|
|
};
|
|
|
|
|
2014-10-30 23:14:00 +00:00
|
|
|
// This simply fully reads another block device and caches it in RAM.
|
|
|
|
// A bit slow to initialize.
|
|
|
|
class RAMBlockDevice : public BlockDevice
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RAMBlockDevice(BlockDevice *device);
|
|
|
|
~RAMBlockDevice();
|
|
|
|
|
2014-10-30 23:35:39 +00:00
|
|
|
bool ReadBlock(int blockNumber, u8 *outPtr) override;
|
|
|
|
u32 GetNumBlocks() override;
|
2014-10-30 23:14:00 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
int totalBlocks_;
|
|
|
|
u8 *image_;
|
|
|
|
};
|
|
|
|
|
2013-04-27 21:16:51 +00:00
|
|
|
|
2014-11-23 21:59:56 +00:00
|
|
|
BlockDevice *constructBlockDevice(FileLoader *fileLoader);
|