-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdump.ts
More file actions
45 lines (39 loc) · 1.28 KB
/
dump.ts
File metadata and controls
45 lines (39 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { deserializePackets } from "./utils/packet.ts";
import { arrayBufferToHexString } from "./utils/string.ts";
// UNSAFE CODE
const importDump = async (path: string): Promise<number[]> => {
const rawData = await Deno.readFile(path);
const textDecoder = new TextDecoder();
const data = textDecoder.decode(rawData);
const lines = data.split("\n");
for (let i = 0; i < lines.length; i++) {
lines[i] = lines[i].substring(4);
lines[i] = lines[i].trim();
lines[i] = "0x" + lines[i];
lines[i] = lines[i].replaceAll(" ", ",0x");
lines[i] = lines[i] + ",";
}
const array = `[${lines.join("").slice(0, -1)}]`;
await Deno.writeTextFile("./dumpArray.txt", array);
const parsedArray = eval(array);
await Deno.writeFile("./dumpArray.bin", new Uint8Array(parsedArray));
return parsedArray;
};
// const uint8ArrayToArray = (uint8Array: Uint8Array): number[] => {
// const array: number[] = [];
// for (const byte of uint8Array) {
// array.push(byte);
// }
// return array;
// };
const dump = new Uint8Array(await importDump("./dump.txt"));
const packets = deserializePackets(dump, true);
for (const packet of packets) {
if (!packet.decoded) {
console.log(
arrayBufferToHexString(packet.payload),
);
} else {
console.log(packet.payload);
}
}