Files: 938b7ea4cfaa3cef6e1690b9ef3ea8bd7a0d2de1 / test / test-50-corrupt-executable / main.js
1211 bytesRaw
1 | |
2 | |
3 | 'use strict'; |
4 | |
5 | const fs = require('fs'); |
6 | const path = require('path'); |
7 | const assert = require('assert'); |
8 | const utils = require('../utils.js'); |
9 | |
10 | assert(!module.parent); |
11 | assert(__dirname === process.cwd()); |
12 | |
13 | const host = 'node' + process.version.match(/^v(\d+)/)[1]; |
14 | const target = process.argv[2] || host; |
15 | const input = './test-x-index.js'; |
16 | const output = './test-output.exe'; |
17 | |
18 | let right; |
19 | |
20 | utils.pkg.sync([ |
21 | '--target', target, |
22 | '--output', output, input |
23 | ]); |
24 | |
25 | const damage = fs.readFileSync(output); |
26 | const boundary = 4096; |
27 | damage[damage.length - 2 * boundary - 10] = 0x2; |
28 | damage[damage.length - 3 * boundary - 10] = 0x2; |
29 | damage[damage.length - 4 * boundary - 10] = 0x2; |
30 | damage[damage.length - 2 * boundary + 10] = 0x2; |
31 | damage[damage.length - 3 * boundary + 10] = 0x2; |
32 | damage[damage.length - 4 * boundary + 10] = 0x2; |
33 | fs.writeFileSync(output, damage); |
34 | |
35 | right = utils.spawn.sync( |
36 | './' + path.basename(output), [], |
37 | { cwd: path.dirname(output), |
38 | stdio: 'pipe', expect: 1 } |
39 | ); |
40 | |
41 | assert.equal(right.stdout, ''); |
42 | assert((right.stderr.indexOf('Invalid') >= 0) || |
43 | (right.stderr.indexOf('ILLEGAL') >= 0) || |
44 | (right.stderr.indexOf('SyntaxError') >= 0)); |
45 | utils.vacuum.sync(output); |
46 |
Built with git-ssb-web