Skip to content

Instantly share code, notes, and snippets.

@krzyzanowskim
Created October 16, 2016 23:20
Show Gist options
  • Save krzyzanowskim/6fcf9fbdf671b8b93e7541bfd3b9cb9e to your computer and use it in GitHub Desktop.
Save krzyzanowskim/6fcf9fbdf671b8b93e7541bfd3b9cb9e to your computer and use it in GitHub Desktop.
Hopper Disassembler Swift names demangle script
import subprocess
def looksLikeBeginning(doc,seg,adr):
if isinstance(seg.getNameAtAddress(adr), str):
label = seg.getNameAtAddress(adr)
pos = label.find("_T")
if pos != -1:
return label[pos:]
return None
def demangle(sym, addr):
proc = subprocess.Popen(['xcrun','swift-demangle',sym],stdout=subprocess.PIPE,stderr=subprocess.PIPE)
output, errors = proc.communicate()
if errors is not None:
doc.log(errors)
if output is not None:
func = output.split('>', 1)[1]
func = func.strip()
if func is not None:
doc.log("Demangle " + sym + " to \"" + func + "\"")
doc.setNameAtAddress(addr,func)
doc = Document.getCurrentDocument()
seg = doc.getCurrentSegment()
#[adr, last] = doc.getSelectionAddressRange()
adr = seg.getStartingAddress() #doc.getCurrentAddress()
last = adr + seg.getLength()
while adr < last:
sym = looksLikeBeginning(doc,seg,adr)
if sym is not None:
demangle(sym, adr)
adr += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment