-
-
Save einstein95/b231bc2a78236b7579165d035acf714c to your computer and use it in GitHub Desktop.
Disassembly of hardware dongle code; compilable in MASM
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .model tiny | |
| .code | |
| start: | |
| push ds ; save DS register | |
| xor cx,cx ; clear CX | |
| mov ds,cx ; set DS to 0 to access BIOS data area | |
| ; Detect parallel port address from BIOS data area (0x0408) | |
| mov bx,408h | |
| mov cl,4 ; check up to 4 parallel port addresses | |
| @@: | |
| mov dx,[bx] ; load parallel port address | |
| or dx,dx | |
| jne parallel_port_found ; if address found, proceed | |
| inc bx | |
| inc bx | |
| loop @B | |
| ; No parallel port found, exit | |
| pop ds | |
| retf | |
| parallel_port_found: | |
| pop ds | |
| cli ; disable interrupts | |
| ; Save current data and status register values | |
| in al,dx ; read data register | |
| mov ah,al | |
| inc dx | |
| in al,dx ; read status register | |
| push ax | |
| dec dx | |
| ; Initialize communication sequence | |
| mov al,82h | |
| call write_and_wait | |
| mov cx,40000 | |
| call wait_loop | |
| mov al,80h | |
| call write_and_wait | |
| mov al,82h | |
| call write_and_wait | |
| mov cx,3880h | |
| call wait_loop | |
| ; Main data collection loop | |
| xor bx,bx ; BX = 0 (will store results) | |
| mov cx,78h ; loop counter = 0x78 | |
| @@: | |
| mov al,0A2h | |
| call write_and_wait | |
| inc dx | |
| in al,dx ; read status register | |
| and al,40h ; test bit 6 | |
| jne check_counter_zero | |
| or bl,bl ; if BL is zero | |
| jne store_current_counter | |
| mov bl,cl ; store current counter in BL | |
| jmp store_current_counter | |
| check_counter_zero: | |
| cmp cl,76h ; if counter equals 0x76 | |
| jne store_current_counter | |
| mov bh,cl ; store 0x76 in BH | |
| store_current_counter: | |
| mov al,82h | |
| dec dx | |
| call write_and_wait | |
| loop @B | |
| ; Cleanup and restore | |
| mov al,0 | |
| call write_and_wait | |
| pop ax | |
| xchg ah,al | |
| out dx,al ; restore data register | |
| inc dx | |
| mov al,ah | |
| out dx,al ; restore status register | |
| sti ; enable interrupts | |
| retf | |
| write_and_wait: | |
| ; Output value to port and wait | |
| ; DX = port address, AL = value to output | |
| out dx,al | |
| push cx | |
| mov cx,40000 | |
| call wait_loop | |
| pop cx | |
| ret | |
| wait_loop: | |
| ; Delay loop: decrement CX until zero | |
| push cx | |
| mov cx,40000 | |
| pop cx | |
| or cx,cx | |
| je @F | |
| jne @F | |
| @@: | |
| loop wait_loop | |
| ret | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment