-
Notifications
You must be signed in to change notification settings - Fork 2
/
exestamp.py
executable file
·28 lines (28 loc) · 971 Bytes
/
exestamp.py
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
#!/usr/bin/env python
if __name__ == '__main__':
from argparse import ArgumentParser as f
from struct import Struct as p
f = f()
f, t = f.add_argument, f.parse_args
f('exe', help='Windows PE32(+) file')
def int_0(x: str) -> int: return int(x, 0)
f('stamp', type=int_0, nargs='?', help='new Unix timestamp,'
' decimal, octal (leading 0o), or hexadecimal (leading 0x)')
f, p = t(), p('<I')
f, t, p, u = f.exe, f.stamp, p.pack, p.unpack
with open(f, 'rb' if t is None else 'rb+') as f:
r, w, s = f.read, f.write, f.seek
def f() -> int: return u(r(4))[0]
m = 'Not a Windows PE32(+) file'
if r(2) != b'MZ': raise ValueError(m)
s(60)
s(f())
if r(4) != b'PE\0\0': raise ValueError(m)
s(4, 1)
if t is None: print(f())
else:
t &= 0xFFFFFFFF
print('old:', f())
print('new:', t)
s(-4, 1)
w(p(t))