; Created  : 31.05.2001 17:45
; Rewritten: 23.10.2005 08:36
; Also	   : 17.02.2007 20:53
;
; Sentinel Pro complete emulation routines. All rights lefted, all lefts =
righted
; (x)1998-2007 by MeteO (meteo@null.net)
; Ultimate dongle removal services http://www.dongle.ru
;
;--------------------------------------------------
; SENTINELPRO FAMILY CODES   =20
;--------------------------------------------------
AB_FAMILY       equ	0C0h            ; 1100 0000
AC_FAMILY       equ	0A0h            ; 1010 0000
AD_FAMILY       equ	090h            ; 1001 0000
AE_FAMILY       equ	088h            ; 1000 1000
AF_FAMILY       equ	084h            ; 1000 0100
AG_FAMILY       equ	082h            ; 1000 0010
AH_FAMILY       equ	081h            ; 1000 0001
;                                                   =20
BC_FAMILY       equ	060h            ; 0110 0000
BD_FAMILY       equ	050h            ; 0101 0000
BE_FAMILY       equ	048h            ; 0100 1000
BF_FAMILY       equ	044h            ; 0100 0100
BG_FAMILY       equ	042h            ; 0100 0010
BH_FAMILY       equ	041h            ; 0100 0001
;                                                   =20
CD_FAMILY       equ	030h            ; 0011 0000
CE_FAMILY       equ	028h            ; 0010 1000
CF_FAMILY       equ	024h            ; 0010 0100
CG_FAMILY       equ	022h            ; 0010 0010
CH_FAMILY       equ	021h            ; 0010 0001
;                                                   =20
DE_FAMILY       equ	018h            ; 0001 1000
DF_FAMILY       equ	014h            ; 0001 0100
DG_FAMILY       equ	012h            ; 0001 0010
DH_FAMILY       equ	011h            ; 0001 0001
;                                                   =20
EF_FAMILY       equ	00ch            ; 0000 1100
EG_FAMILY       equ	00ah            ; 0000 1010
EH_FAMILY       equ	009h            ; 0000 1001
;                                                   =20
FG_FAMILY       equ	006h            ; 0000 0110
FH_FAMILY       equ	005h            ; 0000 0101
;                                                   =20
GH_FAMILY       equ	003h            ; 0000 0011
; =
-------------------------------------------------------------------------=
--
;
DATASEG
;
bTypeOfDongle		db	GH_FAMILY	; What kind of dongle we'll emulate
;
_n4			db	0
;
_pro_dongle		db	GH_FAMILY, BC_FAMILY, BH_FAMILY
			db	-1		; <EOF>
;
_pro_bits		dd	offset _pro_GH_bits, offset _pro_BC_bits, offset =
_pro_BH_bits
;
_pro_GH_bits		db	7,4,6,0,2,1,5,3
_pro_BC_bits		db	5,2,7,0,1,4,3,6
_pro_BH_bits		db	1,6,3,4,0,5,7,2
;
pBits			dd	0
;
CODESEG
;
; =
-------------------------------------------------------------------------=
--
;
pro_Query proc
			mov	bl, bTypeOfDongle	; Got type of Dongle (e.g BC/BH/GH)
			cld
			mov	eax, [_pro_bits]
			mov	pBits, eax
			leax	esi, _pro_dongle
			mov	dx, -1

	@@scandongle:
			lodsb
			cmp	al, bl
			je	@@got_dongle
			add	[pBits], 8
			cmp	al, dl			; got <end>?
			jne	@@scandongle
			jmp	@@failed
	@@got_dongle:
			mov	cx, proQueryLen
			and	ecx, 1FFh
			lea	esi, proResponse	; proResponse
			call	_pro_query

		@@failed:
		@@done:
		ret
pro_Query endp

; =
-------------------------------------------------------------------------=
--
; Input: ESI - query string
;        ECX - length of query string
; Out  : DX  - proQuery value
_pro_query proc
			mov	_n4, 0
			cld
			mov	dx, 0FFFFh
			inc	ecx
			push	ecx
			mov	ecx, 1
			mov	di, 1
			jmp	__1
			pop	ecx

		__0:						=09
			push	ecx
			mov	ecx, 4
			xchg	ax, di
			mov	ah, al
			lodsb
			rol	al, cl
			ror	ax, cl
			ror	ax, cl
			xchg	ax, di
		__1:						=09
			mov	al, _n4
			not	al
			and	al, 20h
			test	di, 1
			jnz	__2
			neg	al
			rcl	dx, 1
		__2:						=09
			rol	di, 1
			jnb	__3
			call	pro_rol_bits
			jmp	__4
		__3:						=09
			call	pro_xor_bits
		__4:						=09
			loop	__1
			pop	ecx
			loop	__0
			mov	al, _n4
			not	al
			and	al, 20h
			test	di, 1
			jnz	__done
			neg	al
			rcl	dx, 1
		__done:					=09
			ret
_pro_query endp
;
pro_rol_bits proc
			pusha
			mov	ecx, 8
			mov	dl, _n4
			mov	dh, 0
			mov	esi, pBits	; ptr to dongle internal data
		__loop:						=20
			push	ecx
			rol	dl, 1
			jnb	__next
			mov	cl, [esi]
			mov	al, 1
			rol	al, cl
			or	dh, al
		__next:						=20
			inc	esi
			pop	ecx
			loop	__loop
			mov	_n4, dh
			popa
			ret
pro_rol_bits endp
;
pro_xor_bits proc
			pusha
			mov	al, _n4
			mov	ah, 10h
			xor	ah, al
			rol	al, 1
			and	ah, 10h
			xor	al, ah
			mov	_n4, al
			popa
			ret
pro_xor_bits endp
;