Optimization for directly using global variables

Open
#3,919 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Needs clarification
Activity status
Stale
Tech stack
cpp

Research direction

Start by locating the decompiler logic responsible for simplifying global-variable accesses and compare the three examples in this issue with cases that are already simplified. Determine which existing decision prevents removing the temporary locals, then verify that the transformation preserves behavior and handles all relevant cases.

Written by the indexing model from the issue text.

Description

Component: Core Core: HLIL Effort: Medium IL Optimization Impact: Medium
140002b7d    HANDLE rax_1
140002b7d    rax_1 = CreateThread(nullptr, nullptr, MainThread, nullptr, THREAD_CREATE_RUN_IMMEDIATELY, nullptr)
140002b83    main_thread_handle = rax_1

could be simplified like this:

main_thread_handle = CreateThread(nullptr, nullptr, MainThread, nullptr, THREAD_CREATE_RUN_IMMEDIATELY, nullptr)

Another example:

140002a54    int64_t* rcx_6 = svc_status_handle
140002a62    ServiceStatus.dwCurrentState = SERVICE_STOPPED
140002a6c    SetServiceStatus(rcx_6, &ServiceStatus)

which could be simplified like this:

140002a62    ServiceStatus.dwCurrentState = SERVICE_STOPPED
140002a6c    SetServiceStatus(svc_status_handle, &ServiceStatus)

Another one:

140002aa0    HANDLE rcx_3 = main_thread_handle
140002aaa    data_140033c5c = 1
140002ab1    WaitForSingleObject(rcx_3, 0xffffffff)

which cold be simplified to:

140002aaa    data_140033c5c = 1
140002ab1    WaitForSingleObject(main_thread_handle, 0xffffffff)

Actually there is cases which codes like above already simplified, but because of some interesting decision these ones does not simplified.

Dominant language
C++
Stars
1.3k
Forks
298
Avg merge
5d 5h
Merged PRs (30d)
19

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Vector35/binaryninja-api

All issues in Vector35/binaryninja-api

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.