| 168 | template<class Func > |
| 169 | #endif |
| 170 | class SafeCall |
| 171 | { |
| 172 | |
| 173 | Func* funcPtr; |
| 174 | |
| 175 | public: |
| 176 | SafeCall(Func* func) :funcPtr(func) {} |
| 177 | |
| 178 | |
| 179 | template<typename... Args> |
| 180 | __forceinline decltype(auto) operator()(Args&&... args) |
| 181 | { |
| 182 | SPOOF_FUNC; |
| 183 | |
| 184 | #ifdef _KERNEL_MODE |
| 185 | using return_type = RetType; |
| 186 | using p_shell_code_generator_type = decltype(&ShellCodeGenerator<RetType, Func*, Args...>); |
| 187 | PVOID self_addr = static_cast<PVOID>(&ShellCodeGenerator<RetType, Func*, Args&&...>); |
| 188 | #else |
| 189 | using return_type = typename std::invoke_result<Func, Args...>::type; |
| 190 | using p_shell_code_generator_type = decltype(&ShellCodeGenerator<Func*, Args...>); |
| 191 | p_shell_code_generator_type self_addr = static_cast<p_shell_code_generator_type>(&ShellCodeGenerator<Func*, Args&&...>); |
| 192 | #endif |
| 193 | |
| 194 | p_shell_code_generator_type p_shellcode{}; |
| 195 | |
| 196 | static size_t count{}; |
| 197 | static p_shell_code_generator_type orig_generator[MAX_FUNC_BUFFERED]{}; |
| 198 | static p_shell_code_generator_type alloc_generator[MAX_FUNC_BUFFERED]{}; |
| 199 | |
| 200 | unsigned index{}; |
| 201 | while (orig_generator[index]) |
| 202 | { |
| 203 | if (orig_generator[index] == self_addr) |
| 204 | { |
| 205 | #ifdef _KERNEL_MODE |
| 206 | //DbgPrint("Found allocated generator"); |
| 207 | #else |
| 208 | //std::cout << "Found allocated generator" << std::endl; |
| 209 | #endif |
| 210 | |
| 211 | p_shellcode = alloc_generator[index]; |
| 212 | break; |
| 213 | } |
| 214 | index++; |
| 215 | } |
| 216 | |
| 217 | if (!p_shellcode) |
| 218 | { |
| 219 | #ifdef _KERNEL_MODE |
| 220 | //DbgPrint("Alloc generator"); |
| 221 | #else |
| 222 | //std::cout << "Alloc generator" << std::endl; |
| 223 | #endif |
| 224 | |
| 225 | p_shellcode = reinterpret_cast<p_shell_code_generator_type>( LocateShellCode(self_addr)); |
| 226 | orig_generator[count] = self_addr; |
| 227 | alloc_generator[count] = p_shellcode; |
nothing calls this directly
no outgoing calls
no test coverage detected