Code pour distribuer ses patch[masm]

Contenu du snippet

c pas trop compliquer mais g galéré un moment pour y arriver..donc ca peut servir au autre!!

Source / Exemple :


.386
.model flat,stdcall
option casemap:none
WinMain proto :DWORD,:DWORD,:DWORD,:DWORD

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
include \masm32\include\comdlg32.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\comdlg32.lib

.data
ButtonID equ 1
ButtonID1 equ 2
MAXSIZE equ 260
OUTPUTSIZE equ 512

ClassName db "SimpleWinClass",0
AppName  db "    -=EEDY 31 patch=-",0

ButtonClassName db "button",0 
ButtonText db "Go!!",0
ButtonText1 db "Quitter",0

MenuName db "FirstMenu",0
ofn  OPENFILENAME <>
FilterString db "All Files",0,"*.*",0
            db "eXecutables",0,"*.exe",0,0
Exe db MAXSIZE dup(0)
OurTitle db "Choisis le file à cracker",0

MsgCaption      db "Erreur",0
MsgBoxText      db "Fichier protégé en écriture ou utilisé!!",0

MsgCaption1      db "Succès!!",0
MsgBoxText1      db "Fichier patché avec succès",0

NbBytesWritten   dd 0 

hInstance HINSTANCE ?
CommandLine LPSTR ?
hwndButton HWND ? 
hwndButton1 HWND ? 
handle dd ?

byte_a_ecrire   db 90h

.code
start:
   invoke GetModuleHandle, NULL
   mov    hInstance,eax
   invoke GetCommandLine
   invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT
   invoke ExitProcess,eax

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
   LOCAL wc:WNDCLASSEX
   LOCAL msg:MSG
   LOCAL hwnd:HWND
   mov  wc.cbSize,SIZEOF WNDCLASSEX
   mov  wc.style, WS_TILED  
   mov  wc.lpfnWndProc, OFFSET WndProc
   mov  wc.cbClsExtra,NULL
   mov  wc.cbWndExtra,NULL
   push  hInst
   pop  wc.hInstance
   mov  wc.hbrBackground,COLOR_BTNTEXT +1
   mov  wc.lpszClassName,OFFSET ClassName
   invoke LoadIcon,NULL,IDI_APPLICATION
   mov  wc.hIcon,eax
   mov  wc.hIconSm,eax
   invoke LoadCursor,NULL,IDC_ARROW
   mov  wc.hCursor,eax
   invoke RegisterClassEx, addr wc
   INVOKE CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\
          WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\
          CW_USEDEFAULT,250,200,NULL,NULL,\
          hInst,NULL
   mov  hwnd,eax
   INVOKE ShowWindow, hwnd,SW_SHOWNORMAL
   INVOKE UpdateWindow, hwnd
   .WHILE TRUE
          INVOKE GetMessage, ADDR msg,NULL,0,0
                .BREAK .IF (!eax)
                INVOKE TranslateMessage, ADDR msg
                INVOKE DispatchMessage, ADDR msg
   .ENDW
   mov    eax,msg.wParam
   ret
WinMain endp

WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM  

   .IF uMsg==WM_DESTROY
      invoke PostQuitMessage,NULL
      .elseif uMsg==WM_CREATE
; -->  CREER  BUTTON
                    invoke CreateWindowEx,NULL, ADDR ButtonClassName,\ 
                                  ADDR ButtonText,\ 
                                  WS_CHILD or WS_VISIBLE or BS_DEFPUSHBUTTON,\ 
                                  10,140,100,20,hWnd,ButtonID,hInstance,NULL 
                                  mov  hwndButton,eax

; -->  CREER BUTTON
        invoke  CreateWindowEx,NULL, ADDR ButtonClassName,ADDR ButtonText1,\
                WS_CHILD or WS_VISIBLE or BS_PUSHBUTTON  ,\
                  130,140,100,20,hWnd,ButtonID1,hInstance,NULL
        mov    hwndButton1,eax
        

   .ELSEIF uMsg==WM_COMMAND
      mov eax,wParam
      .if ax==1

         mov ofn.lStructSize,SIZEOF ofn
         push hWnd
         pop  ofn.hWndOwner
         push hInstance
         pop  ofn.hInstance
         mov  ofn.lpstrFilter, OFFSET FilterString
         mov  ofn.lpstrFile, OFFSET Exe
         mov  ofn.nMaxFile,MAXSIZE
         mov  ofn.Flags, OFN_FILEMUSTEXIST or \
                        OFN_PATHMUSTEXIST or OFN_LONGNAMES or\
                        OFN_EXPLORER or OFN_HIDEREADONLY
         mov  ofn.lpstrTitle, OFFSET OurTitle
         invoke GetOpenFileName, ADDR ofn

         .if eax==TRUE
                     
              ;Ouverture de l'exe
                                         
                     invoke CreateFileA,offset Exe,0C0000000h ,1,0,3,80h,0
                        mov handle, eax
                  ;TRES IMPORTANT DE L'OUVRIR DE CETTE FACON SINON CA MARCHE PAS!!
                        
                        
                        .if eax==INVALID_HANDLE_VALUE
                        invoke MessageBox, NULL,addr MsgBoxText, addr MsgCaption, MB_OK
                        jmp @end
                        .endif 

                ;Deplacement dans le fichier
                              
                        invoke SetFilePointer,handle,0FEh,0,0 ;on se place a l'offset FE
        ;Ecriture dans le fichier    
                        mov esi,offset byte_a_ecrire                    
                        invoke WriteFile,handle,esi,1,offset NbBytesWritten,0
                        
        ;et voila!          
                        invoke MessageBox, NULL,addr MsgBoxText1, addr MsgCaption1, MB_OK
                        invoke CloseHandle,handle  
            
                         .endif
                      
                                 
      .else
         invoke DestroyWindow, hWnd
   
.endif
   .ELSE
      @end:
      invoke DefWindowProc,hWnd,uMsg,wParam,lParam
      ret
   .ENDIF
   xor    eax,eax
   ret
WndProc endp
end start

Conclusion :


des amélioration a venir et je suis en train de concocter un patcher ki compare le fichier d'origine et celui patché et ki sort un patch à distibuer automatikement(100% asm bien sur!)
donc a bientot !!

A voir également

Vous n'êtes pas encore membre ?

inscrivez-vous, c'est gratuit et ça prend moins d'une minute !

Les membres obtiennent plus de réponses que les utilisateurs anonymes.

Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.

Le fait d'être membre vous permet d'avoir des options supplémentaires.