还原DOS时代的乒乓病毒(DOS源码)

本文介绍了1988年首次发现的乒乓病毒及其汇编代码实现。该病毒仅在软盘上发现,且无害,可通过重启清除。文中详细展示了病毒的工作原理及汇编指令。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这是一个DOS程序只支持在WINDOSXP系统和DOS系统下运行

Ping-Pong virus介绍

1988年3月1日,在都灵大学首次发现了乒乓病毒。原始版本的乒乓球病毒发现只在软盘上有,现在大概已经灭绝了。当然,后期也衍生出了一些变种,乒乓病毒用现在的话来讲就是“绿色无公害”,类似于原始的乒乓球游戏,用户倘若不小心将其激活,通过重启的方式就可以进行处理。
运行效果

汇编代码如下(由于注释比较详细,文章中就不再做过多解释)

code segment
  org 100h;com文件需要在开头预留100h字节的空间
  assume cs:code , ds:code
main:
 jmp start;要跳开数据部分,不能执行
 welcome db '+---------------------------------------------------+' ,0ah ,0dh
  db '+     PingPongVirus                                 +' ,0ah ,0dh
  db '+                       ---write by caicaiwoshishui +' ,0ah ,0dh
  db '+---------------------------------------------------+' ,0ah ,0dh ,'$'
 old_int dd ?;保存被截获的中断
 PingPongDirectionUpDown dw ?;乒乓球方向上下	
 PingPongDirectionLeftRight dw ?;乒乓球方向左右
 PingPongPointCol dw ?;乒乓球位置X
 PingPongPointRow dw ?;乒乓球位置Y
 backScreenChar dw ?;备份乒乓球显示位置上的数据
 
 timer dw ?
 ;;乒乓球 95h     25*80
TSR proc far
	
 ;保护现场
 push ax
 push bx
 push cx
 push dx
 push si
 push di
 push bp
 push sp
 push es
 push ds
 sti
 call disp
 cli
 ;返回现场
 pop ds
 pop es
 pop sp
 pop bp
 pop di
 pop si
 pop dx
 pop cx
 pop bx
 pop ax
 jmp cs:old_int
TSR endp
disp proc near
 push ax
 push cx
 push dx
 push es
 push bx
 ;控制球的移动速度//每55mm*3移动一次
 inc timer
 mov ax,3
 cmp ax,timer
 jne timeJump
 mov ax,0
 mov timer,ax
 ;进行初始化
 mov ax,0b800h
 mov es,ax
 ;还原乒乓球覆盖的数据
 mov ax,160
 mov bx,PingPongPointRow
 mul bx
 mov bx,ax
 mov ax,PingPongPointCol
 mov cx,2
 mul cx
 add bx,ax
 mov ax,backScreenChar 
 mov es:[bx],ax
 
 ;计算行
 mov ax,0
 cmp ax,PingPongDirectionUpDown
 je eque;
 cmp PingPongPointRow,ax
 je decc
 dec PingPongPointRow
 jmp func
decc:
 inc PingPongPointRow
 mov PingPongDirectionUpDown,ax
 jmp func
eque:;正向
 mov ax,24
 cmp PingPongPointRow,ax
 je addc
 inc PingPongPointRow
 jmp func
addc:
 dec PingPongPointRow
 mov ax,1
 mov PingPongDirectionUpDown,ax
 
 ;计算列
func:
 mov ax,0
 cmp ax,PingPongDirectionLeftRight
 je eque1;
 cmp PingPongPointCol,ax
 je decc1
 dec PingPongPointCol
 jmp funcD
decc1:
 inc PingPongPointCol
 mov PingPongDirectionLeftRight,ax
 jmp funcD
eque1:;正向
 mov ax,79
 cmp PingPongPointCol,ax
 je addc1
 inc PingPongPointCol
 jmp funcD
addc1:
 dec PingPongPointCol
 mov ax,1
 mov PingPongDirectionLeftRight,ax

;计算球体位置
funcD:
 mov ax,160
 mov bx,PingPongPointRow
 mul bx
 mov bx,ax
 mov ax,PingPongPointCol
 mov cx,2
 mul cx
 add bx,ax
 mov ax,es:[bx]
 ;备份球体位置的数据
 mov backScreenChar,ax
 
 ;显示一个黑底白字的乒乓球
 mov ax,074fh
 mov es:[bx],ax
 ;mov es:[bx],al
 ;mov es:[bx],ah
 
 timeJump: pop bx
 pop es
 pop dx
 pop cx
 pop ax
 ret

disp endp
start: 
 mov dx ,offset welcome
 mov ah ,09h;
 int 21h;显示欢迎语  DS:DX=字符串   '$'结束字符串
 
 ;初始化乒乓球位置属性
 mov ax,0
 mov PingPongDirectionUpDown,ax;初始化乒乓球方向上下	
 mov PingPongDirectionLeftRight,ax;初始化乒乓球方向左右
 mov PingPongPointCol,ax;初始化乒乓球行位置
 mov PingPongPointRow,ax;初始化乒乓球列位置
 mov timer,ax;初始化时间计次--控制球的运行速度
 
 ;备份第一行第一列数据,因为乒乓球显示之前会先还原上个乒乓球覆盖的数据
 mov ax,0b800h
 mov es,ax
 mov ax,es:0;
 mov backScreenChar,ax;
 
 ;可以启用下面的代码在屏幕第一行第一列初始一个乒乓球
 ;显示一个黑底白字的乒乓球
 ;mov ax,074fh
 ;mov es:[bx],ax
 
 ;如果想要调试可以使用下面代码跟踪进乒乓球运算程序
 ;mov cx,500
 ;jm:call disp
 ;loop jm
 
 mov ax ,351Ch
 int 21h;读取中断向量  返回值ES:BX=中断向量

 mov word ptr old_int , bx
 mov word ptr old_int[2] , es
 
 mov dx , offset TSR
 push cs
 pop ds

 mov ax ,251Ch
 int 21h;设置中断向量  DS:DX=中断向量

 mov dx , offset start
 int 27h;驻留程序
 
code ends
  end main

环境要求

系统:WindowsXp 32位

编译约定

源码文件名: t.asm。后面用到的t.asm都代表源码文件。

编译命令

masm命令:masm t.asm(此时会生成t.obj文件)
link命令;link t.obj (此时会生成t.exe文件)
exe2bin命令:exe2bin t.exe t.com (此时会生成t.com文件)

源码和编译器下载-提取码 4rqj

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值