; ; hdsn (Hard Disk Serial Number changer) ; ; $Id: hdsn.asm 8 2004-11-08 07:13:24Z guillem $ ; ; Copyright (C) 2001 Guillem Jover ; ; This program is free software; you can redistribute it and/or modify ; it under the terms of the GNU General Public License as published by ; the Free Software Foundation; either version 2 of the License, or ; (at your option) any later version. ; ; This program is distributed in the hope that it will be useful, ; but WITHOUT ANY WARRANTY; without even the implied warranty of ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ; GNU General Public License for more details. ; ; You should have received a copy of the GNU General Public License ; along with this program; if not, write to the Free Software Foundation, ; Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. ; org 0x100 %macro Write 1 mov ah, 9 mov dx, %1 int 0x21 %endmacro ; process command line mov di, 0x80 mov cl, [di] xor ch, ch inc di mov al, ' ' repne scasb jnz syntax_error ; process drive x: in command-line parse_drive: cmp byte [di+1], ':' jnz syntax_error mov dl, [di] and dl, 0xdf ; to upper case cmp dl, 'A' jb syntax_error cmp dl, 'Z' ja .end sub dl, 'A' - 1 .end: mov [drive], dl add di, 2 sub cl, 2 ; ingore remaining spaces repne scasb jz proc_serial_num syntax_error: Write MsgUsage jmp exit ; converts a hex char to a nibble scan_nibble: lodsb cmp al, '0' jb syntax_error cmp al, '9' ja .letter sub al, '0' ret .letter: and al, 0xdf ; to upper case cmp al, 'A' jb syntax_error cmp al, 'F' ja syntax_error sub al, 'A' - 10 ret ; process serial-number in command-line proc_serial_num: cmp cl, 8 jb syntax_error mov cx, 4 mov si, di mov di, serial_num+3 next_nibble: xor ax, ax call scan_nibble shl ax, 12 call scan_nibble or al, ah std stosb cld loop next_nibble ; ; Main program ; main: ; get drive serial number mov dx, disk_info xor bh, bh mov bl, [drive] mov ax, 0x6900 int 0x21 ; set drive serial number mov di, disk_info mov bp, di add di, 2 mov si, serial_num mov cx, 4 rep movsb xor bh, bh mov bl, [drive] mov ax, 0x6901 int 0x21 exit: ; quit to DOS mov ax, 0x4c00 int 0x21 section .data MsgUsage db 'hdsn v1.0 Guillem Jover (C) 2001', 0xD, 0xA db 'usage: hdsn drive serial-num', 0xD, 0xA db ' drive = c: - z:', 0xD, 0xA db ' sn = 4 bytes in hex', 0xD, 0xA, '$' section .bss drive: resb 1 serial_num: resd 1 disk_info: resb 0x20