|
产生随机字符的代码:
- char CChangeSectionNameDlg::GetChar()
- {
- return (char)(rand()%92+33);
- }
主要功能实现代码:
- void CChangeSectionNameDlg::OnDo()
- {
- UpdateData(TRUE);
- if (m_bak == TRUE)
- {
- CString fn;
- fn = m_FileName + ".bak";
- CopyFile(m_FileName,fn,TRUE);
- fn.ReleaseBuffer();
- }
- CFile f;
- int secNum,n,m;
- IMAGE_DOS_HEADER dh;
- IMAGE_NT_HEADERS nh;
- IMAGE_SECTION_HEADER sh;
- f.Open(m_FileName,CFile::modeReadWrite);
- f.Read(&dh,sizeof(IMAGE_DOS_HEADER));
- f.Seek(dh.e_lfanew,CFile::begin);
- f.Read(&nh,sizeof(IMAGE_NT_HEADERS));
- secNum = nh.FileHeader.NumberOfSections;
- if (m_mode == 0)
- {
- for (n=0;n<secNum;n++)
- {
- f.Read(&sh,sizeof(IMAGE_SECTION_HEADER));
- for (m=0;m<8;m++)
- {
- sh.Name[m] = GetChar();
- }
- f.Seek(-sizeof(IMAGE_SECTION_HEADER),CFile::current);
- f.Write(&sh,sizeof(IMAGE_SECTION_HEADER));
- }
- }
- else if (m_mode == 1)
- {
- for (n=0;n<secNum;n++)
- {
- f.Read(&sh,sizeof(IMAGE_SECTION_HEADER));
- sh.Name[0] = 'z';
- sh.Name[1] = 'a';
- sh.Name[2] = 'p';
- sh.Name[3] = '.';
- for (m=4;m<8;m++)
- {
- sh.Name[m] = GetChar();
- }
- f.Seek(-sizeof(IMAGE_SECTION_HEADER),CFile::current);
- f.Write(&sh,sizeof(IMAGE_SECTION_HEADER));
- }
- }
- else
- {
- char xName[6][8] = {"zapline","zap.vm ","zap.crc",{'z','a','p','.','a','n','t','i'},"zapline",{'f','u','c','k','x','i','m','o'}};
- for (n=0;n<secNum;n++)
- {
- f.Read(&sh,sizeof(IMAGE_SECTION_HEADER));
- for (m=0;m<8;m++)
- {
- sh.Name[m] = xName[n][m];
- }
- f.Seek(-sizeof(IMAGE_SECTION_HEADER),CFile::current);
- f.Write(&sh,sizeof(IMAGE_SECTION_HEADER));
- if (n == 5)
- {
- break;
- }
- }
- for (n=5;n<secNum;n++)
- {
- f.Read(&sh,sizeof(IMAGE_SECTION_HEADER));
- for (m=0;m<8;m++)
- {
- sh.Name[m] = GetChar();
- }
- f.Seek(-sizeof(IMAGE_SECTION_HEADER),CFile::current);
- f.Write(&sh,sizeof(IMAGE_SECTION_HEADER));
- }
- }
- f.Close();
- MessageBox("OK!");
- }
|
|