1
0
mirror of https://github.com/DoctorWkt/unix-jun72.git synced 2026-02-02 15:01:52 +00:00
Files
DoctorWkt.unix-jun72/tools/fixaout.py
tim.newsham c0adf32ada - some helpers for building userland code. Very hacky at the moment but
should work until something better comes along.
2008-05-04 22:20:08 +00:00

42 lines
682 B
Python
Executable File

#!/usr/bin/env python
"""
Convert an 0407 binary into an 0405 binary, under the assumption
that the code starts at 040014 (by ". = . + 40014").
See tools/as.
"""
import struct
def words(bs) :
l = len(bs) / 2
return list(struct.unpack('<%dH' % l, bs))
def unwords(ws) :
l = len(ws)
return struct.pack('<%dH' % l, *ws)
def read(fn) :
f = file(fn, 'rb')
d = f.read()
f.close()
return d
def write(fn, d) :
f = file(fn, 'wb')
f.write(d)
f.close()
orig = 040000
d = words(read('a.out'))
hdr = d[:8]
d = d[8 + orig/2 :]
d[0] = 0405
d[1] = hdr[1] - orig
d[2] = 0
d[3] = 0
d[4] = hdr[4]
d[5] = 0
d = d[:d[1] / 2]
write("b.out", unwords(d))