Skip to content

Instantly share code, notes, and snippets.

@ericpp
Created January 31, 2020 06:31
Show Gist options
  • Save ericpp/bc346ffac3ad2846dd133d233ce09e48 to your computer and use it in GitHub Desktop.
Save ericpp/bc346ffac3ad2846dd133d233ce09e48 to your computer and use it in GitHub Desktop.
Converts a binary file into echo commands which can be copy/pasted into a malfunctioning system
from __future__ import print_function
filename = "busybox"
output = "busybox"
group = 200
with open(filename, 'rb') as file:
print("echo -en '' > %s" % output)
print("echo -en $'", end="")
idx = 0
while True:
byte = file.read(1)
if len(byte) == 0:
break
chr = hex(ord(byte))
if chr == '0x0':
print("\\\\0000", end="")
elif chr == '0x5c':
print("\\x5c\\x5c", end="")
elif len(chr) == 3:
print("\\x0%s" % chr[-1:], end="")
else:
print("\\x%s" % chr[-2:], end="")
if idx % group == 0:
print("' >> %s" % output)
print("echo -en $'", end="")
idx = idx + 1
print("' >> %s" % output)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment