记录QT片断1-(痛苦的win32)

记录QT片断1-(痛苦的win32)_第1张图片

 

qt对QMenu的封装 没有SystemMenu   
        QTextCodec::setCodecForTr(QTextCodec::codecForName("GB2312"));

    HMENU systemMenu = GetSystemMenu(this->winId(),false);
    QString aa = tr("自定义系统菜单");
    AppendMenu(systemMenu,0,MYMENU,aa.toStdWString().c_str());
qtceator对win32的太差 
  QString filename = QFileDialog::getOpenFileName(this,tr("请选择要加壳的文件 ----By satng"),"/","File(*.exe *.dll)");
    Q_ASSERT(filename.length()>0);
    ui->lineEditFileName->setText(filename);
    if(filename.isEmpty() || ui->lineEditFileName->text().isEmpty())
        return;
    MAP_FILE_STRUCT map_file;
    map_file.hFile = CreateFile(filename.toStdWString().c_str(),
               GENERIC_READ | GENERIC_WRITE,
               FILE_SHARE_READ | FILE_SHARE_WRITE,
               NULL,
               OPEN_EXISTING,
               FILE_ATTRIBUTE_NORMAL,
               NULL
               );
    if(map_file.hFile == INVALID_HANDLE_VALUE)
    {
        qDebug() << "could not open file!";
        return;
    }
    qDebug() << "open file ok!";
    map_file.hMapping = CreateFileMapping(map_file.hFile,
                                          NULL,
                                          PAGE_READWRITE,
                                          0,
                                          0,
                                          NULL
                                          );
    if(map_file.hMapping == NULL)
    {
        qDebug() << "could not open file mapping!";
        CloseHandle(map_file.hFile);
        return;
    }
    qDebug() << "mapping ok!";
    map_file.ImageBase = MapViewOfFile(map_file.hMapping,
                                       FILE_MAP_ALL_ACCESS,
                                       0,
                                       0,
                                       0
                                       );
    if(map_file.ImageBase == NULL)
    {
        qDebug() << "not viewoffile!";
        CloseHandle(map_file.hFile);
        CloseHandle(map_file.hMapping);
        return;
    }
     qDebug() << "view of file ok!";
    QPeEntry *pe = new QPeEntry;
    pe->pheader_dos = (PIMAGE_DOS_HEADER)map_file.ImageBase;
    pe->pheader_nt = (PIMAGE_NT_HEADERS32)((DWORD)pe->pheader_dos + pe->pheader_dos->e_lfanew);
    if(pe->isPEFile())
    {
      qDebug() << "ok";
    }
    pe->pheader_file = &pe->pheader_nt->FileHeader;
    pe->pheader_option = &pe->pheader_nt->OptionalHeader;
    pe->sectionNumber = pe->pheader_nt->FileHeader.NumberOfSections;
    pe->get_header_section_first();
    //pe->pheader_section_new =  pe->pheader_section_first + pe->sectionNumber;
    //memcpy(pe->pheader_section_new->Name,".myname",8);
    //pe->pheader_file->NumberOfSections ++;
    //e->pheader_section_new->SizeOfRawData = (DWORD)pe->pheader_option->FileAlignment;
/******************************************
  增加新节
******************************************/
//    pe->fileSize = GetFileSize(map_file.hFile,NULL);
//    pe->addSection();
//    void *code = malloc(0x1000);
//    memset(code,2,0x1000);
//    SetFilePointer(map_file.hFile,pe->pheader_section_new->PointerToRawData,NULL,FILE_BEGIN);
//    qDebug() << pe-> pheader_option->ImageBase;
//    DWORD size_o = 0;
//    WriteFile(map_file.hFile,code,0x1000,&size_o,NULL);
//    qDebug() << sizeof(code);
    DWORD v_addr = pe->pheader_option->DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress;
   PIMAGE_IMPORT_DESCRIPTOR iid = (PIMAGE_IMPORT_DESCRIPTOR)ImageRvaToVa(pe->pheader_nt,(LPVOID)map_file.ImageBase,v_addr,NULL);
   while(iid->Name !=0)
   {
       qDebug() << (char *)ImageRvaToVa(pe->pheader_nt,(LPVOID)map_file.ImageBase,iid->Name,NULL);
       iid++;
   }
.....
.....
.....
记录QT片断1-(痛苦的win32)_第2张图片

你可能感兴趣的:(Win32)