fix(libs): fix nid compute algorithm - no lib name
This commit is contained in:
parent
f23cc495f4
commit
54e66624ec
|
|
@ -1,50 +1,42 @@
|
|||
#include <nid/NidCompute.hpp>
|
||||
#include <nid/Sha1.hpp>
|
||||
#include <stdexcept>
|
||||
#include <cstdint>
|
||||
|
||||
namespace Nid {
|
||||
|
||||
namespace {
|
||||
constexpr uint8_t kNidSuffix[16] = {
|
||||
0x51, 0x8D, 0x64, 0xA6, 0x35, 0xDE, 0xD8, 0xC1,
|
||||
0xE6, 0xB0, 0x39, 0xB1, 0xC3, 0xE5, 0x52, 0x30
|
||||
};
|
||||
|
||||
constexpr char kBase64Chars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-";
|
||||
|
||||
std::string _base64Encode(const std::uint8_t* data, std::size_t len) {
|
||||
std::string out;
|
||||
out.reserve(((len + 2u) / 3u) * 4u);
|
||||
for (std::size_t i = 0; i < len; i += 3u) {
|
||||
std::uint32_t group = static_cast<std::uint32_t>(data[i]) << 16u;
|
||||
if (i + 1u < len) group |= static_cast<std::uint32_t>(data[i+1u]) << 8u;
|
||||
if (i + 2u < len) group |= static_cast<std::uint32_t>(data[i+2u]);
|
||||
|
||||
out.push_back(kBase64Chars[(group >> 18u) & 0x3fu]);
|
||||
out.push_back(kBase64Chars[(group >> 12u) & 0x3fu]);
|
||||
out.push_back((i + 1u < len) ? kBase64Chars[(group >> 6u) & 0x3fu] : '=');
|
||||
out.push_back((i + 2u < len) ? kBase64Chars[(group) & 0x3fu] : '=');
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
}
|
||||
constexpr char kBase64S[] =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+-";
|
||||
|
||||
std::string ComputeNid(const std::string& symbolName, const std::string& libraryName) {
|
||||
if (symbolName.empty()) throw std::invalid_argument("symbolName is empty");
|
||||
if (libraryName.empty()) throw std::invalid_argument("libraryName is empty");
|
||||
if (symbolName.empty())
|
||||
throw std::invalid_argument("symbolName is empty");
|
||||
|
||||
std::vector<std::uint8_t> input;
|
||||
input.reserve(symbolName.size() + 1u + libraryName.size() + 1u + libraryName.size() + 1u);
|
||||
|
||||
for (char c : symbolName) input.push_back(static_cast<std::uint8_t>(c));
|
||||
input.push_back(0x00u);
|
||||
for (char c : libraryName) input.push_back(static_cast<std::uint8_t>(c));
|
||||
input.push_back(0x00u);
|
||||
for (char c : libraryName) input.push_back(static_cast<std::uint8_t>(c));
|
||||
input.push_back(0x00u);
|
||||
std::vector<uint8_t> input;
|
||||
input.reserve(symbolName.size() + 16u);
|
||||
for (char c : symbolName)
|
||||
input.push_back(static_cast<uint8_t>(c));
|
||||
for (uint8_t b : kNidSuffix)
|
||||
input.push_back(b);
|
||||
|
||||
const auto digest = Sha1(input);
|
||||
const std::string b64 = _base64Encode(digest.data(), digest.size());
|
||||
uint64_t v = 0;
|
||||
|
||||
if (b64.size() < 11u) throw std::runtime_error("base64 output too short");
|
||||
return b64.substr(0u, 11u) + '#';
|
||||
for (int i = 0; i < 8; i++)
|
||||
v = (v << 8) | digest[7 - i];
|
||||
char nid[12];
|
||||
for (int i = 10; i >= 0; i--) {
|
||||
nid[i] = kBase64S[v & 0x3F];
|
||||
v >>= 6;
|
||||
}
|
||||
nid[11] = '\0';
|
||||
|
||||
return std::string(nid, 11);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -4,6 +4,8 @@
|
|||
#include <ctime>
|
||||
#include "SceTypes.hpp"
|
||||
|
||||
uint32_t g_need_flag = 1;
|
||||
|
||||
extern "C" {
|
||||
|
||||
void exit_nid_postfix(int code) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue