-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
81 lines (56 loc) · 1.92 KB
/
mainwindow.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QApplication>
#include <QClipboard>
#include <QString>
#include <QUdpSocket>
#include <QByteArray>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_2_clicked()
{
ui->plainTextEdit->setPlainText(QApplication::clipboard()->text());
}
void MainWindow::on_pushButton_clicked()
{
QString ip = ui->lineEdit->text();
int port = ui->spinBox->value();
QString rawData = ui->plainTextEdit->toPlainText();
QByteArray output;
if (rawData.contains("0x0000:")) {
// tcpdump hex format bytes + decode
// no ethernet first 10 bytes src dst and ipv4=0x0800
// 23:07:11.963253 IP 128.73.68.166.50346 > 176.97.76.154.443: UDP, length 32
// 0x0000: 4500 003c 403a 4000 3411 448c 8049 44a6 E..<@:@.4.D..ID.
// 0x0010: b061 4c9a c4aa 01bb 0028 ca07 e509 2117 .aL......(....!.
// frag ttl ch
// ip4 len id offs udp sum src ip
// 0x0000: 4500 003c 403a 4000 3411 448c 8049 44a6 E..<@:@.4.D..ID.
// dst ip srcp dstp len sum
// 0x0010: b061 4c9a c4aa 01bb 0028 ca07 e509 2117 .aL......(....!.
QStringList sl = rawData.split("\n");
for (QString s : sl) {
if (s.contains("UDP, length")) continue;
s = s.trimmed();
s.remove(0, 9);
s = s.mid(0, 39);
qDebug().noquote() << s;
s.replace(" ", "");
output.append(QByteArray::fromHex(s.toLatin1()));
}
// remove 28 bytes header
output = output.mid(28);
qDebug() << "\n";
qDebug().noquote() << "size: " << output.size();
}
QUdpSocket udpSocket;
udpSocket.writeDatagram(output, QHostAddress(ip), port);
}