Ghidra: How to get the labeled instructions using python with ./analyzeHeadless?

Created on 17 Jul 2019  路  2Comments  路  Source: NationalSecurityAgency/ghidra

I am using the ghidra api. I have written a script which nothing but prints the instructions of selected functions. I am iterating from the entrypoint of particular function (say main) and fetching the instructions using getInstructionAt(instruction), but I am getting instructions in the unlabeled format - something like:

00400595 MOV EDX,dword ptr [RBP + -0x1c]

Instead of say:

00400595 MOV EDX,dword ptr [RBP + p]

Here p is the variable label (I can get this information from ghidra gui by analyzing the binary, but I just can't get this information using scripts and ghidra api).

Is there any way (any function in an api) to print this labeled information?

Question

Most helpful comment

How about:

getCodeUnitFormat().getRepresentationString(currentProgram.getListing().getCodeUnitAt(currentAddress))

All 2 comments

How about:

getCodeUnitFormat().getRepresentationString(currentProgram.getListing().getCodeUnitAt(currentAddress))

This is great thanks so much! @ryanmkurtz

Was this page helpful?
0 / 5 - 0 ratings

Related issues

forkoz picture forkoz  路  3Comments

CalcProgrammer1 picture CalcProgrammer1  路  3Comments

awsaba picture awsaba  路  3Comments

ghost picture ghost  路  3Comments

0x6d696368 picture 0x6d696368  路  3Comments