Files
pbz-cppbypass/src/policy.hpp
T
KintaroModding 434f11d743 Allow additional project JavaScript and JSON modules in bypass 1.1
Normalize unlisted module paths with the game's pinned helper and release its
FString output with the matching allocator. Keep engine and outside paths on
original validation, log additional accepted modules, and test malformed paths
and allocation cleanup through the production adapters.

Update scope documentation and keep earlier gameplay results separate from a
new DLL's pending game test. Native tests and offline verification pass.
2026-11-04 17:20:13 +01:00

45 lines
1.6 KiB
C++

#pragma once
#include <cstdint>
#include <string_view>
namespace compat {
// The pinned normalizer returns an owning FString; only the game allocator frees it.
struct GameString {
wchar_t* data{};
std::int32_t count{};
std::int32_t capacity{};
};
static_assert(sizeof(GameString) == 16);
struct ScriptRecord {
const wchar_t* path;
std::uint64_t byte_size;
std::uint64_t wrapped_byte_size;
unsigned char hashes[64];
};
static_assert(sizeof(ScriptRecord) == 88);
inline bool is_project_script(std::wstring_view path) noexcept {
if (!path.starts_with(L"project/")) return false;
if (!path.ends_with(L".js") && !path.ends_with(L".json")) return false;
// Table paths are canonical; refuse traversal and alternate separators.
if (path.find(L'\\') != path.npos || path.find(L':') != path.npos) return false;
for (const auto character : path)
if (character < 32 || character == 127) return false;
for (std::size_t i = 0, end; i < path.size(); i = end + 1) {
end = path.find(L'/', i);
if (end == path.npos) end = path.size();
const auto part = path.substr(i, end-i);
if (part.empty() || part == L"." || part == L"..") return false;
}
return true;
}
inline bool contains_record(const ScriptRecord* record, const ScriptRecord* table,
std::size_t count) noexcept {
const auto address = reinterpret_cast<std::uintptr_t>(record);
const auto begin = reinterpret_cast<std::uintptr_t>(table);
return address >= begin && address-begin < count*sizeof(ScriptRecord) &&
(address-begin)%sizeof(ScriptRecord) == 0;
}
}