home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / das_buch / asemblr / asm / diskpro.asm < prev    next >
Encoding:
Assembly Source File  |  1993-06-05  |  9.1 KB  |  276 lines

  1. ; -----------------------------------------------------------
  2. ; Programm DISKPRO.ASM
  3. ; Funktion: Schutz des Partitionssektors vor Viren
  4. ; Autor: Sven Letzel in Zusammenarbeit mit Knut Pfefferkorn
  5. ; Compiler: MASM,TASM
  6. ; ASM -> OBJ: TASM DISKPRO
  7. ; OBJ -> COM: TLINK /t DISKPRO
  8. ; Datum: 12.04.1993
  9. ; ----------------------------------------------------------
  10.  
  11. CODE   SEGMENT BYTE
  12.        ASSUME  CS: CODE
  13.        ASSUME  DS: CODE
  14.        ORG     100H              ; wegen .COM
  15.  
  16. DiskPro:
  17.        JMP     @@Install
  18.  
  19. @@Bootstrap:
  20.       ;Beginn des Bootstrap-Programms
  21.       ;Diese Stelle wird dann später auf die Festplatte kopiert
  22.       ;und bei jedem Booten ausgeführt
  23.       JMP      SHORT @@Start
  24.  
  25. _Ausgabe       PROC
  26.       ;Ausgabe einer Zeichenkette über Funktion 0Eh des Int 10h,
  27.       ;denn beim Booten gibt es noch keine DOS-Interrupts
  28. @@Schleife1:
  29.       LODSB              ;Ein Byte laden
  30.       OR       AL, AL    ;auf Null testen
  31.       JZ       SHORT @@AusgabeOk
  32.       MOV      AH, 0EH   ;Funktion Zeichenausgabe
  33.       INT      10H
  34.       JMP      SHORT @@Schleife1
  35. @@AusgabeOk:
  36.       RET                ;Rücksprung
  37. _Ausgabe       ENDP
  38.  
  39. _ReadSektor    PROC
  40.      ;Lesen eines Sektors über Funktion 2 des Int 13h
  41.       MOV      DI, 3     ;3 Versuche
  42. @@Schleife2:
  43.       MOV      AX, 0201H ;Funktion einen Sektor lesen
  44.       INT      13H
  45.       JNB      SHORT @@ReadOk
  46.       XOR      AX, AX    ;mov ax,0
  47.       INT      13H       ;Plattensystem zurücksetzen
  48.       DEC      DI
  49.       JNZ      SHORT @@Schleife2
  50.       LEA      SI, LoadError + 4FDH
  51.       ;Adresse für "Ladefehler"
  52.       CALL     _Ausgabe
  53. @@Ewig:
  54.       JMP      SHORT @@Ewig
  55.       ;Endlosschleife
  56. @@ReadOk:
  57.       RET                ;zurück zum Aufrufer
  58. _ReadSektor    ENDP
  59.  
  60. @@Start:                 ;Einsprungpunkt Bootstrap
  61.       CLI                ;keine Interrupts
  62.       XOR      AX, AX
  63.       MOV      SS, AX    ;Stacksegment initial.
  64.       MOV      SP, 7C00H ;Stackpointer setzen
  65.       ;Das Bootstrapprogramm wird immer an Adresse 7C00h geladen
  66.       MOV      SI, SP    ;SP=7C00h
  67.       MOV      ES, AX    ;ES=0
  68.       MOV      DS, AX    ;DS=0
  69.       STI                ;Interrupts an
  70.       CLD                ;Direct.flag setzen
  71.                          ;bei Stringoperationen wird auf-
  72.                          ;wärts gezählt
  73.       MOV      DI, 0600H ;Zieladresse zum Kopieren
  74.       MOV      CX, 0100H ;256 Words (1 Sektor)
  75.       REPNZ    MOVSW     ;Programm kopiert sich
  76.       PUSH     0
  77.       PUSH     OFFSET @@Jump + 4FDH
  78.       RETF
  79.       ;FAR Sprung auf sich selbst
  80.       ;damit wird CS initialisiert
  81. @@Jump:
  82.       LEA      SI, StatusMsg + 4FDH
  83.       CALL     _Ausgabe
  84.       MOV      SI, 07BEH ;Partitiontabelle laden
  85.       MOV      BL, 04    ;maximal 4 Partitionen
  86. @@Repeat:
  87.       CMP      BYTE PTR [SI],80H
  88.                          ;aktive Partition ?
  89.       JZ       SHORT @@Gefunden
  90.       CMP      BYTE PTR [SI],0
  91.                          ;oder inaktiv ?
  92.       JNZ      SHORT @@Unbekannt
  93.       ADD      SI, 10H   ;nächste Partition
  94.       DEC      BL
  95.       JNZ      SHORT @@Repeat
  96.       INT      18H      ;ROM-BASIC starten
  97.                         ;ist zwar Quatsch, aber üblich
  98. @@Unbekannt:
  99.       LEA      SI, BadTableError + 4FDH
  100.       CALL     _Ausgabe
  101.       JMP      SHORT @@Endlos
  102. @@Gefunden:
  103.       MOV      DX, [SI]
  104.       MOV      CX, [SI+2] ;Daten laden
  105.       PUSH     CX
  106.       PUSH     DX
  107.       MOV      CX, 0001H ;ersten Sektor, Spur 0
  108.       MOV      DX, 0080H ;Kopf 0, erste Platte
  109.       MOV      BX, 7C00H
  110.       PUSH     BX
  111.       CALL     _ReadSektor
  112.  
  113.       MOV      CX, 100H  ; 128 Words, d.h. ein Sektor
  114.       MOV      DI, 0600H ; hier steht dieses Programm
  115.       MOV      SI, 7C00H ; hier steht der Partitionssektor
  116.  
  117. @@Gleichtest:
  118.       REPZ     CMPSW
  119.       OR       CX, CX
  120.       JNZ      SHORT @@VirusDa
  121.  
  122.       MOV      BX, 13H*4                ; Überprüfen, ob INT 13h 
  123.       CMP      WORD PTR [BX+02], 0C000H ; im ROM liegt
  124.       JC       SHORT @@VirusDa
  125.  
  126.       LEA      SI, NoVirusMsg + 4FDH
  127.       CALL    _Ausgabe
  128.       JMP      SHORT @@AllesOk
  129. @@VirusDa:
  130.       MOV      AX, 1000H     ; pallettenregister ändern
  131.       MOV      BX, 0400H     ; schwarz --> rot
  132.       INT      10H           ; ausführen
  133.       MOV      BX, 0007H     ; weiß --> schwarz
  134.       INT      10H
  135.       LEA      SI, WarningMsg + 4FDH
  136.       CALL     _Ausgabe
  137.       IN       AL, 60H
  138.       MOV      BL, AL
  139. @@Taste:                     ; auf Taste warten
  140.       IN       AL, 60H
  141.       CMP      BL, AL
  142.       JZ       @@Taste
  143. @@AllesOk:
  144.       POP      BX  ; BX=7C00h
  145.       POP      DX  ;Daten vom Stack holen
  146.       POP      CX
  147.       CALL     _ReadSektor
  148.       MOV      DI, 7DFEH
  149.       CMP      WORD PTR [DI],0AA55H
  150.       ;Anwesenheit eines (DOS)-Boots-
  151.       ;trapprogrammes prüfen
  152.       JZ       @@IstOk
  153.       LEA      SI, NoSystemError + 4FDH
  154.       CALL     _Ausgabe
  155. @@Endlos:
  156.       JMP      SHORT @@Endlos
  157. @@IstOk:
  158.       PUSH     0000
  159.       PUSH     7C00H
  160.       RETF
  161.  
  162. NoSystemError DB 'Kein Betriebssystem.',0
  163. LoadError     DB 'Betriebssystemladefehler.',0
  164. BadTableError DB 'Ungültige Partitionstabelle.',0
  165. StatusMsg     DB 'Prüfe Partitionstabelle...',10,13,0
  166. NoVirusMsg    DB 'Alles Ok.',10,13,0
  167. WarningMsg    DB 7,'Warnung! Virus in Partitionssektor.',10,13,7
  168.               DB 'Warte auf X-beliebige Taste !',10,13,0
  169. B1            DB 50H DUP (0)
  170. B2            DB 200H DUP (?)
  171. Msg       DB '┌─────────────────────────────────────────╖',0AH,0DH
  172.           DB '│ Anti-Viren-Loader                       ║',0AH,0DH
  173.           DB '│ (C) 1993 Sven Letzel & te-wi Verlag     ║',0AH,0DH
  174.           DB '╘═════════════════════════════════════════╝',0AH,0DH
  175.           DB 0
  176. StandBy   DB 'Bitte warten. Das System wird in 5 sec. neu gestartet.'
  177.           DB  0AH,0AH,0AH,0DH, 7,0
  178. Info      DB 'Dieses Programm dient zum Schutz der Partitions'
  179.           DB 'tabelle',0AH,0DH
  180.           DB 'vor Virenbefall.',0AH,0DH
  181.           DB 'Drücken Sie eine beliebige Taste, '
  182.           DB 'um fortzusetzen...',0AH,0DH,'<ESC> = Abbruch.'
  183.           DB  0AH,0DH,0AH,0
  184. Abbruch   DB 'Programm nicht installiert.',0AH,0DH,0
  185. Neustart  DB 'Entfernen Sie nun alle Disketten und drücken dann '
  186.           DB  0AH,0DH,'eine beliebige Taste um den Computer neu '
  187.           DB 'zu starten.',0AH,0DH,'(ESC=Abbruch)', 10,10,13,0
  188. Warnung   DB ' W A R N U N G !!!', 07H, 0AH, 0DH
  189.           DB '==================', 0AH, 0DH, 0AH
  190.           DB 'Der Virusschutz wird erst nach einem Neustart des '
  191.           DB 'Computers wirksam.', 0AH, 0DH, 0AH
  192.           DB 'Drücken Sie Ctrl-Alt-Del (Strg-Alt-Entf), um den '
  193.           DB 'Computer neu zu starten oder', 0AH, 0DH
  194.           DB 'arbeiten Sie normal weiter, dann wird der Schutz '
  195.           DB 'beim nächsten Einschalten', 0AH, 0DH
  196.           DB 'wirksam.', 0AH, 0DH, 0
  197.  
  198. @@UserBreak:
  199.       LEA      SI, Abbruch    ; ' nicht installiert...'
  200.       CALL     _Ausgabe
  201.       MOV      AL, 01         ; ExitCode 1
  202.       MOV      AH, 4CH        ; Programm beenden
  203.       INT      21H
  204.  
  205. @@Noreset:          ; falls kein Warmstart ausgeführt werden soll
  206.       LEA      SI, Warnung
  207.       CALL     _Ausgabe
  208.       MOV      AL, 02         ; Exitcode 2
  209.       MOV      AH, 4CH        ; Beenden
  210.       INT      21H
  211.  
  212. @@Install:
  213.       LEA      SI, Info        ; Infomeldung
  214.       CALL     _Ausgabe
  215.       XOR      AX, AX
  216.       INT      16H             ;auf Taste warten
  217.       XOR      AL, 1BH         ;ist <ESC> ?
  218.       JZ       @@UserBreak
  219.       MOV      CX, 1           ; Spur 0, Sektor 1
  220.       MOV      DX, 80H         ; Kopf 0, erste Platte
  221.       PUSH     CS
  222.       POP      ES
  223.       LEA      BX, B2
  224.       CALL     _ReadSektor     ;Festplatten-Partitionssektor lesen
  225.       LEA      DI, @@Bootstrap+1BEH
  226.                ;1BEh ist Offsetadresse der Partitionstabelle
  227.       LEA      SI, B2+1BEH
  228.       MOV      CX, 22H
  229.       CLD
  230.       REPNZ    MOVSW            ;diese hinter Bootstrapprogramm kopieren
  231.       MOV      DI, 4
  232. @@18:
  233.       DEC      DI
  234.       JZ       @@Exit
  235.       LEA      BX, @@Bootstrap
  236.       MOV      AX, 0301H
  237.       MOV      CX, 1
  238.       MOV      DX, 80H
  239.       INT      13H              ; Bootstrapprogramm auf Festplatte schreiben
  240.       JNC      SHORT @@Exit
  241.       XOR      AX, AX
  242.       INT      13H              ; bei Fehler System zurücksetzen
  243.       JMP      SHORT @@18
  244. @@Exit:
  245.       LEA      SI, Msg          ; Statusmeldung ausgeben
  246.       CALL     _Ausgabe
  247.       LEA      SI, Neustart     ; 'Disketten raus...'
  248.       CALL     _Ausgabe
  249.       XOR      AX, AX
  250.       INT      16H              ; auf Taste warten
  251.       XOR      AL, 1BH          ; ist <ESC> ?
  252.       JZ       @@Noreset        ; kein Warmstart
  253.       LEA      SI, StandBy
  254.       CALL     _Ausgabe
  255.  
  256.       XOR      BX, BX
  257.       MOV      ES, BX
  258.       MOV      BX, 46CH
  259.       MOV      AX, WORD PTR ES:[BX]
  260.       ADD      AX, 50H          ;Das entspricht etwa 5 Sekunden Pause
  261. @@Warte:
  262.       CMP      AX, WORD PTR ES:[BX]
  263.       JNC      @@Warte
  264.       MOV      BX, 0472H
  265.       MOV      DX, 1234H
  266.       MOV      ES:[BX], DX      ;für Warmstart sorgen
  267.  
  268.       PUSH     0FFFFH
  269.       PUSH     0
  270.       RETF                      ;Booten
  271.  
  272. CODE  ENDS
  273.  
  274. END DiskPro
  275.  
  276.