2018-07-28 17:30:54 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <array>
|
2020-01-11 17:33:48 +01:00
|
|
|
#include <boost/serialization/array.hpp>
|
2018-07-28 17:30:54 +02:00
|
|
|
#include "common/common_types.h"
|
|
|
|
#include "common/file_util.h"
|
|
|
|
|
|
|
|
namespace FileSys {
|
|
|
|
|
2020-02-07 05:45:54 +01:00
|
|
|
/**
|
|
|
|
* Interface for reading RomFS data.
|
|
|
|
*/
|
2018-07-28 17:30:54 +02:00
|
|
|
class RomFSReader {
|
|
|
|
public:
|
2020-02-07 09:26:33 +01:00
|
|
|
virtual ~RomFSReader() = default;
|
|
|
|
|
2020-02-07 05:45:54 +01:00
|
|
|
virtual std::size_t GetSize() const = 0;
|
|
|
|
virtual std::size_t ReadFile(std::size_t offset, std::size_t length, u8* buffer) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A RomFS reader that directly reads the RomFS file.
|
|
|
|
*/
|
|
|
|
class DirectRomFSReader : public RomFSReader {
|
|
|
|
public:
|
|
|
|
DirectRomFSReader(FileUtil::IOFile&& file, std::size_t file_offset, std::size_t data_size)
|
2018-07-28 17:30:54 +02:00
|
|
|
: is_encrypted(false), file(std::move(file)), file_offset(file_offset),
|
|
|
|
data_size(data_size) {}
|
|
|
|
|
2020-02-07 05:45:54 +01:00
|
|
|
DirectRomFSReader(FileUtil::IOFile&& file, std::size_t file_offset, std::size_t data_size,
|
|
|
|
const std::array<u8, 16>& key, const std::array<u8, 16>& ctr,
|
|
|
|
std::size_t crypto_offset)
|
2018-07-28 17:30:54 +02:00
|
|
|
: is_encrypted(true), file(std::move(file)), key(key), ctr(ctr), file_offset(file_offset),
|
|
|
|
crypto_offset(crypto_offset), data_size(data_size) {}
|
|
|
|
|
2020-02-07 09:26:33 +01:00
|
|
|
~DirectRomFSReader() override = default;
|
|
|
|
|
2020-02-07 05:45:54 +01:00
|
|
|
std::size_t GetSize() const override {
|
2018-07-28 17:30:54 +02:00
|
|
|
return data_size;
|
|
|
|
}
|
|
|
|
|
2020-02-07 05:45:54 +01:00
|
|
|
std::size_t ReadFile(std::size_t offset, std::size_t length, u8* buffer) override;
|
2018-07-28 17:30:54 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool is_encrypted;
|
|
|
|
FileUtil::IOFile file;
|
|
|
|
std::array<u8, 16> key;
|
|
|
|
std::array<u8, 16> ctr;
|
2020-01-11 17:33:48 +01:00
|
|
|
u64 file_offset;
|
|
|
|
u64 crypto_offset;
|
|
|
|
u64 data_size;
|
|
|
|
|
2020-03-07 22:23:08 +01:00
|
|
|
DirectRomFSReader() = default;
|
2020-01-11 17:33:48 +01:00
|
|
|
|
|
|
|
template <class Archive>
|
|
|
|
void serialize(Archive& ar, const unsigned int) {
|
|
|
|
ar& is_encrypted;
|
|
|
|
ar& file;
|
|
|
|
ar& key;
|
|
|
|
ar& ctr;
|
|
|
|
ar& file_offset;
|
|
|
|
ar& crypto_offset;
|
|
|
|
ar& data_size;
|
|
|
|
}
|
|
|
|
friend class boost::serialization::access;
|
2018-07-28 17:30:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace FileSys
|