177 lines
7.5 KiB
C++
177 lines
7.5 KiB
C++
#include "mainwin.h"
|
|
|
|
#include <QApplication>
|
|
#include <QLocale>
|
|
#include <QTranslator>
|
|
#include <QIcon>
|
|
#include <QMessageBox>
|
|
#include <QDebug>
|
|
|
|
#ifdef _MSC_VER //MSVC编译器
|
|
#define _WINSOCKAPI_
|
|
#include <windows.h>
|
|
#include <DbgHelp.h>
|
|
#if _MSC_VER >= 1600
|
|
#pragma execution_character_set("utf-8")
|
|
#endif
|
|
LONG WINAPI handleException(_EXCEPTION_POINTERS *excep) {
|
|
QString errCode = QString::number(excep->ExceptionRecord->ExceptionCode, 16);
|
|
QString errAddr = QString::number((uint)excep->ExceptionRecord->ExceptionAddress, 16);
|
|
HANDLE hDumpFile = CreateFile(L"c:/ledset-crash.dmp", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
|
|
if(hDumpFile == INVALID_HANDLE_VALUE) {
|
|
qDebug()<<"handleException hDumpFile INVALID"<<"ExceptionCode"<<errCode<<"ExceptionAddress"<<errAddr;
|
|
return EXCEPTION_CONTINUE_SEARCH; //未处理异常, 让 windows 弹出错误框并结束 (Qt会卡死一段时间)
|
|
}
|
|
MINIDUMP_EXCEPTION_INFORMATION dumpInfo{GetCurrentThreadId(), excep, TRUE};
|
|
MiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(), hDumpFile, MiniDumpNormal, &dumpInfo, NULL, NULL);//写入Dump文件内容
|
|
CloseHandle(hDumpFile);
|
|
QMessageBox::critical(nullptr, "程序出错", "<b>程序出错!</b> (code: "+errCode+". addr: "+errAddr+")<br/>请将C盘下的 ledok-crash.dmp 文件发送到 gangphon@qq.com 邮箱, 研发人员会尽快处理.");
|
|
return EXCEPTION_EXECUTE_HANDLER; //已处理异常, 让 windows 正常结束
|
|
// EXCEPTION_CONTINUE_EXECUTION 已修复错误, 让 windows 从异常发生处继续执行
|
|
}
|
|
#endif
|
|
void test();
|
|
int main(int argc, char *argv[]) {
|
|
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
|
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
|
|
QApplication::setHighDpiScaleFactorRoundingPolicy(Qt::HighDpiScaleFactorRoundingPolicy::PassThrough);
|
|
QApplication a(argc, argv);
|
|
QFont font;
|
|
font.setFamilies(QStringList{"Arial","Microsoft YaHei UI"});
|
|
font.setPixelSize(14);
|
|
a.setFont(font);
|
|
QPalette plt = a.palette();
|
|
plt.setBrush(QPalette::Window, QColor(0x333333));
|
|
plt.setBrush(QPalette::WindowText, QColor(0xffffff));
|
|
plt.setBrush(QPalette::Base, QColor(0x444444));
|
|
plt.setBrush(QPalette::AlternateBase, QColor(0x555555));
|
|
plt.setBrush(QPalette::Text, QColor(0xffffff));
|
|
plt.setBrush(QPalette::Button, QColor(0x222222));
|
|
plt.setBrush(QPalette::ButtonText, QColor(0xffffff));
|
|
plt.setBrush(QPalette::ToolTipBase, QColor(0x444466));
|
|
plt.setBrush(QPalette::ToolTipText, QColor(0xffffff));
|
|
plt.setBrush(QPalette::Light, QColor(0x444444));
|
|
plt.setBrush(QPalette::Midlight, QColor(0x666666));
|
|
plt.setBrush(QPalette::Mid, QColor(0x888888));
|
|
plt.setBrush(QPalette::Dark, QColor(0xaaaaaa));
|
|
plt.setBrush(QPalette::BrightText, QColor(0,0,0));
|
|
plt.setBrush(QPalette::Shadow, QColor(0xaaaaaa));
|
|
a.setPalette(plt);
|
|
a.setWindowIcon(QIcon(":/128.ico"));
|
|
|
|
a.setStyleSheet(R"rrr(
|
|
QMessageBox {background: #444;}
|
|
QGroupBox::title {color: #fff;}
|
|
|
|
QLineEdit, QComboBox, QSpinBox, QPushButton, QAbstractScrollArea {border: 1px solid #888;}
|
|
QLineEdit, QComboBox, QSpinBox {border-radius: 2px; padding: 2px; background: #222;}
|
|
|
|
QPushButton{border-radius: 4px; padding: 2px 6px; background: #222;}
|
|
QPushButton:hover {background: #444;}
|
|
QPushButton:pressed {background: #666;}
|
|
QPushButton:checked {background: #026; border-color: #06f;}
|
|
|
|
QPushButton[ss="min"]{border-radius: 4px; padding: 0; width: 30px; height: 25px; background: #07c;}
|
|
QPushButton[ss="close"]{border-radius: 4px; padding: 0; width: 30px; height: 25px; background: #e22;}
|
|
|
|
QRadioButton::indicator {border-image: url(:/imgs/radio-un.png); width: 14px; height: 14px;}
|
|
QRadioButton::indicator:checked {border-image: url(:/imgs/radio-check.png);}
|
|
|
|
QAbstractScrollArea QScrollBar {background: #555;}
|
|
|
|
QTableView {gridline-color:#888;}
|
|
QHeaderView::section, QTableCornerButton:section {background: #555;}
|
|
|
|
QSlider::horizontal {height: 16px;}
|
|
QSlider::groove {background: transparent;}
|
|
QSlider::sub-page:horizontal {background: #07c; margin: 5px 0; border-radius: 2px;}
|
|
QSlider::add-page:horizontal {background: #888; margin: 5px 0; border-radius: 2px;}
|
|
QSlider::handle {background: #eee; border-radius: 2px;}
|
|
QSlider::handle:hover {background: #fff;}
|
|
QSlider::handle:horizontal {width: 8px;}
|
|
)rrr");
|
|
|
|
QTranslator translator;
|
|
if(translator.load(QLocale::system(), "app", "_", ":/i18n")) a.installTranslator(&translator);
|
|
QTranslator qtTrans;
|
|
if(qtTrans.load(QLocale::system(), "qt", "_", ":/i18n")) a.installTranslator(&qtTrans);
|
|
|
|
MainWin w;
|
|
w.show();
|
|
|
|
#ifdef _MSC_VER
|
|
SetUnhandledExceptionFilter(handleException);
|
|
#endif
|
|
//test();
|
|
return a.exec();
|
|
}
|
|
|
|
#define HAVE_REMOTE
|
|
#include "pcapthread.h"
|
|
|
|
void test() {
|
|
pcap_if_t *devs;
|
|
char errbuf[PCAP_ERRBUF_SIZE];
|
|
if(pcap_findalldevs(&devs, errbuf) == -1) {
|
|
qDebug() << "pcap_findalldevs" << errbuf;
|
|
return;
|
|
}
|
|
pcap_if_t *device = 0;
|
|
for(pcap_if_t *dev = devs; dev; dev = dev->next) {
|
|
qDebug() << dev->name << "[desc]" << dev->description << "Loopback" << ((dev->flags & PCAP_IF_LOOPBACK)?"yes":"no");
|
|
pcap_addr_t *a;
|
|
for(a=dev->addresses; a; a=a->next) {
|
|
auto sa_family = a->addr->sa_family;
|
|
if(sa_family==AF_INET) {
|
|
u_char *ip = (u_char *) &((sockaddr_in *) a->addr)->sin_addr.s_addr;
|
|
qDebug(" INET %d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
|
|
if(a->netmask) {
|
|
u_char *ip = (u_char *) &((sockaddr_in *) a->netmask)->sin_addr.s_addr;
|
|
qDebug(" netmask %d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
|
|
}
|
|
if(a->broadaddr) {
|
|
u_char *ip = (u_char *) &((sockaddr_in *) a->broadaddr)->sin_addr.s_addr;
|
|
qDebug(" Broadcast Address %d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
|
|
}
|
|
if(a->dstaddr) {
|
|
u_char *ip = (u_char *) &((sockaddr_in *) a->dstaddr)->sin_addr.s_addr;
|
|
qDebug(" Destination Address %d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]);
|
|
}
|
|
if(device==0) device = dev;
|
|
} else if(sa_family==AF_INET6) {
|
|
qDebug() << " INET6";
|
|
//printf("\tAddress: %s\n", ip6tos(a->addr, ip6str, sizeof(ip6str)));
|
|
} else qDebug() << " Address Family" << sa_family;
|
|
}
|
|
qDebug();
|
|
}
|
|
auto pcap = pcap_open_live(device->name, 65536, 1, 1000, errbuf);
|
|
if(pcap == 0) {
|
|
qDebug("Error openning adapter: %s\n", errbuf);
|
|
return;
|
|
}
|
|
//检查链路层的类型
|
|
if (pcap_datalink(pcap) != DLT_EN10MB) {
|
|
qDebug("This program only run on Ethernet networks\n");
|
|
// pcap_close(fp);
|
|
// pcap_freealldevs(alldevs);
|
|
}
|
|
|
|
auto capthd = new CapThread(pcap);
|
|
capthd->start();
|
|
QThread::sleep(1);
|
|
u_char data[] = {0x55, 0x55,
|
|
0x9A, 0x20, 0x00, 0x20,
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
|
0x00,0x00,0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00};
|
|
if(pcap_sendpacket(pcap, data, sizeof(data))) {
|
|
qDebug()<<pcap_geterr(pcap);
|
|
return;
|
|
}
|
|
|
|
//pcap_close(pcap);
|
|
//pcap_freealldevs(devs);
|
|
}
|