forked from MontagueM/MontevenDynamicExtractor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.cpp
59 lines (51 loc) · 1.2 KB
/
helpers.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "helpers.h"
std::string getReferenceFromHash(std::string hash, std::string pkgsPath)
{
Package pkg(getPkgID(hash), pkgsPath);
std::string reference = pkg.getEntryReference(hash);
return reference;
}
File::File(std::string x, std::string pkgsPath)
{
hash = x;
packagesPath = pkgsPath;
}
int File::getData()
{
if (hash.substr(hash.length() - 2) != "80" || hash.substr(hash.length() - 4) == "8080") return 0;
if (pkgID == "")
{
pkgID = getPkgID(hash);
}
Package pkg(pkgID, packagesPath);
int fileSize;
data = pkg.getEntryData(hash, fileSize);
if (data == nullptr || sizeof(data) == 0) return 0;
return fileSize;
}
std::string getPkgID(std::string hash)
{
std::string pkgID = uint16ToHexStr(floor((hexStrToUint32(hash) - 0x80800000)/8192));
return pkgID;
}
uint16_t getPkgID(uint32_t hash)
{
uint16_t pkgID = floor((hash - 0x80800000) / 8192);
return pkgID;
}
std::string getHash64(uint64_t hash64, std::unordered_map<uint64_t, uint32_t> hash64Table)
{
std::string h64 = "";
try
{
h64 = uint32ToHexStr(hash64Table[hash64]);
if (h64 == "00000000")
throw h64;
}
catch (std::string err)
{
std::cerr << "H64 file is out-of-date. Please delete and retry.\n";
exit(1);
}
return h64;
}