Closed ghost closed 7 years ago
hey @binoopang
You ask a lot of really good questions! Thanks for reporting this issue.
To be honest, I haven't completely recovered the format of these segment blobs. As you can see, the library is able to extract a sequence of integer values, but they may not be mapped correctly. I had reviewed the hex-rays online documentation for hints as to what these fields may be, but haven't verified all of them.
If you can correct the ordering of these fields, I'd be extremely grateful! The relevant code is here. I'll also take a look over the next few days and see what I can add.
Actually, I'm not sure that I'm using python-idb in right way. Can you help me?
What makes you think you are using it incorrectly? From the snippets you've sent me, I think you've found a way to use the library well.
I've tried to set up a python-idb interface so it emulates the IDA Pro one. This means it should be possible to run scripts both in IDA Pro and under python-idb. Take a look at scripts/run_ida_script.py. This might allow you to run the same script in different environments and compare the results.
While the IDA Pro scripting interface can be inconsistent and confusing, IDAPython users should be able to use python-idb without learning many new concepts.
here's a script that runs in IDA Pro and python-idb:
#!/usr/bin/env python
import idc
import idaapi
import idautils
def print_section_list():
for s in idautils.Segments():
seg = idaapi.getseg(s)
print('%s' % idc.SegName(s))
print(' - start address: 0x%x' % seg.startEA)
print(' - sclass: 0x%x' % seg.sclass)
print(' - orgbase: 0x%x' % seg.orgbase)
print(' - align: 0x%x' % seg.align)
print(' - comb: 0x%x' % seg.comb)
print(' - perm: 0x%x' % seg.perm)
print(' - bitness: 0x%x' % seg.bitness)
print(' - flag: 0x%x' % seg.flags)
print(' - sel: 0x%x' % seg.sel)
print(' - defsr: 0x%x' % seg.defsr)
print(' - type: 0x%x' % seg.type)
print(' - color: 0x%x' % seg.color)
print_section_list()
and here are the results, side by side:
IDA python-idb
=== ==========
.init .init
- start address: 0x80496ac - start address: 0x80496ac
- sclass: 0x2 - sclass: 0x2
- orgbase: 0x0 - orgbase: 0x0
- align: 0x5 - align: 0x10
- comb: 0x2 - comb: 0x5
- perm: 0x5 - perm: 0x2
- bitness: 0x1 - bitness: 0x5
- flag: 0x10 - flag: 0x1
- sel: 0x1 - sel: 0x2
- defsr: 0x156653e - defsr: 0x1
- type: 0x2 - type: 0x0
- color: 0xffffffff - color: 0x0
.plt .plt
- start address: 0x80496d0 - start address: 0x80496d0
- sclass: 0x2 - sclass: 0x2
- orgbase: 0x0 - orgbase: 0x0
- align: 0x3 - align: 0x10
- comb: 0x2 - comb: 0x3
- perm: 0x5 - perm: 0x2
- bitness: 0x1 - bitness: 0x5
- flag: 0x10 - flag: 0x1
- sel: 0x2 - sel: 0x2
- defsr: 0x15665ae - defsr: 0x2
- type: 0x2 - type: 0x0
- color: 0xffffffff - color: 0x0
.plt.got .plt.got
- start address: 0x8049de0 - start address: 0x8049de0
- sclass: 0x2 - sclass: 0x2
- orgbase: 0x0 - orgbase: 0x0
- align: 0xa - align: 0x10
- comb: 0x2 - comb: 0xa
- perm: 0x5 - perm: 0x2
- bitness: 0x1 - bitness: 0x5
- flag: 0x10 - flag: 0x1
- sel: 0x3 - sel: 0x2
- defsr: 0x1566656 - defsr: 0x3
- type: 0x2 - type: 0x0
- color: 0xffffffff - color: 0x0
.text .text
- start address: 0x8049df0 - start address: 0x8049df0
- sclass: 0x2 - sclass: 0x2
- orgbase: 0x0 - orgbase: 0x0
- align: 0x3 - align: 0x10
- comb: 0x2 - comb: 0x3
- perm: 0x5 - perm: 0x2
- bitness: 0x1 - bitness: 0x5
- flag: 0x10 - flag: 0x1
- sel: 0x4 - sel: 0x2
- defsr: 0x15666c6 - defsr: 0x4
- type: 0x2 - type: 0x0
- color: 0xffffffff - color: 0x0
.fini .fini
- start address: 0x805b634 - start address: 0x805b634
- sclass: 0x2 - sclass: 0x2
- orgbase: 0x0 - orgbase: 0x0
- align: 0x5 - align: 0x10
- comb: 0x2 - comb: 0x5
- perm: 0x5 - perm: 0x2
- bitness: 0x1 - bitness: 0x5
- flag: 0x10 - flag: 0x1
- sel: 0x5 - sel: 0x2
- defsr: 0x156679e - defsr: 0x5
- type: 0x2 - type: 0x0
- color: 0xffffffff - color: 0x0
.rodata .rodata
- start address: 0x805b660 - start address: 0x805b660
- sclass: 0x8 - sclass: 0x8
- orgbase: 0x0 - orgbase: 0x0
- align: 0x8 - align: 0x10
- comb: 0x2 - comb: 0x8
- perm: 0x4 - perm: 0x2
- bitness: 0x1 - bitness: 0x4
- flag: 0x10 - flag: 0x1
- sel: 0x6 - sel: 0x3
- defsr: 0x156680e - defsr: 0x6
- type: 0x3 - type: 0x0
- color: 0xffffffff - color: 0x0
.eh_frame_hdr .eh_frame_hdr
- start address: 0x8060c14 - start address: 0x8060c14
- sclass: 0x8 - sclass: 0x8
- orgbase: 0x0 - orgbase: 0x0
- align: 0x5 - align: 0x10
- comb: 0x2 - comb: 0x5
- perm: 0x4 - perm: 0x2
- bitness: 0x1 - bitness: 0x4
- flag: 0x10 - flag: 0x1
- sel: 0x7 - sel: 0x3
- defsr: 0x156687e - defsr: 0x7
- type: 0x3 - type: 0x0
- color: 0xffffffff - color: 0x0
.eh_frame .eh_frame
- start address: 0x8061430 - start address: 0x8061430
- sclass: 0x8 - sclass: 0x8
- orgbase: 0x0 - orgbase: 0x0
- align: 0x5 - align: 0x10
- comb: 0x2 - comb: 0x5
- perm: 0x4 - perm: 0x2
- bitness: 0x1 - bitness: 0x4
- flag: 0x10 - flag: 0x1
- sel: 0x8 - sel: 0x3
- defsr: 0x15668ee - defsr: 0x8
- type: 0x3 - type: 0x0
- color: 0xffffffff - color: 0x0
.init_array .init_array
- start address: 0x8067f00 - start address: 0x8067f00
- sclass: 0xc - sclass: 0xc
- orgbase: 0x0 - orgbase: 0x0
- align: 0x5 - align: 0x10
- comb: 0x2 - comb: 0x5
- perm: 0x6 - perm: 0x2
- bitness: 0x1 - bitness: 0x6
- flag: 0x10 - flag: 0x1
- sel: 0x9 - sel: 0x3
- defsr: 0x1566a26 - defsr: 0x9
- type: 0x3 - type: 0x0
- color: 0xffffffff - color: 0x0
.fini_array .fini_array
- start address: 0x8067f04 - start address: 0x8067f04
- sclass: 0xc - sclass: 0xc
- orgbase: 0x0 - orgbase: 0x0
- align: 0x5 - align: 0x10
- comb: 0x2 - comb: 0x5
- perm: 0x6 - perm: 0x2
- bitness: 0x1 - bitness: 0x6
- flag: 0x10 - flag: 0x1
- sel: 0xa - sel: 0x3
- defsr: 0x1566a96 - defsr: 0xa
- type: 0x3 - type: 0x0
- color: 0xffffffff - color: 0x0
.jcr .jcr
- start address: 0x8067f08 - start address: 0x8067f08
- sclass: 0xc - sclass: 0xc
- orgbase: 0x0 - orgbase: 0x0
- align: 0x5 - align: 0x10
- comb: 0x2 - comb: 0x5
- perm: 0x6 - perm: 0x2
- bitness: 0x1 - bitness: 0x6
- flag: 0x10 - flag: 0x1
- sel: 0xb - sel: 0x3
- defsr: 0x1566b06 - defsr: 0xb
- type: 0x3 - type: 0x0
- color: 0xffffffff - color: 0x0
.got .got
- start address: 0x8067ffc - start address: 0x8067ffc
- sclass: 0xc - sclass: 0xc
- orgbase: 0x0 - orgbase: 0x0
- align: 0x5 - align: 0x10
- comb: 0x2 - comb: 0x5
- perm: 0x6 - perm: 0x2
- bitness: 0x1 - bitness: 0x6
- flag: 0x10 - flag: 0x1
- sel: 0xc - sel: 0x3
- defsr: 0x1566b76 - defsr: 0xc
- type: 0x3 - type: 0x0
- color: 0xffffffff - color: 0x0
.got.plt .got.plt
- start address: 0x8068000 - start address: 0x8068000
- sclass: 0xc - sclass: 0xc
- orgbase: 0x0 - orgbase: 0x0
- align: 0x5 - align: 0x10
- comb: 0x2 - comb: 0x5
- perm: 0x6 - perm: 0x2
- bitness: 0x1 - bitness: 0x6
- flag: 0x10 - flag: 0x1
- sel: 0xd - sel: 0x3
- defsr: 0x1566be6 - defsr: 0xd
- type: 0x3 - type: 0x0
- color: 0xffffffff - color: 0x0
.data .data
- start address: 0x80681e0 - start address: 0x80681e0
- sclass: 0xc - sclass: 0xc
- orgbase: 0x0 - orgbase: 0x0
- align: 0x8 - align: 0x10
- comb: 0x2 - comb: 0x8
- perm: 0x6 - perm: 0x2
- bitness: 0x1 - bitness: 0x6
- flag: 0x10 - flag: 0x1
- sel: 0xe - sel: 0x3
- defsr: 0x1566c56 - defsr: 0xe
- type: 0x3 - type: 0x0
- color: 0xffffffff - color: 0x0
.bss
- start address: 0x8068380
- sclass: 0x13
- orgbase: 0x0
- align: 0x9
- comb: 0x2
- perm: 0x6
- bitness: 0x1
- flag: 0x10
- sel: 0xf
- defsr: 0x1566cc6
- type: 0x9
- color: 0xffffffff
extern
- start address: 0x8068fb8
- sclass: 0x0
- orgbase: 0x0
- align: 0x3
- comb: 0x2
- perm: 0x0
- bitness: 0x1
- flag: 0x10
- sel: 0x10
- defsr: 0x1566d36
- type: 0x1
- color: 0xffffffff
python-idb is missing segments:
.bss
extern
fixed segment parsing in c633faa3f2e1f574b791cda6d7346e888b8e7d96.
this should address the issue of parsing segment fields above. it doesn't address where the extern
data is...
Hi @williballenthin ! Thank you for your kind response. I'm using python-idb
for my personal
project. And it is really useful! Thank you again!
Hi!
When I try to read segment descriptor using
api.idaapi.getsegs
, I got partially invalid result.With this segments, I printed out segment information using folowing python code.
And the result is following
I think the value of
sclass
is correct. And value ofbitness
is actually value ofperm
. And the vaule oftype
is always0
. According to the IDA SDK, the value 0 means thatunknown type
. And one more thing, In the result, there is no.bss
section.Actually, I'm not sure that I'm using
python-idb
in right way. Can you help me?I made a following link again. This is a IDB of
/bin/ls
on Ubuntu OS 32bit.ls.idb
Thank you for your help!