From 44393a22da897d1ff85044603bbefb6b68eb23ec Mon Sep 17 00:00:00 2001 From: jerry_liu Date: Tue, 2 Apr 2019 17:33:28 +0800 Subject: [PATCH] More flexiable nexe footer search range to fix digital sign binary launch issue Fix #372 --- src/patches/boot-nexe.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/patches/boot-nexe.ts b/src/patches/boot-nexe.ts index 3b524b3..4dc3d44 100644 --- a/src/patches/boot-nexe.ts +++ b/src/patches/boot-nexe.ts @@ -1,17 +1,20 @@ const fs = require('fs'), fd = fs.openSync(process.execPath, 'r'), stat = fs.statSync(process.execPath), - footer = Buffer.alloc(32, 0) + tailSize = Math.min(stat.size, 16000), + tailWindow = Buffer.from(Array(tailSize)) -fs.readSync(fd, footer, 0, 32, stat.size - 32) +fs.readSync(fd, tailWindow, 0, tailSize, stat.size - tailSize) -if (!footer.slice(0, 16).equals(Buffer.from(''))) { +const footerPosition = tailWindow.indexOf('') +if (footerPosition == -1) { throw 'Invalid Nexe binary' } -const contentSize = footer.readDoubleLE(16), +const footer = tailWindow.slice(footerPosition, footerPosition + 32), + contentSize = footer.readDoubleLE(16), resourceSize = footer.readDoubleLE(24), - contentStart = stat.size - 32 - resourceSize - contentSize, + contentStart = stat.size - tailSize + footerPosition - resourceSize - contentSize, resourceStart = contentStart + contentSize Object.defineProperty(