Ghidra: How to get the address of vertex in Function graph by using some python api?

Created on 29 Jun 2019  路  7Comments  路  Source: NationalSecurityAgency/ghidra

I want to get the basic block in Function graph by containing address,and then get the start address and end address of it.How to get it?

Question

Most helpful comment

from ghidra.program.model.block import BasicBlockModel

basicBlockModel = BasicBlockModel(currentProgram)
codeBlocks = basicBlockModel.getCodeBlocksContaining(currentAddress, monitor)
listing = currentProgram.getListing()

for codeBlock in codeBlocks:
    print listing.getCodeUnitContaining(codeBlock.getMinAddress()).getAddress(), listing.getCodeUnitContaining(codeBlock.getMaxAddress()).getAddress()

All 7 comments

See #92, #444, #613.

Thanks, @saruman9. Did you get what you needed from that @Kingkingyoung?

Thanks, @saruman9. Did you get what you needed from that @Kingkingyoung?

Not yet,Code Block or Code unit is not what I want.I want to get a vertex(in function graph view) start/end address by a containg address.I found getBasicBlocks() in ghidra.program.model.pcode.PcodeSyntaxTree and the class PcodeBlockBasic seems has start/end address.But I have not find how to get it properly.And I also found ghidra.app.plugin.core.functiongraph in source code,but I can't find it in doc. And I'm trying to figure it out.But I'm not sure it is the correct way.
vertex
e.g I want to get address 8e48 and 8e59 by any address in this block

from ghidra.program.model.block import BasicBlockModel

basicBlockModel = BasicBlockModel(currentProgram)
codeBlocks = basicBlockModel.getCodeBlocksContaining(currentAddress, monitor)
listing = currentProgram.getListing()

for codeBlock in codeBlocks:
    print listing.getCodeUnitContaining(codeBlock.getMinAddress()).getAddress(), listing.getCodeUnitContaining(codeBlock.getMaxAddress()).getAddress()
from ghidra.program.model.block import BasicBlockModel

basicBlockModel = BasicBlockModel(currentProgram)
codeBlocks = basicBlockModel.getCodeBlocksContaining(currentAddress, monitor)
listing = currentProgram.getListing()

for codeBlock in codeBlocks:
    print listing.getCodeUnitContaining(codeBlock.getMinAddress()).getAddress(), listing.getCodeUnitContaining(codeBlock.getMaxAddress()).getAddress()

Thanks! This is exactly what I want.Thanks again!

from ghidra.program.model.block import BasicBlockModel

basicBlockModel = BasicBlockModel(currentProgram)
codeBlocks = basicBlockModel.getCodeBlocksContaining(currentAddress, monitor)
listing = currentProgram.getListing()

for codeBlock in codeBlocks:
    print listing.getCodeUnitContaining(codeBlock.getMinAddress()).getAddress(), listing.getCodeUnitContaining(codeBlock.getMaxAddress()).getAddress()

And I will close this issue.

Thanks @saruman9!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

loudinthecloud picture loudinthecloud  路  3Comments

Merculous picture Merculous  路  3Comments

forkoz picture forkoz  路  3Comments

rrivera1849 picture rrivera1849  路  3Comments

Barakat picture Barakat  路  3Comments