Explorar o código

Z991239-2059 #comment 修改获取硬盘序号的代码(其他后续有空再看)

杨诗友80174847 %!s(int64=4) %!d(string=hai) anos
pai
achega
fd1d602d85
Modificáronse 2 ficheiros con 24 adicións e 8 borrados
  1. 23 8
      Module/mod_Initializer/comm.cpp
  2. 1 0
      Tool/guardian/guardian.cpp

+ 23 - 8
Module/mod_Initializer/comm.cpp

@@ -1,6 +1,13 @@
 #include "comm.h"
 #include <cstdarg>
 #define MAX_PATH_SIZE 256
+#ifdef RVC_OS_WIN
+#else
+#include <sys/ioctl.h>
+#include <sys/stat.h>
+#include <linux/hdreg.h>
+#include <sys/fcntl.h>
+#endif //RVC_OS_WIN
 void GetNewForm(const char* form, char* newForm) {
 	int indexNum = 0;
 	int acount = 0;
@@ -448,15 +455,23 @@ char* Str2Hex(const char* src, int srcLen)
 		strcpy(lshw_result, save_path.c_str());
 		strcat(lshw_result, "/.lshw_result.txt");
 		
-		char command[512] = { 0 };
-		snprintf(command, sizeof(command), "lshw -class disk | grep serial > %s", lshw_result);
-
-		if (0 == system(command))
-		{
-			get_disk_serial(lshw_result, "serial:", serial_no);
-		}
-		else {
+		//char command[512] = { 0 };
+		//snprintf(command, sizeof(command), "lshw -class disk | grep serial > %s", lshw_result);
+
+		//if (0 == system(command))
+		//{
+		//	get_disk_serial(lshw_result, "serial:", serial_no);
+		//}
+		//else {
+		//	return false;
+		//}
+		struct hd_driveid id;
+		int fd = open("/dev/hda", O_RDONLY|O_NONBLOCK);
+		if (fd < 0)
 			return false;
+		if (!ioctl(fd, HDIO_GET_IDENTITY, &id))
+		{
+			serial_no.push_back((const char*)(id.serial_no));
 		}
 		unlink(lshw_result);
 

+ 1 - 0
Tool/guardian/guardian.cpp

@@ -592,6 +592,7 @@ void DataProcessLinux(int socket,const char*data)
 {
 	GuardianInfo* pInfo = (GuardianInfo*)data;
 	LogToFile(false, true, false, "eType:", "", pInfo->eType);
+	LogToFile(false, true, false, "dwParam1:", "", pInfo->dwParam1);
 	cout << "eType:" << pInfo->eType << ",p1:" <<  pInfo->dwParam1 << ",p2:" << pInfo->dwParam2 << ",dwSize:" << pInfo->dwSize << endl;
 	//LogToFile(false,true,false,"clientsocket:", "", pPerHandleData->Socket);
 	switch (pInfo->eType)