-
-
Save Adobels/eaeb3bb4871b98303095d9b63ed8f863 to your computer and use it in GitHub Desktop.
Hopper Disassembler Swift names demangle script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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