qt - C++ DLL Injection: path with special characters -


i'm trying solve situation. have win32 program, waiting until specific process started "example.exe", program inject "my.dll" process "example.exe"

it works fine until user have program under folder specific, allowed characters, example in country default folder name "nová složka" (new folder)

i tried use relative path

"//my.dll" "/my.dll" "\\my.dll" "\my.dll" 

unsuccessfully... tried different ways convert string(qstring) char array.

developed in qt 5.1.1

here code program finding path of .dll

qstring actualpath(qdir::currentpath() + "/my.dll"); ui->lbldebug->settext(actualpath); const char* mychar = qstring(actualpath.toutf8()).tostdstring().c_str(); qstring q = qstring::fromstdstring(mychar); ui->lbldebug->settext(q); 

here injection part

hprocess = openprocess(process_all_access, false, pe32.th32processid); hmodule = (lpvoid)virtualallocex(hprocess, null, 512, mem_reserve | mem_commit, page_readwrite); writeprocessmemory(hprocess, hmodule, (lpvoid)mychar, 512, null); createremotethread(hprocess, null, null, (lpthread_start_routine)getprocaddress(getmodulehandle(l"kernel32"), "loadlibrarya"), hmodule, null, null); closehandle(hprocess); closehandle(hsnapshot); qdebug() << "inject:done!"; return true; exitprocess(0); break; 

do have ideas, how pass function writeprocessmemory right path correct characters? thanks.

you're using ansi version of loadlibrary. should using local 8 bit encoding, not utf-8. gyrations go through ansi version of path unnecessary. shouldn't using fixed buffer size.

qstring const actualpath(qdir::currentpath() + "/my.dll"); // byte array must exist until `writeprocessmemory` call. qbytearray const path = actualpath.tolocal8bit(); int const buflen = path.size() + 1;  hprocess = openprocess(process_all_access, false, pe32.th32processid); hmodule = virtualallocex(hprocess, null, buflen,                           mem_reserve | mem_commit, page_readwrite); writeprocessmemory(hprocess, hmodule, (lpvoid)path.constdata(), buflen, null); createremotethread(hprocess, null, null, (lpthread_start_routine)   getprocaddress(getmodulehandle(l"kernel32"), "loadlibrarya"),   hmodule, null, null); closehandle(hprocess); 

what should doing, though, using ucs-2 encoding loadlibraryw:

qstring const path(qdir::currentpath() + "/my.dll"); int const buflen = (path.length()+1) * 2;  hprocess = openprocess(process_all_access, false, pe32.th32processid); hmodule = virtualallocex(hprocess, null, buflen,                          mem_reserve | mem_commit, page_readwrite); writeprocessmemory(hprocess, hmodule, (lpvoid)path.constdata(), buflen, null); createremotethread(hprocess, null, null, (lpthread_start_routine)   getprocaddress(getmodulehandle(l"kernel32"), "loadlibraryw"),   hmodule, null, null); closehandle(hprocess); 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -