原文:http://www.pediy.com/kssd/index.html -- 病毒技术 -- 病毒知识 -- Anti Virus专题
如何编写病毒代码?
首先我把最重要的两个方面列举出来。
1. 处理病毒各个绝对地址的重定位。
2. 所有需调用的api函数地址,均通过动态搜索来获得。
做到以上2点,我们的病毒代码就可以移植到任意的程序中。没错,就和我们写shellcode一样。
先来看一些代码的优化方法:
(1)测试寄存器是否为0
cmp eax,00000000h ; 6 bytes
jz bribriblibli ; 2 bytes (if jz is short)
optimization:
or eax,eax ; 2 bytes
jz bribriblibli ; 2 bytes (if jz is short)
xchg eax,ecx ; 1 byte
jecxz bribriblibli ; 2 bytes (if it is short)
(2)测试寄存器是否为-1
cmp eax,0FFFFFFFFh ; 6 bytes
jz insumision ; 2 bytes (if short)
optimization:
inc eax ; 1 byte
xchg eax,ecx ; 1 byte
jecxz insumision ; 2 bytes (if short)
dec ecx ; 1 byte
inc eax ; 1 byte
jz insumision ; 2 bytes
dec eax ; 1 byte
(3)寄存器清0并传送低位字数值
xor eax,eax ; 2 bytes
mov ax,word ptr [esi+6] ; 4 bytes
opti