:336.105KB : :1 :2022-10-08 14:33:12
qt inject dll 实例代码如果开发者对于本文件有需要的可以参考。
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QObject::connect(ui->newButton,SIGNAL(clicked()),this,SLOT(on_newButton_clicked()));
//QObject::connect(ui->browserFileToolButton,SIGNAL(clicked()),this,SLOT(on_browserFileToolButton_clicked()));
QObject::connect(ui->procListWidget,SIGNAL(itemSelectionChanged()),this,SLOT(itemTextSolt()));
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_newButton_clicked()
{
HANDLE hSnapProcess = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if(INVALID_HANDLE_VALUE == hSnapProcess)
{
QMessageBox::information(this,"ERROR","Error when create snapshot !");
return;
}
PROCESSENTRY32 pe;
pe.dwSize = sizeof (pe);
if(FALSE == Process32First(hSnapProcess,&pe))
{
QMessageBox::information(this,"ERROR","Error when Process32First !");
return;
}
while(Process32Next(hSnapProcess,&pe))
{
//WCHAR ProcessName = pe.szExeFile;
QString ProcessName = QString::fromWCharArray(pe.szExeFile);
//ui->procTextEdit->append(ProcessName);
//QString ProcessID = pe.th32ProcessID;
int ProcessID = (int)pe.th32ProcessID;
ui->procListWidget->addItem("PID[" QString::number(ProcessID) "] " ProcessName);
//qDebug()<
}
}
void MainWindow::on_browserFileToolButton_clicked()
{
dllName = QFileDialog::getOpenFileName(this,"open file",QDir::currentPath());
if(dllName.isEmpty())
{
QMessageBox::information(this,"ERROR","Open Dll Failed , Please Select Again !");
}
ui->dllNameLineEdit->setText(dllName);
}
void MainWindow::itemTextSolt()
{
//qDebug()<
QString ProInfo = ui->procListWidget->currentItem()->text();
//QStringList ProInfoList = ProInfo.split("[");
QString stProID = ProInfo.split("[").at(1).split("]").at(0);
//qDebug()<
}
void MainWindow::on_injectButton_clicked()
{
HANDLE hProHandle = OpenProcess(PROCESS_ALL_ACCESS,FALSE,PrcoID);
//qDebug()<
{
QMessageBox::information(this,"ERROR","Get PROCESS HANDLE FAILED !");
return;
}
LPVOID IpAdrr = VirtualAllocEx(hProHandle,NULL,0x1000,MEM_COMMIT,PAGE_EXECUTE_READWRITE);
if(IpAdrr == NULL)
{
QMessageBox::information(this,"ERROR","Get IPADRR FAILED !");
return;
}
//qDebug()<
strcpy(dllNameBuf,dllName.toLocal8Bit().data());
//qDebug()<<*dllNameBuf;
bool ok = WriteProcessMemory(hProHandle,IpAdrr,dllNameBuf,strlen(dllNameBuf),NULL);
if(!ok)
{
QMessageBox::information(this,"ERROR","Wirte dll name failed !");
}
//qDebug()<
//qDebug()<
//FARPROC pfThread = GetProcAddress(GetModuleHandleA("Kernel32.dll"),"LoadLibraryA");
LPTHREAD_START_ROUTINE pfThread = (LPTHREAD_START_ROUTINE)0x74F1A270;
// QLibrary mylib("C:\\Windows\\System32\\kernel32.dll");
// if(mylib.load())
// {
// LPFNDLLFUN hLoadLibrary = (LPFNDLLFUN)mylib.resolve("LoadLibraryA");
// qDebug()<
DWORD dwThreadID;
HANDLE hThread = CreateRemoteThread(hProHandle,NULL,0,(LPTHREAD_START_ROUTINE)pfThread,IpAdrr,0,&dwThreadID);
//qDebug()<
VirtualFreeEx(hProHandle,IpAdrr,0x1000,MEM_RELEASE);
QMessageBox::information(this,"Success","Dll run over !");
}
void MainWindow::on_uninjectButton_clicked()
{
qDebug()<
//qDebug()<
char dllNameBuf[MAX_PATH] = {NULL};
strcpy(dllNameBuf,dllname2.toLocal8Bit().data());
//qDebug()<
MODULEENTRY32 me32 = {0};
me32.dwSize = sizeof (me32);
BOOL bRet = Module32First(hSnap,&me32);
while(bRet)
{
// if(qstrcmp((char*)me32.szExePath,dllNameBuf) == 0)
// {
// QMessageBox::information(this,"find","ok");
// }
// bRet = Module32Next(hSnap,&me32);
qDebug()<
}
CloseHandle(hSnap);
}
02-09动态载入DLL
02-03升级加载内存Dll,兼容性极佳
02-03BBTC_v4_0_无DLL落地版
02-02dll或模块调用主程序中的子程序
02-02dll验证时间实例
01-29读取图片资源dll函数FOA