Skip to content

Commit 773312e

Browse files
committed
Added x86/x64 check.
1 parent b5374ea commit 773312e

File tree

2 files changed

+52
-6
lines changed

2 files changed

+52
-6
lines changed

PipeServer/Messages.cpp

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,60 @@ bool EnumerateRemoteSectionsAndModulesRequest::Handle(MessageClient& client)
7676
//---------------------------------------------------------------------------
7777
bool EnumerateProcessHandlesRequest::Handle(MessageClient& client)
7878
{
79+
enum class Platform
80+
{
81+
Unknown,
82+
X86,
83+
X64
84+
};
85+
86+
const auto GetProcessPlatform = [](HANDLE process) -> Platform
87+
{
88+
static USHORT processorArchitecture = PROCESSOR_ARCHITECTURE_UNKNOWN;
89+
if (processorArchitecture == PROCESSOR_ARCHITECTURE_UNKNOWN)
90+
{
91+
SYSTEM_INFO info = {};
92+
GetNativeSystemInfo(&info);
93+
94+
processorArchitecture = info.wProcessorArchitecture;
95+
}
96+
97+
switch (processorArchitecture)
98+
{
99+
case PROCESSOR_ARCHITECTURE_INTEL:
100+
return Platform::X86;
101+
case PROCESSOR_ARCHITECTURE_AMD64:
102+
BOOL isWow64 = FALSE;
103+
if (IsWow64Process(process, &isWow64))
104+
{
105+
return isWow64 ? Platform::X86 : Platform::X64;
106+
}
107+
108+
#ifdef RECLASSNET64
109+
return Platform::X64;
110+
#else
111+
return Platform::X86;
112+
#endif
113+
}
114+
return Platform::Unknown;
115+
};
116+
79117
auto handles = GetAvailableHandles(PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE);
80118

81119
for (auto handle : handles)
82120
{
83-
WCHAR path[PATH_MAXIMUM_LENGTH];
84-
GetModuleFileNameExW(handle, nullptr, path, PATH_MAXIMUM_LENGTH);
85-
86-
client.Send(EnumerateProcessHandlesResponse(handle, path));
121+
auto platform = GetProcessPlatform(handle);
122+
#ifdef RECLASSNET64
123+
if (platform == Platform::X64)
124+
#else
125+
if (platform == Platform::X86)
126+
#endif
127+
{
128+
WCHAR path[PATH_MAXIMUM_LENGTH];
129+
GetModuleFileNameExW(handle, nullptr, path, PATH_MAXIMUM_LENGTH);
130+
131+
client.Send(EnumerateProcessHandlesResponse(handle, path));
132+
}
87133
}
88134

89135
client.Send(StatusResponse(nullptr, true));

PipeServer/PipeServer.vcxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
</PrecompiledHeader>
105105
<WarningLevel>Level3</WarningLevel>
106106
<Optimization>Disabled</Optimization>
107-
<PreprocessorDefinitions>_DEBUG;_WINDOWS;_USRDLL;PIPESERVER_EXPORTS;NOMINMAX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
107+
<PreprocessorDefinitions>_DEBUG;_WINDOWS;_USRDLL;PIPESERVER_EXPORTS;NOMINMAX;RECLASSNET64;%(PreprocessorDefinitions)</PreprocessorDefinitions>
108108
</ClCompile>
109109
<Link>
110110
<SubSystem>Windows</SubSystem>
@@ -136,7 +136,7 @@
136136
<Optimization>MaxSpeed</Optimization>
137137
<FunctionLevelLinking>true</FunctionLevelLinking>
138138
<IntrinsicFunctions>true</IntrinsicFunctions>
139-
<PreprocessorDefinitions>NDEBUG;_WINDOWS;_USRDLL;PIPESERVER_EXPORTS;NOMINMAX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
139+
<PreprocessorDefinitions>NDEBUG;_WINDOWS;_USRDLL;PIPESERVER_EXPORTS;NOMINMAX;RECLASSNET64;%(PreprocessorDefinitions)</PreprocessorDefinitions>
140140
</ClCompile>
141141
<Link>
142142
<SubSystem>Windows</SubSystem>

0 commit comments

Comments
 (0)