Open joelreymont opened 3 weeks ago
What is the size of the enum E_DjiAircraftType
in IDA? Is it 4 bytes or 8 bytes wide? Your enum in BN is typed to uint32_t
and the access is 8 bytes wide.
It's 4 bytes, same as BN
FFFFFFFF ; enum E_DjiAircraftType, copyof_59, width 4 bytes
FFFFFFFF DJI_AIRCRAFT_TYPE_UNKNOWN EQU 0
FFFFFFFF DJI_AIRCRAFT_TYPE_M200_V2 EQU 0x2C
FFFFFFFF DJI_AIRCRAFT_TYPE_M210_V2 EQU 0x2D
FFFFFFFF DJI_AIRCRAFT_TYPE_M210RTK_V2 EQU 0x2E
FFFFFFFF DJI_AIRCRAFT_TYPE_M300_RTK EQU 0x3C
FFFFFFFF DJI_AIRCRAFT_TYPE_M30 EQU 0x43
FFFFFFFF DJI_AIRCRAFT_TYPE_M30T EQU 0x44
FFFFFFFF DJI_AIRCRAFT_TYPE_M3E EQU 0x4D
FFFFFFFF DJI_AIRCRAFT_TYPE_FC30 EQU 0x4E
FFFFFFFF DJI_AIRCRAFT_TYPE_M3T EQU 0x4F
FFFFFFFF DJI_AIRCRAFT_TYPE_M350_RTK EQU 0x59
FFFFFFFF DJI_AIRCRAFT_TYPE_M3D EQU 0x5B
FFFFFFFF DJI_AIRCRAFT_TYPE_M3TD EQU 0x5D
So, firstly, this has nothing to do with the stack. The variables x0_10
and x1_3
are actually in registers. You can confirm this by hovering over the variable:
It also shows this at the top of the function if you turn on Hamburger Icon -> Show Variable Types -> At Top of Function
:
Instead, it has everything to do with our split load/store simplification. These are both equivalent and correct:
// IDA Pro
*&type = *&AIRCRAFT_INFO.aircraftType;
*&info->aircraftSeries = *&AIRCRAFT_INFO.aircraftSeries;
*&info->aircraftType = *&type;
info->mountPosition = AIRCRAFT_INFO.mountPosition;
// Binary Ninja
x0_10.d = s_aircraftBaseInfo.aircraftSeries // This read has been split into two, 4-byte reads
x0_10:4.d = *(&s_aircraftBaseInfo + 4)
int64_t x1_3 = s_aircraftBaseInfo.aircraftType.q
arg1->aircraftSeries = x0_10.d
arg1->mountPositionType = x0_10:4.d
arg1->aircraftType = x1_3.d
arg1->djiAdapterType = x1_3:4.d
arg1->mountPosition = s_aircraftBaseInfo.mountPosition
Our output is definitely less clear at the top (because we split up the reads for reasons I don't quite understand), but I think it's more clear at the bottom (because we show each individual write to a structure field).
If you agree, I think it's reasonable for us to investigate why the x0_10
assignment is being split in half. I can see that being confusing. But, these are 8-byte reads, so I expect both Binary Ninja and IDA to use 8-byte types here.
Co-authored by @fuzyll
If you agree, I think it's reasonable for us to investigate why the x0_10 assignment is being split in half. I can see that being confusing.
I definitely agree!
But, these are 8-byte reads, so I expect both Binary Ninja and IDA to use 8-byte types here.
I can split the expressions with IDA so that this
*&type = *&AIRCRAFT_INFO.aircraftType;
*&info->aircraftSeries = *&AIRCRAFT_INFO.aircraftSeries;
*&info->aircraftType = *&type;
info->mountPosition = AIRCRAFT_INFO.mountPosition;
becomes this
mount_pos_type = AIRCRAFT_INFO.mountPositionType;
type = AIRCRAFT_INFO.aircraftType;
sdk_adapter_type = AIRCRAFT_INFO.djiAdapterType;
info->aircraftSeries = AIRCRAFT_INFO.aircraftSeries;
info->mountPositionType = mount_pos_type;
info->aircraftType = type;
info->djiAdapterType = sdk_adapter_type;
info->mountPosition = AIRCRAFT_INFO.mountPosition;
Yes, you are correct. In order of issue priority:
x0_3
then x1_3
should be split, and vice versa.info
that the partial accesses (on x0_3
and x1_3
) are the only use and move them into that expression.
Version and Platform (required):
Internal binary
major dine favor
._DjiAircraftInfo_GetBaseInfo
...IDA does this
whereas BN outputs this HLIL
I thought BN needs help with the stack so I went to look at it. Unfortunately, the stack layout window doesn't let me copy the contents so I'm attaching a pic:
Where are
x0_9
andx1_3
in the stack? How can I split them into 32-bit ints?I thought that these could be at offset
-0x50
but creating a variable there doesn't affect the use ofx0_9
andx1_3
.Why do I have both
var_10
andvar_10_1
at offset-0x10
in the stack layout, at the same offset aserr_code
?It would be very helpful to carry the variable names into the stack. For example, BN knows that
struct T_DjiAircraftInfoBaseInfo*
is at-0x38
but calls itvar_38'. When try to rename it to
infoBN doesn't detect it's an alias and wants to call it
info_1`.I can get highlights of
err_code
in the HLIL when I click onerr_code
in the stack layout but it doesn't happen withvar_38
. Why?IDA stack
Full IDA Pro output
Full BN output