diff --git a/DaemonService/Daemon.ico b/DaemonService/Daemon.ico
new file mode 100644
index 0000000..c426844
Binary files /dev/null and b/DaemonService/Daemon.ico differ
diff --git a/DaemonService/DaemonService.pro b/DaemonService/DaemonService.pro
index 6bef36e..f0f34a4 100644
--- a/DaemonService/DaemonService.pro
+++ b/DaemonService/DaemonService.pro
@@ -5,6 +5,8 @@
#-------------------------------------------------
QT += core gui network sql
+RESOURCES += res.qrc
+RC_ICONS = Daemon.ico
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
@@ -51,3 +53,6 @@ RC_FILE = uac.rc
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target
+
+RESOURCES += \
+ res.qrc
diff --git a/DaemonService/DaemonService.pro.user b/DaemonService/DaemonService.pro.user
index 0451085..17b1fef 100644
--- a/DaemonService/DaemonService.pro.user
+++ b/DaemonService/DaemonService.pro.user
@@ -1,10 +1,10 @@
-
+
EnvironmentId
- {2d03fc4c-541a-4fa5-8f5c-ae92a1998dce}
+ {6a2adf44-d351-4499-8d66-24024cfa2d9d}
ProjectExplorer.Project.ActiveTarget
@@ -64,14 +64,14 @@
ProjectExplorer.Project.Target.0
- Desktop Qt 5.11.2 MinGW 32bit
- Desktop Qt 5.11.2 MinGW 32bit
- qt.qt5.5112.win32_mingw53_kit
- 0
+ Desktop Qt 5.6.2 MinGW 32bit
+ Desktop Qt 5.6.2 MinGW 32bit
+ qt.56.win32_mingw49_kit
+ 1
0
0
- E:/C++/Qt/build-DaemonService-Desktop_Qt_5_11_2_MinGW_32bit-Debug
+ F:/Qt/build-DaemonService-Desktop_Qt_5_6_2_MinGW_32bit-Debug
true
@@ -89,10 +89,11 @@
Make
Qt4ProjectManager.MakeStep
-
+
false
+ false
2
Build
@@ -105,10 +106,11 @@
Make
Qt4ProjectManager.MakeStep
-
+
true
clean
+ false
1
Clean
@@ -125,7 +127,7 @@
true
- E:/C++/Qt/build-DaemonService-Desktop_Qt_5_11_2_MinGW_32bit-Release
+ F:/Qt/build-DaemonService-Desktop_Qt_5_6_2_MinGW_32bit-Release
true
@@ -136,17 +138,18 @@
false
false
- true
+ false
true
Make
Qt4ProjectManager.MakeStep
-
+
false
+ false
2
Build
@@ -159,10 +162,11 @@
Make
Qt4ProjectManager.MakeStep
-
+
true
clean
+ false
1
Clean
@@ -179,7 +183,7 @@
true
- E:/C++/Qt/build-DaemonService-Desktop_Qt_5_11_2_MinGW_32bit-Profile
+ F:/Qt/build-DaemonService-Desktop_Qt_5_6_2_MinGW_32bit-Profile
true
@@ -190,17 +194,18 @@
false
true
- true
+ false
true
Make
Qt4ProjectManager.MakeStep
-
+
false
+ false
2
Build
@@ -213,10 +218,11 @@
Make
Qt4ProjectManager.MakeStep
-
+
true
clean
+ false
1
Clean
@@ -291,18 +297,18 @@
DaemonService
- Qt4ProjectManager.Qt4RunConfiguration:E:/C++/Qt/DaemonService/DaemonService.pro
- true
-
+ Qt4ProjectManager.Qt4RunConfiguration:F:/Qt/DaemonService/DaemonService.pro
DaemonService.pro
-
- E:/C++/Qt/build-DaemonService-Desktop_Qt_5_11_2_MinGW_32bit-Debug
+
3768
false
true
+ true
false
false
true
+
+ F:/Qt/build-DaemonService-Desktop_Qt_5_6_2_MinGW_32bit-Release
1
@@ -313,10 +319,10 @@
ProjectExplorer.Project.Updater.FileVersion
- 18
+ 20
Version
- 18
+ 20
diff --git a/DaemonService/DaemonService.pro.user.2d03fc4.4.8-pre1 b/DaemonService/DaemonService.pro.user.2d03fc4.4.8-pre1
new file mode 100644
index 0000000..0451085
--- /dev/null
+++ b/DaemonService/DaemonService.pro.user.2d03fc4.4.8-pre1
@@ -0,0 +1,322 @@
+
+
+
+
+
+ EnvironmentId
+ {2d03fc4c-541a-4fa5-8f5c-ae92a1998dce}
+
+
+ ProjectExplorer.Project.ActiveTarget
+ 0
+
+
+ ProjectExplorer.Project.EditorSettings
+
+ true
+ false
+ true
+
+ Cpp
+
+ CppGlobal
+
+
+
+ QmlJS
+
+ QmlJSGlobal
+
+
+ 2
+ UTF-8
+ false
+ 4
+ false
+ 80
+ true
+ true
+ 1
+ true
+ false
+ 0
+ true
+ true
+ 0
+ 8
+ true
+ 1
+ true
+ true
+ true
+ false
+
+
+
+ ProjectExplorer.Project.PluginSettings
+
+
+ -fno-delayed-template-parsing
+
+ true
+
+
+
+ ProjectExplorer.Project.Target.0
+
+ Desktop Qt 5.11.2 MinGW 32bit
+ Desktop Qt 5.11.2 MinGW 32bit
+ qt.qt5.5112.win32_mingw53_kit
+ 0
+ 0
+ 0
+
+ E:/C++/Qt/build-DaemonService-Desktop_Qt_5_11_2_MinGW_32bit-Debug
+
+
+ true
+ qmake
+
+ QtProjectManager.QMakeBuildStep
+ true
+
+ false
+ false
+ false
+
+
+ true
+ Make
+
+ Qt4ProjectManager.MakeStep
+
+ false
+
+
+
+ 2
+ Build
+
+ ProjectExplorer.BuildSteps.Build
+
+
+
+ true
+ Make
+
+ Qt4ProjectManager.MakeStep
+
+ true
+ clean
+
+
+ 1
+ Clean
+
+ ProjectExplorer.BuildSteps.Clean
+
+ 2
+ false
+
+ Debug
+ Debug
+ Qt4ProjectManager.Qt4BuildConfiguration
+ 2
+ true
+
+
+ E:/C++/Qt/build-DaemonService-Desktop_Qt_5_11_2_MinGW_32bit-Release
+
+
+ true
+ qmake
+
+ QtProjectManager.QMakeBuildStep
+ false
+
+ false
+ false
+ true
+
+
+ true
+ Make
+
+ Qt4ProjectManager.MakeStep
+
+ false
+
+
+
+ 2
+ Build
+
+ ProjectExplorer.BuildSteps.Build
+
+
+
+ true
+ Make
+
+ Qt4ProjectManager.MakeStep
+
+ true
+ clean
+
+
+ 1
+ Clean
+
+ ProjectExplorer.BuildSteps.Clean
+
+ 2
+ false
+
+ Release
+ Release
+ Qt4ProjectManager.Qt4BuildConfiguration
+ 0
+ true
+
+
+ E:/C++/Qt/build-DaemonService-Desktop_Qt_5_11_2_MinGW_32bit-Profile
+
+
+ true
+ qmake
+
+ QtProjectManager.QMakeBuildStep
+ true
+
+ false
+ true
+ true
+
+
+ true
+ Make
+
+ Qt4ProjectManager.MakeStep
+
+ false
+
+
+
+ 2
+ Build
+
+ ProjectExplorer.BuildSteps.Build
+
+
+
+ true
+ Make
+
+ Qt4ProjectManager.MakeStep
+
+ true
+ clean
+
+
+ 1
+ Clean
+
+ ProjectExplorer.BuildSteps.Clean
+
+ 2
+ false
+
+ Profile
+ Profile
+ Qt4ProjectManager.Qt4BuildConfiguration
+ 0
+ true
+
+ 3
+
+
+ 0
+ 部署
+
+ ProjectExplorer.BuildSteps.Deploy
+
+ 1
+ Deploy Configuration
+
+ ProjectExplorer.DefaultDeployConfiguration
+
+ 1
+
+
+ false
+ false
+ 1000
+
+ true
+
+ false
+ false
+ false
+ false
+ true
+ 0.01
+ 10
+ true
+ 1
+ 25
+
+ 1
+ true
+ false
+ true
+ valgrind
+
+ 0
+ 1
+ 2
+ 3
+ 4
+ 5
+ 6
+ 7
+ 8
+ 9
+ 10
+ 11
+ 12
+ 13
+ 14
+
+ 2
+
+ DaemonService
+
+ Qt4ProjectManager.Qt4RunConfiguration:E:/C++/Qt/DaemonService/DaemonService.pro
+ true
+
+ DaemonService.pro
+
+ E:/C++/Qt/build-DaemonService-Desktop_Qt_5_11_2_MinGW_32bit-Debug
+ 3768
+ false
+ true
+ false
+ false
+ true
+
+ 1
+
+
+
+ ProjectExplorer.Project.TargetCount
+ 1
+
+
+ ProjectExplorer.Project.Updater.FileVersion
+ 18
+
+
+ Version
+ 18
+
+
diff --git a/DaemonService/daemonservice.cpp b/DaemonService/daemonservice.cpp
index cb90711..1598ddb 100644
--- a/DaemonService/daemonservice.cpp
+++ b/DaemonService/daemonservice.cpp
@@ -18,7 +18,7 @@
*/
void DaemonService::incomingConnection(qintptr socketDescriptor)
{
- qDebug("new connect is connect %d", socketDescriptor);
+ qDebug("new connect is connect %d(有新的连接进入!)", socketDescriptor);
Worker *worker = new Worker(socketDescriptor, this->m_portList);
QThreadPool::globalInstance()->start(worker);
}
diff --git a/DaemonService/dal.cpp b/DaemonService/dal.cpp
index f6e0202..1e53de4 100644
--- a/DaemonService/dal.cpp
+++ b/DaemonService/dal.cpp
@@ -115,11 +115,11 @@ DAL::DAL()
{
// 如果打开失败 退出程序
qCritical()<setupUi(this);
+ setWindowIcon(QIcon(":/Daemon.ico"));
connect(&Log::instance(), &Log::appendEvent, this, &MainWindow::log_append);
}
@@ -20,44 +21,55 @@ MainWindow::~MainWindow()
void MainWindow::on_pushButton_clicked()
{
- QString temp = ui->txtPortList->toPlainText().trimmed();
- if (temp.isEmpty())
+ if (ui->pushButton->text() == "启动服务")
{
- log_append("Please enter the port number to be guarded!");
- return;
- }
- QTextStream ts(&temp);
- QList portList;
- int port = 0;
- while (!ts.atEnd())
- {
- ts >> port;
-
- if (port < 1 || port > 65535)
+ QString temp = ui->txtPortList->toPlainText().trimmed();
+ if (temp.isEmpty())
{
- log_append("Illegal input detected! Please enter the correct port number!");
+ log_append("Please enter the port number to be guarded!(请输入要保护的端口号!)");
return;
}
+ QTextStream ts(&temp);
+ QList portList;
+ int port = 0;
+ while (!ts.atEnd())
+ {
+ ts >> port;
- portList.append(port);
- }
- if (portList.isEmpty())
- {
- log_append("Please enter the port number to be guarded!");
- return;
- }
- DaemonService::instance().setPortList(portList);
- qDebug("The service is starting up...");
- // 开始监听,绑定端口为8796
- if (DaemonService::instance().listen(QHostAddress::AnyIPv4, 8796))
- {
- qDebug("Service started successfully!");
- ui->txtPortList->setReadOnly(true);
- ui->pushButton->setEnabled(false);
+ if (port < 1 || port > 65535)
+ {
+ log_append("Illegal input detected! Please enter the correct port number!(检测到非法输入! 请输入正确的端口号!)");
+ return;
+ }
+
+ portList.append(port);
+ }
+ if (portList.isEmpty())
+ {
+ log_append("Please enter the port number to be guarded!(请输入要保护的端口号!)");
+ return;
+ }
+ DaemonService::instance().setPortList(portList);
+ qDebug("The service is starting up...(服务正在启动中...)");
+ // 开始监听,绑定端口为8796
+ if (DaemonService::instance().listen(QHostAddress::AnyIPv4, 8796))
+ {
+ qDebug("Service started successfully!(服务启动成功!)");
+ ui->txtPortList->setReadOnly(true);
+ ui->pushButton->setText("关闭服务");
+ }
+ else
+ {
+ qCritical() << ("Service startup failed with error message(服务启动失败,错误消息:):" + DaemonService::instance().errorString());
+ }
}
else
{
- qCritical() << ("Service startup failed with error message:" + DaemonService::instance().errorString());
+ qDebug("The service is shutting down...(服务正在关闭...)");
+ DaemonService::instance().close();
+ ui->txtPortList->setReadOnly(false);
+ ui->pushButton->setText("启动服务");
+ qDebug("Service closed!(服务已关闭)");
}
}
diff --git a/DaemonService/mainwindow.ui b/DaemonService/mainwindow.ui
index b04ad43..12ae0bd 100644
--- a/DaemonService/mainwindow.ui
+++ b/DaemonService/mainwindow.ui
@@ -53,9 +53,7 @@ p, li { white-space: pre-wrap; }
- 9876
-9877
-
+ 7001
diff --git a/DaemonService/md5.cpp b/DaemonService/md5.cpp
index d9884de..ab7370d 100644
--- a/DaemonService/md5.cpp
+++ b/DaemonService/md5.cpp
@@ -1,273 +1,394 @@
-/**
- * @file md5.cpp
- * @The implement of md5.
- * @author Jiewei Wei
- * @mail weijieweijerry@163.com
- * @github https://github.com/JieweiWei
- * @data Oct 19 2014
- *
- */
+#include
+#include
+#include
+#include
+#include
+#include "md5.h"
+/* POINTER defines a generic pointer type */
+typedef unsigned char *POINTER;
-#include "md5.h"
+/* UINT2 defines a two byte word */
+typedef unsigned short int UINT2;
-/* Define the static member of MD5. */
-const byte MD5::PADDING[64] = { 0x80 };
-const char MD5::HEX_NUMBERS[16] = {
- '0', '1', '2', '3',
- '4', '5', '6', '7',
- '8', '9', 'a', 'b',
- 'c', 'd', 'e', 'f'
+/* UINT4 defines a four byte word */
+typedef unsigned long int UINT4;
+
+#define PROTO_LIST(list) list
+
+/* MD5 context. */
+typedef struct _MD5_CTX
+{
+ UINT4 state[4]; /* state (ABCD) */
+ UINT4 count[2]; /* number of bits, modulo 2^64 (lsb first) */
+ unsigned char buffer[64]; /* input buffer */
+} MD5_CTX;
+
+/* Constants for MD5Transform routine.
+*/
+#define S11 7
+#define S12 12
+#define S13 17
+#define S14 22
+#define S21 5
+#define S22 9
+#define S23 14
+#define S24 20
+#define S31 4
+#define S32 11
+#define S33 16
+#define S34 23
+#define S41 6
+#define S42 10
+#define S43 15
+#define S44 21
+
+static unsigned char PADDING[64] = {
+0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
-/**
- * @Construct a MD5 object with a string.
- *
- * @param {message} the message will be transformed.
- *
- */
-MD5::MD5(const string& message) {
- finished = false;
- /* Reset number of bits. */
- count[0] = count[1] = 0;
- /* Initialization constants. */
- state[0] = 0x67452301;
- state[1] = 0xefcdab89;
- state[2] = 0x98badcfe;
- state[3] = 0x10325476;
-
- /* Initialization the object according to message. */
- init(reinterpret_cast(message.c_str()), message.length());
-}
-
-/**
- * @Generate md5 digest.
- *
- * @return the message-digest.
- *
- */
-const byte* MD5::getDigest() {
- if (!finished) {
- finished = true;
-
- byte bits[8];
- bit32 oldState[4];
- bit32 oldCount[2];
- bit32 index, padLen;
-
- /* Save current state and count. */
- memcpy(oldState, state, 16);
- memcpy(oldCount, count, 8);
-
- /* Save number of bits */
- encode(count, bits, 8);
-
- /* Pad out to 56 mod 64. */
- index = static_cast((count[0] >> 3) & 0x3f);
- padLen = (index < 56) ? (56 - index) : (120 - index);
- init(PADDING, padLen);
-
- /* Append length (before padding) */
- init(bits, 8);
-
- /* Store state in digest */
- encode(state, digest, 16);
-
- /* Restore current state and count. */
- memcpy(state, oldState, 16);
- memcpy(count, oldCount, 8);
- }
- return digest;
-}
-
-/**
- * @Initialization the md5 object, processing another message block,
- * and updating the context.
- *
- * @param {input} the input message.
- *
- * @param {len} the number btye of message.
- *
- */
-void MD5::init(const byte* input, size_t len) {
-
- bit32 i, index, partLen;
-
- finished = false;
-
- /* Compute number of bytes mod 64 */
- index = static_cast((count[0] >> 3) & 0x3f);
-
- /* update number of bits */
- if ((count[0] += (static_cast(len) << 3)) < (static_cast(len) << 3)) {
- ++count[1];
- }
- count[1] += (static_cast(len) >> 29);
-
- partLen = 64 - index;
-
- /* transform as many times as possible. */
- if (len >= partLen) {
-
- memcpy(&buffer[index], input, partLen);
- transform(buffer);
-
- for (i = partLen; i + 63 < len; i += 64) {
- transform(&input[i]);
- }
- index = 0;
-
- } else {
- i = 0;
- }
-
- /* Buffer remaining input */
- memcpy(&buffer[index], &input[i], len - i);
-}
-
-/**
- * @MD5 basic transformation. Transforms state based on block.
- *
- * @param {block} the message block.
- */
-void MD5::transform(const byte block[64]) {
-
- bit32 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
-
- decode(block, x, 64);
-
- /* Round 1 */
- FF (a, b, c, d, x[ 0], s11, 0xd76aa478);
- FF (d, a, b, c, x[ 1], s12, 0xe8c7b756);
- FF (c, d, a, b, x[ 2], s13, 0x242070db);
- FF (b, c, d, a, x[ 3], s14, 0xc1bdceee);
- FF (a, b, c, d, x[ 4], s11, 0xf57c0faf);
- FF (d, a, b, c, x[ 5], s12, 0x4787c62a);
- FF (c, d, a, b, x[ 6], s13, 0xa8304613);
- FF (b, c, d, a, x[ 7], s14, 0xfd469501);
- FF (a, b, c, d, x[ 8], s11, 0x698098d8);
- FF (d, a, b, c, x[ 9], s12, 0x8b44f7af);
- FF (c, d, a, b, x[10], s13, 0xffff5bb1);
- FF (b, c, d, a, x[11], s14, 0x895cd7be);
- FF (a, b, c, d, x[12], s11, 0x6b901122);
- FF (d, a, b, c, x[13], s12, 0xfd987193);
- FF (c, d, a, b, x[14], s13, 0xa679438e);
- FF (b, c, d, a, x[15], s14, 0x49b40821);
-
- /* Round 2 */
- GG (a, b, c, d, x[ 1], s21, 0xf61e2562);
- GG (d, a, b, c, x[ 6], s22, 0xc040b340);
- GG (c, d, a, b, x[11], s23, 0x265e5a51);
- GG (b, c, d, a, x[ 0], s24, 0xe9b6c7aa);
- GG (a, b, c, d, x[ 5], s21, 0xd62f105d);
- GG (d, a, b, c, x[10], s22, 0x2441453);
- GG (c, d, a, b, x[15], s23, 0xd8a1e681);
- GG (b, c, d, a, x[ 4], s24, 0xe7d3fbc8);
- GG (a, b, c, d, x[ 9], s21, 0x21e1cde6);
- GG (d, a, b, c, x[14], s22, 0xc33707d6);
- GG (c, d, a, b, x[ 3], s23, 0xf4d50d87);
- GG (b, c, d, a, x[ 8], s24, 0x455a14ed);
- GG (a, b, c, d, x[13], s21, 0xa9e3e905);
- GG (d, a, b, c, x[ 2], s22, 0xfcefa3f8);
- GG (c, d, a, b, x[ 7], s23, 0x676f02d9);
- GG (b, c, d, a, x[12], s24, 0x8d2a4c8a);
-
- /* Round 3 */
- HH (a, b, c, d, x[ 5], s31, 0xfffa3942);
- HH (d, a, b, c, x[ 8], s32, 0x8771f681);
- HH (c, d, a, b, x[11], s33, 0x6d9d6122);
- HH (b, c, d, a, x[14], s34, 0xfde5380c);
- HH (a, b, c, d, x[ 1], s31, 0xa4beea44);
- HH (d, a, b, c, x[ 4], s32, 0x4bdecfa9);
- HH (c, d, a, b, x[ 7], s33, 0xf6bb4b60);
- HH (b, c, d, a, x[10], s34, 0xbebfbc70);
- HH (a, b, c, d, x[13], s31, 0x289b7ec6);
- HH (d, a, b, c, x[ 0], s32, 0xeaa127fa);
- HH (c, d, a, b, x[ 3], s33, 0xd4ef3085);
- HH (b, c, d, a, x[ 6], s34, 0x4881d05);
- HH (a, b, c, d, x[ 9], s31, 0xd9d4d039);
- HH (d, a, b, c, x[12], s32, 0xe6db99e5);
- HH (c, d, a, b, x[15], s33, 0x1fa27cf8);
- HH (b, c, d, a, x[ 2], s34, 0xc4ac5665);
-
- /* Round 4 */
- II (a, b, c, d, x[ 0], s41, 0xf4292244);
- II (d, a, b, c, x[ 7], s42, 0x432aff97);
- II (c, d, a, b, x[14], s43, 0xab9423a7);
- II (b, c, d, a, x[ 5], s44, 0xfc93a039);
- II (a, b, c, d, x[12], s41, 0x655b59c3);
- II (d, a, b, c, x[ 3], s42, 0x8f0ccc92);
- II (c, d, a, b, x[10], s43, 0xffeff47d);
- II (b, c, d, a, x[ 1], s44, 0x85845dd1);
- II (a, b, c, d, x[ 8], s41, 0x6fa87e4f);
- II (d, a, b, c, x[15], s42, 0xfe2ce6e0);
- II (c, d, a, b, x[ 6], s43, 0xa3014314);
- II (b, c, d, a, x[13], s44, 0x4e0811a1);
- II (a, b, c, d, x[ 4], s41, 0xf7537e82);
- II (d, a, b, c, x[11], s42, 0xbd3af235);
- II (c, d, a, b, x[ 2], s43, 0x2ad7d2bb);
- II (b, c, d, a, x[ 9], s44, 0xeb86d391);
-
- state[0] += a;
- state[1] += b;
- state[2] += c;
- state[3] += d;
-}
-
-/**
-* @Encodes input (unsigned long) into output static_cast.
-*
-* @param {input} usigned long.
-*
-* @param {output} byte.
-*
-* @param {length} the length of input.
-*
+/* F, G, H and I are basic MD5 functions.
*/
-void MD5::encode(const bit32* input, byte* output, size_t length) {
+#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
+#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
+#define H(x, y, z) ((x) ^ (y) ^ (z))
+#define I(x, y, z) ((y) ^ ((x) | (~z)))
- for (size_t i = 0, j = 0; j < length; ++i, j += 4) {
- output[j]= static_cast(input[i] & 0xff);
- output[j + 1] = static_cast((input[i] >> 8) & 0xff);
- output[j + 2] = static_cast((input[i] >> 16) & 0xff);
- output[j + 3] = static_cast((input[i] >> 24) & 0xff);
- }
+/* ROTATE_LEFT rotates x left n bits.
+*/
+#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
+
+/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
+Rotation is separate from addition to prevent recomputation.
+*/
+#define FF(a, b, c, d, x, s, ac) { (a) += F ((b), (c), (d)) + (x) + (UINT4)(ac);(a) = ROTATE_LEFT ((a), (s)); (a) += (b);}
+#define GG(a, b, c, d, x, s, ac) {(a) += G ((b), (c), (d)) + (x) + (UINT4)(ac);(a) = ROTATE_LEFT ((a), (s)); (a) += (b); }
+#define HH(a, b, c, d, x, s, ac) {(a) += H ((b), (c), (d)) + (x) + (UINT4)(ac);(a) = ROTATE_LEFT ((a), (s)); (a) += (b);}
+#define II(a, b, c, d, x, s, ac) {(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac);(a) = ROTATE_LEFT ((a), (s));(a) += (b);}
+
+#define TEST_BLOCK_LEN 1000
+#define TEST_BLOCK_COUNT 1000
+
+static void MD5Transform PROTO_LIST((UINT4[4], unsigned char[64]));
+static void Encode PROTO_LIST((unsigned char *, UINT4 *, unsigned int));
+static void Decode PROTO_LIST((UINT4 *, unsigned char *, unsigned int));
+static void MD5_memcpy PROTO_LIST((POINTER, POINTER, unsigned int));
+static void MD5_memset PROTO_LIST((POINTER, int, unsigned int));
+static void MD5Init PROTO_LIST((MD5_CTX *));
+static void MD5Update PROTO_LIST((MD5_CTX *, unsigned char *, unsigned int));
+static void MD5Final PROTO_LIST((unsigned char[16], MD5_CTX *));
+static void MDTimeTrial PROTO_LIST((void));
+static void StringAddOne PROTO_LIST((char *));
+static void Encode PROTO_LIST((unsigned char *, UINT4 *, unsigned int));
+static void Decode PROTO_LIST((UINT4 *, unsigned char *, unsigned int));
+
+/* MD5 initialization. Begins an MD5 operation, writing a new context.
+*/
+static void MD5Init(MD5_CTX *context)
+{
+ context->count[0] = context->count[1] = 0;
+ /* Load magic initialization constants.
+ */
+ context->state[0] = 0x67452301;
+ context->state[1] = 0xefcdab89;
+ context->state[2] = 0x98badcfe;
+ context->state[3] = 0x10325476;
}
-/**
- * @Decodes input static_cast into output (usigned long).
- *
- * @param {input} bytes.
- *
- * @param {output} unsigned long.
- *
- * @param {length} the length of input.
- *
- */
-void MD5::decode(const byte* input, bit32* output, size_t length) {
- for (size_t i = 0, j = 0; j < length; ++i, j += 4) {
- output[i] = (static_cast(input[j])) | ((static_cast(input[j + 1])) << 8) |
- ((static_cast(input[j + 2])) << 16) | ((static_cast(input[j + 3])) << 24);
- }
+/* MD5 block update operation. Continues an MD5 message-digest
+operation, processing another message block, and updating the
+context.
+*/
+static void MD5Update(
+ MD5_CTX *context, /* context */
+ unsigned char *input, /* input block */
+ unsigned int inputLen /* length of input block */
+)
+{
+ unsigned int i, index, partLen;
+
+ /* Compute number of bytes mod 64 */
+ index = (unsigned int)((context->count[0] >> 3) & 0x3F);
+
+ /* Update number of bits */
+ if ((context->count[0] += ((UINT4)inputLen << 3))
+ < ((UINT4)inputLen << 3))
+ context->count[1]++;
+ context->count[1] += ((UINT4)inputLen >> 29);
+
+ partLen = 64 - index;
+
+ /* Transform as many times as possible.
+ */
+ if (inputLen >= partLen) {
+ MD5_memcpy
+ ((POINTER)&context->buffer[index], (POINTER)input, partLen);
+ MD5Transform(context->state, context->buffer);
+
+ for (i = partLen; i + 63 < inputLen; i += 64)
+ MD5Transform(context->state, &input[i]);
+
+ index = 0;
+ }
+ else
+ i = 0;
+
+ /* Buffer remaining input */
+ MD5_memcpy
+ ((POINTER)&context->buffer[index], (POINTER)&input[i],
+ inputLen - i);
}
+/* MD5 finalization. Ends an MD5 message-digest operation, writing the
+the message digest and zeroizing the context.
+*/
+static void MD5Final(
+ unsigned char digest[16], /* message digest */
+ MD5_CTX *context /* context */
+)
+{
+ unsigned char bits[8];
+ unsigned int index, padLen;
-/**
- * @Convert digest to string value.
- *
- * @return the hex string of digest.
- *
- */
-string MD5::toStr() {
- const byte* digest_ = getDigest();
- string str;
- str.reserve(16 << 1);
- for (size_t i = 0; i < 16; ++i) {
- int t = digest_[i];
- int a = t / 16;
- int b = t % 16;
- str.append(1, HEX_NUMBERS[a]);
- str.append(1, HEX_NUMBERS[b]);
- }
- return str;
+ /* Save number of bits */
+ Encode(bits, context->count, 8);
+
+ /* Pad out to 56 mod 64.
+ */
+ index = (unsigned int)((context->count[0] >> 3) & 0x3f);
+ padLen = (index < 56) ? (56 - index) : (120 - index);
+ MD5Update(context, PADDING, padLen);
+
+ /* Append length (before padding) */
+ MD5Update(context, bits, 8);
+
+ /* Store state in digest */
+ Encode(digest, context->state, 16);
+
+ /* Zeroize sensitive information.
+ */
+ MD5_memset((POINTER)context, 0, sizeof(*context));
+}
+
+/* MD5 basic transformation. Transforms state based on block.
+*/
+static void MD5Transform(
+ UINT4 state[4],
+ unsigned char block[64]
+)
+{
+ UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
+
+ Decode(x, block, 64);
+
+ /* Round 1 */
+ FF(a, b, c, d, x[0], S11, 0xd76aa478); /* 1 */
+ FF(d, a, b, c, x[1], S12, 0xe8c7b756); /* 2 */
+ FF(c, d, a, b, x[2], S13, 0x242070db); /* 3 */
+ FF(b, c, d, a, x[3], S14, 0xc1bdceee); /* 4 */
+ FF(a, b, c, d, x[4], S11, 0xf57c0faf); /* 5 */
+ FF(d, a, b, c, x[5], S12, 0x4787c62a); /* 6 */
+ FF(c, d, a, b, x[6], S13, 0xa8304613); /* 7 */
+ FF(b, c, d, a, x[7], S14, 0xfd469501); /* 8 */
+ FF(a, b, c, d, x[8], S11, 0x698098d8); /* 9 */
+ FF(d, a, b, c, x[9], S12, 0x8b44f7af); /* 10 */
+ FF(c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
+ FF(b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
+ FF(a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
+ FF(d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
+ FF(c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
+ FF(b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
+
+ /* Round 2 */
+ GG(a, b, c, d, x[1], S21, 0xf61e2562); /* 17 */
+ GG(d, a, b, c, x[6], S22, 0xc040b340); /* 18 */
+ GG(c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
+ GG(b, c, d, a, x[0], S24, 0xe9b6c7aa); /* 20 */
+ GG(a, b, c, d, x[5], S21, 0xd62f105d); /* 21 */
+ GG(d, a, b, c, x[10], S22, 0x2441453); /* 22 */
+ GG(c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
+ GG(b, c, d, a, x[4], S24, 0xe7d3fbc8); /* 24 */
+ GG(a, b, c, d, x[9], S21, 0x21e1cde6); /* 25 */
+ GG(d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
+ GG(c, d, a, b, x[3], S23, 0xf4d50d87); /* 27 */
+ GG(b, c, d, a, x[8], S24, 0x455a14ed); /* 28 */
+ GG(a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
+ GG(d, a, b, c, x[2], S22, 0xfcefa3f8); /* 30 */
+ GG(c, d, a, b, x[7], S23, 0x676f02d9); /* 31 */
+ GG(b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
+
+ /* Round 3 */
+ HH(a, b, c, d, x[5], S31, 0xfffa3942); /* 33 */
+ HH(d, a, b, c, x[8], S32, 0x8771f681); /* 34 */
+ HH(c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
+ HH(b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
+ HH(a, b, c, d, x[1], S31, 0xa4beea44); /* 37 */
+ HH(d, a, b, c, x[4], S32, 0x4bdecfa9); /* 38 */
+ HH(c, d, a, b, x[7], S33, 0xf6bb4b60); /* 39 */
+ HH(b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
+ HH(a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
+ HH(d, a, b, c, x[0], S32, 0xeaa127fa); /* 42 */
+ HH(c, d, a, b, x[3], S33, 0xd4ef3085); /* 43 */
+ HH(b, c, d, a, x[6], S34, 0x4881d05); /* 44 */
+ HH(a, b, c, d, x[9], S31, 0xd9d4d039); /* 45 */
+ HH(d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
+ HH(c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
+ HH(b, c, d, a, x[2], S34, 0xc4ac5665); /* 48 */
+
+ /* Round 4 */
+ II(a, b, c, d, x[0], S41, 0xf4292244); /* 49 */
+ II(d, a, b, c, x[7], S42, 0x432aff97); /* 50 */
+ II(c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
+ II(b, c, d, a, x[5], S44, 0xfc93a039); /* 52 */
+ II(a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
+ II(d, a, b, c, x[3], S42, 0x8f0ccc92); /* 54 */
+ II(c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
+ II(b, c, d, a, x[1], S44, 0x85845dd1); /* 56 */
+ II(a, b, c, d, x[8], S41, 0x6fa87e4f); /* 57 */
+ II(d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
+ II(c, d, a, b, x[6], S43, 0xa3014314); /* 59 */
+ II(b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
+ II(a, b, c, d, x[4], S41, 0xf7537e82); /* 61 */
+ II(d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
+ II(c, d, a, b, x[2], S43, 0x2ad7d2bb); /* 63 */
+ II(b, c, d, a, x[9], S44, 0xeb86d391); /* 64 */
+
+ state[0] += a;
+ state[1] += b;
+ state[2] += c;
+ state[3] += d;
+
+ /* Zeroize sensitive information.
+ */
+ MD5_memset((POINTER)x, 0, sizeof(x));
+}
+
+/* Encodes input (UINT4) into output (unsigned char). Assumes len is
+a multiple of 4.
+*/
+static void Encode(
+ unsigned char *output,
+ UINT4 *input,
+ unsigned int len
+)
+{
+ unsigned int i, j;
+
+ for (i = 0, j = 0; j < len; i++, j += 4) {
+ output[j] = (unsigned char)(input[i] & 0xff);
+ output[j + 1] = (unsigned char)((input[i] >> 8) & 0xff);
+ output[j + 2] = (unsigned char)((input[i] >> 16) & 0xff);
+ output[j + 3] = (unsigned char)((input[i] >> 24) & 0xff);
+ }
+}
+
+/* Decodes input (unsigned char) into output (UINT4). Assumes len is
+a multiple of 4.
+*/
+static void Decode(
+ UINT4 *output,
+ unsigned char *input,
+ unsigned int len
+)
+{
+ unsigned int i, j;
+
+ for (i = 0, j = 0; j < len; i++, j += 4)
+ output[i] = ((UINT4)input[j]) | (((UINT4)input[j + 1]) << 8) |
+ (((UINT4)input[j + 2]) << 16) | (((UINT4)input[j + 3]) << 24);
+}
+
+/* Note: Replace "for loop" with standard memcpy if possible.
+*/
+static void MD5_memcpy(
+ POINTER output,
+ POINTER input,
+ unsigned int len
+)
+{
+ unsigned int i;
+
+ for (i = 0; i < len; i++)
+ output[i] = input[i];
+}
+
+/* Note: Replace "for loop" with standard memset if possible.
+*/
+static void MD5_memset(
+ POINTER output,
+ int value,
+ unsigned int len
+)
+{
+ unsigned int i;
+
+ for (i = 0; i < len; i++)
+ ((char *)output)[i] = (char)value;
+}
+
+/* Digests a string and prints the result.
+*/
+char* MD5String(char *string, unsigned int len)
+{
+ MD5_CTX context;
+ unsigned char digest[16];
+ char output1[33];
+ static char output[33] = { "" };
+ int i;
+
+ MD5Init(&context);
+ MD5Update(&context, (unsigned char*)string, len);
+ MD5Final(digest, &context);
+
+ for (i = 0; i < 16; i++)
+ {
+ sprintf(&(output1[2 * i]), "%02x", (unsigned char)digest[i]);
+ sprintf(&(output1[2 * i + 1]), "%02x", (unsigned char)(digest[i] << 4));
+ }
+ for (i = 0; i < 32; i++)
+ {
+ output[i] = output1[i];
+ }
+ return output;
+}
+
+/* get the string add one.
+*/
+static void StringAddOne(char * orstring)
+{
+ unsigned int len;
+ int i, n;
+
+ len = strlen(orstring);
+ n = len - 1;
+ for (i = n; i >= 0; i--)
+ {
+ if (orstring[i] == '9')
+ {
+ orstring[i] = 'A';
+ break;
+ }
+ else if (orstring[i] == 'Z')
+ {
+ orstring[i] = 'a';
+ break;
+ }
+ else if (orstring[i] == 'z')
+ {
+ orstring[i] = '0';
+ continue;
+ }
+ else
+ orstring[i] += 1;
+ break;
+ }
+}
+
+/* check the md5 strings one by one,get the password.
+*/
+bool MD5Check(char *md5string, char* string, unsigned int stringlen)
+{
+ return strcmp(md5string, MD5String(string, stringlen)) == 0;
}
diff --git a/DaemonService/md5.h b/DaemonService/md5.h
index 958d839..67ec8b5 100644
--- a/DaemonService/md5.h
+++ b/DaemonService/md5.h
@@ -1,136 +1,10 @@
-/**
- * @file md5.h
- * @The header file of md5.
- * @author Jiewei Wei
- * @mail weijieweijerry@163.com
- * @github https://github.com/JieweiWei
- * @data Oct 19 2014
- *
- */
+#ifndef __MD5_H_
+#define __MD5_H_
-#ifndef MD5_H
-#define MD5_H
+char* MD5String( char* string ,unsigned int stringlen);
-/* Parameters of MD5. */
-#define s11 7
-#define s12 12
-#define s13 17
-#define s14 22
-#define s21 5
-#define s22 9
-#define s23 14
-#define s24 20
-#define s31 4
-#define s32 11
-#define s33 16
-#define s34 23
-#define s41 6
-#define s42 10
-#define s43 15
-#define s44 21
-/**
- * @Basic MD5 functions.
- *
- * @param there bit32.
- *
- * @return one bit32.
- */
-#define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
-#define G(x, y, z) (((x) & (z)) | ((y) & (~z)))
-#define H(x, y, z) ((x) ^ (y) ^ (z))
-#define I(x, y, z) ((y) ^ ((x) | (~z)))
+bool MD5Check( char *md5string, char* string ,unsigned int stringlen);
-/**
- * @Rotate Left.
- *
- * @param {num} the raw number.
- *
- * @param {n} rotate left n.
- *
- * @return the number after rotated left.
- */
-#define ROTATELEFT(num, n) (((num) << (n)) | ((num) >> (32-(n))))
-
-/**
- * @Transformations for rounds 1, 2, 3, and 4.
- */
-#define FF(a, b, c, d, x, s, ac) { \
- (a) += F ((b), (c), (d)) + (x) + ac; \
- (a) = ROTATELEFT ((a), (s)); \
- (a) += (b); \
-}
-#define GG(a, b, c, d, x, s, ac) { \
- (a) += G ((b), (c), (d)) + (x) + ac; \
- (a) = ROTATELEFT ((a), (s)); \
- (a) += (b); \
-}
-#define HH(a, b, c, d, x, s, ac) { \
- (a) += H ((b), (c), (d)) + (x) + ac; \
- (a) = ROTATELEFT ((a), (s)); \
- (a) += (b); \
-}
-#define II(a, b, c, d, x, s, ac) { \
- (a) += I ((b), (c), (d)) + (x) + ac; \
- (a) = ROTATELEFT ((a), (s)); \
- (a) += (b); \
-}
-
-#include
-
-using std::string;
-
-/* Define of btye.*/
-typedef unsigned char byte;
-/* Define of byte. */
-typedef unsigned int bit32;
-
-class MD5 {
-public:
- /* Construct a MD5 object with a string. */
- MD5(const string& message);
-
- /* Generate md5 digest. */
- const byte* getDigest();
-
- /* Convert digest to string value */
- string toStr();
-
-private:
- /* Initialization the md5 object, processing another message block,
- * and updating the context.*/
- void init(const byte* input, size_t len);
-
- /* MD5 basic transformation. Transforms state based on block. */
- void transform(const byte block[64]);
-
- /* Encodes input (usigned long) into output (byte). */
- void encode(const bit32* input, byte* output, size_t length);
-
- /* Decodes input (byte) into output (usigned long). */
- void decode(const byte* input, bit32* output, size_t length);
-
-private:
- /* Flag for mark whether calculate finished. */
- bool finished;
-
- /* state (ABCD). */
- bit32 state[4];
-
- /* number of bits, low-order word first. */
- bit32 count[2];
-
- /* input buffer. */
- byte buffer[64];
-
- /* message digest. */
- byte digest[16];
-
- /* padding for calculate. */
- static const byte PADDING[64];
-
- /* Hex numbers. */
- static const char HEX_NUMBERS[16];
-};
-#endif // MD5_H
+#endif //_MD5_H_
diff --git a/DaemonService/res.qrc b/DaemonService/res.qrc
new file mode 100644
index 0000000..4e72c4f
--- /dev/null
+++ b/DaemonService/res.qrc
@@ -0,0 +1,5 @@
+
+
+ Daemon.ico
+
+
diff --git a/DaemonService/worker.cpp b/DaemonService/worker.cpp
index 9971243..2e6a4ec 100644
--- a/DaemonService/worker.cpp
+++ b/DaemonService/worker.cpp
@@ -1,6 +1,7 @@
#include
#include
#include
+#include
#include
#include "worker.h"
#include "md5.h"
@@ -15,16 +16,16 @@ void Worker::run()
this->m_socket->setSocketDescriptor(this->m_socketDescriptor);
if (!this->m_socket->waitForConnected(100000))
{
- qDebug("IP:%s Connect Fail", m_socket->peerAddress().toString().toStdString().data());
+ qDebug("IP:%s Connect Fail(该IP连接失败)", m_socket->peerAddress().toString().toStdString().data());
return;
}
std::string ip = m_socket->peerAddress().toString().toStdString();
- qDebug("IP:%s Connect Success, Waiting for verification...", ip.data());
+ qDebug("IP:%s Connect Success, Waiting for verification...(该IP连接成功,等待发送校验信息)", ip.data());
if (this->m_socket->waitForReadyRead(3000))
{
QByteArray data = this->m_socket->readAll();
- qDebug("IP:%s send data:'%s' ---- Verifying password...", ip.data(), data.toStdString().data());
+ qDebug("IP:%s send data:'%s' ---- Verifying password...(正在校验中...)", ip.data(), data.toStdString().data());
QString ip = this->m_socket->peerAddress().toString();
// 校验
@@ -34,9 +35,11 @@ void Worker::run()
// + ip.toStdString()
// + "ioer6719024yoiuew6f178934056").toStr()
// + "sjavlkc907*$!@(.12i.dy1").toStr())
- if (data.toStdString() == "0d87e84deb68ae435735e0f8ae4668b0")
+ QString password = ip + "asdfas35.v;cxv-123ioer6719024yosjavlkc907*$!@(.12i.dy1iuew6f178934056xck3dy$^@1309uyrew";
+
+ if (MD5Check(const_cast(data.toStdString().data()), const_cast(password.toStdString().data()), password.toStdString().length()))
{
- qDebug("Verify successful");
+ qDebug("Verify successful!(校验成功!)");
auto list = DAL::instance().getWhiteList(ip);
for (int port : this->m_portList)
@@ -52,7 +55,7 @@ void Worker::run()
}
if (!flag)
{
- qDebug("Add to whitelists...");
+ qDebug("Add to whitelists...(正在将该IP添加到白名单...)");
// 添加到白名单中
QProcess p(nullptr);
p.start("netsh",
@@ -72,30 +75,30 @@ void Worker::run()
}
else
{
- qDebug("Update last login time...");
+ qDebug("Update last login time...(检测到该IP已在白名单,更新其最后上线时间...)");
}
}
if (DAL::instance().updateWhiteList(ip, this->m_portList))
- qDebug("Update completed!");
+ qDebug("Update completed!(更新完成!)");
else
- qWarning("Update failed!");
+ qWarning("Update failed!(更新失败)");
}
else
{
- qWarning("Verification failed");
+ qWarning("Verification failed!(校验失败!)");
// 校验失败,若不是算法问题,则可能是其他人想猜密码
}
}
else
{
- qDebug("Check timeout");
+ qWarning("Check timeout(超过指定时间未发送任何消息,超时!)");
// 这个连接连上以后不发任何消息,说明不是登录器的socket
// 登录器的socket会在连接后立刻发送校验数据
// 所以将这个IP进行记录,当这个IP累计超过一定数量次连接,则将其拉黑
// TODO:拉黑
}
- qDebug("Close Socket connection");
+ qDebug("Close Socket connection(关闭Socket连接)");
// 关闭socket连接
this->m_socket->close();
this->m_socket->deleteLater();