Vector35 / Vector35/binaryninja-api

Improved copying of data structures

Open
#3,720 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Component: UI IL Optimization Impact: Medium
Dominant language
C++
Stars
1.3k
Forks
298
Avg merge
5d 5h
Merged PRs (30d)
19

Description

I see that there is room to making a nice optimization when copying of data structures. Here is an example:

Test code:

SYSTEMTIME a;
FILETIME b;

void struct_copy()
{
	SYSTEMTIME systemTime;
	FILETIME filetime;
	GetSystemTime(&systemTime);
	SystemTimeToFileTime(&systemTime, &filetime);

	a = systemTime;
	b = filetime;
	
}

HLIL result:

void sub_140001010()

struct SYSTEMTIME systemTime
GetSystemTime(&systemTime)
struct FILETIME fileTime
SystemTimeToFileTime(&systemTime, &fileTime)
struct SYSTEMTIME* rdi = &a
struct SYSTEMTIME* rsi = &systemTime
for (int64_t rcx_2 = 0x10; rcx_2 != 0; rcx_2 = rcx_2 - 1)
  rdi->wYear.b = rsi->wYear.b
  rdi = &rdi->wYear + 1
  rsi = &rsi->wYear + 1
int64_t rax
rax.d = fileTime.dwLowDateTime
rax:4.d = fileTime.dwHighDateTime
b.dwLowDateTime = rax.d
*(&b + 4) = rax:4.d

It would be great if binary ninja could turn these two into a simple = operation.

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.

Research direction

The issue provides a C example using SYSTEMTIME and FILETIME and shows the resulting HLIL. Start by reproducing this example and inspecting how these structure copies are represented. Done means both copies are emitted as simple assignment operations rather than expanded copy loops or scalar stores.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
reverse-engineering
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.