MCPcopy Create free account
hub / github.com/ElyDotDev/windows-kill / findAddressByStackBackTrace

Method findAddressByStackBackTrace

windows-kill-library/ctrl-routine.cpp:132–168  ·  view source on GitHub ↗

TODO: a rewrite needed.

Source from the content-addressed store, hash-verified

130
131 // TODO: a rewrite needed.
132 void CtrlRoutine::findAddressByStackBackTrace() {
133 LPVOID ctrlRoutine;
134
135 USHORT count = CaptureStackBackTrace((ULONG)2, (ULONG)1, &ctrlRoutine, NULL);
136 if (count != 1) {
137 return;
138 /* TODO: Remove. No Exception Available here.
139 throw runtime_error(string("Cannot capture stack back trace."));
140 */
141 }
142
143 HANDLE hProcess = GetCurrentProcess();
144 if (!SymInitialize(hProcess, NULL, TRUE)) {
145 return;
146 /* TODO: Remove. No Exception Available here.
147 throw runtime_error(string("Cannot SymInitialize. Code: ") + std::to_string(GetLastError()));
148 */
149 }
150
151 ULONG64 buffer[(sizeof(SYMBOL_INFO) + MAX_SYM_NAME * sizeof(TCHAR) + sizeof(ULONG64) - 1) / sizeof(ULONG64)];
152 PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)buffer;
153 pSymbol->SizeOfStruct = sizeof(SYMBOL_INFO);
154 pSymbol->MaxNameLen = MAX_SYM_NAME;
155
156 LPVOID funcCtrlRoutine = NULL;
157 DWORD64 dwDisplacement = 0;
158 if (!SymFromAddr(hProcess, (DWORD64)ctrlRoutine, &dwDisplacement, pSymbol)) {
159 return;
160 /* TODO: Remove. No Exception Available here.
161 throw runtime_error(string("Cannot SymFromAddr. Code: ") + std::to_string(GetLastError()));
162 */
163 }
164 funcCtrlRoutine = reinterpret_cast<LPVOID>(pSymbol->Address);
165
166 SymCleanup(hProcess);
167 this->address = (LPTHREAD_START_ROUTINE)funcCtrlRoutine;
168 }
169}

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected