rpcsx/rpcs3/Loader/PUP.h

67 lines
1 KiB
C
Raw Normal View History

#pragma once
2020-12-12 13:01:29 +01:00
#include "util/types.hpp"
#include "../../Utilities/File.h"
#include <vector>
2017-02-22 14:08:53 +01:00
struct PUPHeader
{
le_t<u64> magic;
be_t<u64> package_version;
be_t<u64> image_version;
be_t<u64> file_count;
be_t<u64> header_length;
be_t<u64> data_length;
2017-02-22 14:08:53 +01:00
};
2017-02-22 14:08:53 +01:00
struct PUPFileEntry
{
be_t<u64> entry_id;
be_t<u64> data_offset;
be_t<u64> data_length;
u8 padding[8];
2017-02-22 14:08:53 +01:00
};
2017-02-22 14:08:53 +01:00
struct PUPHashEntry
{
be_t<u64> entry_id;
2017-02-22 14:08:53 +01:00
u8 hash[20];
u8 padding[4];
};
// PUP loading error
enum class pup_error : u32
{
ok,
stream,
header_read,
header_magic,
header_file_count,
expected_size,
file_entries,
hash_mismatch,
};
2017-02-22 14:08:53 +01:00
class pup_object
{
2021-04-03 18:38:02 +02:00
fs::file m_file{};
pup_error m_error{};
2021-04-03 18:38:02 +02:00
std::string m_formatted_error{};
2020-12-12 13:01:29 +01:00
2021-04-03 18:38:02 +02:00
std::vector<PUPFileEntry> m_file_tbl{};
std::vector<PUPHashEntry> m_hash_tbl{};
pup_error validate_hashes();
public:
pup_object(fs::file&& file);
explicit operator pup_error() const { return m_error; }
const std::string& get_formatted_error() const { return m_formatted_error; }
fs::file get_file(u64 entry_id) const;
2017-02-22 14:08:53 +01:00
};