script names

This commit is contained in:
Skillbert
2024-01-12 20:15:38 +01:00
parent 159edf19a6
commit 18e2512ecf
3 changed files with 17 additions and 7 deletions

View File

@@ -1017,18 +1017,21 @@ function fixControlFlow(ast: AstNode, scriptjson: clientscript) {
}
export class ClientScriptFunction extends AstNode {
name: string;
scriptid: number;
returntype: StackList;
argtype: StackList;
constructor(name: string, returntype: StackList, argtype: StackList) {
constructor(scriptid: number, returntype: StackList, argtype: StackList) {
super(0);
this.name = name;
this.scriptid = scriptid;
this.returntype = returntype;
this.argtype = argtype;
}
getCode(calli: ClientscriptObfuscation, indent: number) {
let res = `${codeIndent(indent)}function ${this.name.match(/^\d/) ? `script${this.name}` : this.name}(${this.argtype.toTypeScriptVarlist()}):${this.returntype.toTypeScriptReturnType()}`;
let meta = calli.scriptargs.get(this.scriptid);
let res = "";
res += `//${meta?.scriptname ?? "unknown name"}\n`;
res += `${codeIndent(indent)}function script${this.scriptid}(${this.argtype.toTypeScriptVarlist()}):${this.returntype.toTypeScriptReturnType()}`;
res += this.children[0].getCode(calli, indent);
return res;
}
@@ -1349,7 +1352,7 @@ export async function renderClientScript(source: CacheFileSource, buf: Buffer, f
let returntype = getReturnType(calli, script.opcodedata);
let argtype = getArgType(script);
let func = new ClientScriptFunction(fileid + "", returntype, new StackList([argtype]));
let func = new ClientScriptFunction(fileid, returntype, new StackList([argtype]));
let res = "";
if (full) {
func.push(program);

View File

@@ -14,6 +14,7 @@ import { params } from "../../generated/params";
import { clientscriptParser } from "./codeparser";
import { ClientScriptOp, ImmediateType, StackConstants, StackDiff, StackInOut, StackList, StackType, knownClientScriptOpNames, namedClientScriptOps, variableSources } from "./definitions";
import { dbtables } from "../../generated/dbtables";
import { reverseHashes } from "../libs/rshashnames";
globalThis.parser = clientscriptParser;
@@ -70,6 +71,7 @@ export class OpcodeInfo {
export type ScriptCandidate = {
id: number,
scriptname: string,
solutioncount: number,
buf: Buffer,
script: clientscriptdata,
@@ -262,6 +264,7 @@ export class ClientscriptObfuscation {
varmeta: Map<number, { name: string, vars: Map<number, typeof varInfoParser extends FileParser<infer T> ? T : never> }> = new Map();
parammeta = new Map<number, params>();
scriptargs = new Map<number, {
scriptname: string,
args: StackDiff,
returns: StackList
arglist: StackList | null,//seperate entries since order is not well defined
@@ -285,6 +288,7 @@ export class ClientscriptObfuscation {
let args = StackDiff.fromJson(v.args)!;
let returns = StackList.fromJson(v.returns);
return [v.id, {
scriptname: "",
args: args,
returns: returns!,
arglist: args.getArglist(),
@@ -387,6 +391,7 @@ export class ClientscriptObfuscation {
if (!entry) { continue; }
yield source.getFile(entry.major, entry.minor, entry.crc).then<ScriptCandidate>(buf => ({
id: entry.minor,
scriptname: reverseHashes.get(index[entry.minor].name!) ?? "",
solutioncount: 0,
buf,
script: parse.clientscriptdata.read(buf, source),
@@ -429,7 +434,7 @@ export class ClientscriptObfuscation {
async runCallibrationFrom(previousCallibration: ClientscriptObfuscation) {
let refscript = await previousCallibration.generateDump();
await this.runCallibration(refscript);
console.log("callibrated", this);
// console.log("callibrated", this);
}
setNonObbedMappings() {
//originally all <0x80 were ints
@@ -611,6 +616,7 @@ function parseCandidateContents(calli: ClientscriptObfuscation) {
cand.returnType = getReturnType(calli, cand.scriptcontents);
cand.argtype = getArgType(cand.script);
calli.scriptargs.set(cand.id, {
scriptname: cand.scriptname,
args: cand.argtype,
returns: cand.returnType,
arglist: cand.argtype.getArglist(),

View File

@@ -465,7 +465,8 @@ export function clientscriptParser(deob: ClientscriptObfuscation) {
yield whitespace;
let ops: AstNode[] = yield statementlist;
let codeblock = new CodeBlockNode(-1, -1, ops);
let res = new ClientScriptFunction(name, returntype, argtype);
let namematch = name.match(/^script(\d+)$/);
let res = new ClientScriptFunction((namematch ? +namematch[1] : -1), returntype, argtype);
res.push(codeblock);
return res;
}