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

Support for multiple return points

Open op2786 opened this issue 2 years ago • 0 comments

As far as I can see, BN always uses one return point at the end of the function. I think supporting for multiple return points would be useful in some situations.

180001000  int64_t get_dll_info(wchar16* name, struct MODULEENTRY32W* lpme)

18000101c  void var_258
18000101c  int64_t rax_1 = data_180023000 ^ &var_258
180001035  HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, 0)
180001042  CHAR Log[256]
180001042  if (hSnap == -1) {
18000107d      sprintf_s(&Log, 256, "CreateToolhelp32Snapshot failed")
180001087      OutputDebugStringA(&Log)
180001082  } else {
180001097      lpme->dwSize = 1080
1800010a8      if (Module32FirstW(hSnap, lpme) == 0) {
1800010e3          sprintf_s(&Log, 256, "ModuleFirst failed")
1800010ed          OutputDebugStringA(&Log)
1800010f6          CloseHandle(hSnap)
1800010f6      } else {
18000111f          BOOL rax_12
18000111f          do {
18000110f              if (wcsstr(&lpme->szModule, name) != 0) {
18000110f                  break
18000110f              }
180001117              rax_12 = Module32NextW(hSnap, lpme)
180001117          } while (rax_12 != 0)
18000112c          CloseHandle(hSnap)
18000112c      }
18000112c  }
18000115c  return __security_check_cookie(rax_1 ^ &var_258)

Why not return at address 180001087 directly? This way we can eliminate else {...} block indent.

In a lot of situations, returning in the beginning would generate way more readable code. Because a lot of time in the functions we code like "if this is false, return" things.

op2786 avatar Aug 11 '22 07:08 op2786