Skip to content

Instantly share code, notes, and snippets.

@uyjulian
Created July 5, 2020 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uyjulian/c60f28619d4aa8fff8e34d6317a430dd to your computer and use it in GitHub Desktop.
Save uyjulian/c60f28619d4aa8fff8e34d6317a430dd to your computer and use it in GitHub Desktop.
import re
import sys
import json
funcname_match = re.compile('^static char funcname\\[\\] = "(.*)";$')
typedef_match = re.compile('^typedef (.*)\\(__stdcall \\* __functype\\)\\((.*)\\);$')
funccall_match = re.compile('^r?e?t?u?r?n? ?\\(\\(__functype\\)\\((TVPImportFuncPtr.*)\\)\\)\\((.*)\\);$')
outarr = []
with open(sys.argv[1]) as in_file:
funcname = None
typedef_ret = None
typedef_args = None
funccall_lval = None
funccall_args = None
for line in in_file:
ln = line.lstrip()
matc = funcname_match.match(ln)
if matc is not None:
if funcname is None:
funcname = matc.group(1)
continue
else:
raise Exception("funcname is not none")
matc = typedef_match.match(ln)
if matc is not None:
if typedef_ret is None and typedef_args is None:
typedef_ret = matc.group(1).rstrip()
typedef_args = matc.group(2)
if typedef_args == "":
typedef_args = []
else:
typedef_args = typedef_args.split(", ")
typedef_args = [x.rstrip() for x in typedef_args]
continue
else:
raise Exception("typedef is not none")
matc = funccall_match.match(ln)
if matc is not None:
if funccall_lval is None and funccall_args is None:
funccall_lval = matc.group(1)
funccall_args = matc.group(2)
if funccall_args == "":
funccall_args = []
else:
funccall_args = funccall_args.split(", ")
funccall_args = [x.rstrip() for x in funccall_args]
dict_to_add = {"funcname" : funcname, "typedef_ret" : typedef_ret, "typedef_args" : typedef_args, "funccall_lval" : funccall_lval, "funccall_args" : funccall_args}
outarr.append(dict_to_add)
funcname = None
typedef_ret = None
typedef_args = None
funccall_lval = None
funccall_args = None
continue
else:
raise Exception("funccall is not none")
with open(sys.argv[2], "w") as out_file:
out_file.write(json.dumps(outarr, indent=4))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment