Skip to content

Instantly share code, notes, and snippets.

@xerpi
Last active July 22, 2018 16:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xerpi/36d0f839bc3567aa8b90fc7a9c8cdded to your computer and use it in GitHub Desktop.
Save xerpi/36d0f839bc3567aa8b90fc7a9c8cdded to your computer and use it in GitHub Desktop.
vitafunctiondefs.py
'''
vitafunctiondefs.py by xerpi
arm-vita-eabi-gcc -E $VITASDK/arm-vita-eabi/include/vitasdk.h -D"__attribute__(x)=" -D"__extension__(x)=" > preprocessor_user.h
arm-vita-eabi-gcc -E $VITASDK/arm-vita-eabi/include/vitasdkkern.h -D"__attribute__(x)=" -D"__extension__(x)=" > preprocessor_kern.h
'''
import sys
import os.path
import struct
from idautils import *
from idc import *
def check_function(f, content):
fname = GetFunctionName(f)
it = iter(content)
for line in it:
if line.find(fname) != -1:
prototype = line
while line.find(");") == -1:
line = next(it)
prototype += line
prototype = prototype.replace('\r', '').replace('\n', '').rstrip()
found_name = prototype[prototype.find(" ") + 1:prototype.rfind("(")]
if found_name != fname:
continue
print "Found:", prototype
MakeName(f, fname)
SetType(f, prototype)
break
def main():
print os.path.basename(sys.argv[0]), "by xerpi"
execdir = os.path.dirname(sys.argv[0])
with open(os.path.join(execdir, "preprocessor_user.h"), 'r') as f:
content_user = f.readlines()
f.close()
with open(os.path.join(execdir, "preprocessor_kern.h"), 'r') as f:
content_kern = f.readlines()
f.close()
functions = Functions()
for f in functions:
fname = GetFunctionName(f)
if fname.find("sce") == -1 and fname.find("Sce") == -1:
continue
if fname.find("_imp_") != -1:
fname = fname.split("_imp_")[0]
MakeName(f, fname)
print "Looking for:", fname
check_function(f, content_user)
check_function(f, content_kern)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment