实例介绍
【实例简介】
【实例截图】
【核心代码】
#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()<<ui->procListWidget->currentItem()->text();
}
}
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()<<ui->procListWidget->currentItem()->text();
QString ProInfo = ui->procListWidget->currentItem()->text();
//QStringList ProInfoList = ProInfo.split("[");
QString stProID = ProInfo.split("[").at(1).split("]").at(0);
//qDebug()<<stProID.toInt();
//qDebug()<<dllName;
PrcoID=(DWORD)stProID.toDouble();
}
void MainWindow::on_injectButton_clicked()
{
HANDLE hProHandle = OpenProcess(PROCESS_ALL_ACCESS,FALSE,PrcoID);
//qDebug()<<hProHandle;
if(hProHandle == NULL)
{
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()<<IpAdrr;
char dllNameBuf[MAX_PATH] = {NULL};
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()<<strlen(dllNameBuf) 1;
//qDebug()<<dllNameBuf;
//HMODULE hModule = LoadLibrary(TEXT("kernel32"));
//qDebug()<<hModule;
//LPTHREAD_START_ROUTINE pfThread = (LPTHREAD_START_ROUTINE)GetProcAddress(hModule,"LoadLibraryA");
//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()<<hLoadLibrary;
// }
DWORD dwThreadID;
HANDLE hThread = CreateRemoteThread(hProHandle,NULL,0,(LPTHREAD_START_ROUTINE)pfThread,IpAdrr,0,&dwThreadID);
//qDebug()<<dwThreadID;
//qDebug()<<pfThread;
WaitForSingleObject(hThread,INFINITE);
VirtualFreeEx(hProHandle,IpAdrr,0x1000,MEM_RELEASE);
QMessageBox::information(this,"Success","Dll run over !");
}
void MainWindow::on_uninjectButton_clicked()
{
qDebug()<<PrcoID;
QStringList dllnameList = dllName.split("/");
//qDebug()<<dllnameList.last();
QString dllname2 = dllnameList.last();
char dllNameBuf[MAX_PATH] = {NULL};
strcpy(dllNameBuf,dllname2.toLocal8Bit().data());
//qDebug()<<dllNameBuf;
HANDLE hSnap =CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, PrcoID);
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()<<QString::fromWCharArray(me32.szModule);
bRet = Module32Next(hSnap,&me32);
}
CloseHandle(hSnap);
}
好例子网口号:伸出你的我的手 — 分享!
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明


网友评论
我要评论