Skip to content

Instantly share code, notes, and snippets.

@H0neyBadger
Created December 19, 2022 18:46
Show Gist options
  • Save H0neyBadger/00e6eb2e7f28608ac753b4e9de9e97b7 to your computer and use it in GitHub Desktop.
Save H0neyBadger/00e6eb2e7f28608ac753b4e9de9e97b7 to your computer and use it in GitHub Desktop.
import sys
template_elf = """window.{name}_len = {length};
window.{name} = malloc(window.{name}_len);
write_mem(window.{name}, [{payload}]);
"""
template_bin = """window.{name} = malloc(65536);
write_mem(window.{name}, [{payload}]);
"""
def bin2js(name, infile, outfile):
with open(infile, "rb") as mira:
data = mira.read()
data = [str(int(tmp)) for tmp in data]
with open(outfile, "w", encoding="utf8") as mira:
payload = ", ".join(data)
template = template_bin
if infile.endswith(".elf"):
template = template_elf
data = template.format(
name=name,
length=len(data),
payload=payload,
)
mira.write(data)
def main(mira_project_path):
loader = "loader/build/MiraLoader_Orbis_MIRA_PLATFORM_ORBIS_BSD_900.bin"
kernel = "kernel/build/Mira_Orbis_MIRA_PLATFORM_ORBIS_BSD_900.elf"
bin2js("mira_blob", mira_project_path + "/" + loader, "mira.js")
bin2js("window.mira_blob_2", mira_project_path + "/" + kernel, "mira2.js")
if __name__ == "__main__":
main(sys.argv[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment