Bitwise dataflow
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- cpp
Research direction
The issue names no files or tests. Start by reviewing the existing LLIL flag APIs shown—flag_bit, set_flag, and test_bit—and how processor flags are represented; use the 8086 PushF/PopF example to understand the current workaround. Done means the API supports combining flags into a register and addresses the requested flag sub-register cases.
Written by the indexing model from the issue text.
Description
Currently, binja allows referring to the various processor flags individually, but in the hardware, they are combined into one register. Although common ISAs like x86 do not provide rich operations on flags and commonly encountered code does not invoke them, on microcontrollers it is very common to have extensive operations on flags for two reasons:
- the flags register is often either directly addressable via a memory, or easily accessible via a dedicated instruction;
- some call/return constructs, in particular interrupts, implicitly push flags.
Because the flags aren't addressable as a whole, it is necessary to use a workaround, where the flags are either concatenated into one LLIL value, or individually set from one LLIL value. For example, this (written for 8086):
flags_bits = [
('c', 0),
('p', 2),
('a', 4),
('z', 6),
('s', 7),
('i', 9),
('d', 10),
('o', 11),
]
class PushF(Instruction):
def lift(self, il, addr):
flags = None
for flag, flag_bit in flags_bits:
bit = il.flag_bit(2, flag, flag_bit)
if flags is None:
flags = bit
else:
flags = il.or_expr(2, bit, flags)
il.append(il.push(2, flags))
class PopF(Instruction):
def lift(self, il, addr):
flags = LLIL_TEMP(il.temp_reg_count)
il.append(il.set_reg(2, flags, il.pop(2)))
for flag, flag_bit in flags_bits:
bit = il.test_bit(2, il.reg(2, flags), il.const(2, flag_bit))
il.append(il.set_flag(flag, bit))
This workaround generates large and complicated expressions that obscure useful information and impede analysis. It is tedious to implement when there are many instructions accessing flags, and essentially unfeasible when the flags register is memory-mapped due to the volume of generated LLIL.
Please provide, at least, a way to combine flags into a single register. Ideally, it would be also possible to have flags sub-registers (similar to normal sub-registers), because many architectures split the flags register into unprivileged and privileged portions that are used separately; simply have large flag regsiters that may not fit into GPRs with the available addressing modes; or have multi-bit fields in the flags register denoting privilege level, interrupt level, etc.
- 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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Vector35/binaryninja-api
-
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
Vector35/binaryninja-api#8540 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Vector35/binaryninja-api#8516 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
Vector35/binaryninja-api#8503 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
Vector35/binaryninja-api#8446 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
Vector35/binaryninja-api#8444 ·
All issues in Vector35/binaryninja-api
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
Sensor initialization takes very long when `--initial-sim-time` is set to current UNIX timestamp Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
gazebosim/gz-sensors#662 · 1 comment ·
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
comp-datalake
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
ClickHouse/ClickHouse#121222 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
LadybirdBrowser/ladybird#12123 ·