Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Improve Enums for SEGMENT_FLAGS
  • Loading branch information
romainthomas committed Aug 2, 2017
1 parent 3b200b3 commit d70ef9e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
8 changes: 3 additions & 5 deletions api/python/ELF/pyELFStructures.cpp
Expand Up @@ -392,11 +392,9 @@ void init_ELF_Structures_enum(py::module& m) {

//! Enum for the *p_flags* field of ElfXX_Phdr
py::enum_<SEGMENT_FLAGS>(m, "SEGMENT_FLAGS", py::arithmetic())
.value("PF_X", SEGMENT_FLAGS::PF_X)
.value("PF_W", SEGMENT_FLAGS::PF_W)
.value("PF_R", SEGMENT_FLAGS::PF_R)
.value("PF_MASKOS", SEGMENT_FLAGS::PF_MASKOS)
.value("PF_MASKPROC", SEGMENT_FLAGS::PF_MASKPROC)
.value(PY_ENUM(SEGMENT_FLAGS::PF_X))
.value(PY_ENUM(SEGMENT_FLAGS::PF_W))
.value(PY_ENUM(SEGMENT_FLAGS::PF_R))
.export_values();


Expand Down
6 changes: 3 additions & 3 deletions examples/python/elf_reader.py
Expand Up @@ -129,13 +129,13 @@ def print_segments(binary):
sections = segment.sections
s = ", ".join([section.name for section in sections])
flags_str = ["-"] * 3
if ELF.SEGMENT_FLAGS.PF_R in segment:
if ELF.SEGMENT_FLAGS.R in segment:
flags_str[0] = "r"

if ELF.SEGMENT_FLAGS.PF_W in segment:
if ELF.SEGMENT_FLAGS.W in segment:
flags_str[1] = "w"

if ELF.SEGMENT_FLAGS.PF_X in segment:
if ELF.SEGMENT_FLAGS.X in segment:
flags_str[2] = "x"
flags_str = "".join(flags_str)

Expand Down
1 change: 1 addition & 0 deletions include/LIEF/ELF/EnumToString.hpp
Expand Up @@ -45,6 +45,7 @@ DLL_PUBLIC const char* to_string(IDENTITY e);
DLL_PUBLIC const char* to_string(SYMBOL_SECTION_INDEX e);
DLL_PUBLIC const char* to_string(DYNAMIC_FLAGS e);
DLL_PUBLIC const char* to_string(DYNAMIC_FLAGS_1 e);
DLL_PUBLIC const char* to_string(SEGMENT_FLAGS e);

DLL_PUBLIC const char* to_string(PPC64_EFLAGS e);
DLL_PUBLIC const char* to_string(ARM_EFLAGS e);
Expand Down
12 changes: 12 additions & 0 deletions src/ELF/EnumToString.cpp
Expand Up @@ -1133,6 +1133,18 @@ const char* to_string(DYNAMIC_FLAGS_1 e) {
return it == enum_strings_flags1.end() ? "UNDEFINED" : it->second;
}

const char* to_string(SEGMENT_FLAGS e) {
const std::map<SEGMENT_FLAGS, const char*> enum_strings {
{ SEGMENT_FLAGS::PF_X, "X" },
{ SEGMENT_FLAGS::PF_W, "W" },
{ SEGMENT_FLAGS::PF_R, "R" },
};

auto it = enum_strings.find(e);
return it == enum_strings.end() ? "UNDEFINED" : it->second;
}




} // namespace ELF
Expand Down

0 comments on commit d70ef9e

Please sign in to comment.