ddr working now

This commit is contained in:
GEEKiDoS
2025-04-11 17:29:42 +08:00
parent bfc994a8ff
commit 9f92ff5056
15 changed files with 1476 additions and 297 deletions
+16 -3
View File
@@ -2,7 +2,6 @@ import { to_bin, to_xml } from "@kamyu/kbinxml";
import { XMLParser } from "fast-xml-parser";
import _ from "lodash";
import { Serializable } from "./kxml-value.js";
import { writeFileSync } from "fs";
export const parser = new XMLParser({
ignoreAttributes: false,
@@ -135,10 +134,24 @@ function serializeValue(value: any, type: string): string {
return value.toString('hex');
}
if (['ip4', 'str', 'string'].includes(type)) {
if (['ip4'].includes(type)) {
return value;
}
if (['str', 'string'].includes(type)) {
return value.replace(/[<>&'"]/g, (ch: string) => {
switch (ch) {
case '<': return '&lt;';
case '>': return '&gt;';
case '&': return '&amp;';
case '\'': return '&apos;';
case '"': return '&quot;';
}
return ch;
});
}
if (type == 'time') {
if (value instanceof Date) {
return Math.floor(value.valueOf() / 1000).toString();
@@ -228,6 +241,6 @@ function serializeObject(obj: Serializable, name: string, linePrefix: string = '
export function toKBinXml(topName: string, obj: Serializable, encoding: 'UTF-8' | 'SHIFT_JIS' = 'UTF-8') {
const xml = `<?xml version="1.0" encoding="${encoding}"?>` + serializeObject(obj, topName);
writeFileSync('dump.xml', xml);
console.log(xml);
return to_bin(xml);
}