Skip to content

Commit d5ae2ba

Browse files
committed
[REFACT] In exceptions_parser: refactored for backward compatibility with C99. Small cleanup
1 parent 0fe6eda commit d5ae2ba

File tree

2 files changed

+20
-22
lines changed

2 files changed

+20
-22
lines changed

libpeconv/src/exceptions_parser.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@ namespace details {
161161
_In_ ULONG MinorVersion,
162162
_In_ ULONG BuildNumber
163163
) {
164-
NtVersion version{};
165-
RtlSecureZeroMemory(&version, sizeof(NtVersion));
164+
NtVersion version = { 0 };
166165
RtlCurrentVersion(&version);
167166
if (version.MajorVersion == MajorVersion) {
168167
if (version.MinorVersion == MinorVersion) return version.BuildNumber >= BuildNumber;
@@ -177,8 +176,7 @@ namespace details {
177176
_In_ ULONG BuildNumber,
178177
_In_ BYTE Flags
179178
) {
180-
NtVersion version{};
181-
RtlSecureZeroMemory(&version, sizeof(NtVersion));
179+
NtVersion version = { 0 };
182180
RtlCurrentVersion(&version);
183181
if (version.MajorVersion == MajorVersion &&
184182
((Flags & RTL_VERIFY_FLAGS_MINOR_VERSION) ? version.MinorVersion == MinorVersion : true) &&
@@ -331,7 +329,7 @@ namespace details {
331329
ULONG old;
332330

333331
if (!MrdataBase) {
334-
MEMORY_BASIC_INFORMATION mbi{};
332+
MEMORY_BASIC_INFORMATION mbi= { 0 };
335333
status = NtQueryVirtualMemory(NtCurrentProcess(), mrdata, MemoryBasicInformation, &mbi, sizeof(mbi), nullptr);
336334
if (!NT_SUCCESS(status))return status;
337335
MrdataBase = mbi.BaseAddress;
@@ -362,9 +360,9 @@ namespace details {
362360
if (!hNtdll) return nullptr;
363361
auto NtdllHeaders = reinterpret_cast<PIMAGE_NT_HEADERS>(RtlImageNtHeader(hNtdll));
364362
PIMAGE_NT_HEADERS ModuleHeaders = nullptr;
365-
_RTL_INVERTED_FUNCTION_TABLE_ENTRY_64 entry{};
363+
_RTL_INVERTED_FUNCTION_TABLE_ENTRY_64 entry = { 0 };
366364
PIMAGE_DATA_DIRECTORY dir = nullptr;
367-
SEARCH_CONTEXT SearchContext{};
365+
SEARCH_CONTEXT SearchContext= { 0 };
368366
SearchContext.SearchPattern = reinterpret_cast<LPBYTE>(&entry);
369367
SearchContext.PatternSize = sizeof(entry);
370368
RtlSecureZeroMemory(&entry, sizeof(entry));
@@ -491,7 +489,7 @@ namespace details {
491489
ULONG CurrentSize = InvertedTable->Count;
492490
PIMAGE_RUNTIME_FUNCTION_ENTRY FunctionTable = nullptr;
493491
ULONG SizeOfTable = 0;
494-
bool IsWin8OrGreater = RtlIsWindowsVersionOrGreater(6, 2, 0);
492+
BOOL IsWin8OrGreater = RtlIsWindowsVersionOrGreater(6, 2, 0);
495493
ULONG Index = static_cast<ULONG>(IsWin8OrGreater);
496494

497495
if (CurrentSize != InvertedTable->MaxCount) {
@@ -590,7 +588,7 @@ namespace details {
590588
#ifdef _DEBUG
591589
std::cout << "Found exception table: " << std::hex << table << std::endl;
592590
#endif
593-
bool need_virtual_protect = RtlIsWindowsVersionOrGreater(6, 3, 0);
591+
BOOL need_virtual_protect = RtlIsWindowsVersionOrGreater(6, 3, 0);
594592
// Windows 8.1 and above require to set PAGE_READWRITE protection
595593
#ifdef _DEBUG
596594
std::cout << "Need virtual protect: " << std::boolalpha << need_virtual_protect << std::endl;
@@ -621,5 +619,5 @@ bool peconv::setup_exceptions(IN BYTE* modulePtr, IN size_t moduleSize)
621619
}
622620
moduleSize = img_size;
623621
}
624-
return NT_SUCCESS(details::RtlInsertInvertedFunctionTable(modulePtr, moduleSize));
622+
return NT_SUCCESS(details::RtlInsertInvertedFunctionTable(modulePtr, (ULONG)moduleSize)) ? true : false;
625623
}

libpeconv/src/ntddk.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3582,24 +3582,24 @@ extern "C" {
35823582
NTSTATUS
35833583
NTAPI
35843584
NtQueryVirtualMemory(
3585-
_In_ HANDLE ProcessHandle,
3586-
_In_opt_ PVOID BaseAddress,
3587-
_In_ MEMORY_INFORMATION_CLASS MemoryInformationClass,
3588-
_Out_writes_bytes_(MemoryInformationLength) PVOID MemoryInformation,
3589-
_In_ SIZE_T MemoryInformationLength,
3590-
_Out_opt_ PSIZE_T ReturnLength
3585+
IN HANDLE ProcessHandle,
3586+
IN OPTIONAL PVOID BaseAddress,
3587+
IN MEMORY_INFORMATION_CLASS MemoryInformationClass,
3588+
OUT PVOID MemoryInformation,
3589+
IN SIZE_T MemoryInformationLength,
3590+
OUT OPTIONAL PSIZE_T ReturnLength
35913591
);
35923592

35933593
NTSYSCALLAPI
35943594
NTSTATUS
35953595
NTAPI
35963596
ZwQueryVirtualMemory(
3597-
_In_ HANDLE ProcessHandle,
3598-
_In_opt_ PVOID BaseAddress,
3599-
_In_ MEMORY_INFORMATION_CLASS MemoryInformationClass,
3600-
_Out_writes_bytes_(MemoryInformationLength) PVOID MemoryInformation,
3601-
_In_ SIZE_T MemoryInformationLength,
3602-
_Out_opt_ PSIZE_T ReturnLength
3597+
IN HANDLE ProcessHandle,
3598+
IN OPTIONAL PVOID BaseAddress,
3599+
IN MEMORY_INFORMATION_CLASS MemoryInformationClass,
3600+
OUT OPTIONAL PVOID MemoryInformation,
3601+
IN SIZE_T MemoryInformationLength,
3602+
OUT OPTIONAL PSIZE_T ReturnLength
36033603
);
36043604

36053605

0 commit comments

Comments
 (0)