📚 OpenRCE is preserved as a read-only archive. Launched at RECon Montreal in 2005. Registration and posting are disabled.








Flag: Tornado! Hurricane!

 Forums >>  IDA Pro  >>  IDA Python Scripts

Topic created on: March 3, 2007 03:50 CST by stam321 .

Hi All,

1. Is it possible to easily get the start addresses
   of all basic blocks?(I know pida script does it but
   is't there a simple way to enumerate basic blocks?)
2. Is it possible to color ida basic blocks using ida
   python?

thx,
  stam

  ero     March 4, 2007 11:18.35 CST
A way of doing this could be by first getting all the addresses of code belonging to a function:


# Collecting function chunks
function_instructions = list()

# Get the tail iterator
func_iter = func_tail_iterator_t(get_func(ea))

# While the iterator's status is valid
status = func_iter.main()

while status:
    # Get the chunk
    chunk = func_iter.chunk()

    # Go through all instructions in the basic block
    # and add them to our list
    #
    for head in Heads(chunk.startEA, chunk.endEA):
        if isCode(getFlags(head)):
            function_instructions.append(head)

    # Get the last status
    status = func_iter.next()



Then, for each of the addresses we check if there're outgoing references and add them to our set of possible basic block start addresses:


basic_blocks = set()

for address in function_instructions:
    refs_from = CodeRefsFrom(address, 1)
    if len(refs_from)>1:
        basic_blocks.update(refs_from)


After we collect those, we clean up the list leaving only references pointing within the function:


basic_blocks = filter(lambda i: i in function_instructions, basic_blocks)

print map(hex, basic_blocks)


And that's the list of start addresses of the basic blocks.

The only problems that i foresee could arise in highly optimized code if IDA did not properly assign all function chunks to the function, but for most cases it'll do just fine.

Hope this helps,

  stam321     March 5, 2007 03:44.24 CST
Thanks.
This is almost the code i used already.
I hoped there is a simpler way :)

  memo5     March 6, 2007 11:24.32 CST
Hello All
I'm trying to download IDAPython v0.8.0 plugin but it seems like the download link is broken any one can post a link to a mirror or some thing.

  ero     March 6, 2007 17:57.13 CST
This is the official site, the links should work there.

  pedram     March 8, 2007 17:33.44 CST
I meant to respond to this sooner, but better late than never. Here is a simple function I use to color from IDA Python:

def color_block (bb, color):
    '''
        color = 0xBBGGRR

        use DEFCOLOR to remove coloring
    '''

    for ea in Heads(bb.ea_start, bb.ea_end):
        SetColor(ea, CIC_ITEM, color)

The only non-straight forward portion of which is that IDA handles color in BGR vs. RGB.

  MohammadHosein     March 8, 2007 20:14.31 CST
> ero: This is the official site, the links should work there.

ero , something must be wrong with your Server , because i'm having trouble too , domain name doesnt even resolve but using an American web proxy its available . i had this problem once before but never told you thought its only me now i see others have this problem . btw i realized me and the other guy who had problem both reside on ME area , does it make any sense ?

( sorry to interrupt with off topic post )

  ero     March 9, 2007 02:42.29 CST
It's not my site/server so unfortunately I can't do much else than pinging the owner.

  tOpO     March 9, 2007 12:59.32 CST
> pedram: I meant to respond to this sooner, but better late
> than never. Here is a simple function I use to color from
>IDA Python:

At this moment i can't access the idapython site, but in my version of idapython the SetColor() function it is commented in the file idc.py... do i have an old version or what?

  pedram     March 9, 2007 15:51.19 CST
I made a quick mirror of the latest IDA Python here:

http://www.openrce.org/ida_python/

Until the original site becomes accessible. Try the latest version and see if the SetColor() routine works for you, it should.

  stam321     March 9, 2007 17:05.35 CST
SetColor dont work for me as well.

Note: Registration is required to post to the forums.

There are 31,328 total registered users.


Recently Created Topics
[help] Unpacking VMP...
Mar/12
Reverse Engineering ...
Jul/06
let 'IDAPython' impo...
Sep/24
set 'IDAPython' as t...
Sep/24
GuessType return une...
Sep/20
About retrieving the...
Sep/07
How to find specific...
Aug/15
How to get data depe...
Jul/07
Identify RVA data in...
May/06
Question about memor...
Dec/12


Recent Forum Posts
Finding the procedur...
rolEYder
Question about debbu...
rolEYder
Identify RVA data in...
sohlow
let 'IDAPython' impo...
sohlow
How to find specific...
hackgreti
Problem with ollydbg
sh3dow
How can I write olly...
sh3dow
New LoadMAP plugin v...
mefisto...
Intel pin in loaded ...
djnemo
OOP_RE tool available?
Bl4ckm4n


Recent Blog Entries
halsten
Mar/14
Breaking IonCUBE VM

oleavr
Oct/24
Anatomy of a code tracer

hasherezade
Sep/24
IAT Patcher - new tool for ...

oleavr
Aug/27
CryptoShark: code tracer ba...

oleavr
Jun/25
Build a debugger in 5 minutes

More ...


Recent Blog Comments
nieo on:
Mar/22
IAT Patcher - new tool for ...

djnemo on:
Nov/17
Kernel debugger vs user mod...

acel on:
Nov/14
Kernel debugger vs user mod...

pedram on:
Dec/21
frida.github.io: scriptable...

capadleman on:
Jun/19
Using NtCreateThreadEx for ...

More ...


Imagery
SoySauce Blueprint
Jun 6, 2008

[+] expand

View Gallery (11) / Submit