-
-
Notifications
You must be signed in to change notification settings - Fork 633
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8dc62e8
commit c1a7332
Showing
42 changed files
with
1,625 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import enum | ||
import lief.assembly.aarch64 | ||
from typing import Iterator, Optional, Union | ||
|
||
import lief | ||
|
||
|
||
class Immediate(lief.assembly.aarch64.Operand): | ||
@property | ||
def value(self) -> int: ... | ||
|
||
class Memory(lief.assembly.aarch64.Operand): | ||
class SHIFT(enum.Enum): | ||
UNKNOWN = 0 | ||
|
||
LSL = 1 | ||
|
||
UXTX = 2 | ||
|
||
UXTW = 3 | ||
|
||
SXTX = 4 | ||
|
||
SXTW = 5 | ||
|
||
class shift_info_t: | ||
@property | ||
def type(self) -> Memory.SHIFT: ... | ||
|
||
@property | ||
def value(self) -> int: ... | ||
|
||
@property | ||
def base(self) -> lief.assembly.aarch64.REG: ... | ||
|
||
@property | ||
def offset(self) -> Optional[Union[lief.assembly.aarch64.REG, int]]: ... | ||
|
||
@property | ||
def shift(self) -> Memory.shift_info_t: ... | ||
|
||
class PCRelative(lief.assembly.aarch64.Operand): | ||
@property | ||
def value(self) -> int: ... | ||
|
||
class Register(lief.assembly.aarch64.Operand): | ||
@property | ||
def value(self) -> Optional[Union[lief.assembly.aarch64.REG, lief.assembly.aarch64.SYSREG]]: ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
target_sources(pyLIEF PRIVATE | ||
pyImmediate.cpp | ||
pyRegister.cpp | ||
pyMemory.cpp | ||
pyPCRelative.cpp | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include "asm/aarch64/init.hpp" | ||
#include "LIEF/asm/aarch64/operands/Immediate.hpp" | ||
|
||
namespace LIEF::assembly::aarch64::py { | ||
template<> | ||
void create<aarch64::operands::Immediate>(nb::module_& m) { | ||
nb::class_<aarch64::operands::Immediate, aarch64::Operand> obj(m, "Immediate", | ||
R"doc( | ||
This class represents an immediate operand (i.e. a constant) | ||
For instance: | ||
.. code-block:: text | ||
mov x0, #8; | ||
| | ||
+---> Immediate(8) | ||
)doc"_doc | ||
); | ||
|
||
obj | ||
.def_prop_ro("value", &operands::Immediate::value, | ||
R"doc(The constant value wrapped by this operand)doc"_doc | ||
) | ||
; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#include <nanobind/nanobind.h> | ||
|
||
#include "asm/aarch64/init.hpp" | ||
#include "LIEF/asm/aarch64/operands/Memory.hpp" | ||
|
||
namespace nanobind::detail { | ||
template<> | ||
struct type_caster<LIEF::assembly::aarch64::operands::Memory::offset_t> { | ||
NB_TYPE_CASTER(LIEF::assembly::aarch64::operands::Memory::offset_t, | ||
const_name("Optional[Union[lief.assembly.aarch64.REG, int]]")); | ||
|
||
bool from_python(handle src, uint8_t, cleanup_list *) noexcept { | ||
return false; | ||
} | ||
|
||
static handle from_cpp(LIEF::assembly::aarch64::operands::Memory::offset_t val, | ||
rv_policy, cleanup_list *) noexcept | ||
{ | ||
using namespace LIEF::assembly::aarch64; | ||
using namespace LIEF::assembly::aarch64::operands; | ||
switch (val.type) { | ||
case Memory::offset_t::TYPE::REG: | ||
return make_caster<REG>::from_cpp(val.reg, rv_policy::copy, | ||
/*cleanup_list*/nullptr); | ||
|
||
case Memory::offset_t::TYPE::DISP: | ||
return make_caster<int64_t>::from_cpp(val.displacement, rv_policy::copy, | ||
/*cleanup_list*/nullptr); | ||
case Memory::offset_t::TYPE::NONE: | ||
return nb::none(); | ||
} | ||
return nb::none(); | ||
} | ||
}; | ||
} | ||
|
||
|
||
namespace LIEF::assembly::aarch64::py { | ||
template<> | ||
void create<aarch64::operands::Memory>(nb::module_& m) { | ||
nb::class_<aarch64::operands::Memory, aarch64::Operand> obj(m, "Memory", | ||
R"doc( | ||
This class represents a memory operand. | ||
.. code-block:: text | ||
ldr x0, [x1, x2, lsl #3] | ||
| | | | ||
+------------+ | +--------+ | ||
| | | | ||
v v v | ||
Base Reg Offset Shift | ||
)doc"_doc | ||
); | ||
|
||
nb::enum_<operands::Memory::SHIFT>(obj, "SHIFT") | ||
.value("UNKNOWN", operands::Memory::SHIFT::UNKNOWN) | ||
.value("LSL", operands::Memory::SHIFT::LSL) | ||
.value("UXTX", operands::Memory::SHIFT::UXTX) | ||
.value("UXTW", operands::Memory::SHIFT::UXTW) | ||
.value("SXTX", operands::Memory::SHIFT::SXTX) | ||
.value("SXTW", operands::Memory::SHIFT::SXTW) | ||
; | ||
|
||
nb::class_<operands::Memory::shift_info_t>(obj, "shift_info_t", | ||
R"doc(This structure holds shift info (type + value))doc"_doc | ||
) | ||
.def_ro("type", &operands::Memory::shift_info_t::type) | ||
.def_ro("value", &operands::Memory::shift_info_t::value) | ||
; | ||
|
||
obj | ||
.def_prop_ro("base", &operands::Memory::base, | ||
R"doc( | ||
The base register. | ||
For ``str x3, [x8, #8]`` it would return ``x8``. | ||
)doc"_doc | ||
) | ||
.def_prop_ro("offset", &operands::Memory::offset, | ||
R"doc( | ||
The addressing offset. | ||
It can be either: | ||
- A register (e.g. ``ldr x0, [x1, x3]``) | ||
- An offset (e.g. ``ldr x0, [x1, #8]``) | ||
)doc"_doc | ||
) | ||
.def_prop_ro("shift", &operands::Memory::shift, | ||
R"doc( | ||
Shift information. | ||
For instance, for ``ldr x1, [x2, x3, lsl #3]`` it would | ||
return a :attr:`~.Memory.SHIFT.LSL` with a :attr:`~.Memory.shift_info_t.value` | ||
set to ``3``. | ||
)doc"_doc | ||
) | ||
; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include "asm/aarch64/init.hpp" | ||
#include "LIEF/asm/aarch64/operands/PCRelative.hpp" | ||
|
||
namespace LIEF::assembly::aarch64::py { | ||
template<> | ||
void create<aarch64::operands::PCRelative>(nb::module_& m) { | ||
nb::class_<aarch64::operands::PCRelative, aarch64::Operand> obj(m, "PCRelative", | ||
R"doc( | ||
This class represents a PC-relative operand. | ||
.. code-block:: text | ||
ldr x0, #8 | ||
| | ||
v | ||
PC Relative operand | ||
)doc"_doc | ||
); | ||
|
||
obj | ||
.def_prop_ro("value", &aarch64::operands::PCRelative::value, | ||
R"doc( | ||
The effective value that is relative to the current ``pc`` register | ||
)doc"_doc | ||
) | ||
; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#include <nanobind/nanobind.h> | ||
|
||
#include "asm/aarch64/init.hpp" | ||
#include "LIEF/asm/aarch64/operands/Register.hpp" | ||
|
||
namespace nanobind::detail { | ||
template<> | ||
struct type_caster<LIEF::assembly::aarch64::operands::Register::reg_t> { | ||
NB_TYPE_CASTER(LIEF::assembly::aarch64::operands::Register::reg_t, | ||
const_name("Optional[Union[lief.assembly.aarch64.REG, lief.assembly.aarch64.SYSREG]]")); | ||
|
||
bool from_python(handle src, uint8_t, cleanup_list *) noexcept { | ||
return false; | ||
} | ||
|
||
static handle from_cpp(LIEF::assembly::aarch64::operands::Register::reg_t val, | ||
rv_policy, cleanup_list *) noexcept | ||
{ | ||
using namespace LIEF::assembly::aarch64; | ||
using namespace LIEF::assembly::aarch64::operands; | ||
switch (val.type) { | ||
case Register::reg_t::TYPE::REG: | ||
return make_caster<REG>::from_cpp(val.reg, rv_policy::copy, | ||
/*cleanup_list*/nullptr); | ||
|
||
case Register::reg_t::TYPE::SYSREG: | ||
return make_caster<SYSREG>::from_cpp(val.sysreg, rv_policy::copy, | ||
/*cleanup_list*/nullptr); | ||
case Register::reg_t::TYPE::NONE: | ||
return nb::none(); | ||
} | ||
return nb::none(); | ||
} | ||
}; | ||
} | ||
|
||
namespace LIEF::assembly::aarch64::py { | ||
template<> | ||
void create<aarch64::operands::Register>(nb::module_& m) { | ||
nb::class_<aarch64::operands::Register, aarch64::Operand> obj(m, "Register", | ||
R"doc( | ||
This class represents a register operand. | ||
.. code-block:: text | ||
mrs x0, TPIDR_EL0 | ||
| | | ||
+------+ +-------+ | ||
| | | ||
v v | ||
REG SYSREG | ||
)doc"_doc | ||
); | ||
|
||
obj | ||
.def_prop_ro("value", &operands::Register::value, | ||
R"doc( | ||
The effective register as either: a :class:`lief.assembly.aarch64.REG` or | ||
a :class:`lief.assembly.aarch64.SYSREG`. | ||
)doc"_doc | ||
) | ||
; | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.