Skip to content

Commit 02cd1bd

Browse files
committed
Formatting.
1 parent 55081a8 commit 02cd1bd

File tree

1 file changed

+31
-18
lines changed

1 file changed

+31
-18
lines changed

PipeServer/MemoryHelper.cpp

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ template<typename T>
1111
class FlexibleBuffer
1212
{
1313
public:
14-
FlexibleBuffer(std::size_t initialSize)
14+
FlexibleBuffer(size_t initialSize)
1515
: data(initialSize)
1616
{
1717

@@ -213,32 +213,37 @@ void EnumerateRemoteSectionsAndModules(RC_Pointer remoteId, const std::function<
213213
std::vector<HMODULE> modules(needed / sizeof(HMODULE));
214214
if (EnumProcessModules(remoteId, modules.data(), needed, &needed))
215215
{
216-
for (HMODULE curModule : modules)
216+
for (auto module : modules)
217217
{
218218
MODULEINFO moduleInfo = {};
219219
wchar_t modulepath[MAX_PATH] = {};
220220

221-
if (GetModuleInformation(remoteId, curModule, &moduleInfo, sizeof(moduleInfo)) &&
222-
GetModuleFileNameExW(remoteId, curModule, modulepath, MAX_PATH))
221+
if (GetModuleInformation(remoteId, module, &moduleInfo, sizeof(moduleInfo)) &&
222+
GetModuleFileNameExW(remoteId, module, modulepath, MAX_PATH))
223223
{
224-
moduleCallback((RC_Pointer)moduleInfo.lpBaseOfDll, (RC_Pointer)moduleInfo.SizeOfImage, modulepath);
224+
moduleCallback(
225+
static_cast<RC_Pointer>(moduleInfo.lpBaseOfDll),
226+
reinterpret_cast<RC_Pointer>(moduleInfo.SizeOfImage),
227+
modulepath
228+
);
225229

230+
const auto it = std::lower_bound(
231+
std::begin(sections),
232+
std::end(sections),
233+
static_cast<LPVOID>(moduleInfo.lpBaseOfDll),
234+
[&sections](const auto& lhs, const LPVOID& rhs) { return lhs.BaseAddress < rhs; }
235+
);
226236

227-
auto it = std::lower_bound(std::begin(sections), std::end(sections), static_cast<LPVOID>(moduleInfo.lpBaseOfDll), [&sections](const auto& lhs, const LPVOID& rhs)
228-
{
229-
return lhs.BaseAddress < rhs;
230-
});
231-
232-
IMAGE_DOS_HEADER DosHdr = {};
233-
IMAGE_NT_HEADERS NtHdr = {};
237+
IMAGE_DOS_HEADER dosHdr = {};
238+
IMAGE_NT_HEADERS ntHdr = {};
234239

235-
ReadProcessMemory(remoteId, ((BYTE*)moduleInfo.lpBaseOfDll), &DosHdr, sizeof(IMAGE_DOS_HEADER), NULL);
236-
ReadProcessMemory(remoteId, ((BYTE*)moduleInfo.lpBaseOfDll) + DosHdr.e_lfanew, &NtHdr, sizeof(IMAGE_NT_HEADERS), NULL);
240+
ReadProcessMemory(remoteId, static_cast<BYTE*>(moduleInfo.lpBaseOfDll), &dosHdr, sizeof(IMAGE_DOS_HEADER), nullptr);
241+
ReadProcessMemory(remoteId, static_cast<BYTE*>(moduleInfo.lpBaseOfDll) + dosHdr.e_lfanew, &ntHdr, sizeof(IMAGE_NT_HEADERS), nullptr);
237242

238-
std::vector<IMAGE_SECTION_HEADER> sectionHeaders(NtHdr.FileHeader.NumberOfSections);
239-
ReadProcessMemory(remoteId, ((BYTE*)moduleInfo.lpBaseOfDll) + DosHdr.e_lfanew + sizeof(IMAGE_NT_HEADERS), sectionHeaders.data(), NtHdr.FileHeader.NumberOfSections * sizeof(IMAGE_SECTION_HEADER), NULL);
243+
std::vector<IMAGE_SECTION_HEADER> sectionHeaders(ntHdr.FileHeader.NumberOfSections);
244+
ReadProcessMemory(remoteId, static_cast<BYTE*>(moduleInfo.lpBaseOfDll) + dosHdr.e_lfanew + sizeof(IMAGE_NT_HEADERS), sectionHeaders.data(), ntHdr.FileHeader.NumberOfSections * sizeof(IMAGE_SECTION_HEADER), nullptr);
240245

241-
for (auto i = 0; i < NtHdr.FileHeader.NumberOfSections; ++i)
246+
for (auto i = 0; i < ntHdr.FileHeader.NumberOfSections; ++i)
242247
{
243248
auto&& sectionHeader = sectionHeaders[i];
244249

@@ -273,7 +278,15 @@ void EnumerateRemoteSectionsAndModules(RC_Pointer remoteId, const std::function<
273278

274279
for (auto&& section : sections)
275280
{
276-
sectionCallback(section.BaseAddress, reinterpret_cast<RC_Pointer>(section.Size), section.Type, section.Category, section.Protection, reinterpret_cast<const WCHAR*>(section.Name), reinterpret_cast<const WCHAR*>(section.ModulePath));
281+
sectionCallback(
282+
section.BaseAddress,
283+
reinterpret_cast<RC_Pointer>(section.Size),
284+
section.Type,
285+
section.Category,
286+
section.Protection,
287+
reinterpret_cast<const WCHAR*>(section.Name),
288+
reinterpret_cast<const WCHAR*>(section.ModulePath)
289+
);
277290
}
278291
}
279292
}

0 commit comments

Comments
 (0)