def load_dll_in_remote_process(target, dll_name):
    rpeb = target.peb
    if rpeb.Ldr:
        # LDR est parcourable, ca va etre deja plus simple..
        modules = rpeb.modules
        if any(mod.name == dll_name for mod in modules):
            # DLL already loaded
            dbgprint("DLL already present in target", "DLLINJECT")
            return True
        k32 = [mod for mod in modules if mod.name.lower() == "kernel32.dll"]
        if k32:
            # We have kernel32 \o/
            k32 = k32[0]
            try:
                load_libraryA = k32.pe.exports["LoadLibraryA"]
            except __HOLE__:
                raise ValueError("Kernel32 have no export <LoadLibraryA> (wtf)")

            with target.allocated_memory(0x1000) as addr:
                target.write_memory(addr, dll_name + "\x00")
                t = target.create_thread(load_libraryA, addr)
                t.wait()
            dbgprint("DLL Injected via LoadLibray", "DLLINJECT")
            return True
    # Hardcore mode
    # We don't have k32 or PEB->Ldr
    # Go inject a GetProcAddress(LoadLib) + LoadLib shellcode :D
    if target.bitness == 32:
        return perform_manual_getproc_loadlib_32(target, dll_name)
    return perform_manual_getproc_loadlib_64(target, dll_name)
dataset/ETHPy150Open hakril/PythonForWindows/windows/injection.py/load_dll_in_remote_process