MCPcopy Create free account
hub / github.com/d35ha/CallObfuscator / resolve_api_set

Method resolve_api_set

src/shellcode.cpp:258–350  ·  view source on GitHub ↗

Resolve the api set schema for the dll name.

Source from the content-addressed store, hash-verified

256
257// Resolve the api set schema for the dll name.
258BOOL shellcode::resolve_api_set(HANDLE pe_base, PDWORD sh_funs, PVOID schema_map, PCWSTR virtual_dll, PWCHAR real_dll)
259{
260 // Resolving the needed functions.
261 auto fun_wstr_cpy = sh_resolve(pe_base, sh_funs, wstr_cpy);
262 auto fun_wstr_i_cmp = sh_resolve(pe_base, sh_funs, wstr_i_cmp);
263
264 // Reading the version.
265 DWORD Version = *(DWORD*)schema_map;
266
267 // Two versions with two methods.
268 if (Version >= 3) {
269
270 // Use the proper structures.
271 PApiSetHeader63 pHeader = (PApiSetHeader63)schema_map;
272 PApisetNameEntry pApiSets = (PApisetNameEntry)((PBYTE)schema_map + pHeader->NamesOffset);
273
274 // Use binary search to enumerate the dlls.
275 INT Start, End, Next, CmpResult;
276 Start = Next = 0;
277 End = (DWORD)pHeader->NumberOfApisets - 1;
278
279 // Binary search loop.
280 while (End >= Start) {
281
282 Next = (Start + End) >> 1;
283 PWCHAR VirtualDll = (PWCHAR)((PBYTE)schema_map + pApiSets[Next].Offset);
284
285 // Compare and conditions.
286 CmpResult = fun_wstr_i_cmp(VirtualDll, virtual_dll, pApiSets[Next].Size / 2);
287 if (CmpResult < 0)
288 End = Next - 1;
289 else if (CmpResult > 0)
290 Start = Next + 1;
291 else break;
292 };
293
294 // We've found the right entry.
295 if (End >= Start && pApiSets[Next].NumberOfHosts) {
296
297 // Get the value.
298 PApisetValueEntry pValue = (PApisetValueEntry)((PBYTE)schema_map + pApiSets[Next].HostOffset);
299 pValue += pApiSets[Next].NumberOfHosts - 1;
300
301 // Fill the buffer address and return true.
302 fun_wstr_cpy(real_dll, (PWCHAR)((PBYTE)schema_map + pValue->ValueOffset),
303 pValue->ValueLength / 2);
304 return TRUE;
305 };
306 }
307 else {
308
309 // Use the proper structures.
310 PApiSetHeader6 pHeader = (PApiSetHeader6)schema_map;
311 PApisetNameEntry2 pApiSets = (PApisetNameEntry2)((PBYTE)schema_map + sizeof(ApiSetHeader6));
312
313 // Use binary search to enumerate the dlls.
314 int Start, End, Next, CmpResult;
315 Start = Next = 0;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected