Reverse Engineering - Zoom on Snippet

SECTION  .data
my_str:
    db     'The pool on the roof must have a leak.', 0
SECTION  .text
GLOBAL _start
_start:
    nop
    push byte 'x'      ; second function parameter
    push dword my_str  ; first function parameter
    call black_out     ; call function
    add esp, 8         ; cleaning out the stack
    mov  ebx,0         ; parameter for exit call (return value)
    mov  eax,1         ; exit system call
    int 080h           ; run system call, see page 79 pal

black_out:
    push ebp           ; function prologue, save stack base pointer
    mov ebp, esp       ; point base pointer to ESP  
    ; ------------ start code from book ---------

    mov edi, [ebp+8]  
;  mette in edi l'indirizzo del primo parametro della funzione
   
    mov edx, edi        
; backup dell'indirizzo
   
    xor eax, eax          
; azzera eax
   
   or ecx, 0FFFFFFFFh
; mette a -1 ecx

   repne scasb              
;  scansiona tutta la stringa fino al byte null 0 presente in eax  
   
   add ecx, 2              
   neg ecx                     ; nega ecx, 38

   mov al, [ebp+0Ch]  
; copia il carattere presente in ebp+12
   mov edi, edx            
; rimette in edi l'indirizzo dell'inizio della stringa

   rep stosb                  
; riempie la stringa di x        
   mov eax, edx          
; copia l'indirizzo della stringa in eax che ritorna il valore della funzione    


   ; ------------ end code from book -----------
   mov esp, ebp       ; restore stack pointer
   pop ebp            ; restore stack base pointer
   ret

Categories: , , Share

Leave a Reply