angr / ailment

AIL: The angr Intermediate Language.
BSD 2-Clause "Simplified" License
27 stars 16 forks source link

Handle JumpKind.Exit in VEXIRSBConverter #198

Open xxr0ss opened 4 months ago

xxr0ss commented 4 months ago

Description

I'm trying to convert an irsb of custom arch (eBPF example in angr-platforms) to AILBlock

diff --git a/tests/test_ebpf.py b/tests/test_ebpf.py
index 0d23ec8..8aa10a5 100644
--- a/tests/test_ebpf.py
+++ b/tests/test_ebpf.py
@@ -2,6 +2,7 @@ import unittest
 from pathlib import Path

 import angr
+import ailment
 from angr_platforms.ebpf import ArchExtendedBPF, LifterEbpf

@@ -36,8 +37,12 @@ class TestEbpf(unittest.TestCase):
         state = proj.factory.entry_state()
         block = proj.factory.block(state.addr)
         lifter = LifterEbpf(proj.arch, block.addr)
-        lifter.lift(block.bytes)
+        irsb = lifter.lift(block.bytes)
         assert len(lifter.disassemble()) == 2
+        
+        manager = ailment.Manager(arch=proj.arch)
+        ailblock = ailment.IRSBConverter.convert(irsb, manager)
+        assert isinstance(ailblock.statements[0], ailment.statement.Assignment)

 if __name__ == "__main__":

but the converter raises NotImplementedError.

To my understanding, If a irsb ends with a Ijk_Exit, we can simply do nothing, right? Maybe we can modify converter_vex.py as following:

diff --git a/ailment/converter_vex.py b/ailment/converter_vex.py
index 6523695..dc9bf5e 100644
--- a/ailment/converter_vex.py
+++ b/ailment/converter_vex.py
@@ -753,6 +753,9 @@ class VEXIRSBConverter(Converter):
                     vex_stmt_idx=DEFAULT_STATEMENT,
                 )
             )
+        elif irsb.jumpkind == "Ijk_Exit":
+            # exit
+            pass
         else:
             raise NotImplementedError("Unsupported jumpkind")

Alternatives

No response

Additional context

No response

xxr0ss commented 4 months ago

well, the eBPF's exit is not a proper example, according to the eBPF instruction set docs, the instruction exit refers to "return". but I still think it'll be great if JumpKind.Exit is handled