#!/usr/bin/env python2

"""
Crappy script that reads the offsets in the Metasploit module,
turns it into json, and write Python files
"""

import json

def parse_offsets(data):
    data = data.split("@offsets = {")[1]
    data = data.split("}")[0]

    str = "{"
    for line in data.split("\n"):
        line = line.strip()
        line = line.split("#")[0]
        str += line

    str += "}"
    data = json.loads(str.replace("=>", ":"))

    for key, value in data.iteritems():
        str = "##\n## this file autogenerated\n"
        str += "## " + key + "\n##\n\n"

        str += "jmp_esp_offset = \"" + value[0] + "\"\n"
        str += "saferet_offset = \"" + value[1] + "\"\n"
        str += "fix_ebp = \"" + value[2] + "\"\n"
        str += "pmcheck_bounds = \"" + value[3] + "\"\n"
        str += "pmcheck_offset = \"" + value[4] + "\"\n"
        str += "pmcheck_code = \"" + value[5] + "\"\n"
        str += "admauth_bounds = \"" + value[6] + "\"\n"
        str += "admauth_offset = \"" + value[7] + "\"\n"
        str += "admauth_code = \"" + value[8] + "\"\n"

        str += '\n\n# "%s" = ["%s"],' % (key, '","'.join(value))

        fname = "shellcode_" + key.replace(".", "_") + ".py"
        print fname
        with open(fname, "w") as f:
            f.write(str)

if __name__ == '__main__':
    import sys
    data = open(sys.argv[1]).read()
    parse_offsets(data)

#!/usr/bin/env python2

"""
Crappy script that reads the offsets in the Metasploit module,
turns it into json, and write Python files
"""

import json

def parse_offsets(data):
    data = data.split("@offsets = {")[1]
    data = data.split("}")[0]

    str = "{"
    for line in data.split("\n"):
        line = line.strip()
        line = line.split("#")[0]
        str += line

    str += "}"
    data = json.loads(str.replace("=>", ":"))

    for key, value in data.iteritems():
        str = "##\n## this file autogenerated\n"
        str += "## " + key + "\n##\n\n"

        str += "jmp_esp_offset = \"" + value[0] + "\"\n"
        str += "saferet_offset = \"" + value[1] + "\"\n"
        str += "fix_ebp = \"" + value[2] + "\"\n"
        str += "pmcheck_bounds = \"" + value[3] + "\"\n"
        str += "pmcheck_offset = \"" + value[4] + "\"\n"
        str += "pmcheck_code = \"" + value[5] + "\"\n"
        str += "admauth_bounds = \"" + value[6] + "\"\n"
        str += "admauth_offset = \"" + value[7] + "\"\n"
        str += "admauth_code = \"" + value[8] + "\"\n"

        str += '\n\n# "%s" = ["%s"],' % (key, '","'.join(value))

        fname = "shellcode_" + key.replace(".", "_") + ".py"
        print fname
        with open(fname, "w") as f:
            f.write(str)

if __name__ == '__main__':
    import sys
    data = open(sys.argv[1]).read()
    parse_offsets(data)

#!/usr/bin/env python2 Crappy script that reads the offsets in the Metasploit module, turns it into json, and write Python files #\n## this file autogenerated\n" # " + key + "\n##\n\n" # "%s" = ["%s"],' % (key, '","'.join(value))