Thread: exe & dll
View Single Post
Old 11.06.2006, 09:10   #3
Thunderstorm
Архивный участник
 
Join Date: Dec 2005
Posts: 56
Default Re: exe & dll

Quote:
Originally Posted by Pipec
Вообщем решил себе немного голову "поломать".
Но столкнулся с проблемой знания с++ =)
Вообщем суть такова, есть файл ехе, при его запуске он загружает библиотеку dll, которая внутри запущеного процесса меняет у оператора call адрес функции на которую надо прыгнуть.
has decided a few head "to break" to itself. But has faced a problem of knowledge with ++ =) Вообщем the essence is those, there is a file ехе, at its start it loads library dll which inside запущеного process changes at the operator call the address of function on which it is necessary to jump. Here a piece dll (for an example):

Quote:
Originally Posted by Pipec
Вот кусок dll (для примера):
Here a piece dll (for an example):
Code:
void func(); 
void AddFunc(); 

DWORD dwProcessId; 
HANDLE hMainInst; 

BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)  
{ 
   switch( fdwReason ){ 
      case DLL_PROCESS_ATTACH: 
         dwProcessId = GetCurrentProcessId(); 
         hMainInst = OpenProcess(PROCESS_ALL_ACCESS,NULL,dwProcessId); 
         AddFunc(); 
         break; 
      case DLL_THREAD_ATTACH:          

         break;        
      case DLL_THREAD_DETACH: 
          
         break; 
      case DLL_PROCESS_DETACH: 

         break;    
   }    
   return TRUE; 
} 

void AddFunc() 
{ 
   DWORD OldCodeBuff = 0; 
   DWORD NewCodeBuff = 0; 
    
   DWORD addr = 0x00401028; 
   DWORD dbaddr = 0x00000001E8; 
    
   if(ReadProcessMemory(hMainInst,(LPCVOID)addr,&OldCodeBuff,sizeof(dbaddr),NULL)) 
   { 
      if(OldCodeBuff==dbaddr) 
      { 
         __asm 
         { 
            mov  eax,offset func 
            mov  [NewCodeBuff],eax 
         } 
         WriteProcessMemory(hMainInst,(LPVOID)(addr+1),&NewCodeBuff,sizeof(NewCodeBuff),NULL); 
      } 
      else 
      { 
         MessageBox(0,"Wrong file version!","Error Notice!",MB_OK | MB_ICONSTOP); 
      } 
   } 
   else 
   { 
      MessageBox(0,"Can't read process memory!","Error Notice!",MB_OK | MB_ICONSTOP); 
   } 
} 

void func() 
{ 
   MessageBox(0,"GOOD!","OK!",MB_OK); 
}
Quote:
Originally Posted by Pipec
Сам файл ехе (тестовый) имеет следующую структуру:
The file ехе (test) has following structure:

Code:
.text:00401017 sub_401017      proc near                
.text:00401017                 push  offset LibFileName 
.text:0040101C                 call   LoadLibraryA 
.text:00401021                 nop 
.text:00401022                 nop 
.text:00401023                 mov     eax, 123456h 
.text:00401028                 call    sub_40102E 
.text:0040102D                 retn 
.text:0040102D sub_401017      endp
Quote:
Originally Posted by Pipec
После загрузки dll получаю:
After loading dll I receive:
Code:
.text:00401028                  call   near ptr 104120AAh
Quote:
Originally Posted by Pipec
Но это не работает, неверный адрес памяти.
Вообщем нужно чтобы вместо sub_40102E вызывалась функция func

Подскажите, может я что-то не так сделал?
But it does not work, the incorrect address of memory. Вообщем it is necessary that instead of sub_40102E function func was caused Prompt, I can something not so have made?
Thunderstorm is offline