MCPcopy Create free account
hub / github.com/Barracudach/CallStack-Spoofer / ShellCodeGenerator

Function ShellCodeGenerator

include/CallStack-Spoofer.h:131–161  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

129#else
130 template <typename Func, typename ...Args>
131 typename std::invoke_result<Func, Args...>::type
132#endif
133 __declspec(safebuffers)ShellCodeGenerator(Func f, Args&... args)
134 {
135#ifdef _KERNEL_MODE
136 using this_func_type = decltype(ShellCodeGenerator<RetType, Func, Args&...>);
137 using return_type = RetType;
138#else
139 using this_func_type = decltype(ShellCodeGenerator<Func, Args&...>);
140 using return_type = typename std::invoke_result<Func, Args...>::type;
141#endif
142 const uintptr_t xor_key = 0xff00ff00ff00ff00;
143 void* ret_addr_in_stack = _AddressOfReturnAddress();
144 uintptr_t temp = *(uintptr_t*)ret_addr_in_stack;
145 temp ^= xor_key;
146 *(uintptr_t*)ret_addr_in_stack = 0;
147
148 if constexpr (std::is_same<return_type, void>::value)
149 {
150 f(args...);
151 temp ^= xor_key;
152 *(uintptr_t*)ret_addr_in_stack = temp;
153 }
154 else
155 {
156 return_type&& ret = f(args...);
157 temp ^= xor_key;
158 *(uintptr_t*)ret_addr_in_stack = temp;
159 return ret;
160 }
161 }
162
163
164

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected