3 # Force an executable or library to pass the validator by overwriting
4 # any non-validating instruction with hlt instructions.
12 ncval
= os
.path
.join(os
.path
.dirname(__file__
),
13 "../scons-out/dbg-linux/staging/ncval")
16 def fix_up_file(obj_file
):
17 proc
= subprocess
.Popen([ncval
, obj_file
], stdout
=subprocess
.PIPE
)
19 "VALIDATOR: [0-9a-f]+ \((?P<file_addr>[0-9a-f]+):(?P<size>[0-9a-f]+)\)")
21 for line
in proc
.stdout
:
22 match
= regexp
.match(line
)
24 sys
.stdout
.write("%s: %s" % (obj_file
, line
))
25 offset
= int(match
.group("file_addr"), 16)
26 size
= int(match
.group("size"), 16)
27 rewrites
.append((offset
, size
))
28 fh
= os
.fdopen(os
.open(obj_file
, os
.O_WRONLY
), "w")
29 for offset
, size
in rewrites
:
31 # Overwrite with hlt instructions
32 fh
.write("\xf4" * size
)
41 if __name__
== "__main__":