Created
June 6, 2022 12:13
-
-
Save rpetrich/8f5679ed0c9acf6e0ae3efa121a91199 to your computer and use it in GitHub Desktop.
Hopper Disassembler script to assign names to CET-enabled PLT stubs
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
doc = Document.getCurrentDocument() | |
for i in range(0, doc.getSegmentCount()): | |
segment = doc.getSegment(i) | |
for j in range(0, segment.getSectionCount()): | |
section = segment.getSection(j) | |
if section.getName() == ".plt.sec": | |
address = section.getStartingAddress() | |
length = section.getLength() | |
off = 0 | |
while off < length: | |
ins = segment.getInstructionAtAddress(address + off) | |
name = segment.getNameAtAddress(address + off) | |
if name is not None and ins.getInstructionString() == "endbr64": | |
next_ins = address + off + ins.getInstructionLength() | |
if segment.getInstructionAtAddress(next_ins).getInstructionString() == "bnd jmp": | |
refs = segment.getReferencesFromAddress(next_ins) | |
if len(refs) == 1: | |
new_name = doc.getNameAtAddress(refs[0]) | |
new_name = new_name.rsplit("@GOT", 1)[0] + "@plt" | |
segment.setNameAtAddress(address + off, new_name) | |
off += ins.getInstructionLength() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment