Guest User

Untitled

a guest
Jul 1st, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ScanPattern proc uses ecx esi edi pattern:dword,pattern_mask:dword,modulename:dword,pSize:dword,
  2.  
  3. LOCAL aSize:dword,aAddress:dword,EndofAlloc:dword,mSnapshot:dword,module:MODULEENTRY32,sAddress:dword,eAddress:dword,pHandle:dword
  4.  
  5.     invoke  CreateToolhelp32Snapshot,TH32CS_SNAPMODULE,pid
  6.     .if (eax != 0)
  7.         mov mSnapshot,eax
  8.         mov [module.dwSize],sizeof module
  9.         invoke Module32First,mSnapshot,addr module
  10.         .if (eax)
  11.         @@:
  12.             invoke lstrcmpi,modulename,addr module.szModule
  13.             .if (eax == 0)    
  14. ;SCAN=================================================================================================
  15.                 ;push ecx
  16.                 ;push esi
  17.                 ;push edi          
  18.                 ;mov    pSize,sizeof pattern
  19.                 push    module.modBaseAddr
  20.                 pop     sAddress   
  21.                 push    module.modBaseSize
  22.                 pop     aSize   ; how much must we allocate
  23.                 mov     eax,module.modBaseAddr
  24.                 add     eax,module.modBaseSize
  25.                 mov     eAddress,eax
  26.                 ;mov eax,EndAddy
  27.     ;sub eax,StartAddy  ; eax now size to alloc
  28.     ;mov AllocSize,eax  ; how much must we allocate
  29.  
  30.     invoke VirtualAlloc,0,aSize,MEM_COMMIT,PAGE_EXECUTE_READWRITE
  31.     mov aAddress,eax    ; adresse of allocated mem
  32.    
  33.     add eax,aSize
  34.     dec eax         ; last addr must be dec  (or its@newsection)
  35.     mov EndofAlloc,eax  ; End of allocated mem
  36.  
  37.     invoke OpenProcess,PROCESS_ALL_ACCESS,NULL,pid
  38.     push    eax
  39.     invoke ReadProcessMemory, eax, sAddress, aAddress, aSize, 0  ;map all    (mapping is fast)
  40.     pop eax
  41.     invoke CloseHandle,eax
  42.     mov edi,aAddress
  43.     mov esi,pattern    
  44.  
  45.     .WHILE 1
  46.         xor ecx,ecx
  47.         .while ecx!=pSize
  48.             mov eax,pattern_mask     ; here we check for Notation "x"
  49.             mov al,[eax+ecx]
  50.             cmp al,"x"
  51.             jne AB
  52.  
  53.             mov al,[esi+ecx]
  54.             mov ah,[edi+ecx]
  55.             cmp al,ah       ;lets compare our bytes
  56.             jne Bdnm        ;if something doesnt match jump out  Bytesdoesntmatch(Bdnm)
  57.         AB:
  58.             inc ecx
  59.         .endw
  60.  
  61.         mov eax,edi         ;--we found it
  62.         sub eax,aAddress
  63.         add eax,sAddress
  64.         push eax
  65.         invoke VirtualFree,aAddress,aSize,MEM_DECOMMIT 
  66.         pop eax
  67.         ret
  68.        
  69.     Bdnm:
  70.         cmp edi,EndofAlloc      ;check if are at the section End
  71.         jae OutOfScanRange      ;if so no signature found
  72.        
  73.         inc edi
  74.     .ENDW
  75. OutOfScanRange:
  76.  
  77.     mov eax,-1
  78.     push eax
  79.     invoke VirtualFree,aAddress,aSize,MEM_DECOMMIT 
  80.     pop eax
  81.                 ret
  82. ;SCAN=================================================================================================             
  83.             .endif
  84.             invoke  Module32Next, mSnapshot,ADDR module
  85.             test    eax,eax
  86.             jnz     @B      
  87.         .endif
  88.         invoke  CloseHandle, mSnapshot  
  89.     .endif
  90.     ret
  91. ScanPattern EndP
Add Comment
Please, Sign In to add comment