tags:

views:

70

answers:

1

hello all,I'am trying to work-out the LdrLoadDll function and am having no luck with that..i also googled for some examples there is no much documentation or correct example about this.I know what it exactly does..Please check the code below.

//declaration function pointer for LdrLoadDll
typedef NTSTATUS (_stdcall*fp_LdrLoadDll)(
IN PWCHAR PathToFile OPTIONAL,
IN ULONG Flags OPTIONAL, 
IN PUNICODE_STRING ModuleFileName, 
OUT PHANDLE ModuleHandle ); 

//calling LdrLoadDll using getprocaddress
 HANDLE handle;
  HMODULE module = LoadLibrary(L"ntdll.dll");
    fp_LdrLoadDll loadDll;
    loadDll = (fp_LdrLoadDll)GetProcAddress(module,"LdrLoadDll");
    if(loadDll == NULL)
    {
        MessageBox(0,L"Not able to load the function",L"LdrLoadDll",&handle);
    }
    UNICODE_STRING input;
    input.Buffer = L"C:\\Desktop\\myDll.dll";
    input.Length = wcslen(input.Buffer)*2;
    input.MaximumLength = wcslen(input.Buffer) +2;

    NTSTATUS status = loadDll(NULL,LOAD_WITH_ALTERED_SEARCH_PATH,&input,0);

When i execute the above am not getting the handle niether valid status.Please help me with this.

A: 

It worked for me when I intialized the Unicode string like the following

RtlInitUnicodeString(&input,L"myDll.dll");
kiddo