-
Notifications
You must be signed in to change notification settings - Fork 1
/
subsystem.coffee
30 lines (21 loc) · 914 Bytes
/
subsystem.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
fs = require "fs"
struct = require "bufferpack"
module.exports = (exe_path, subsystem="gui")->
exe = fs.openSync exe_path, "r+"
read = (position, length)->
buffer = new Buffer length
fs.readSync exe, buffer, 0, length, position
buffer
write = (position, buffer)->
fs.writeSync exe, buffer, 0, buffer.length, position
[PeHeaderOffset] = struct.unpack "<H", read 0x3c, 2
[PeSignature] = struct.unpack "<I", read PeHeaderOffset, 4
if PeSignature isnt 0x4550
throw new Error "File is missing PE header signature"
subsystem_value = switch subsystem.toLowerCase()
when "console" then 3
when "gui", "windows" then 2
console.log "Current subsystem value:", (struct.unpack "<H", read PeHeaderOffset + 0x5C, 2)[0]
write PeHeaderOffset + 0x5C, struct.pack "<H", [subsystem_value]
console.log "New subsystem value:", (struct.unpack "<H", read PeHeaderOffset + 0x5C, 2)[0]
fs.close exe