吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 645|回复: 2
收起左侧

[求助] QT程序如何再加一列?

[复制链接]
冥界3大法王 发表于 2023-9-19 09:18
本帖最后由 冥界3大法王 于 2023-9-19 09:34 编辑

如图12所示:
image.png
   image.png
截图2中的文本 ,同样也需要增加1列注释,忘记图片上说明了,就这意思吧。
只需要关注 .1337的行

越看越不顺眼,于是问题来: 能不能再加一个注释列?

[C++] 纯文本查看 复制代码
#include "PatchDialog.h"#include "ui_PatchDialog.h"
#include <QMessageBox>
#include <QIcon>
#include <QFileDialog>
#include <QTextStream>
#include "MiscUtil.h"
#include "StringUtil.h"
#include "Configuration.h"
#include <QClipboard>


void PatchDialog::on_btnImport_clicked()
{
    QStringList filenamelist = QFileDialog::getOpenFileNames(this, tr("Open patch"), "", tr("Patch files (*.1337)"));
    int patched = 0;
    bool bBadOriginal = false;
    bool bAlreadyDone = false;

    typedef struct _IMPORTSTATUS
    {
        bool badoriginal;
        bool alreadypatched;
    } IMPORTSTATUS;
    QList<QPair<DBGPATCHINFO, IMPORTSTATUS>> patchList;
    DBGPATCHINFO curPatch;

    for(const auto & filename1 : filenamelist)
    {
        if(!filename1.length())
            continue;
        QString filename = QDir::toNativeSeparators(filename1); //convert to native path format (with backlashes)
        QFile file(filename);
        file.open(QFile::ReadOnly | QFile::Text);
        QTextStream in(&file);
        QString patch = in.readAll();
        file.close();
        patch = patch.replace("\r\n", "\n");
        QStringList lines = patch.split("\n", QString::SkipEmptyParts);
        if(!lines.size())
        {
            SimpleErrorBox(this, tr("Error!"), tr("The patch file is empty..."));
            continue;
        }

        dsint modbase = 0;
        for(int i = 0; i < lines.size(); i++)
        {
            ULONGLONG rva;
            unsigned int oldbyte;
            unsigned int newbyte;
            QString curLine = lines.at(i);
            if(curLine.startsWith(">")) //module
            {
                strcpy_s(curPatch.mod, curLine.toUtf8().constData() + 1);
                modbase = DbgFunctions()->ModBaseFromName(curPatch.mod);
                continue;
            }
            if(!modbase)
                continue;
            curLine = curLine.replace(" ", "");
            if(sscanf_s(curLine.toUtf8().constData(), "%llX:%X->%X", &rva, &oldbyte, &newbyte) != 3)
            {
                //File format is error. Don't continue processing this file
                SimpleErrorBox(this, tr("Error!"), tr("Patch file format is incorrect..."));
                break;
            }
            oldbyte &= 0xFF;
            newbyte &= 0xFF;
            curPatch.addr = rva + modbase;
            if(!DbgMemIsValidReadPtr(curPatch.addr))
                continue;
            unsigned char checkbyte = 0;
            DbgMemRead(curPatch.addr, &checkbyte, sizeof(checkbyte));
            IMPORTSTATUS status;
            status.alreadypatched = (checkbyte == newbyte);
            status.badoriginal = (checkbyte != oldbyte);
            if(status.alreadypatched)
                bAlreadyDone = true;
            else if(status.badoriginal)
                bBadOriginal = true;
            curPatch.oldbyte = oldbyte;
            curPatch.newbyte = newbyte;
            patchList.push_back(QPair<DBGPATCHINFO, IMPORTSTATUS>(curPatch, status));
        }
    }

    //Check if any patch exists
    if(!patchList.size())
    {
        SimpleInfoBox(this, tr("Information"), tr("No patches to apply in the current process."));
        return;
    }

    //Warn if some are already patched
    bool bUndoPatched = false;
    if(bAlreadyDone)
    {
        QMessageBox msg(QMessageBox::Question, tr("Question"), tr("Some patches are already applied.\n\nDo you want to remove these patches?"), QMessageBox::Yes | QMessageBox::No);
        msg.setWindowIcon(DIcon("question.png"));
        msg.setParent(this, Qt::Dialog);
        msg.setWindowFlags(msg.windowFlags() & (~Qt::WindowContextHelpButtonHint));
        if(msg.exec() == QMessageBox::Yes)
            bUndoPatched = true;
    }

    bool bPatchBadOriginals = false;
    if(bBadOriginal)
    {
        QMessageBox msg(QMessageBox::Question, tr("Question"), tr("Some bytes do not match the original in the patch file.\n\nDo you want to apply these patches anyway?"), QMessageBox::Yes | QMessageBox::No);
        msg.setWindowIcon(DIcon("question.png"));
        msg.setParent(this, Qt::Dialog);
        msg.setWindowFlags(msg.windowFlags() & (~Qt::WindowContextHelpButtonHint));
        if(msg.exec() == QMessageBox::Yes)
            bPatchBadOriginals = true;
    }

    //Apply all of the patches
    for(int i = 0; i < patchList.size(); i++)
    {
        if(!bPatchBadOriginals && patchList.at(i).second.badoriginal)
            continue;
        curPatch = patchList.at(i).first;
        if(bUndoPatched && patchList.at(i).second.alreadypatched)
        {
            if(DbgFunctions()->MemPatch(curPatch.addr, &curPatch.oldbyte, 1))
                patched++;
        }
        else
        {
            if(DbgFunctions()->MemPatch(curPatch.addr, &curPatch.newbyte, 1))
                patched++;
        }
    }

    updatePatches();
    GuiUpdateAllViews();

    SimpleInfoBox(this, tr("Information"), tr("%1/%2 patch(es) applied!").arg(patched).arg(patchList.size()));
}

void PatchDialog::on_btnExport_clicked()
{
    if(!mPatches.size())
        return;

    if(containsRelocatedBytes() && !showRelocatedBytesWarning())
        return;

    QString filename = QFileDialog::getSaveFileName(this, tr("Save patch"), "", tr("Patch files (*.1337)"));
    if(!filename.length())
        return;
    filename = QDir::toNativeSeparators(filename); //convert to native path format (with backlashes)
    if(filename.endsWith(QString(".1337")))
        saveAs1337(filename);
    // TODO: C program source
}

void PatchDialog::saveAs1337(const QString & filename)
{
    QStringList lines;

    int patches = 0;
    for(PatchMap::iterator i = mPatches.begin(); i != mPatches.end(); ++i)
    {
        const PatchInfoList & curPatchList = i.value();
        bool bModPlaced = false;
        dsint modbase = DbgFunctions()->ModBaseFromName(i.key().toUtf8().constData());
        if(!modbase)
            continue;
        for(int j = 0; j < curPatchList.size(); j++)
        {
            if(!curPatchList.at(j).status.checked) //skip unchecked patches
                continue;
            if(!bModPlaced)
            {
                lines.push_back(">" + i.key());
                bModPlaced = true;
            }
            QString addrText = ToPtrString(curPatchList.at(j).patch.addr - modbase);
            lines.push_back(addrText + QString().sprintf(":%.2X->%.2X", curPatchList.at(j).patch.oldbyte, curPatchList.at(j).patch.newbyte));
            patches++;
        }
    }

    if(!lines.size())
    {
        SimpleInfoBox(this, tr("Information"), tr("No patches to export."));
        return;
    }

    QFile file(filename);
    file.open(QFile::WriteOnly | QFile::Text);
    QString text = lines.join("\n");
    QByteArray textUtf8 = text.toUtf8();
    file.write(textUtf8.constData(), textUtf8.length());
    file.close();

    SimpleInfoBox(this, tr("Information"), tr("%1 patch(es) exported!").arg(patches));
}

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

阳光好青年 发表于 2023-9-19 09:50
控件都不一样吧
chenzhigang 发表于 2023-9-19 09:58
如果有ui文件的话 就在ui里patches 水平布局添加一个
如果没有就收到在cpp 文件添加一个布局 再把注释放进去
    QLabel * mylabel = new QLabel(); //注释
    mylabel->setFixedSize(32, 32);   //改成你的大小
   mylabel->setText("xxxxxx");   //注释文字
    mylabel->setAlignment(Qt::AlignCenter);
    QHBoxLayout *myLayout = new QHBoxLayout();
    myLayout->setContentsMargins(0, 0, 0, 0);
    myLayout->addSpacing(10);
    myLayout->addWidget(mylabel);
    myLayout->addStretch();
    patches->addLayout(myLayout);

免费评分

参与人数 1吾爱币 +4 热心值 +1 收起 理由
冥界3大法王 + 4 + 1 谢谢@Thanks!

查看全部评分

您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-24 19:55

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表