!(function() { /* (c) Dyrk.org 2024 - 2025 ZipDetailsExplorer 1.0 Dave-Hill [{o.o}] Dyrk.org */ let html = document.getElementsByTagName('html')[0], genEl = (parrent, type, value) => { let el = document.createElement(type); if (value) el.textContent = value; if (parent) parrent.appendChild(el); return el; }, fileHeaderStruct = function() { return { "Signature": 4, // (0x04034b50) "Version Needed to Extract": 2, "General Purpose Bit Flag": 2, "Compression Method": 2, "Last Mod File Time": 2, "Last Mod File Date": 2, "CRC-32": 4, "Compressed Size": 4, "Uncompressed Size": 4, "File Name Length": 2, "Extra Field Length": 2, "File Name": null, "Extra Field": null, "RawFileData": null }; }, CentralDirectoryFileHeader = function() { return { "Signature": 4, // (0x02014b50), "Version Made by": 2, "Version Needed to Extract": 2, "General Purpose Bit Flag": 2, "Compression Method": 2, "Last Mod File Time": 2, "Last Mod File Date": 2, "CRC-32": 4, "Compressed Size": 4, "Uncompressed Size": 4, "File Name Length": 2, "Extra Field Length": 2, "File Comment Length": 2, "Disk Number Start": 2, "Internal File Attributes": 2, "External File Attributes": 4, "Relative Offset of Local Header": 4, "File Name": null, "Extra Field": null, "File Comment": null, "RawFileData": null }; }, EndCentralDirectoryRecord = function() { return { "Signature": 4, //(0x06054b50) "Number of this Disk": 2, "Disk where Central Directory starts": 2, "Number of Central Directory Records on this Disk": 2, "Total Number of Central Directory Records": 2, "Size of Central Directory": 4, "Offset of Start of Central Directory": 4, "ZIP File Comment Length": 2, "ZIP File Comment": null, "RawFileData": null }; }, file = document.createElement('input'); html.textContent = ''; file.type = 'file'; file.addEventListener('change', (evt) => { reader = new FileReader(); reader.addEventListener('load', (content) => { let bin2Hex = (str, prefix) => (prefix ? '0x' : '').concat(str.split('').map(l => '0'.concat(l.charCodeAt(0).toString(16)).substr(-2)).reverse().join('').toUpperCase()), binContent = content.target.result, hexContent = bin2Hex(binContent), zipStruct = { 'LocalFileHeader': { 'signature': '04034B50', 'model': fileHeaderStruct() }, 'CentralDirectoryFileHeader': { 'signature': '02014B50', 'model': CentralDirectoryFileHeader() }, 'EndCentralDirectoryRecord': { 'signature': '06054B50', 'model': EndCentralDirectoryRecord() } }, position, sum, part; table = genEl(html, 'table'); table.border = 1; table.width = '100%'; hexContent.match(/.+?(04034B50|02014B50|06054B50)/g).map(function(fileContent) { if (fileContent.length == 0) return; //console.log(fileContent); position = 0; part = Object.keys(zipStruct).filter(kpart => zipStruct[kpart].signature == fileContent.substr(-8))[0]; tmpBinContent = fileContent.match(/[0-9A-Z]{2}/g).reverse().map(e => String.fromCharCode(parseInt(e, 16))).join(''); newFile = Object.assign({}, zipStruct[part].model); Object.keys(newFile).map(k => { bin = tmpBinContent.substr(position, k == 'RawFileData' ? tmpBinContent.length : newFile[k]); isDynamicField = ["File Name", "Extra Field", "File Comment", "ZIP File Comment"].indexOf(k) != -1; if (isDynamicField) bin = tmpBinContent.substr(position, newFile[k.concat(" Length")].val); newFile[k] = { bin: bin, hex: bin2Hex(bin, true), dec: bin.split('').map(d => d.charCodeAt(0)), position: position, offset: newFile[k], val: null }, position += !isDynamicField ? newFile[k].offset : newFile[k.concat(" Length")].val; if (k.indexOf('Length') != -1) { sum = 0; newFile[k].dec.forEach(x => sum += x); newFile[k].val = sum; }; }); console.log(part, newFile); let tr = genEl(table, 'tr'); let td = genEl(tr, 'td', part); td.setAttribute('colspan', 7); td.style = 'background:#000;color:#FFF'; Object.keys(newFile).map(k => { let tr = genEl(table, 'tr'); [k].concat(Object.values(newFile[k])).map((v, pos) => { let td = genEl(tr, 'td', v); td.style = 'word-break: break-all;width:15%'; }); }); }); }); reader.readAsBinaryString(evt.target.files[0]); }); file.click(); }());