Skip to content

Add some checks that should fix some issues with certain packers #144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from Jan 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions NativeCore/Windows/EnumerateRemoteSectionsAndModules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,27 @@ void RC_CallConv EnumerateRemoteSectionsAndModules(RC_Pointer process, Enumerate
const auto sectionAddress = reinterpret_cast<size_t>(me32.modBaseAddr) + sectionHeader.VirtualAddress;
for (auto j = it; j != std::end(sections); ++j)
{
if (sectionAddress >= reinterpret_cast<size_t>(j->BaseAddress) && sectionAddress < reinterpret_cast<size_t>(j->BaseAddress) + static_cast<size_t>(j->Size))
if (sectionAddress >= reinterpret_cast<size_t>(j->BaseAddress)
&& sectionAddress < reinterpret_cast<size_t>(j->BaseAddress) + static_cast<size_t>(j->Size)
&& sectionHeader.VirtualAddress + sectionHeader.Misc.VirtualSize <= me32.modBaseSize )
{
// Copy the name because it is not null padded.
char buffer[IMAGE_SIZEOF_SHORT_NAME + 1] = { 0 };
std::memcpy(buffer, sectionHeader.Name, IMAGE_SIZEOF_SHORT_NAME);

if (std::strcmp(buffer, ".text") == 0 || std::strcmp(buffer, "code") == 0)
if ((sectionHeader.Characteristics & IMAGE_SCN_CNT_CODE) == IMAGE_SCN_CNT_CODE)
{
j->Category = SectionCategory::CODE;
}
else if (std::strcmp(buffer, ".data") == 0 || std::strcmp(buffer, "data") == 0 || std::strcmp(buffer, ".rdata") == 0 || std::strcmp(buffer, ".idata") == 0)
else if (sectionHeader.Characteristics & (IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_CNT_UNINITIALIZED_DATA))
{
j->Category = SectionCategory::DATA;
}

MultiByteToUnicode(buffer, j->Name, IMAGE_SIZEOF_SHORT_NAME);
try {
// Copy the name because it is not null padded.
char buffer[IMAGE_SIZEOF_SHORT_NAME + 1] = { 0 };
std::memcpy(buffer, sectionHeader.Name, IMAGE_SIZEOF_SHORT_NAME);
MultiByteToUnicode(buffer, j->Name, IMAGE_SIZEOF_SHORT_NAME);
} catch (std::range_error &) {
std::memset(j->Name, 0, sizeof j->Name);
}
std::memcpy(j->ModulePath, me32.szExePath, std::min(MAX_PATH, PATH_MAXIMUM_LENGTH));

break;
Expand Down