Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Something messed up with my injection code

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Fri Dec 04, 2009 12:22 pm    Post subject: Something messed up with my injection code Reply with quote

that's my injection code for dll files
Code:

BOOL InjectDll(__in_bcount_z(256) _TCHAR *szDllFile, __in DWORD dwProcessId)
{
   HANDLE hProcess;
   DWORD dwMemSize, dwWritten, dwThreadId;
   FARPROC hLoadLib;
   HMODULE hKernel;
   LPVOID lpvMem;

   hProcess = OpenProcess(PROCESS_VM_READ | PROCESS_VM_WRITE | PROCESS_VM_OPERATION | PROCESS_CREATE_THREAD,FALSE,dwProcessId);
   if (hProcess) {
      dwMemSize = lstrlen(szDllFile);
      hKernel = GetModuleHandle(_T("Kernel32.Dll"));
      hLoadLib = GetProcAddress(hKernel,"LoadLibraryW");
      if (hLoadLib) {
         lpvMem = VirtualAllocEx(hProcess,NULL,dwMemSize,MEM_COMMIT,PAGE_EXECUTE_READWRITE);
         if (lpvMem) {
            if (WriteProcessMemory(hProcess,lpvMem,(void*)szDllFile,dwMemSize,&dwWritten)) {
               if (CreateRemoteThread(hProcess,0,0,(LPTHREAD_START_ROUTINE)lpvMem,hLoadLib,0,&dwThreadId)) {
                  MessageBox(0,_T("Injection Succeeded"),_T("Dll Injector"),MB_ICONINFORMATION);
                  return TRUE;
               }
            }
         }
      }
   }

   return FALSE;
}

it compiles fine but when i select dll to inject and press my injection button
the injector crushes!@!@
:S maybe i'm missing something here?
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Fri Dec 04, 2009 2:39 pm    Post subject: Reply with quote

something tells me this would become immediately obvious if you actually ran it with the debugger
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 470

Joined: 09 May 2003
Posts: 25796
Location: The netherlands

PostPosted: Fri Dec 04, 2009 3:16 pm    Post subject: Reply with quote

I really dislike unicode, and I bet this is one of those situations where unicode is the reason it goes wrong (lstrlen returns the number of characters, not the number of bytes)
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Fri Dec 04, 2009 3:18 pm    Post subject: Reply with quote

oh my...
shoot me please
but there's one more thing
now that i exchanged the allocated address with loadlib handle
it's successfully inject it but nothing's happening
i have messagebox that should pop up when the dll is injected but it ain't poping up
edit: i read your message now db i'll try replacing to ascii or try fixing the unicode part

edit2:
yes db you were right
it was a problem with lstrlen
i just multiplied the returned value by 2 since unicode = 2 bytes and it's worked
thank u both :]
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites