Skip to content

Commit d70ef9e

Browse files
committed
Improve Enums for SEGMENT_FLAGS
1 parent 3b200b3 commit d70ef9e

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

api/python/ELF/pyELFStructures.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -392,11 +392,9 @@ void init_ELF_Structures_enum(py::module& m) {
392392

393393
//! Enum for the *p_flags* field of ElfXX_Phdr
394394
py::enum_<SEGMENT_FLAGS>(m, "SEGMENT_FLAGS", py::arithmetic())
395-
.value("PF_X", SEGMENT_FLAGS::PF_X)
396-
.value("PF_W", SEGMENT_FLAGS::PF_W)
397-
.value("PF_R", SEGMENT_FLAGS::PF_R)
398-
.value("PF_MASKOS", SEGMENT_FLAGS::PF_MASKOS)
399-
.value("PF_MASKPROC", SEGMENT_FLAGS::PF_MASKPROC)
395+
.value(PY_ENUM(SEGMENT_FLAGS::PF_X))
396+
.value(PY_ENUM(SEGMENT_FLAGS::PF_W))
397+
.value(PY_ENUM(SEGMENT_FLAGS::PF_R))
400398
.export_values();
401399

402400

examples/python/elf_reader.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,13 @@ def print_segments(binary):
129129
sections = segment.sections
130130
s = ", ".join([section.name for section in sections])
131131
flags_str = ["-"] * 3
132-
if ELF.SEGMENT_FLAGS.PF_R in segment:
132+
if ELF.SEGMENT_FLAGS.R in segment:
133133
flags_str[0] = "r"
134134

135-
if ELF.SEGMENT_FLAGS.PF_W in segment:
135+
if ELF.SEGMENT_FLAGS.W in segment:
136136
flags_str[1] = "w"
137137

138-
if ELF.SEGMENT_FLAGS.PF_X in segment:
138+
if ELF.SEGMENT_FLAGS.X in segment:
139139
flags_str[2] = "x"
140140
flags_str = "".join(flags_str)
141141

include/LIEF/ELF/EnumToString.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ DLL_PUBLIC const char* to_string(IDENTITY e);
4545
DLL_PUBLIC const char* to_string(SYMBOL_SECTION_INDEX e);
4646
DLL_PUBLIC const char* to_string(DYNAMIC_FLAGS e);
4747
DLL_PUBLIC const char* to_string(DYNAMIC_FLAGS_1 e);
48+
DLL_PUBLIC const char* to_string(SEGMENT_FLAGS e);
4849

4950
DLL_PUBLIC const char* to_string(PPC64_EFLAGS e);
5051
DLL_PUBLIC const char* to_string(ARM_EFLAGS e);

src/ELF/EnumToString.cpp

+12
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,18 @@ const char* to_string(DYNAMIC_FLAGS_1 e) {
11331133
return it == enum_strings_flags1.end() ? "UNDEFINED" : it->second;
11341134
}
11351135

1136+
const char* to_string(SEGMENT_FLAGS e) {
1137+
const std::map<SEGMENT_FLAGS, const char*> enum_strings {
1138+
{ SEGMENT_FLAGS::PF_X, "X" },
1139+
{ SEGMENT_FLAGS::PF_W, "W" },
1140+
{ SEGMENT_FLAGS::PF_R, "R" },
1141+
};
1142+
1143+
auto it = enum_strings.find(e);
1144+
return it == enum_strings.end() ? "UNDEFINED" : it->second;
1145+
}
1146+
1147+
11361148

11371149

11381150
} // namespace ELF

0 commit comments

Comments
 (0)