CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/Core/ELF/PBPReader.h
Views: 1401
1
// Copyright (c) 2013- PPSSPP Project.
2
3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, version 2.0 or later versions.
6
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
// GNU General Public License 2.0 for more details.
11
12
// A copy of the GPL 2.0 should have been included with the program.
13
// If not, see http://www.gnu.org/licenses/
14
15
// Official git repository and contact information can be found at
16
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
17
18
19
#pragma once
20
21
#include <vector>
22
23
#include "Common/CommonTypes.h"
24
#include "Common/Swap.h"
25
26
enum PBPSubFile {
27
PBP_PARAM_SFO,
28
PBP_ICON0_PNG,
29
PBP_ICON1_PMF,
30
PBP_PIC0_PNG,
31
PBP_PIC1_PNG,
32
PBP_SND0_AT3,
33
PBP_EXECUTABLE_PSP,
34
PBP_UNKNOWN_PSAR,
35
};
36
37
struct PBPHeader {
38
char magic[4];
39
u32_le version;
40
u32_le offsets[8];
41
};
42
43
class FileLoader;
44
45
class PBPReader {
46
public:
47
PBPReader(FileLoader *fileLoader);
48
~PBPReader();
49
50
bool IsValid() const { return file_ != nullptr; }
51
bool IsELF() const { return file_ == nullptr && isELF_; }
52
53
bool GetSubFile(PBPSubFile file, std::vector<u8> *out);
54
void GetSubFileAsString(PBPSubFile file, std::string *out);
55
56
size_t GetSubFileSize(PBPSubFile file) {
57
int num = (int)file;
58
if (num < 7) {
59
return header_.offsets[file + 1] - header_.offsets[file];
60
} else {
61
return fileSize_ - header_.offsets[file];
62
}
63
}
64
65
private:
66
FileLoader *file_;
67
size_t fileSize_;
68
const PBPHeader header_;
69
bool isELF_;
70
};
71
72