Skip to content

Commit 3213d68

Browse files
committed
Use "SEG,SEC" for section names on macOS
1 parent 8b854be commit 3213d68

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

src/os/mac/Process.cpp

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ namespace hat::process {
109109
std::span<std::byte> module::get_section_data(std::string_view name) const {
110110
std::span<std::byte> data{};
111111
for_each_section_impl(this->address(), [&](uintptr_t slide, const segment_command_t*, const section_t* sec) {
112+
const std::string_view segmentName{
113+
static_cast<const char*>(seg->segname),
114+
strnlen(static_cast<const char*>(seg->segname), 16)
115+
};
112116
const std::string_view sectionName{
113117
static_cast<const char*>(sec->sectname),
114118
strnlen(static_cast<const char*>(sec->sectname), 16)
@@ -117,7 +121,14 @@ namespace hat::process {
117121
reinterpret_cast<std::byte*>(sec->addr + slide),
118122
sec->size
119123
};
120-
if (sectionName == name) {
124+
125+
// Check for "SEGMENT,SECTION" first
126+
const bool qualified = name.size() == segmentName.size() + sectionName.size() + 1
127+
&& name.starts_with(segmentName)
128+
&& name[segmentName.size()] == ','
129+
&& name.ends_with(sectionName);
130+
131+
if (qualified || sectionName == name) {
121132
data = sectionData;
122133
return false;
123134
}
@@ -128,15 +139,20 @@ namespace hat::process {
128139

129140
void module::for_each_section(const std::function<bool(std::string_view, std::span<std::byte>, hat::protection)>& callback) const {
130141
for_each_section_impl(this->address(), [&](uintptr_t slide, const segment_command_t* seg, const section_t* sec) {
131-
const std::string_view name{
142+
const std::string_view segmentName{
143+
static_cast<const char*>(seg->segname),
144+
strnlen(static_cast<const char*>(seg->segname), 16)
145+
};
146+
const std::string_view sectionName{
132147
static_cast<const char*>(sec->sectname),
133148
strnlen(static_cast<const char*>(sec->sectname), 16)
134149
};
135150
const std::span data{
136151
reinterpret_cast<std::byte*>(sec->addr + slide),
137152
sec->size
138153
};
139-
return callback(name, data, to_hat_prot(seg->initprot));
154+
const std::string qualified = std::string{segmentName} + ',' + sectionName;
155+
return callback(qualified, data, to_hat_prot(seg->initprot));
140156
});
141157
}
142158

0 commit comments

Comments
 (0)