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

Method get_dll_handle

src/shellcode.cpp:163–205  ·  view source on GitHub ↗

Get the dll base by name.

Source from the content-addressed store, hash-verified

161
162// Get the dll base by name.
163HANDLE shellcode::get_dll_handle(HANDLE pe_base, PDWORD sh_funs, PWSTR dll_name)
164{
165 // Resolving the needed functions.
166 auto fun_wstr_i_cmp = sh_resolve(pe_base, sh_funs, wstr_i_cmp);
167 auto fun_resolve_api_set = sh_resolve(pe_base, sh_funs, resolve_api_set);
168
169 // Needed local variables.
170 PPEB pPeb = NtCurrentTeb()->ProcessEnvironmentBlock;
171 PLIST_ENTRY head = &pPeb->Ldr->InMemoryOrderModuleList;
172
173QUERY_LDR:
174
175 // Looping on the LDR modules (ordered as in memory).
176 PLIST_ENTRY current = head;
177 while ((current = current->Flink) != head)
178 {
179 // Get and test the current module.
180 PLDR_DATA_TABLE_ENTRY data_table = CONTAINING_RECORD(current, LDR_DATA_TABLE_ENTRY, InMemoryOrderLinks);
181
182 // If the current module is the needed one.
183 if (!fun_wstr_i_cmp(((PUNICODE_STRING)(&data_table->Reserved4))->Buffer,
184 dll_name, 0))
185 {
186 // Return the module base.
187 return data_table->DllBase;
188 };
189 };
190
191 // Check if api set schema.
192 WCHAR api_schema[] = { L'a', L'p', L'i', L'-', L'\0' };
193 WCHAR ext_schema[] = { L'e', L'x', L't', L'-', L'\0' };
194 if (!fun_wstr_i_cmp(dll_name, api_schema, sizeof("api")) ||
195 !fun_wstr_i_cmp(dll_name, ext_schema, sizeof("ext")))
196 {
197 // The length of the dll name is more than the api set dll name.
198 if (fun_resolve_api_set(pe_base, sh_funs, pPeb->Reserved9[0], dll_name, dll_name)) {
199 goto QUERY_LDR;
200 };
201 };
202
203 // Not found.
204 return NULL;
205};
206
207// Load the dll base by name.
208HANDLE shellcode::load_dll(HANDLE pe_base, PDWORD sh_funs, PCHAR dll_name)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected