Skip to content

Instantly share code, notes, and snippets.

@liaogang
Created January 22, 2019 07:20
Show Gist options
  • Save liaogang/5f68d8ead1081d55d95b39dcb9094efa to your computer and use it in GitHub Desktop.
Save liaogang/5f68d8ead1081d55d95b39dcb9094efa to your computer and use it in GitHub Desktop.
This is a python script of LLDB to set breakpoint using file address when ASLR is on. I copy from network and changed a little
#!/usr/bin/python
#coding:utf-8
import lldb
import commands
import optparse
import shlex
def get_ASLR(debugger):
target = debugger.GetSelectedTarget()
module = target.GetModuleAtIndex(1)
filename = module.file.GetFilename()
interpreter = lldb.debugger.GetCommandInterpreter()
returnObject = lldb.SBCommandReturnObject()
theCommand = 'image list -o -f ' + filename
interpreter.HandleCommand(theCommand, returnObject)
output = returnObject.GetOutput();
index0 = output.find('] ')
index1 = output.find(' /')
return output[index0+2: index1]
def sbr(debugger, command, result, internal_dict):
if command:
ASLR = get_ASLR(debugger)
if ASLR:
after = hex( int(ASLR, 16) + int(command, 16) )
debugger.HandleCommand('br set -a "%s"' % (after))
else:
print >>result, 'ASLR not found!'
else:
print >>result, 'Please input the address!'
def padr(debugger, command, result, internal_dict):
if not command:
print >>result, 'Please input the address!'
return
ASLR = get_ASLR(debugger)
if ASLR:
after = hex( int(ASLR, 16) + int(command, 16) )
print after
else:
print >>result, 'ASLR not found!'
def adr(debugger, command, result, internal_dict):
if not command:
print >>result, 'Please input the address!'
return
ASLR = get_ASLR(debugger)
if ASLR:
after = hex( int(command, 16) - int(ASLR, 16) )
print after
else:
print >>result, 'ASLR not found!'
def __lldb_init_module(debugger, internal_dict):
debugger.HandleCommand('command script add sbr -f sbr.sbr')
debugger.HandleCommand('command script add padr -f sbr.padr')
debugger.HandleCommand('command script add adr -f sbr.adr')
print 'The "sbr/padr/adr" python command has been installed and is ready for use.'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment