xx_分析病毒 -- 寫文件 讀文件 改主頁

簡單的使用writefile寫文件、

#include <windows.h>

#include <stdio.h>

int main( )

{

       //調用CreateFile函數以只寫方式打開一個文件

   HANDLE hFile=CreateFile("c:\\a.txt",   GENERIC_WRITE,FILE_SHARE_READ,   NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,NULL);

       if(hFile==INVALID_HANDLE_VALUE)

       {

              printf("CreateFile error\n");

              return 0;

       }

       //調用SetFilePointer函數調整文件指針位置,移動到文件末尾

       if( SetFilePointer(hFile,0,NULL,FILE_END) == -1)

       {

              printf("SetFilePointer error \n");    

           return 0;  

       }

       char buff[256]="我是寫入的信息哦";

       DWORD dwWrite;

       //把buff中的內容寫入到文件末尾

       if(!WriteFile(hFile,&buff,strlen(buff),&dwWrite,NULL))

       {

              printf("WriteFile error \n");    

           return 0;  

       }

       printf("往c:\\a.txt中寫入數據成功\n");

       CloseHandle(hFile); //關閉句柄

       return 0;

}

通過註冊表修改IE主頁、

#include <windows.h>

#include <stdio.h>

//用於修改字符串類型鍵值常用函數、

void CreateStringReg(HKEY hRoot, char *szSubKey, char* ValueName, char *Data)

{

       HKEY hKey;

       //打開註冊表鍵,不存在則創建它

       long lRet=RegCreateKeyEx(hRoot,szSubKey,0,NULL, REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,     NULL,&hKey,NULL);

          if (lRet != ERROR_SUCCESS)

       {

              printf("error no RegCreateKeyEx %s\n", szSubKey);

              return ;

       }

       //修改註冊表鍵值,沒有則創建它

       lRet=RegSetValueEx(hKey,ValueName,0,REG_SZ,(BYTE*)Data,strlen(Data));

       if (lRet!=ERROR_SUCCESS)

       {

              printf("error no RegSetValueEx %s\n", ValueName);

              return ;

       }

       RegCloseKey(hKey);

}

 

int main()

{

       //要修改成的網址

       char StartPage[255]="http://hi.baidu.com/xx375/home";  //http://www.baidu.com/

       //調用修改字符串類型鍵值的函數

       CreateStringReg(HKEY_CURRENT_USER,"Software\\Microsoft\\Internet Explorer\\Main","Start Page",StartPage);

       return 0;

}

簡單的使用CreateFile創建文件

#include <windows.h>

#include <string>

int main()

{

       char Path[255];

       char FileName[255];

       char Data[512]="------hello ---";

       for(int i=0;i<10000;i++)// 創建10000個txt嘎嘎、

       {

              //得到windows目錄

              GetWindowsDirectory(Path,sizeof(Path));

              //用i的值加.txt來給文件命名

              wsprintf(FileName,"\\%d.txt",i);// FileName 即爲\i.txt

              //給path賦以完整路徑

              strcat(Path,FileName);//連接字符串形成完整路徑、

              HANDLE  hFile;

              //創建文件

              hFile=CreateFile(Path,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);

              if(hFile==INVALID_HANDLE_VALUE)

              {

                     continue;

              }

              DWORD dwWrite;

              //把Data中的數據寫入文件

              WriteFile(hFile,&Data,strlen(Data),&dwWrite,NULL);

              //關閉文件句柄 並且清空字符數組

              CloseHandle(hFile);

              memset(Path,0x00,255);

              memset(FileName,0x00,255);

       }

       return 0;

}

---------------------------------------簡單小程序集-----------------------------------------------------------

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章