Files
reverse-engineering-anything/src/domain/binaryGuid.ts
T

24 lines
776 B
TypeScript

import type { BinaryReader } from "./binaryContainer.js";
export const BINARY_GUID_BYTES = 16;
/** Lowercase GUID text. The reader orders the three numeric fields; the final eight bytes stay in source order. */
export const formatBinaryGuid = (
reader: BinaryReader,
offset: number,
): string => {
const { bytes } = reader;
const data1 = reader.u32(offset).toString(16).padStart(8, "0");
const data2 = reader
.u16(offset + 4)
.toString(16)
.padStart(4, "0");
const data3 = reader
.u16(offset + 6)
.toString(16)
.padStart(4, "0");
const clockSeq = bytes.toString("hex", offset + 8, offset + 10);
const node = bytes.toString("hex", offset + 10, offset + BINARY_GUID_BYTES);
return `${data1}-${data2}-${data3}-${clockSeq}-${node}`;
};