11// #include <experimental/filesystem>
22#include < boost/filesystem.hpp>
33#include < sstream>
4+ #include < fstream>
45
56#include " NativeCore.hpp"
67
7- // using fs = std::experimental::filesystem;
8- // using sys = std;
9- /* using fs = boost::filesystem;
10- using sys = boost::system;*/
11-
12- enum class Platform
13- {
14- Unknown,
15- X86,
16- X64
17- };
18-
198bool is_number (const std::string& s)
209{
2110 std::string::const_iterator it = s.begin ();
@@ -33,6 +22,40 @@ T parse_type(const std::string& s)
3322 return val;
3423}
3524
25+ enum class Platform
26+ {
27+ Unknown,
28+ X86,
29+ X64
30+ };
31+
32+ Platform GetProcessPlatform (const std::string& auxvPath)
33+ {
34+ auto platform = Platform::Unknown;
35+
36+ std::ifstream file (auxvPath);
37+ if (file)
38+ {
39+ char buffer[16 ];
40+ while (true )
41+ {
42+ file.read (buffer, 16 );
43+
44+ if (!file)
45+ {
46+ return Platform::X64;
47+ }
48+
49+ if (buffer[4 ] != 0 || buffer[5 ] != 0 || buffer[6 ] != 0 || buffer[7 ] != 0 )
50+ {
51+ return Platform::X86;
52+ }
53+ }
54+ }
55+
56+ return platform;
57+ }
58+
3659extern " C" void EnumerateProcesses (EnumerateProcessCallback callbackProcess)
3760{
3861 // using namespace std::experimental::filesystem;
@@ -69,13 +92,21 @@ extern "C" void EnumerateProcesses(EnumerateProcessCallback callbackProcess)
6992
7093 if (!ec)
7194 {
72- // auto elfHeader = processPath / "";
73-
74- EnumerateProcessData data = {};
75- data.Id = pid;
76- MultiByteToUnicode (e.string ().c_str (), data.ModulePath , PATH_MAXIMUM_LENGTH);
77-
78- callbackProcess (&data);
95+ auto auxvPath = processPath / " auxv" ;
96+
97+ auto platform = GetProcessPlatform (auxvPath.string ());
98+ #ifdef NATIVE_CORE_64
99+ if (platform == Platform::X64)
100+ #else
101+ if (platform == Platform::X86)
102+ #endif
103+ {
104+ EnumerateProcessData data = {};
105+ data.Id = pid;
106+ MultiByteToUnicode (e.string ().c_str (), data.ModulePath , PATH_MAXIMUM_LENGTH);
107+
108+ callbackProcess (&data);
109+ }
79110 }
80111 }
81112 }
0 commit comments