UNPKG

unreal.js

Version:

A pak reader for games like VALORANT & Fortnite written in Node.JS

69 lines (68 loc) 2.42 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AbstractVfsReader = void 0; const Utils_1 = require("../../util/Utils"); const FByteArchive_1 = require("../reader/FByteArchive"); class AbstractVfsReader { constructor(path, versions) { this.files = []; this.mountPoint = ""; this.concurrent = false; this.path = path; this.versions = versions; const _path = Utils_1.Utils.replaceAll(path, "\\", "/"); this.name = _path.substring(_path.lastIndexOf("/") + 1); } get fileCount() { return this.files.length; } get game() { return this.versions.game; } set game(v) { this.versions.game = v; } get ver() { return this.versions.ver; } set ver(v) { this.versions.ver = v; } validateMountPoint(mountPoint) { let badMountPoint = !mountPoint.startsWith("../../.."); mountPoint = mountPoint.substring(mountPoint.indexOf("../../.." + "../../..".length)); if (mountPoint[0] != "/" || (mountPoint.length > 1 && mountPoint[1] == ".")) badMountPoint = true; if (badMountPoint) { // warn mountPoint = "/"; } if (mountPoint.startsWith("/")) mountPoint = mountPoint.substring(1); return mountPoint; } static isValidIndex(source) { if (Buffer.isBuffer(source)) return this.isValidIndex(new FByteArchive_1.FByteArchive(source)); const stringLength = source.readInt32(); if (stringLength > this.MAX_MOUNTPOINT_TEST_LENGTH || stringLength < -this.MAX_MOUNTPOINT_TEST_LENGTH) return false; // Calculate the pos of the null terminator for this string // Then read the null terminator byte and check whether it is actually 0 if (stringLength === 0) return source.readInt8() === 0; if (stringLength < 0) { // UTF16 source.pos = 4 - (stringLength - 1) * 2; return source.readInt16() === 0; } // UTF8 source.pos = 4 + stringLength - 1; return source.readInt8() === 0; } toString() { return this.path; } } exports.AbstractVfsReader = AbstractVfsReader; AbstractVfsReader.MAX_MOUNTPOINT_TEST_LENGTH = 128;