MCPcopy Create free account
hub / github.com/DFHack/dfhack / Process

Method Process

library/Process.cpp:112–228  ·  view source on GitHub ↗

WIN32 */

Source from the content-addressed store, hash-verified

110
111#endif /* WIN32 */
112Process::Process(const VersionInfoFactory& known_versions) : identified(false)
113{
114#ifndef WIN32
115 std::string self_exe_name;
116#ifndef _DARWIN
117 const char * exe_link_name = "/proc/self/exe";
118
119 // valgrind replaces readlink for /proc/self/exe, but not open.
120 char self_exe[1024];
121 memset(self_exe, 0, sizeof(self_exe));
122 if (readlink(exe_link_name, self_exe, sizeof(self_exe) - 1) < 0)
123 self_exe_name = exe_link_name;
124 else
125 self_exe_name = self_exe;
126#else /* _DARWIN */
127 char path[1024];
128 char *exec_link_name;
129 uint32_t size = sizeof(path);
130 if (_NSGetExecutablePath(path, &size) == 0) {
131 exec_link_name = realpath(path, NULL);
132 self_exe_name = std::string(exec_link_name);
133 }
134#endif /* _DARWIN */
135#else /* WIN32 */
136 HMODULE hmod = NULL;
137 DWORD needed;
138 bool found = false;
139
140 d = new PlatformSpecific();
141 // open process
142 d->my_pid = GetCurrentProcessId();
143 d->my_handle = GetCurrentProcess();
144 // try getting the first module of the process
145 if (EnumProcessModules(d->my_handle, &hmod, sizeof(hmod), &needed) == 0)
146 {
147 return; //if enumprocessModules fails, give up
148 }
149 // got base ;)
150 d->base = (char*)hmod;
151
152 // read from this process
153 try
154 {
155 uint32_t pe_offset = readDWord(d->base + 0x3C);
156 read(d->base + pe_offset, sizeof(d->pe_header), (uint8_t*)&(d->pe_header));
157 const size_t sectionsSize = sizeof(IMAGE_SECTION_HEADER) * d->pe_header.FileHeader.NumberOfSections;
158 d->sections = (IMAGE_SECTION_HEADER*)std::malloc(sectionsSize);
159 read(d->base + pe_offset + sizeof(d->pe_header), sectionsSize, (uint8_t*)(d->sections));
160 }
161 catch (std::exception&)
162 {
163 return;
164 }
165#endif /* WIN32 */
166
167#ifndef WIN32
168 my_pe = 0;
169 md5wrapper md5;

Callers

nothing calls this directly

Calls 7

readDWordFunction · 0.85
readFunction · 0.85
getBaseFunction · 0.85
getHashFromFileMethod · 0.80
getVersionInfoByMD5Method · 0.80
printFunction · 0.50

Tested by

no test coverage detected