heh!3:(keyemu.asm):17/05/2000 << Back To heh!3


; ;KEYEMU.ASM - (c) 1998 - Maruja ; ;Programa residente que emula a la perfeccion a la llave de hardware ;marca 'SOStuare Look' que protege a un programa berreta de facturacion ; .model tiny .code org 100h inicio: jmp Arranque ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; IN_BYTE EQU 0ECh ;IN AL, DX IPanterior dw 0 ;CS:IP Instruccion anterior CSanterior dw 0 lpt11 dw ? ;Direccion base (1er registro) de LPT1 lpt13 dw ? ;Direccion 3er registro de LPT1 IRET_CODE EQU 0CFh ;Opcode de 'IRET' OFF_PROTEGIDO EQU 0892h ;Offset del programa protegido en el ;que se anula el llamado a la rutina ;de la llave KEYBUF EQU 444 keyindex dw 0 keydata db 000, 085, 170, 000, 204, 150, 150, 150, 150, 150 db 150, 150, 150, 150, 150, 150, 150, 150, 150, 150 db 150, 150, 150, 150, 150, 150, 150, 150, 150, 150 db 150, 150, 150, 150, 150, 150, 150, 150, 150, 150 db 150, 150, 150, 150, 150, 150, 150, 150, 150, 150 db 150, 150, 150, 150, 150, 150, 150, 150, 150, 150 db 150, 150, 150, 150, 150, 150, 150, 150, 150, 150 db 150, 150, 150, 150, 150, 150, 150, 150, 150, 150 db 150, 150, 150, 150, 150, 150, 150, 150, 150, 150 db 150, 150, 150, 150, 150, 150, 150, 150, 150, 150 db 150, 150, 150, 150, 150, 150, 150, 150, 150, 150 db 150, 150, 150, 150, 150, 150, 150, 150, 150, 150 db 150, 150, 150, 150, 150, 150, 150, 150, 150, 150 db 150, 150, 150, 150, 150, 150, 150, 150, 150, 150 db 150, 150, 150, 150, 150, 150, 150, 150, 150, 150 db 150, 150, 150, 150, 150, 150, 150, 150, 150, 150 db 150, 150, 150, 150, 150, 150, 150, 150, 150, 150 db 150, 150, 150, 150, 150, 150, 150, 150, 150, 150 db 150, 150, 150, 150, 150, 150, 150, 150, 150, 150 db 150, 150, 150, 150, 150, 150, 150, 150, 150, 150 db 150, 150, 150, 150, 150, 150, 150, 150, 150, 150 db 150, 150, 150, 150, 150, 150, 150, 150, 150, 150 db 150, 150, 150, 150, 150, 150, 150, 150, 150, 150 db 150, 150, 150, 150, 150, 150, 150, 150, 150, 150 db 150, 150, 150, 150, 150, 150, 150, 150, 150, 150 db 150, 150, 150, 150, 150, 150, 150, 150, 150, 150 db 150, 150, 000, 000, 204, 150, 150, 150, 150, 150 db 150, 150, 150, 150, 150, 150, 150, 150, 150, 150 db 150, 150, 150, 150, 134, 134, 150, 134, 134, 150 db 134, 150, 134, 134, 134, 150, 150, 134, 134, 150 db 150, 150, 150, 150, 150, 150, 150, 150, 150, 134 db 134, 134, 150, 150, 150, 150, 150, 150, 150, 150 db 150, 150, 150, 150, 150, 150, 150, 150, 150, 150 db 150, 150, 150, 150, 150, 150, 150, 150, 150, 150 db 150, 150, 150, 150, 134, 134, 134, 134, 134, 134 db 134, 134, 150, 150, 150, 134, 150, 134, 134, 150 db 150, 150, 150, 134, 134, 150, 134, 134, 150, 134 db 150, 134, 134, 134, 150, 150, 133, 204, 150, 150 db 150, 150, 150, 150, 150, 150, 150, 150, 150, 150 db 150, 150, 150, 150, 150, 150, 150, 150, 150, 150 db 150, 150, 150, 150, 150, 150, 150, 150, 150, 150 db 149, 204, 150, 150, 150, 150, 150, 150, 150, 150 db 150, 150, 150, 150, 150, 150, 150, 150, 150, 150 db 150, 150, 150, 150, 150, 150, 150, 150, 150, 150 db 150, 150, 150, 150 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; SetTrap: push ax push bp mov bp, sp mov ax, [bp+8] ;Obtener flags de la pila or ah, 1 ;Activar bit T mov [bp+8], ax ;Colocar nuevos flags en la pila push dx push ds push cs pop ds mov ax, 2501h ;Setear nuestro vector de int TRAP lea dx, Trap int 21h pop ds pop dx pop bp pop ax ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; INSTRUCCION ORIGINAL EN EL ARCHIVO DE PROTECCION ; QUE FUE CAMBIADA POR EL 'INT 90h' (CD 90) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ADD DI, AX ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; iret ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Trap: SP_INICIAL EQU $ push cx ;Salvar registros utilizados push si push ds push bp SP_FINAL EQU $ cmp cs:CSanterior, 0 ;CSanterior tiene un valor incorrecto ? jz Trap_salir ;Si: salir mov si, cs:CSanterior mov ds, si mov si, cs:IPanterior ;DS:SI = CS:IP instruccion anterior mov cl, byte ptr [si] ;Obtener opcode cmp cl, IN_BYTE ;El opcode es IN_BYTE ? jne Trap_salir ;No: salir push cs pop ds cmp dx, lpt11 ;Acceso a alguno de los puertos LPT1 ? jb Trap_salir cmp dx, lpt13 ja Trap_salir ;No: salir call EmularKey ;Si: emular llave Trap_salir: mov bp, sp ;Guardar CS:IP de proxima instruccion mov si, [bp + (SP_FINAL-SP_INICIAL)*2 + 2 ] mov cs:CSanterior, si mov si, [bp + (SP_FINAL-SP_INICIAL)*2 ] mov cs:IPanterior, si pop bp ;Recuperar registros y salir pop ds pop si pop cx iret ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; EmularKey: ;En AL pone el mismo dato que pondria la llave lea si, keydata ;Posicionarse en el buffer add si, keyindex mov al, byte ptr [si] ;Obtener dato de la llave ;) inc keyindex cmp keyindex, KEYBUF ;Ya llego al ultimo dato ? jne EK_salir mov keyindex, 0 ;Si: resetear posicion en el buffer EK_salir: ret ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; SetJMP: push si push ds push bx push ax mov ah, 51h ;Obtener direccion del PSP int 21h mov ds, bx mov si, 0Ch ;El offset 0Ch del PSP contiene el ;segmento del codigo al que se debe ;volver cuando termine el programa de ;proteccion mov bx, word ptr [si] ;Cancelar llamada a la rutina de mov ds, bx ;lectura de la llave mov si, OFF_PROTEGIDO mov byte ptr [si], IRET_CODE pop ax pop bx pop ds pop si ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; INSTRUCCION ORIGINAL EN EL ARCHIVO DE PROTECCION ; QUE FUE CAMBIADA POR EL 'INT 92h' ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; MOV AH, 4Ch ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; iret ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; FINRESID EQU $ ;Aca termina el residente ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; SetearVectores: mov ax, 2590h ;Hacer que una INT 90h ejecute el lea dx, SetTrap ;codigo 'SetTrap' int 21h mov ax, 2592h ;Hacer que una INT 92h ejecute el lea dx, SetJMP ;codigo 'SetJMP' int 21h ret ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; GetLPT1: push es ;Obtener registros de LPT1 mov di, 40h mov es, di mov di, 8 ;ES:DI = 0040:0008h mov ax, word ptr es:[di] mov lpt11, ax ;lpt11 = Registro 1 LPT1 add ax, 2 mov lpt13, ax ;lpt13 = Registro 3 LPT1 pop es ret ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; mok db 13, 10, 'OK', 13, 10, '$' myaestoy db 13, 10, 'Ya estaba residente', 13, 10, '$' ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Arranque: push ds ;El offset del vector de xor si, si ;interrupcion 90h es igual mov ds, si ;al offset de la SetTrap ? mov si, 240h mov ax, word ptr [si] pop ds cmp ax, offset SetTrap jne A_instalar ;No: instalar residente lea dx, myaestoy ;Como el residente ya estaba mov ah, 9 ;instalado mostrar mensaje int 21h ;y salir mov ax, 4C00h int 21h A_instalar: call GetLPT1 ;Obtener direcciones de LPT1 call SetearVectores ;Setear nuevos vectores de ints lea dx, mok ;Mostrar mensaje 'OK' mov ah, 9 int 21h mov ax, 3100h ;Terminar y quedar residente lea dx, FINRESID shr dx, 4 inc dx int 21h end inicio ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;