p align="left">00C0 4C 54 53 4C 4F 41 44 20-43 4F 4D 20 00 00 00 00 LTSLOAD.COM..... 00D0 00 00 00 00 00 00 E0 0A-E1 06 A7 01 A0 27 00 00 ......'.a....... 00E0 4D 43 49 2D 53 46 20 20-58 54 4B 20 00 00 00 00 MCI-SE...XTK.... 00F0 00 00 00 00 00 00 46 19-32 0D B1 01 79 04 00 00 .......F.2.1.y.. 0100 58 54 41 4C 4B 20 20 20-48 4C 50 20 00 00 00 00 XTALK...HLP..... 0110 00 00 00 00 00 00 C5 6D-73 07 A3 02 AF 88 00 00 ......Ems.#..... 0120 54 58 20 20 20 20 20 20-43 4F 4D 20 00 00 00 00 TX COM.... 0130 00 00 00 00 00 00 05 61-65 0C 39 01 E8 20 00 00 ................. 0140 43 4F 4D 4D 41 4E 44 20-43 4F 4D 20 00 00 00 00 COMMAND COM ..... 0150 00 00 00 00 00 00 41 49-52 0A 27 00 55 3F 00 00 ......AIR.'.UP... 0160 E5 32 33 20 20 20 20 20-45 58 45 20 00 00 00 00 e23 EXE..... 0170 00 00 00 00 00 00 9C B2-85 0B 42 01 80 5F 01 00 ........2..B..... 0180 47 44 20 20 20 20 20 20-44 52 56 20 00 00 00 00 GD.......DRV..... 0190 00 00 00 00 00 00 E0 0A-E1 06 9A 01 5B 08 00 00 .......'a...'.... 01A0 4B 42 20 20 20 20 20 20-44 52 56 20 00 00 00 00 KB.......DRV..... 01B0 00 00 00 00 00 00 E0 0A-E1 06 9D 01 60 01 00 00 .......'a...'.... 01C0 50 52 20 20 20 20 20 20-44 52 56 20 00 00 00 00 PR.......DRV..... 01D0 00 00 00 00 00 00 E0 0A-E1 06 9E 01 49 01 00 00 .......'a..'..... 01E0 00 F6 F6 F6 F6 F6 F6 F6-F6 F6 F6 F6 F6 F6 F6 F6 ................. 01F0 F6 F6 F6 F6 F6 F6 F6 F6-F6 F6 F6 F6 F6 F6 F6 F6 ................. Шестнадцатеричный дамп сектора каталогу обсягом 512 байт Область файлу Область файлу містить підкаталоги, даних файлу й нерозподілені кластери. Область розділяється на кластери фіксованого розміру й використання кожного кластера регламентується відповідним входом FAT. Практична частина Лістинг модулів програми Модуль, який блокує запуск COM та EXE файлів #include <fcntl.h> #include <io.h> #include <dos.h> #include <stdio.h> #include <string.h> #include <process.h> unsigned char buffer[3]; FILE *fd; int handle; fail(char *); void pass(char *); main(int argc,char *argv[]) { int n; if(argc!=3) { printf("\nFailpass Utility v1.0 Email: chingpongin@yahoo.co.in"); printf("\nEnable/Disable .EXE or .COM execution"); printf("\nsyntex failpass fail <filename.extension>"); printf("\n or"); printf("\n failpass pass <filename.extension>"); exit(2); } strupr(argv[1]); n=strcmp(argv[1],"FAIL"); if(n==0) { fail(argv[2]); exit(2); } n=strcmp(argv[1],"PASS"); if(n==0) { pass(argv[2]); exit(2); } return 0; } fail(char *fname) { _chmod(fname,1,FA_ARCH); fd=fopen(fname,"rb+"); if(fd==NULL) { printf("\nCann't open %s\n\n",fname); exit(2); } fseek(fd,0,SEEK_SET); fread(buffer,2,1,fd); if(buffer[0]==0xcd) if(buffer[1]==0x20) { fclose(fd); printf("\n%s already protected...\n\n",fname); exit(2); } fseek(fd,0,SEEK_END); fwrite(buffer,2,1,fd); fseek(fd,0,SEEK_SET); buffer[0]=0xcd; /* don't take any PANGA with this line */ buffer[1]=0x20; /* don't take any PANGA with this line */ fwrite(buffer,2,1,fd); fclose(fd); return 0; } void pass(char *fname) { int xyz; fd=fopen(fname,"rb+"); if(fd==NULL) { fclose(fd); printf("\nCannot open file %s\n\n",fname); exit(2); } fseek(fd,0,SEEK_SET); fread(buffer,2,1,fd); if(buffer[0]!=0xcd) if(buffer[1]!=0x20) { fclose(fd); printf("\n%s is NOT protected....\n\n",fname); exit(2); } fseek(fd,-2,SEEK_END); fread(buffer,2,1,fd); fseek(fd,0,SEEK_SET); fwrite(buffer,2,1,fd); fclose(fd); handle=open(fname,O_RDWR); chsize(handle,(filelength(handle))-2); close(handle); } Модуль, який пише та читає інформацію напряму в ділянку диску без звертання до FAT системи include common.mac text segment use16 assume CS:text, DS:text org 256 myproc proc mov AH,09h ;printing function printf g ;print g printf g1 ;print g1 ;parse the command line... getf guff ;guff will have the command line ;is the command line empty? cmp guff[0], 0 je expl ;is the command line starting with ? cmp guff[0], '?' je expl ;we are reading the disk cmp guff[0], '^' je readdisk ;nothing else but to write... jmp writedisk writedisk: printf g2 waitenter mov AH, 09h ;writing out printf g3 ;what are we doing printf guff ;file name call disk_write ;write to disk jmp rc readdisk: printf g2 waitenter call disk_read ;write from disk jmp rc expl: printf gline jmp rc rc: ;return mov AX, 4C00h int 21h myproc endp ;==================================================================== ;==================================================================== ;==================== Procedure: disk_read ======================= ;==================================================================== ;==================================================================== disk_read proc mov AH, 02h ;read raw input mov AL, 1 ;number of sectors mov CH, 0 ;cylinder mov CL, 1 ;sector mov DH, 1 ;head mov DL, 0 ;disk drive - floppy lea BX, guff int 13h ;call BIOS jnae ocr ;now guff stores file name mov AH, 02h mov AL, 1 mov CH, 1 mov CL, 1 mov DH, 0 mov DL, 0 lea BX, file int 13h ;call BIOS jnae ocr ;decrypt data call chiper ;write output to the file saved mov AH, 3Ch ;create file mov CX, 0 ;no attributes lea DX, guff ;name int 21h ;call DOS mov handle, AX ;get file handle mov AH, 40h ;write to file mov BX, handle ;handle ;get len mov CX, 0 ;dump CX and SI mov SI, 0 clen: cmp file[SI], 0 ;is it zero yet? je clenf ;this is the len inc SI ;increase counting inc CX ;increase counting jmp clen ;jump back clenf: lea DX, file ;file data int 21h ;call DOS mov AH, 3Eh ;close file mov BX, handle ;handle int 21h ;call DOS ;open file for writing.... mov AH, 09h printf success jmp finr ocr: mov AH, 09h printf error finr: ret disk_read endp ;==================================================================== ;==================================================================== ;==================================================================== ;==================================================================== ;==================== Procedure: disk_write ====================== ;==================================================================== ;==================================================================== disk_write proc ;write file name mov AH, 03h ;write raw output mov AL, 1 ;write 1 sector mov CH, 0 ;cylinder zero mov CL, 1 ;sector no 1 mov DH, 1 ;head 1 mov DL, 0 ;disk drive A: lea BX, guff ;set buffer int 13h ;call BIOS ;read file... mov AH, 3Dh ;open file mov AL, 2 ;read-write lea DX, guff ;file name int 21h ;call DOS mov handle, AX ;get handle mov AH, 3Fh ;reading file mov BX, handle ;set handle mov CX, 1024 ;reading lea DX, file ;buffer int 21h ;call DOS ;encrypt data call chiper ;looping through each mov AH, 03h mov AL, 1 mov CH, 1 mov CL, 1 mov DH, 0 mov DL, 0 lea BX, file int 13h ;show message jnb okw occ: mov AH, 09h printf error jmp fin okw: mov AH, 09h printf success fin: ret ;return backwards disk_write endp ;==================================================================== ;==================================================================== ;==================================================================== ;==================================================================== ;==================== Procedure: chiper ========================== ;==================================================================== ;==================================================================== chiper proc mov SI, 0 ;xor values chipe: cmp file[SI], 0 je chipf ;jump if zero... xor file[SI], 3 inc SI ;increase counter jmp chipe chipf: ret ;return chiper endp ;==================================================================== ;==================================================================== g db 'Welcome to Disk Encryptor 1.1...', 10, 13, 'This program allows you to save encrypted data onto the disk....', 10, 13, 'Features: Data Chipering, Maximum of 1024 bytes of raw data', 10, 13,'Software Written in Assembler', 10, 13, '$' gline db 10, 13, '? - help', 10, 13, '^ - reads a file from the floppy', 10, 13, '[Filename] - Saves the file onto a floppy', 10, 13, '$' g1 db 'Copyright (C) Daniel Moisyeyev 2002. All Rights Reserved.', 10, 13, 10, 13, '$' g2 db 10, 13, 'Please insert a floppy and press any key...', 10, 13, '$' g3 db 10, 13, 'About to write $' error db 10, 13, 'Error occured$' success db 10, 13, 'Operation Completed$' num db 4 dup(0), '$' guff db 15 dup(0) ;file storage handle dw 0 file db 1024 dup(0) text ends end myproc Робота з програмою Розроблена програма являє собою дві утіліти командного рядку. Перша дозволяє блокувати запуск виконавчіх файлів COM та EXE: failpass fail <filename.extension> failpass pass <filename.extension> друга - тестує роботу з ділянкою диску в обхід FAT системи Please insert a floppy and press any key... About to write Operation Completed Висновки Наприкінці роботи відмітимо лише, що доступ до блокових пристроїв здійснюється по секторах. Ядро MS-DOS за допомогою драйвера пристрою розглядає блоковий пристрій як логічний кінцевий масив секторів і припускає, що цей масив містить припустиму в MS-DOS файлову організацію. Драйвер пристрою, у свою чергу, перетворить запит MS-DOS на логічний сектор у фізичну адресу блокового пристрою. Первісна файлова система MS DOS записана за допомогою програми MS-DOS FORMAT (див. теоретичну частину роботи). Література 1. Нейбауэр А. Моя первая программа на С/С++. П., 1995. 368 С. 2. Бруно Бабэ. Просто и ясно о Borland C++. М., 1996. 400 С. 3. ObjectWindows для C++. К., 1993., 208 С. 4. Н. Барканати. Программирование игр для Windows на Borland C++. М., 1994.
Страницы: 1, 2, 3
|