Per incominciare a programmare una buona idea è munirsi di un buon disassembler; questo non vuol dire andare a scarire un programma per disassemblare su internet e farne uso all'interno di un qualsiasi sistema operativo, penso che sia la cosa più inutile del mondo.
Quello che intendo con "Disassembler" stà di fattto nello scriverci direttamente il codice del disassemblatore, come esempio nel codice seguente.
Partendo da una deduzione elementare si può dire che ogni calcolatore dispone di un piccolo programmino per l'avvio di nome "Bios" per poi passare al sistema operativo; il Bios contiene tutte le funzioni che servono per gestire il nostro calcolatore più porte per il trasferimento dati dei vari componenti quali stampanti, dischi in generale e scheda video.
Quindi il più è fatto, il Bios gira in memoria reale ed è facilmente disassemblabile.......

Guida all'assembler



Partiamo con il codice del programma
              ;bios  09:0000
;00,08,04,00  segmento impostazioni
;00,08,04,80  segmento codice
;00,01,06,00  definizioni
;03:0000      database
      jmp 0000
      jmp 0101
      jmp 0102
*00 00 00
*00 00 00
*00 00 00
*00 00 00
*00 00 00
*00 00 00
*00 00 00
*00           ;001e pagina video
*00           ;001f modo istruzione
*00 04 00 00 00 00  ;00020 tabella idt
*6d 00        ;0026 int xx
*09 4f 00 00  ;0028 eax
*00 00 00 00  ;002c ebx
*04 00 00 00  ;0030 ecx
*00 00 00 00  ;0034 edx
*00 00 00 00  ;0038 ebp
*00 00 00 00  ;003c esi
*00 00 00 00  ;0040 edi
*00 f0 00 00  ;0044 esp
*00 90        ;0048 ds
*00 30        ;004a es
*00 90        ;004c ss
*00 00        ;004e fs
*00 00        ;0050 gs
*00           ;0052 test primo punto
*ea           ;0053 salto codice
*00 00 00 00  ;0054 registro cs:ip
*00 00 00 00  ;0058 eflags
*ea 92 00 00 c0 ;int ff
:0001 push es ;stampa i registri************************
      push ds
      push gs
      push fs
      push ss
      push es
      push ds
      pushd [00000054]
      push esp
      push edi
      push esi
      push ebp
      push edx
      push ecx
      push ebx
      push eax
      pushfd
      mov ebp,esp
      mov eax,[ebp+20]   ;registro esp
      add ax,0016
      mov [ebp+20],eax
      mov ax,0500        ;pagina 00
      int 10
      mov ax,B800        ;memoria video
      mov es,ax
      mov ax,3000        ;definizioni del bios
      mov ds,ax
      lea esi,00000000
      lea edi,000003C0
      mov cx,000A
:0002 pop eax            ;registri memoria
      push cx
      mov ecx,00000004
      repz
      movsd
      mov cx,0008
:0004 rol eax,04
      push ax
      mov ah,0F
      and al,0F
      add al,30
      cmp al,3A
      jb 0003
      add al,27
:0003 stosw
      pop ax
      loop 0004
      add di,0080
      pop cx
      loop 0002
      mov cx,0005
:0005 pop ax             ;registri segmento
      push cx
      mov ecx,00000004
      repz
      movsd
      mov cx,0004
:0007 rol ax,04
      push ax
      mov ah,0F
      and al,0F
      add al,30
      cmp al,3A
      jb 0006
      add al,27
:0006 stosw
      pop ax
      loop 0007
      add di,0088
      pop cx
      loop 0005
      mov ah,00          ;pausa
      int 16
      pop ds
      pop es
      ret
:0008 push esi ;stampa buffer informazioni*****************
      push edi
      push cx
      push ds
      push es
      mov ax,0501        ;pagina 1
      int 10
      mov ax,B900        ;memoria video
      mov es,ax
      mov ax,3000        ;definizioni del bios
      mov ds,ax
      mov esi,edi
      lea edi,000000A2
      lea ebp,00001600
      mov ah,0F
:0009 mov al,[esi]
      shr al,04
      add al,30
      cmp al,3A
      jb 000A
      add al,27
:000a stosw
      mov al,[esi]
      and al,0F
      add al,30
      cmp al,3A
      jb 000B
      add al,27
:000b stosw
      add di,0006
      inc si
      loop 0009
      mov ah,00          ;pausa
      int 16
      pop es
      pop ds
      pop cx
      pop edi
      pop esi
      ret
:000c push ebp ;stampa l'istruzione**************
      xor ecx,ecx
      mov [esi],00
      mov esi,00000100
      lea edi,00000000
      mov ax,[esi+F0]
      mov es,ax
      add ax,000A
      cmp al,FA          ;fine pagina
      jnz 000D
      mov al,00
      add ax,0100
      cmp ax,C000        ;fine segmento
      jnz 000D
      mov ax,B800
:000d mov [esi+F0],ax
      mov cx,0050
      mov ah,03
      add di,0002
:000e mov al,[esi]
      stosw
      inc si
      dec cx
      cmp al,00
      jnz 000E
      sub di,0002
      mov ax,0000
      repz
      stosw
      lea ebp,00000058   ;stampa i registri
      mov es,[000000F0]
      mov si,0002
      mov di,0002
      movsd
      movsw
      call 0011
      mov bp,0028
      add si,0008
      call 0011
      mov bp,002C
      add si,0008
      call 0011
      mov bp,0030
      add si,0008
      call 0011
      mov bp,0034
      add si,0008
      call 0011
      mov bp,0038
      add si,0008
      call 0011
      mov ax,[000000F0]  ;nuova riga
      add ax,000A
      cmp al,FA
      jnz 000F
      mov al,00
      add ax,0100
      cmp ax,C000
      jnz 000F
      mov ax,B800
:000f mov es,ax
      mov bp,003C
      add si,0008
      mov di,0002
      call 0011
      mov bp,0040
      add si,0008
      call 0011
      mov bp,0044
      add si,0008
      call 0011
      mov bp,0054
      add si,0008
      call 0011
      mov ax,es          ;nuova riga
      add ax,000A
      cmp al,FA
      jnz 0010
      mov al,00
      add ax,0100
      cmp ax,C000
      jnz 0010
      mov ax,B800
:0010 mov es,ax
      mov bp,0048
      add si,000A
      mov di,0002
      call 0014
      mov bp,004A
      add si,000A
      call 0014
      mov bp,004C
      add si,000A
      call 0014
      mov bp,004E
      add si,000A
      call 0014
      mov bp,0050
      add si,000A
      call 0014
      pop ebp
      ret
:0011 push ds ;converte registro eax**********
      movsd
      movsd
      mov ax,9000
      mov ds,ax
      mov eax,[ebp+00]
      mov cx,0008
:0013 rol eax,04
      push ax
      mov ah,0F
      and al,0F
      add al,30
      cmp al,3A
      jb 0012
      add al,27
:0012 stosw
      pop ax
      loop 0013
      pop ds
      ret
:0014 push ds ;converte registro ax**********
      movsd
      movsw
      mov ax,9000
      mov ds,ax
      mov eax,[ebp+00]
      mov cx,0004
:0016 rol ax,04
      push ax
      mov ah,0F
      and al,0F
      add al,30
      cmp al,3A
      jb 0015
      add al,27
:0015 stosw
      pop ax
      loop 0016
      pop ds
      ret
jmp 0100
:0000 mov ax,0080        ;inizio codice*********************
      mov [00010214],ax
      mov eax,00010600
      mov [00010218],eax
      mov eax,00030000
      mov [0001021C],eax
      callf 0008:000D    ;carica le definizioni
      cli
      lidt [00090020]
      mov eax,00000010
      mov cr0,eax
      mov ax,0000
      mov ds,ax
      mov es,ax
      mov fs,ax
      mov gs,ax
      mov ax,9000
      mov ss,ax
      mov esp,0000FFFF
      mov dx,0000
      sti
      jmps 9000:0003
:0101 mov eax,90000006
      mov [00000004],eax ;int 01
      mov eax,9000005C
      mov [000003FC],eax ;int ff
      mov ax,9000
      mov ds,ax
      mov ax,0003        ;modo video 720x400
      int 10
      mov ah,01          ;modo cursore
      mov ch,20
      int 10
      cmp [0000001F],01
      jz 0100
      mov eax,[00000028] ;imposta i registri
      mov ebx,[0000002C]
      mov ecx,[00000030]
      mov edx,[00000034]
      mov ebp,[00000038]
      mov esi,[0000003C]
      mov edi,[00000040]
      cli
      mov esp,[00000044]
      mov ds,[00000048]
      mov es,[0000004A]
      mov ss,[0000004C]
      mov fs,[0000004E]
      mov gs,[00000050]
      sti
      push bx            ;indirizzo della funzione
      push ds
      xor eax,eax
      mov ax,[00000026]
      shl ax,02
      mov bx,0000
      mov ds,bx
      mov eax,[eax]
      pop ds
      pop bx
      mov [00000054],eax
      pushf
      pop ax
      or ax,0100
      push ax
      mov eax,[00000028]
      popf
      jmps 9000:0053
:0102 push ds            ;int 01++++++++++++++++++++++++++++
      pushf
      push ax
      mov ax,9000
      mov ds,ax
      cmp sp,EFF4
      jna 0103
      mov ah,00          ;fine programma
      int 16
      jmp 0100
:0103 cmp [00000052],01
      jz 0104
      mov [00000052],01
      pop ax
      popf
      pop ds
      iret
:0104 pop ax             ;salva i registri
      mov [00000028],eax
      mov [0000002C],ebx
      mov [00000030],ecx
      mov [00000034],edx
      mov [00000038],ebp
      mov [0000003C],esi
      mov [00000040],edi
      mov eax,esp
      add ax,000A
      mov [00000044],eax
      pop ax
      mov [00000058],ax
      pop ax
      mov [00000048],ax
      mov ax,es
      mov [0000004A],ax
      mov ax,ss
      mov [0000004C],ax
      mov ax,fs
      mov [0000004E],ax
      mov ax,gs
      mov [00000050],ax
      mov ax,9000
      mov ds,ax
      mov ebp,esp
      mov eax,[ebp+00]
      mov [00000054],eax
      mov ax,3000
      mov ds,ax
      mov ax,[ebp+00]
      mov ss,[ebp+02]
      mov bp,ax
      lea esi,00000100   ;buffer istruzione
      lea edi,00000200   ;definizioni istruzione
      mov bx,0000
      mov dx,0000
:0105 mov ah,00
      mov al,[ebp+00]    ;prefisso istruzione
      inc bp
      cmp al,66
      jnz 0106
      mov bh,01
      jmp 0105
:0106 cmp al,67
      jnz 0107
      mov bl,01
      jmp 0105
:0107 cmp al,F0          ;lock
      jnz 0108
      mov eax,6B636F6C
      mov [esi],eax
      mov [esi+04],20
      add si,0005
      jmp 0105
:0108 cmp al,F2          ;repz
      jnz 0109
      mov eax,7A706572
      mov [esi],eax
      mov [esi+04],20
      add si,0005
      jmp 0105
:0109 cmp al,F3          ;repnz
      jnz 010A
      mov eax,6E706572
      mov [esi],eax
      mov [esi+04],207A
      add si,0006
      jmp 0105
:010a cmp al,26          ;es
      jnz 010B
      mov dx,7365
      jmp 0105
:010b cmp al,2E          ;cs
      jnz 010C
      mov dx,7363
      jmp 0105
:010c cmp al,36          ;ss
      jnz 010D
      mov dx,7373
      jmp 0105
:010d cmp al,3E          ;ds
      jnz 010E
      mov dx,7364
      jmp 0105
:010e cmp al,64          ;fs
      jnz 010F
      mov dx,7366
      jmp 0105
:010f cmp al,65          :gs
      jnz 0110
      mov dx,7367
      jmp 0105
:0110 mov [000000E0],al  ;opcode
      shl ax,04
      add di,ax
:0112 mov al,[edi]       ;istruzione modo
      cmp al,00
      jz 0111
      mov [esi],al
      inc si
      inc di
      jmp 0112
:0111 inc di
      mov al,[edi]
      cmp al,00
      jz 0113
      cmp al,FF
      jz 0114
      cmp al,FE
      jz 0115
      cmp al,FD
      jz 0116
      cmp al,FC
      jz 0117
      cmp al,FB
      jz 0118
      cmp al,FA
      jz 0145
      cmp al,F9
      jz 014B
      cmp al,F8
      jz 014C
      jmp 0119
:0114 mov al,[ebp+00]    ;numero 8bit
      inc bp
      mov cx,0002
:011b rol al,04
      mov [000000F6],al
      and al,0F
      add al,30
      cmp al,3A
      jb 011A
      add al,27
:011a mov [esi],al
      inc si
      mov al,[000000F6]
      loop 011B
      jmp 0111
:0115 cmp bh,01          ;numero 16bit
      jz 011C
      mov ax,[ebp+00]
      add bp,0002
      mov cx,0004
:011e rol ax,04
      mov [000000F6],ax
      and al,0F
      add al,30
      cmp al,3A
      jb 011D
      add al,27
:011d mov [esi],al
      inc si
      mov ax,[000000F6]
      loop 011E
      jmp 0111
:011c mov eax,[ebp+00]
      add bp,0004
      mov cx,0008
:0120 rol eax,04
      mov [000000F6],eax
      and al,0F
      add al,30
      cmp al,3A
      jb 011F
      add al,27
:011f mov [esi],al
      inc si
      mov eax,[000000F6]
      loop 0120
      jmp 0111
:0116 mov [esi],2C       ;virgola
      inc si
      jmp 0111
:0117 cmp bh,00          ;doppia word
      jz 0111
      mov [esi],7764
      add si,0002
      jmp 0111
:0118 xor ax,ax          ;salto relativo 8bit
      mov al,[ebp+00]
      add al,02
      cmp al,80
      jb 0142
      mov ah,FF
:0142 dec bp
      add ax,bp
      mov cx,0004
:0143 rol ax,04
      mov [000000F6],ax
      and al,0F
      add al,30
      cmp al,3A
      jb 0144
      add al,27
:0144 mov [esi],al
      inc si
      mov ax,[000000F6]
      loop 0143
      jmp 0111
:0145 mov ax,[ebp+02]    ;call far
      mov cx,0004
:0147 rol ax,04
      mov [000000F6],ax
      and al,0F
      add al,30
      cmp al,3A
      jb 0146
      add al,27
:0146 mov [esi],al
      inc si
      mov ax,[000000F6]
      loop 0147
      mov [esi],3A
      inc si
      mov ax,[ebp+00]
      add bp,0004
      mov cx,0004
:0149 rol ax,04
      mov [000000F6],ax
      and al,0F
      add al,30
      cmp al,3A
      jb 0148
      add al,27
:0148 mov [esi],al
      inc si
      mov ax,[000000F6]
      loop 0149
      jmp 0111
:014b mov [esi],6C61     ;al
      add si,0002
      jmp 0111
:014c mov ax,[ebp+00]    ;salto relativo 16bit
      add ax,0003
      dec bp
      add ax,bp
      mov cx,0004
:014e rol ax,04
      mov [000000F6],ax
      and al,0F
      add al,30
      cmp al,3A
      jb 014D
      add al,27
:014d mov [esi],al
      inc si
      mov ax,[000000F6]
      loop 014E
      jmp 0111
:0119 mov al,[ebp+00]    ;istruzione mem/reg
      mov [000000D0],al
      inc bp
:0121 xor ax,ax
      mov al,[edi]
      shl ax,08
      inc di
      mov [000000F2],di
      mov [000000F4],dx
      cmp [edi],01
      jz 0122
      cmp [edi],02
      jz 0123
      cmp [edi],03
      jz 0124
      cmp [edi],04
      jz 0125
      cmp [edi],05
      jz 0126
      cmp [edi],06
      jz 0127
      cmp [edi],07
      jz 0150
:0122 mov di,ax          ;indirizzo di memoria
      mov ah,00
      mov al,[000000D0]
      shr al,06
      shl ax,07
      add di,ax
      mov ah,00
      mov al,[000000D0]
      mov cx,0008
      mov dx,0000
      div cx
      shl dl,04
      add di,dx
      mov al,[000000D0]
      cmp al,C0
      jb 0128
      cmp bh,00          ;66
      jz 0129
      add di,0200
      jmp 0129
:0128 cmp bl,00          ;67
      jz 0129
      add di,0400
      jmp 0129
:0123 mov di,ax          ;indirizzo di registro
      add di,0180
      mov ah,00
      mov al,[000000D0]
      mov cx,0040
      mov dx,0000
      div cx
      shr dl,03
      shl dl,04
      add di,dx
      cmp bh,00          ;66
      jz 0129
      add di,0200
      jmp 0129
:0124 mov di,ax          ;indirizzo in ax
      add di,0180
      dec bp
      cmp bh,00          ;66
      jz 0129
      add di,0200
      jmp 0129
:0125 mov di,ax          ;indirizzo in un registro
      add di,0180
      mov ah,00
      mov al,[000000E0]
      mov cx,0008
      mov dx,0000
      div cx
      shl dl,04
      add di,dx
      dec bp
      cmp bh,00          ;66
      jz 0129
      add di,0200
      jmp 0129
:0126 mov ax,[edi+01]    ;sposta la tabella
      mov di,ax
      mov ah,00
      mov al,[000000D0]
      mov cx,0040
      mov dx,0000
      div cx
      shr dl,03
      shl dl,04
      add di,dx
      dec bp
      mov dx,[000000F4]
      jnz 0112
:0127 mov [000000D0],06  ;indirizzo in al,[0000]
      dec bp
      inc di
      jmp 0121
:0150 mov di,ax          ;tabella 0f
      mov ah,00
      mov al,[ebp+FF]
      mov [000000E0],al
      shl ax,04
      add di,ax
      mov dx,[000000F4]
      jmp 0112
:0129 mov al,[edi]       ;rotazione blocco
      inc di
      cmp al,00
      jz 012A
      cmp al,FF
      jz 012B
      cmp al,FE
      jz 012C
      cmp al,5B
      jnz 012D
      cmp [000000F4],0000
      jz 012D
      mov ax,[000000F4]
      mov [esi],ax
      add si,0002
      mov al,[edi+FF]
:012d mov [esi],al
      inc si
      jmp 0129
:012b mov al,[ebp+00]    ;numero 8bit
      inc bp
      mov cx,0002
:012f rol al,04
      mov [000000F6],al
      and al,0F
      add al,30
      cmp al,3A
      jb 012E
      add al,27
:012e mov [esi],al
      inc si
      mov al,[000000F6]
      loop 012F
      jmp 0129
:012c cmp bl,01          ;numero 16bit
      jz 0130
      mov ax,[ebp+00]
      add bp,0002
      mov cx,0004
:0132 rol ax,04
      mov [000000F6],ax
      and al,0F
      add al,30
      cmp al,3A
      jb 0131
      add al,27
:0131 mov [esi],al
      inc si
      mov ax,[000000F6]
      loop 0132
      jmp 0129
:0130 mov eax,[ebp+00]
      add bp,0004
      mov cx,0008
:0134 rol eax,04
      mov [000000F6],eax
      and al,0F
      add al,30
      cmp al,3A
      jb 0133
      add al,27
:0133 mov [esi],al
      inc si
      mov eax,[000000F6]
      loop 0134
      jmp 0129
:012a mov dx,[000000F4]  ;fine blocco
      mov di,[000000F2]
:0135 inc di
      mov al,[edi]
      cmp al,00
      jz 0113
      cmp al,FF
      jz 0136
      cmp al,FE
      jz 0137
      cmp al,FD
      jz 0138
      cmp al,FC
      jz 0139
      cmp al,FB
      jz 013A
      cmp al,FA
      jz 014A
      cmp al,F9
      jz 014F
      jmp 0121
:0136 mov al,[ebp+00]    ;numero 8bit
      inc bp
      mov cx,0002
:013c rol al,04
      mov [000000F6],al
      and al,0F
      add al,30
      cmp al,3A
      jb 013B
      add al,27
:013b mov [esi],al
      inc si
      mov al,[000000F6]
      loop 013C
      jmp 0135
:0137 cmp bh,01          ;numero 16bit
      jz 013D
      mov ax,[ebp+00]
      add bp,0002
      mov cx,0004
:013f rol ax,04
      mov [000000F6],ax
      and al,0F
      add al,30
      cmp al,3A
      jb 013E
      add al,27
:013e mov [esi],al
      inc si
      mov ax,[000000F6]
      loop 013F
      jmp 0135
:013d mov eax,[ebp+00]
      add bp,0004
      mov cx,0008
:0141 rol eax,04
      mov [000000F6],eax
      and al,0F
      add al,30
      cmp al,3A
      jb 0140
      add al,27
:0140 mov [esi],al
      inc si
      mov eax,[000000F6]
      loop 0141
      jmp 0135
:0138 mov [esi],2C       ;virgola
      inc si
      jmp 0135
:0139 cmp bh,00          ;doppia word
      jz 0135
      mov [esi],7764
      add si,0002
      jmp 0135
:013a mov [esi],3130     ;01
      add si,0002
      jmp 0135
:014a mov [esi],6C63     ;cl
      add si,0002
      jmp 0135
:014f mov [esi],7864     ;dx
      add si,0002
      jmp 0135
:0113 mov ax,9000        ;fine istruzione++++++++++++++++++
      mov ss,ax
      call 000C
      mov ax,9000
      mov ds,ax
:0151 mov ah,00
      int 16
      cmp ah,50
      jz 0152
      cmp ah,48
      jz 0153
      cmp ah,1F          ;tasto s
      jz 0154
      cmp ah,39          ;tasto spazio
      jz 0155
      cmp ah,1C          ;tasto invio
      jz 0100
      jmp 0151
:0152 mov ah,05          ;pagina in basso
      mov al,[0000001E]
      cmp al,07
      jz 0151
      inc al
      mov [0000001E],al
      int 10
      jmp 0151
:0153 mov ah,05          ;pagina il alto
      mov al,[0000001E]
      cmp al,00
      jz 0151
      dec al
      mov [0000001E],al
      int 10
      jmp 0151
:0154 mov ss,[0000004C]  ;salta l'istruzione
      pop ax
      push bp
:0155 mov eax,[00000028]
      mov ebx,[0000002C]
      mov ecx,[00000030]
      mov edx,[00000034]
      mov ebp,[00000038]
      mov esi,[0000003C]
      mov edi,[00000040]
      mov es,[0000004A]
      mov ss,[0000004C]
      mov fs,[0000004E]
      mov gs,[00000050]
      mov ds,[00000048]
      iret
:0100
      call 0001          ;fine programma*****************************
jmps 1000:0000
      


Introduzione alla programmazione in "Assembler"
invia E-mail