pheonix-pkg-plugin
Version:
Webpack Plugin For the Newer NodeJS v22.9.0 Single Executable Bundling Process Provided By Johnathan Edward Brown! Now includes a Simple Runtime Script Integrity Check! Using SEA assets! With a Binary Tamper Proof Included!
22 lines (18 loc) • 856 B
text/typescript
import * as fs from 'fs';
import * as path from 'path';
import * as crypto from 'crypto';
function verifyBinaryIntegrity(): void {
const binaryPath: string = process.execPath;
const binaryContent: Buffer = fs.readFileSync(binaryPath);
const currentHash: string = crypto.createHash('sha256').update(binaryContent).digest('hex');
const hashFilePath: string = path.resolve(__dirname, path.basename(binaryPath) + '-hash.txt');
const storedHash: string = fs.readFileSync(hashFilePath, 'utf8').trim();
if (currentHash !== storedHash) {
const hashFilePath: string = path.resolve(__dirname, 'hash.txt');
const storedHash: string = fs.readFileSync(hashFilePath, 'utf8').trim();
if (currentHash !== storedHash) {
throw new Error('Binary integrity check failed!');
}
}
}
verifyBinaryIntegrity();