Commentçamarche.net
CodeS-SourceS
Rechercher un code, un tuto, une réponse

Patch tout exe 32bits pour y inserer une image (gif ,jpg,bmp )affichée le temps désiré

0/5 (12 avis)

Vue 11 251 fois - Téléchargée 820 fois

Description

Ce programme permet d'inserer une image (GIF,JPG,BMP) dans n'importre quel exe 32bits
cette image s'affichera en premier plan le temps désiré par l'utilisateur

Source / Exemple :


.386
.model flat,stdcall
option casemap:none

include c:\masm32\include\windows.inc
include c:\masm32\include\user32.inc
include c:\masm32\include\kernel32.inc
include c:\masm32\include\gdi32.inc
include c:\masm32\include\comdlg32.inc
include c:\masm32\include\GetValue.inc
include c:\masm32\include\oleaut32.inc
include c:\masm32\include\ole32.inc
include c:\masm32\include\winmm.inc

includelib c:\masm32\lib\user32.lib
includelib c:\masm32\lib\kernel32.lib
includelib c:\masm32\lib\gdi32.lib
includelib c:\masm32\lib\comdlg32.lib
includelib c:\masm32\lib\winmm.lib

includelib c:\masm32\lib\oleaut32.lib
includelib c:\masm32\lib\ole32.lib
includelib c:\masm32\lib\GetValue.lib

DialogProc PROTO : HWND, : UINT, : WPARAM, : LPARAM
OnCommand  PROTO : HWND, : WPARAM
FileOpen   PROTO : DWORD,:DWORD,:DWORD
FileMap    PROTO : DWORD,:DWORD,:DWORD,:DWORD

.CONST

OPCODESIZE            equ 70Dh
OFF_JUMP_PT_ENTRY     equ 332h
OFF_ELAPSE_TIME       equ 45Ah

IDD_DIALOG             equ 100
IDB_BKG                equ 300
IDB_EXIT               equ 301
IDB_OPEN1         equ 302
IDB_OPEN2         equ 303
IDB_PATCH         equ 304
IDC_EXENAME       equ 400
IDC_BMPNAME       equ 401
IDC_TIME          equ 402
IDC_TEST          equ 403

CR_BACKGROUND     equ 00876265h
CR_TEXT           equ 00FFDADDh
KEYCOLOR          equ 00FEFEFEh

NOTE_C            equ 403C78C0h
NOTE_E            equ 40407BC0h
NOTE_G            equ 40437BC0h

.DATA

old_pt_entry        DD 0
new_pt_entry        DD 0
imagebase           DD 0
off_new_section     DD 0
off_to_file         DD 0
off_v_data          DD 0
hBKG                DD 0
hBgColor            DD 0
hBgEdit             DD 0
hPatch              DD 0

ptr_PE              DD 0
h_mapPE             DD 0
h_filePE            DD 0
SIZE_PE             DD 0
   

ptr_PICTURE         DD 0
h_mapPICTURE        DD 0
h_filePICTURE       DD 0 
SIZE_FILE_PICTURE   DD 0

FilterStrBMP db "Image Files (*.bmp;*.gif;*.jpg)",0,"*.bmp;*.gif;*.jpg",0,0
FilterStrEXE db "Executable Files (*.exe)",0,"*.exe",0,0
             
filename     db 200 dup(0)
lpfile       db 50  dup(0)
OPFN         dd  76
hwnd         dd  0,0,0,0,0,0,offset filename,200
             dd  offset lpfile,50,0,0,0,0,0,0,0

msg1     db '(*.EXE) NON VALIDE !',0 
msg2     db '(*.EXE) NON PATCHABLE',0
msg3     db '(*.EXE) DEJA CHARGER OU EN LECTURE SEUL !'
STRNULL  db  0
STRDEFT  db '5000',0

hMidiOut DD 0
include patch03.hex
include xlpicture.asm
include skinbtn.asm
.CODE
PROGRAMME:

;###########################################
;------------------- WINMAIN ---------------
;###########################################

Invoke XLoadImage,IDB_BKG 
Invoke CreatePatternBrush,eax
mov    hBKG,eax
INVOKE CreateSolidBrush, CR_BACKGROUND
mov hBgColor, eax
INVOKE DialogBoxParam,400000h, IDD_DIALOG,0, ADDR DialogProc, 0
INVOKE DeleteObject,hBKG
INVOKE DeleteObject,hBgColor
INVOKE ExitProcess, 0

;###########################################      
;------------------- DIALOGPROC ------------
;###########################################

  DialogProc PROC hWnd: HWND, uMsg: UINT, wParam: WPARAM, lParam: LPARAM
  mov  eax,[ebp+12]
  cmp  eax,WM_CTLCOLORDLG
  je   WMCOLORDLG
  cmp  eax,WM_CTLCOLORSTATIC
  je   WMCOLORSTATIC
  cmp  eax,WM_CTLCOLOREDIT
  je   WMCOLOREDIT
  cmp  eax,WM_LBUTTONDOWN
  je   WMLBTNDOWN
  cmp  eax,WM_COMMAND
  je   WMCOMMAND
  cmp  eax,WM_INITDIALOG
  je   WMINITDLG
  cmp  eax,WM_CLOSE
  je   WMCLOSE
  jmp  DLG
WMCOLORDLG:    mov eax, hBgColor
               ret
WMCOLORSTATIC: INVOKE SetBkMode, wParam, TRANSPARENT
               INVOKE GetDlgCtrlID, lParam
               cmp    eax,IDC_TEST
               jne    @static
               mov    eax,hBKG
               ret
@static:       INVOKE SetTextColor, wParam, CR_TEXT
               mov eax, hBgColor
               ret
WMCOLOREDIT:   INVOKE SetBkMode, wParam,TRANSPARENT
               INVOKE SetTextColor, wParam, CR_TEXT
               mov eax,hBgColor
               ret
WMLBTNDOWN:    Invoke SendMessage,hWnd,WM_NCLBUTTONDOWN,HTCAPTION,[ebp+20]
               jmp  DLG
WMCOMMAND:     Invoke OnCommand,hWnd,wParam
               jmp DLG
WMINITDLG:     mov    eax,hWnd
               mov    hwnd,eax
               Invoke midiOutOpen,ADDR hMidiOut,0,0,0,CALLBACK_NULL
               Invoke XButton,hWnd,NOTE_C,219,208,IDB_EXIT,600
               Invoke XButton,hWnd,NOTE_E,330,88,IDB_OPEN1,601
               Invoke XButton,hWnd,NOTE_G,330,128,IDB_OPEN2,602
               Invoke XButton,hwnd,NOTE_C,37,208,IDB_PATCH,603
              
               Invoke GetDlgItem,hWnd,603
               mov    hPatch,eax
               Invoke ShowWindow,eax,SW_HIDE
              
               jmp DLG
WMCLOSE:       Invoke    midiOutClose, hMidiOut 
               INVOKE EndDialog, hWnd, 0
DLG:           xor eax, eax
               ret
DialogProc ENDP

;##################################################
;----------------------- ONCOMMAND ----------------
;##################################################

OnCommand PROC hWnd: HWND, wParam : WPARAM

       mov  eax,wParam
       cmp  ax,602
       je   CMD_OPENBMP
       cmp  ax,601
       je   CMD_OPENEXE
       cmp  ax,603
       je   CMD_PATCH
       cmp  ax,600
       je   CMD_QUIT
       ret

CMD_OPENBMP: Invoke FileOpen,ADDR h_filePICTURE,ADDR FilterStrBMP,0
             test eax,eax
             jnz  @mapbmp
             ret
@mapbmp:     invoke GetFileSize, eax, NULL    
             mov    SIZE_FILE_PICTURE,eax
             Invoke FileMap,h_filePICTURE,ADDR h_mapPICTURE,PAGE_READONLY,0
             mov  ptr_PICTURE,eax
             call GetInfoBMP
             Invoke UnmapViewOfFile,ptr_PICTURE
             Invoke CloseHandle,h_mapPICTURE
             ret
        
CMD_OPENEXE: Invoke FileOpen,ADDR h_filePE,ADDR FilterStrEXE,GENERIC_WRITE
             test eax,eax
             jnz  @mapexe
             ret
@mapexe:     invoke GetFileSize, eax, NULL
              mov  SIZE_PE,eax
             Invoke FileMap,h_filePE,ADDR h_mapPE,PAGE_READWRITE,0
             mov ptr_PE,eax
             call GetInfoPE
             Invoke UnmapViewOfFile,ptr_PE
             Invoke CloseHandle,h_mapPE
             ret
       
CMD_PATCH:   Invoke ShowWindow,hPatch,SW_HIDE
             Invoke EnableWindow,hPatch,FALSE

             mov  eax,OPCODESIZE
             add  eax,SIZE_FILE_PICTURE
             add  eax,4
             test eax,511
             jz @mul512
             shr eax,9
             inc eax
             shl eax,9
@mul512:     add  eax,SIZE_PE
             Invoke FileMap,h_filePE,ADDR h_mapPE,PAGE_READWRITE,eax
             mov ptr_PE,eax
             Invoke FileMap,h_filePICTURE,ADDR h_mapPICTURE,PAGE_READONLY,0
             mov  ptr_PICTURE,eax

             call Patch
       
             Invoke UnmapViewOfFile,ptr_PE
             Invoke CloseHandle,h_mapPE
             Invoke CloseHandle,h_filePE
             mov    h_filePE,0
      
             Invoke UnmapViewOfFile,ptr_PICTURE
             Invoke CloseHandle,h_mapPICTURE
             Invoke CloseHandle,h_filePICTURE
             mov    h_filePICTURE,0
       
             Invoke SetDlgItemText ,hwnd,IDC_EXENAME,ADDR STRNULL
             Invoke SetDlgItemText ,hwnd,IDC_BMPNAME,ADDR STRNULL
             Invoke SetDlgItemText ,hwnd,IDC_TIME,ADDR STRDEFT

             ret
CMD_QUIT:    Invoke SendMessage,hwnd,WM_CLOSE,0,0
             ret  
OnCommand ENDP
;#####################################################
;-------------- OUVERTURE D'UN FICHIER AVEC BOITE OPEN
;#####################################################
FileOpen PROC addrhfile : DWORD,addrfilter : DWORD,DesirAccess : DWORD

   
     ;--------boite open
       lea   eax,filename
       mov   byte ptr [eax],0

       mov eax,addrfilter
       mov [OPFN+12],eax
       
       mov [OPFN+52],OFN_LONGNAMES or OFN_HIDEREADONLY \
       or OFN_FILEMUSTEXIST or OFN_PATHMUSTEXIST  
       mov [OPFN+44],0
       push offset OPFN
       call GetOpenFileName
       test eax,eax
       jz   Annuler
;----------------------fermer hande file       
       mov  edi,addrhfile
       Invoke CloseHandle,[edi]
       
;-----------------------désactive btn patch
        Invoke ShowWindow,hPatch,SW_HIDE
        Invoke EnableWindow,hPatch,FALSE

;-------------ouvrir fichier
       mov    eax,DesirAccess
       or     eax,GENERIC_READ
       Invoke CreateFile,ADDR filename,eax,\
       0,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0
 
       mov  edx,eax
       inc  edx
       jnz  openOK
       push offset msg3
       call MSGERROR
       xor  eax,eax
       jmp  Annuler
openOK:
        stosd

Annuler:
       ret
FileOpen ENDP
;############################################
;----------------------- MAPPAGE D'UN FICHIER
;############################################
FileMap PROC hfile : DWORD,addrhMap : DWORD,desirAccess : DWORD,sizeMap : DWORD
       mov    esi,desirAccess
       Invoke CreateFileMapping,hfile,0,esi,0,sizeMap,0
       mov  edi,addrhMap 
       mov [edi],eax
       ;-------------optenir le pointeur
       add    esi,2
       Invoke MapViewOfFile,eax,esi,0,0,0
       ret 

FileMap ENDP
;//////////////////////////////////////
;------------------OPTENIR INFO BITMAP
;//////////////////////////////////////
GetInfoBMP proc
         Invoke SetDlgItemText ,hwnd,IDC_BMPNAME,ADDR filename
         mov    eax,h_filePE
         test   eax,eax
         jz     nopatch
         Invoke ShowWindow,hPatch,SW_SHOW
         Invoke EnableWindow,hPatch,TRUE
nopatch: ret
GetInfoBMP endp
;//////////////////////////////////////
;----------------- OPTENIR INFO SUR  PE
;//////////////////////////////////////
GetInfoPE proc
      
;----test validité
       cmp word ptr [eax],'ZM'
       jnz noValidePE
;--------taille sections header
       mov  edx,[eax+60];PEH
       add  eax,edx     ;+ptr_mapp
;----test validité

       cmp  dword ptr [eax],4550h
       jnz  noValidePE
       push [eax+40]
       pop  old_pt_entry
       push [eax+52]
       pop  imagebase
       mov  di,[eax+6]  ;nbrsection
       mov  cx,[eax+6]
       shl  di,5
       shl  cx,3
       add  di,cx
       movzx edi,di
       
;---------taille place libre dans header

       add  edx,248  ;+size peh
       add  edx,edi  ;+size section header
       mov off_new_section,edx 
       add  edx,[eax+212];+size bound import
       mov  ecx,[eax+84] ;size header to file
       sub  ecx,edx
       
;--------
       cmp  ecx,40
       jl   noPlace
       Invoke SetDlgItemText ,hwnd,IDC_EXENAME,ADDR filename
       mov    eax,h_filePICTURE
       test   eax,eax
       jz     noPa
       Invoke ShowWindow,hPatch,SW_SHOW
       Invoke EnableWindow,hPatch,TRUE

       ret 
noValidePE:
       push offset msg1
       call MSGERROR
       ret 
noPlace:
       push offset msg2
       call MSGERROR
 noPa:      
       ret 
GetInfoPE endp
;###############################
;---------------------- PATCHAGE 
;###############################      
Patch proc
     
      
       
;-----decalage du bound import

      mov  eax,ptr_PE
      add  eax,[eax+60]
      inc word ptr [eax+6];inc nbr sections
      mov  ecx,[eax+212] ;size bound import

      test ecx,ecx 

      jz     noboundimport
      mov  esi,[eax+208] ;off bound import
      add  esi,ecx
      add  esi,ptr_PE
      add  dword ptr [eax+208],40
      mov  edi,[eax+208]
      add  edi,ecx
      add  edi,ptr_PE
      std
      rep movsb
      cld
noboundimport:

;###################################################################
;--------------ECRIRE DS HEADER : AJOUT SECTION,NOUVEAU PT D'ENTREE,
;              NOUVELLE TAILLE DE L'IMAGE
;###################################################################

;-------------  AJOUT SECTION
    
     mov  edi,off_new_section
     add  edi,ptr_PE
     
;-------------- NOM

      mov dword ptr [edi],'ttt.'
      mov dword ptr [edi+4],0
      
;-------------- TAILLE VIRTUELLE

      mov eax,OPCODESIZE 
      add eax,SIZE_FILE_PICTURE
      mov dword ptr [edi+8],eax
      
;-------------- offset virtuelle

      mov  eax,[edi-32]
      add  eax,[edi-28]
      test eax,0FFFh
      jz @mul1000h
      shr   eax,12
      inc   eax
      shl   eax,12
@mul1000h:
      mov  dword ptr [edi+12],eax
      mov  edx,imagebase
      add  edx,eax
      mov  off_v_data,edx
      mov  new_pt_entry,eax
      

;------- size to file

      mov  eax,OPCODESIZE;size_opcode
      add  eax,SIZE_FILE_PICTURE
      test eax,511
      jz mul200h
      shr eax,9
      inc eax
      shl eax,9
mul200h:
      mov  dword ptr [edi+16],eax
;------- off to file

      mov  eax,[edi-24]
      add  eax,[edi-20]
      mov  dword ptr [edi+20],eax
      mov  off_to_file,eax

;----------
     mov  dword ptr [edi+24],0
     mov  dword ptr [edi+28],0
     mov  dword ptr [edi+32],0
;-------- caracteristic
mov   dword ptr [edi+36],0FE000020h

;--------------- NOUVELLE TAILLE DE L'IMAGE

     mov  eax,[edi+8]
     add  eax,[edi+12]
     test eax,0FFFh
     jz   SizeOfImage
     and  eax,0FFFFF000h
     add  eax,1000h
SizeOfImage:
    mov  edx,ptr_PE
    add  edx,[edx+60]
    mov  [edx+80],eax
   
;----------------- NOUVEAU PT D'ENTREE 
    push new_pt_entry
    pop  [edx+40]
    
;######################################################### 
;----------------- PETITE MODIFICATION DANS L'OPCODE -----
;#########################################################

   lea edi,opcode
 
;-------- CALCUL DU SAUT AU POINT D'ENTREE INITIAL

   mov  edx,new_pt_entry
   add  edx,OFF_JUMP_PT_ENTRY
   add  edx,3
   sub  edx,old_pt_entry
   not  edx
   mov  dword ptr [edi+OFF_JUMP_PT_ENTRY],edx ;saut ancien point d'entree
   
;------- REGLAGE TIMER

  Invoke GetDlgItemInt,hwnd,IDC_TIME,0,FALSE
  push eax
  pop  [edi+OFF_ELAPSE_TIME] ;elapse time

;#####################################################################
;--------------- COPIE DE L'OPCODE ET DU FICHIER IMAGE DANS PROG CIBLE
;#####################################################################

;---------- copie opcode dans fichier 
  lea esi,opcode
  mov edi,ptr_PE
  add edi,off_to_file
  mov ecx,OPCODESIZE
  rep movsb 
;---------- copie fichier image dans fichier
  mov esi,ptr_PICTURE
  push SIZE_FILE_PICTURE
  pop  [edi]
  add  edi,4
  mov ecx,SIZE_FILE_PICTURE
  rep movsb  

     
       ret  
Patch endp

;////////////////////////////////////////////
MSGERROR PROC
      Invoke MessageBox,hwnd,[esp+12],ADDR lpfile,MB_ICONEXCLAMATION
      Invoke CloseHandle,h_filePE
      mov    h_filePE,0
      Invoke SetDlgItemText ,hwnd,IDC_EXENAME,ADDR STRNULL
      ret 4
MSGERROR ENDP
end PROGRAMME

Conclusion :


Je tiens à remercier BLUEBIBUBBLE pour sa participation graphique
j'ai mis un Readme.txt dans le zip.

Codes Sources

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.