MCPcopy Create free account
hub / github.com/NetSPI/BOF-PE / UpdateSectionPermissions

Function UpdateSectionPermissions

loader/mappedmodule.cpp:135–157  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

133}
134
135static void UpdateSectionPermissions(const Pe::PeNative& pe) {
136
137 for (const auto& section : pe.sections()) {
138
139 auto pagePermissions = PAGE_READONLY;
140 auto oldPermissions = 1ul;
141
142 if (section.Characteristics & IMAGE_SCN_CNT_CODE || section.Characteristics & IMAGE_SCN_MEM_EXECUTE) {
143 if (section.Characteristics & IMAGE_SCN_MEM_WRITE) {
144 pagePermissions = PAGE_EXECUTE_WRITECOPY;
145 }
146 else {
147 pagePermissions = PAGE_EXECUTE_READ;
148 }
149 }
150 else if (section.Characteristics & IMAGE_SCN_MEM_WRITE) {
151 pagePermissions = PAGE_READWRITE;
152 }
153
154 if(pagePermissions != PAGE_READWRITE)
155 VirtualProtect(LPVOID(pe.byRva<void>(section.VirtualAddress)), section.SizeOfRawData, pagePermissions, &oldPermissions);
156 }
157}
158
159static const Pe::GenericTypes::SecHeader* FindSection(const std::string& name, const Pe::PeNative& mappedPe) {
160

Callers 1

MappedModuleMethod · 0.85

Calls 1

sectionsMethod · 0.45

Tested by

no test coverage detected