avast / avast/retdec

Wrong decompilation of division by multiplication

Open
#797 1 comment 0 reactions 0 assignees View on GitHub
P-output
Dominant language
C++
Stars
8.6k
Forks
1k
PR merge metrics
No merged PRs in 30d

Description

Subject: https://github.com/rfalke/decompiler-subjects/tree/master/from_holdec/dmi/exp/ia32_elf/subject.exe

Source:
```
int intermediate_3_division_by_multiplication(int arg)
{
putchar(arg / 7);
return 0;
}
```

Output
```
int32_t intermediate_3_division_by_multiplication(int32_t c) {
// 0x80485be
putchar(c);
return 0;
}
```

An older version of retdec gave:
```
int32_t intermediate_3_division_by_multiplication(int64_t a1) {
int32_t v1 = a1; // 0x80485c6
putchar(((int32_t)(-0x6db6db6d * a1 / 0x100000000) + v1) / 4 - (v1 >> 31));
return 0;
}
```
which may be more correct.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reproducing the decompilation of subject.exe from the linked decompiler-subjects path and compare the result for intermediate_3_division_by_multiplication with the source and older output shown here. Done means the generated code preserves the division by 7 instead of emitting putchar(c), with the return value unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers, reverse-engineering
Issue type
Bug
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.