CSDN博客

img kingcaiyao

硬盘加密--解析二

发表于2003/2/11 11:50:00  1155人阅读

在对硬盘主引导记录熟悉之后,就可以编出很多种硬盘加密程序(完全取决于你自已的需要),随着硬盘容量越来越大,其实我们可以将硬盘分为两个盘,一个是C盘,一个是D盘,平时将C盘重要的文件拷贝至D盘,并将D盘加锁,这样当C盘受到破坏时,就可以解锁D盘,将D盘上存储的文件恢复过来,我下面的程序就是以这一原理来编写的,请看代码:
Announcement:You can use any editor to edit source codes,such as Notepad,QE,Edit and so on.
Source Codes:
  data segment
    FQB DB 512 dup(0);To define a buffer,which will be used to store harddisk's MBR
    MESSAGE1 DB 0DH,0AH,"C------------LOCK C"
             DB 0DH,0AH,"D------------LOCK D"
             DB 0DH,0AH,"E------------Exit"
             DB 0DH,0AH,"Enter your selection!$"
    MESSAGE2 DB 0DH,0AH,"OK!$"
    MESSAGE3 DB "NOT FOUND DRIVE D!$"
    ERROR    DB "ENTER ERROR!$"
    IOERROR  DB "HARDDISK I/O ERROR!$"
    CXD      DW 0
  data ends
  stack segment
        DB 512 dup(0)
  stack ends
  code segment
     assume cs:code,ds:data,ss:stack
   START:
      mov AX,0201
      mov BX,OFFSET FQB
      mov CX,0001
      mov CXD,CX
      mov DX,0080
      INT 13;Read Main Boot Record,which is in 0 Header,0 Cylinder,1 Sector
      JB ERR
      MOV DX,OFFSET MESS1
      MOV AH,9
      INT 21
  AA0: ;Accept user's enter
      MOV AH,1
      INT 21 
      CMP AL,'E';Exit
      JZ EXIT
      CMP AL,'e';Exit
      JZ EXIT
      CMP AL,'C';Lock Drive C
      JZ LockC
      CMP AL,'c';Lock Drive C
      JZ LockC
      CMP AL,'D'
      JZ LockD;//Lock Drive D
      CMP AL,'d'
      JZ LockD;//Lock Drive D
      LEA DX,ERROR;Enter Error
      MOV AH,9
      INT 21
      JMP EXIT
  LockC:
      MOV AH,55H
      CLD
      MOV SI,OFFSET FQB
      MOV DI,SI
      MOV CX,01FE
  AA1:
      LOADSB
      XOR AL,AH
      ROL AH,1
      STOSB;//Encrypt Partition-Table
      LOOP AA1
  AA3:
      MOV AX,0301
      MOV BX,OFFSET BUF
      MOV CX,CXD
      MOV DX,0080
      INT 13
      JB ERR
      LEA DX,MESSAGE2
      MOV AH,9
      INT 21
      MOV AX,0040;Reset
      MOV DS,AX
      MOV AX,1234
      MOV SI,0072
      MOV [SI],AX
      JMP FFFF:0000
      INT 20
  LockD:
      CMP BYTE PTR [BUF+1D0],0
      JNZ AA2
      MOV DX,MESSAGE3;No Drive D
      MOV AH,9
      INT 21
      JMP EXIT
  AA2:
      MOV AX,0201
      MOV BX,OFFSET BUF
      MOV CX,WORD PTR [BUF+1D0];Read Logic Drive D Partition-Table
      MOV DX,0080
      INT 13
      JB ERR
      JMP LockC
  ERR:
     MOV DX,OFFSET IOERROR
     MOV AH,9
     INT 21
  EXIT:
     MOV AH,4CH
     INT 21

code ends
end start

上面的程序适合于只有两个分区的硬盘,不过程序也可以改进成多个分区的硬盘。在注释RESET处是热启动的代码,即交1234送至偏移地址0040:0072处,然后再跳转到FFFF:0处,即可以进行热启动。

0 0

相关博文

我的热门文章

img
取 消
img