mirror of
https://github.com/laochan-eacnet/backend.git
synced 2026-10-05 21:17:57 +03:00
ddr working now
This commit is contained in:
+16
-3
@@ -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 '<';
|
||||
case '>': return '>';
|
||||
case '&': return '&';
|
||||
case '\'': return ''';
|
||||
case '"': return '"';
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user