Explicit is better than implicit:

Add api to specify if the virtual address given to
LIEF::Binary::patch_address or
LIEF::Binary::get_content_from_virtual_address
is relative or absolute
This commit is contained in:
Romain Thomas
2018-03-27 15:36:08 +02:00
parent 508a1bd0c8
commit 5a6448c00d
13 changed files with 121 additions and 35 deletions
+26 -7
View File
@@ -21,6 +21,8 @@
using namespace LIEF;
#define PY_ENUM(x) LIEF::to_string(x), x
template<class T>
using getter_t = T (Binary::*)(void) const;
@@ -34,8 +36,16 @@ template<class T, class P>
using no_const_func = T (Binary::*)(P);
void init_LIEF_Binary_class(py::module& m) {
py::class_<Binary, Object>(m, "Binary")
py::class_<Binary, Object> pybinary(m, "Binary");
py::enum_<LIEF::Binary::VA_TYPES>(pybinary, "VA_TYPES")
.value(PY_ENUM(LIEF::Binary::VA_TYPES::AUTO))
.value(PY_ENUM(LIEF::Binary::VA_TYPES::VA))
.value(PY_ENUM(LIEF::Binary::VA_TYPES::RVA));
pybinary
.def_property_readonly("format",
&Binary::format,
"File format " RST_CLASS_REF(lief.EXE_FORMATS) " of the underlying binary.")
@@ -139,20 +149,29 @@ void init_LIEF_Binary_class(py::module& m) {
"function_name"_a)
.def("patch_address",
static_cast<void (Binary::*) (uint64_t, const std::vector<uint8_t>&)>(&Binary::patch_address),
static_cast<void (Binary::*) (uint64_t, const std::vector<uint8_t>&, LIEF::Binary::VA_TYPES)>(&Binary::patch_address),
"Patch the address with the given value",
py::arg("address"), py::arg("patch_value"))
"Virtual address is specified in the first argument and the content in the second (as a list of bytes).\n"
"If the underlying binary is a PE, one can specify if the virtual address is a " RST_ATTR_REF(lief.Binary.VA_TYPES.RVA) ""
" or a " RST_ATTR_REF(lief.Binary.VA_TYPES.VA) ". By default it is set to " RST_ATTR_REF(lief.Binary.VA_TYPES.VA) "",
"address"_a, "patch_value"_a, "va_type"_a = LIEF::Binary::VA_TYPES::AUTO)
.def("patch_address",
static_cast<void (Binary::*) (uint64_t, uint64_t, size_t)>(&Binary::patch_address),
static_cast<void (Binary::*) (uint64_t, uint64_t, size_t, LIEF::Binary::VA_TYPES)>(&Binary::patch_address),
"Patch the address with the given value",
py::arg("address"), py::arg("patch_value"), py::arg_v("size", 8))
"Virtual address is specified in the first argument, integer in the second and sizeof the integer in third one.\n"
"If the underlying binary is a PE, one can specify if the virtual address is a " RST_ATTR_REF(lief.Binary.VA_TYPES.RVA) ""
" or a " RST_ATTR_REF(lief.Binary.VA_TYPES.VA) ". By default it is set to " RST_ATTR_REF(lief.Binary.VA_TYPES.VA) "",
"address"_a, "patch_value"_a, "size"_a = 8, "va_type"_a = LIEF::Binary::VA_TYPES::AUTO)
.def("get_content_from_virtual_address",
&Binary::get_content_from_virtual_address,
"Return the content located at virtual address",
"virtual_address"_a, "size"_a)
"Return the content located at virtual address.\n\n"
"Virtual address is specified in the first argument and size to read (in bytes) in the second.\n"
"If the underlying binary is a PE, one can specify if the virtual address is a " RST_ATTR_REF(lief.Binary.VA_TYPES.RVA) ""
" or a " RST_ATTR_REF(lief.Binary.VA_TYPES.VA) ". By default it is set to " RST_ATTR_REF(lief.Binary.VA_TYPES.VA) "",
"virtual_address"_a, "size"_a, "va_type"_a = LIEF::Binary::VA_TYPES::AUTO)
.def_property_readonly("abstract",
[m] (py::object& self) {