jevey / idapython

Automatically exported from code.google.com/p/idapython
Other
1 stars 0 forks source link

StructMembers() operates incorrectly on structures with gaps #90

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
# What steps will reproduce the problem?

1. Create a structure with gaps in it:

00000000 MyExampleStruc struc ; (sizeof=0x101)
00000000 None db ?
00000001 bar db ?
00000002     db ? ; undefined
00000003     db ? ; undefined
00000004     db ? ; undefined
00000005     db ? ; undefined
00000006 field_6 dd ?
0000000A field_A db ?
0000000B     db ? ; undefined
...
00000012     db ? ; undefined
00000013 xxx dd ?
00000017     db ? ; undefined
...
000000EF     db ? ; undefined
000000F0 Field2 dd ?
000000F4     db ? ; undefined
...
000000FD     db ? ; undefined
000000FE Field3 dw ?
00000100 xField db ?
00000101 MyExampleStruc ends

2. Iterate over the fields in the structure with StructMembers:
for (o,n,s) in StructMembers(sid): print "%s @ %s-%s" % (n,o,o+(s or 0))

# What is the expected output? 

Python>for (o,n,s) in StructMembers2(sid): print "%s @ %s-%s" % (n,o,o+(s or 0))
None @ 0-1
bar @ 1-2
field_6 @ 6-10
field_A @ 10-11
xxx @ 19-23
Field2 @ 240-244
Field3 @ 254-256
xField @ 256-257

# What do you see instead?

Python>for (o,n,s) in StructMembers(sid): print "%s @ %s-%s" % (n,o,o+(s or 0))
None @ 0-1
bar @ 1-2
None @ 2-2
None @ 3-3
None @ 4-4
None @ 5-5
field_6 @ 6-10
field_A @ 10-11

# What version of the product are you using? On what operating system?

6.4.130306

# Please provide any additional information below.

I have attached a patch which resolves the issue.

Original issue reported on code.google.com by zachrig...@gmail.com on 29 Nov 2013 at 4:31

Attachments:

GoogleCodeExporter commented 9 years ago
Updated version of the patch which fixes a regression against zero-member 
structures.

Original comment by zachrig...@gmail.com on 30 Nov 2013 at 4:31

Attachments:

GoogleCodeExporter commented 9 years ago
Noticed this issue while looking for another--I encountered this problem myself 
before even seeing this report. I reported it to Hex-Rays and it's fixed in the 
latest IDA service pack.

Original comment by m...@60hz.org on 28 Jan 2014 at 11:31

GoogleCodeExporter commented 9 years ago
Can confirm this is fixed, at least as of 6.6

AddStruc(-1, 'example')
sid = GetStrucIdByName('example')

for offset in range(0,0x20,4):
    AddStrucMember(sid=sid,
                   name='field_%x' % offset,
                   offset=offset,
                   flag=SizeToFlag[4],
                   typeid=-1,
                   nbytes=4)

DelStrucMember(sid, 4)

for member in StructMembers(sid):
    print member

# (0, 'field_0', 4)
# (8, 'field_8', 4)
# (12, 'field_c', 4)
# (16, 'field_10', 4)
# (20, 'field_14', 4)
# (24, 'field_18', 4)
# (28, 'field_1c', 4)

Original comment by zachrig...@gmail.com on 19 Jun 2014 at 6:53