Skip to content

Commit

Permalink
More flexiable nexe footer search range to fix digital sign binary la…
Browse files Browse the repository at this point in the history
…unch issue

Fix nexe#372
  • Loading branch information
jerry_liu authored and calebboyd committed Apr 3, 2019
1 parent b5e1863 commit c16c8c6
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/patches/boot-nexe.ts
Original file line number Diff line number Diff line change
@@ -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('<nexe~~sentinel>'))) {
const footerPosition = tailWindow.indexOf('<nexe~~sentinel>')
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(
Expand Down

0 comments on commit c16c8c6

Please sign in to comment.