import { deflateRawSync } from 'node:zlib'; function crc32(bytes: Uint8Array): number { let value = 0xffffffff; for (const byte of bytes) { value ^= byte; for (let bit = 0; bit < 8; bit += 1) value = (value >>> 1) ^ (0xedb88320 & -(value & 1)); } return (value ^ 0xffffffff) >>> 0; } function syntheticRegistryPolicy(): Buffer { const header = Buffer.alloc(8); header.write('PReg', 0, 'ascii'); header.writeUInt32LE(1, 4); const type = Buffer.alloc(4); type.writeUInt32LE(4); const size = Buffer.alloc(4); size.writeUInt32LE(4); const data = Buffer.alloc(4); data.writeUInt32LE(1); const unicode = (value: string) => Buffer.from(value, 'utf16le'); return Buffer.concat([ header, unicode('['), unicode('Software\\Policies\\Synthetic'), Buffer.alloc(2), unicode(';'), unicode('Mode'), Buffer.alloc(2), unicode(';'), type, unicode(';'), size, unicode(';'), data, unicode(']') ]); } export function syntheticGpoBackupZip(): Uint8Array { const entries = [ { path: 'synthetic/Backup.xml', content: Buffer.from('{22222222-2222-4222-8222-222222222222}{11111111-1111-4111-8111-111111111111}synthetic.example2026-07-20T10:00:00Z') }, { path: 'synthetic/DomainSysvol/GPO/Machine/Registry.pol', content: syntheticRegistryPolicy() }, { path: 'synthetic/DomainSysvol/GPO/Machine/Microsoft/Windows NT/SecEdit/GptTmpl.inf', content: Buffer.from('[Unicode]\r\nUnicode=yes\r\n[System Access]\r\nMinimumPasswordLength=14\r\n[Version]\r\nsignature="$CHICAGO$"') }, { path: 'synthetic/DomainSysvol/GPO/Machine/Microsoft/Windows NT/Audit/audit.csv', content: Buffer.from('Machine Name,Policy Target,Subcategory,Subcategory GUID,Inclusion Setting,Exclusion Setting,Setting Value\r\n,System,ignored,{0cce9210-69ae-11d9-bed3-505054503030},Success and Failure,,3') }, { path: 'synthetic/DomainSysvol/GPO/Machine/Preferences/Registry/Registry.xml', content: Buffer.from('') }, { path: 'synthetic/DomainSysvol/GPO/Machine/Preferences/Groups/Groups.xml', content: Buffer.from('') }, { path: 'synthetic/DomainSysvol/GPO/Machine/Preferences/Services/Services.xml', content: Buffer.from('') }, { path: 'synthetic/DomainSysvol/GPO/User/Preferences/Drives/Drives.xml', content: Buffer.from('') }, { path: 'synthetic/DomainSysvol/GPO/gpt.ini', content: Buffer.from('[General]') } ]; const localParts: Buffer[] = []; const centralParts: Buffer[] = []; let localOffset = 0; for (const entry of entries) { const name = Buffer.from(entry.path); const compressed = deflateRawSync(entry.content); const checksum = crc32(entry.content); const local = Buffer.alloc(30 + name.length); local.writeUInt32LE(0x04034b50, 0); local.writeUInt16LE(20, 4); local.writeUInt16LE(0x0800, 6); local.writeUInt16LE(8, 8); local.writeUInt32LE(checksum, 14); local.writeUInt32LE(compressed.length, 18); local.writeUInt32LE(entry.content.length, 22); local.writeUInt16LE(name.length, 26); name.copy(local, 30); localParts.push(local, compressed); const central = Buffer.alloc(46 + name.length); central.writeUInt32LE(0x02014b50, 0); central.writeUInt16LE(20, 4); central.writeUInt16LE(20, 6); central.writeUInt16LE(0x0800, 8); central.writeUInt16LE(8, 10); central.writeUInt32LE(checksum, 16); central.writeUInt32LE(compressed.length, 20); central.writeUInt32LE(entry.content.length, 24); central.writeUInt16LE(name.length, 28); central.writeUInt32LE(localOffset, 42); name.copy(central, 46); centralParts.push(central); localOffset += local.length + compressed.length; } const directory = Buffer.concat(centralParts); const end = Buffer.alloc(22); end.writeUInt32LE(0x06054b50, 0); end.writeUInt16LE(entries.length, 8); end.writeUInt16LE(entries.length, 10); end.writeUInt32LE(directory.length, 12); end.writeUInt32LE(localOffset, 16); return Buffer.concat([...localParts, directory, end]); }