binaryninja-api icon indicating copy to clipboard operation
binaryninja-api copied to clipboard

Strange clearing of local variables with auto-generated memset

Open joelreymont opened this issue 1 year ago • 0 comments

Version and Platform (required):

  • Binary Ninja Version: 4.1.5260-dev, 7f6bb9ee
  • OS: macos
  • OS Version: 14.4
  • CPU Architecture: arm64

Internal binary major dine favor. Related to #5389?

BN auto-generates these calls to memset periodically. They are sometimes useful to determine the size of a stack allocated structure. Still, what is this memset doing?

0006815c  struct ErrObj* DjiError_GetErrorMsgElements(int64_t err_code, struct ErrDesc* err_desc @ x8)

00068178      char* description
00068178      __builtin_memset(s: &description, c: 0, n: 0x20)
000681a4      struct ErrObj* err_obj
000681a4      uint32_t err = zx.d(DjiError_IsSuccess(DjiError_SearchObject(err_code, err_obj: &err_obj)) ^ 1)
000681ac      if (err != 0)
000681d8          DjiLogger_Output("errno", 0, "[%s:%d) Search error object fail…", "DjiError_GetErrorMsgElements", 0x55)
000681ec      if (err == 0 && err_obj->description == 0)
00068218          DjiLogger_Output("errno", 0, "[%s:%d) Error description is nul…", "DjiError_GetErrorMsgElements", 0x5a)
000681ec      char* suggestion_1
000681ec      char* recovery_1
000681ec      if (err != 0 || err_obj->description == 0)
000682b0          DjiLogger_Output("errno", 0, "[%s:%d) Print error message fail…", "DjiError_GetErrorMsgElements", 0x66, err_code)
000681ec      else
00068228          description = err_obj->description
00068238          char* suggestion
00068238          if (err_obj->recovery == 0)
00068250              suggestion = &ERR_EMPTY
00068238          else
00068244              suggestion = ERR_SUGGESTION
00068254          suggestion_1 = suggestion
00068264          char* recovery
00068264          if (err_obj->recovery == 0)
00068278              recovery = &ERR_EMPTY
00068264          else
0006826c              recovery = err_obj->recovery
0006827c          recovery_1 = recovery
000682c0      err_desc->description = description
000682c0      err_desc->suggestion = suggestion_1
000682c8      err_desc->recovery = recovery_1
000682d8      return err_desc

joelreymont avatar May 10 '24 12:05 joelreymont