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

Method load_dll

src/shellcode.cpp:208–255  ·  view source on GitHub ↗

Load the dll base by name.

Source from the content-addressed store, hash-verified

206
207// Load the dll base by name.
208HANDLE shellcode::load_dll(HANDLE pe_base, PDWORD sh_funs, PCHAR dll_name)
209{
210 // Resolving the needed functions.
211 auto fun_ansi_to_wide = sh_resolve(pe_base, sh_funs, ansi_to_wide);
212 auto fun_get_dll_handle = sh_resolve(pe_base, sh_funs, get_dll_handle);
213 auto fun_get_symbol_ptr = sh_resolve(pe_base, sh_funs, get_symbol_ptr);
214 auto fun_wstr_len = sh_resolve(pe_base, sh_funs, wstr_len);
215 auto fun_hash_string = sh_resolve(pe_base, sh_funs, hash_string);
216
217 // Converting the dll name.
218 WCHAR dll_buffer[MAX_PATH];
219 fun_ansi_to_wide(dll_name, dll_buffer, sizeof(dll_buffer));
220
221 // Quering the ldr first.
222 HANDLE h_dll = fun_get_dll_handle(pe_base, sh_funs, dll_buffer);
223 if (h_dll) return h_dll;
224
225 // Getting the base of the ntdll.
226 WCHAR ntdll_name[] = { L'n', L't', L'd', L'l', L'l', L'.', L'd', L'l', L'l', L'\0' };
227 HANDLE h_ntdll = fun_get_dll_handle(pe_base, sh_funs, ntdll_name);
228 if (!h_ntdll) return NULL;
229
230 // Resolving `LdrLoadDll` to load the new dll.
231 u_sym_info ldr_load_dll_info;
232 CHAR ldrloaddll_name[] = { 'L', 'd', 'r', 'L', 'o', 'a', 'd', 'D', 'l', 'l', '\0' };
233 ldr_load_dll_info.sym_hash = fun_hash_string(ldrloaddll_name);
234 pLdrLoadDll fLdrLoadDll = (pLdrLoadDll)fun_get_symbol_ptr(pe_base, sh_funs, h_ntdll, ldr_load_dll_info, TRUE);
235 if (fLdrLoadDll == NULL) {
236 return NULL;
237 };
238
239 // Loading the required dll using `LdrLoadDll`.
240 UNICODE_STRING u_module = {
241 (USHORT)(fun_wstr_len(dll_buffer) * 2),
242 (USHORT)(fun_wstr_len(dll_buffer) * 2 + 2),
243 (PWCHAR)dll_buffer
244 };
245
246 // Loading the dll.
247 if (!NT_SUCCESS(fLdrLoadDll(
248 NULL, 0,
249 &u_module,
250 &h_dll
251 ))) return NULL;
252
253 // Return the loaded module base.
254 return h_dll;
255};
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)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected