DGA-MI-SSI / YaCo

YaCo is an Hex-Rays IDA plugin. When enabled, multiple users can work simultaneously on the same binary. Any modification done by any user is synchronized through git version control.
GNU General Public License v3.0
313 stars 36 forks source link

segment base corruption #52

Open SpenserStyles opened 5 years ago

SpenserStyles commented 5 years ago

I'm attempting to use YaCo v2.6 with IDA 7.0 on a 8051 code base that uses banking for code pages. The segment base is corrupted when opening the _local IDB. This appears to be caused by incorrect use of the ida_segment.get_segm_base() and ida_segment.set_segm_base().

The following steps can be used to replicate the issue:

now when using set_segm_base(seg) it screws it up the base

ida_segment.set_segm_base(seg, base)

get segment base linear address

seg = ida_segment.get_segm_by_name("B03") base = ida_segment.get_segm_base(seg) print(base) # this prints 65536 when should be 4096

now when using set_segm_base(seg) it screws it up the base for segment B03

ida_segment.set_segm_base(seg, base)


![image](https://user-images.githubusercontent.com/31034116/48194567-62711380-e31b-11e8-957c-b827733297ba.png)

- Run script command
- Close and re-open Program Segmentation view and the BASE value has now been changed to incorrect values
![image](https://user-images.githubusercontent.com/31034116/48194557-59804200-e31b-11e8-8a93-494bc8e94a38.png)

YaCo is currently relying on get_segm_base() to return the value that should be used when calling set_segm_base().  This is incorrect.  I believe you must shift the value obtained by calling get_segm_base() right 4 bits for the value to use when calling set_segm_base().

Ultimately I think IDA may have this screwed up because I would have expected these to be complimentary functions.  I am unable to test this on IDA 7.1 so it could be possible that it may be corrected.
bamiaux commented 5 years ago

Thanks for the bug report, I've reproduced the bug on 7.2 & added the right shift on master. https://github.com/DGA-MI-SSI/YaCo/commit/9b85e6ca1809114c4df1382c11255f7e38408912 Please check if it fixes your issue. Note that IDA does not send any event when changing the segment base leading to potentially missing changes.