Quellcode durchsuchen

Z991239-958 #comment fix:在linux ram上调试通过

雷志明80280620 vor 4 Jahren
Ursprung
Commit
f336f79596

+ 65 - 2
Module/mod_Initializer/comm.cpp

@@ -233,11 +233,12 @@ char* Str2Hex(const char* src, int srcLen)
 
 	bool get_cpu_id_by_asm(std::string& cpu_id)
 	{
+		/*
 		cpu_id.clear();
 
 		unsigned int s1 = 0;
 		unsigned int s2 = 0;
-		asm volatile
+		__asm volatile
 			(
 				"movl $0x01, %%eax; \n\t"
 				"xorl %%edx, %%edx; \n\t"
@@ -255,10 +256,72 @@ char* Str2Hex(const char* src, int srcLen)
 		char cpu[32] = { 0 };
 		snprintf(cpu, sizeof(cpu), "%08X%08X", htonl(s2), htonl(s1));
 		std::string(cpu).swap(cpu_id);
-
+		*/
 		return(true);
 	}
 
+	void parse_cpu_id(const char* file_name, const char* match_words, std::string& cpu_id)
+	{
+		cpu_id.c_str();
+
+		std::ifstream ifs(file_name, std::ios::binary);
+		if (!ifs.is_open())
+		{
+			return;
+		}
+
+		char line[4096] = { 0 };
+		while (!ifs.eof())
+		{
+			ifs.getline(line, sizeof(line));
+			if (!ifs.good())
+			{
+				break;
+			}
+
+			const char* cpu = strstr(line, match_words);
+			if (NULL == cpu)
+			{
+				continue;
+			}
+			cpu += strlen(match_words);
+
+			while ('\0' != cpu[0])
+			{
+				if (' ' != cpu[0])
+				{
+					cpu_id.push_back(cpu[0]);
+				}
+				++cpu;
+			}
+
+			if (!cpu_id.empty())
+			{
+				break;
+			}
+		}
+
+		ifs.close();
+	}
+
+	bool get_cpu_id_by_system(std::string& cpu_id)
+	{
+		cpu_id.c_str();
+
+		const char* dmidecode_result = ".dmidecode_result.txt";
+		char command[512] = { 0 };
+		snprintf(command, sizeof(command), "dmidecode -t 4 | grep ID > %s", dmidecode_result);
+
+		if (0 == system(command))
+		{
+			parse_cpu_id(dmidecode_result, "ID:", cpu_id);
+		}
+
+		unlink(dmidecode_result);
+
+		return(!cpu_id.empty());
+	}
+
 	void parse_board_serial(const char* file_name, const char* match_words, std::string& board_serial)
 	{
 		board_serial.c_str();

+ 1 - 0
Module/mod_Initializer/comm.h

@@ -48,6 +48,7 @@ char* Str2Hex(const char* str, int strLen);
 #include <unistd.h>
 	int getIPFromLinux(char* ip);
 	bool get_cpu_id_by_asm(std::string& cpu_id);
+	bool get_cpu_id_by_system(std::string& cpu_id);
 	bool get_board_serial_by_system(std::string& board_serial);
 	bool get_disk_serial_by_system(std::vector<string>& serial_no);
 	bool file_is_exist(string filePath);

+ 2 - 1
Module/mod_Initializer/mod_Initializer.cpp

@@ -2133,7 +2133,8 @@ bool CInitializerEntity::GetTerminalFingerPrint(BYTE *pBuf, int &nBufLen)
 #ifdef RVC_OS_WIN
 	if (!QueryWMIDevice(Processor, "ProcessorId", szTmp, &nTmpBufLen))
 #else
-	if(!get_cpu_id_by_asm(strTmp))
+	//if(!get_cpu_id_by_asm(strTmp))
+	if(!get_cpu_id_by_system(strTmp))
 #endif // RVC_OS_WIN
 	{
 		LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_GET_PROCCESSOR_ID,

+ 64 - 1
Module/mod_accessauth/comm.cpp

@@ -240,6 +240,7 @@ char* Str2Hex(const char* src, int srcLen)
 
 	bool get_cpu_id_by_asm(std::string& cpu_id)
 	{
+		/*
 		cpu_id.clear();
 
 		unsigned int s1 = 0;
@@ -262,10 +263,72 @@ char* Str2Hex(const char* src, int srcLen)
 		char cpu[32] = { 0 };
 		snprintf(cpu, sizeof(cpu), "%08X%08X", htonl(s2), htonl(s1));
 		std::string(cpu).swap(cpu_id);
-
+		*/
 		return(true);
 	}
 
+	void parse_cpu_id(const char* file_name, const char* match_words, std::string& cpu_id)
+	{
+		cpu_id.c_str();
+
+		std::ifstream ifs(file_name, std::ios::binary);
+		if (!ifs.is_open())
+		{
+			return;
+		}
+
+		char line[4096] = { 0 };
+		while (!ifs.eof())
+		{
+			ifs.getline(line, sizeof(line));
+			if (!ifs.good())
+			{
+				break;
+			}
+
+			const char* cpu = strstr(line, match_words);
+			if (NULL == cpu)
+			{
+				continue;
+			}
+			cpu += strlen(match_words);
+
+			while ('\0' != cpu[0])
+			{
+				if (' ' != cpu[0])
+				{
+					cpu_id.push_back(cpu[0]);
+				}
+				++cpu;
+			}
+
+			if (!cpu_id.empty())
+			{
+				break;
+			}
+		}
+
+		ifs.close();
+	}
+
+	bool get_cpu_id_by_system(std::string& cpu_id)
+	{
+		cpu_id.c_str();
+
+		const char* dmidecode_result = ".dmidecode_result.txt";
+		char command[512] = { 0 };
+		snprintf(command, sizeof(command), "dmidecode -t 4 | grep ID > %s", dmidecode_result);
+
+		if (0 == system(command))
+		{
+			parse_cpu_id(dmidecode_result, "ID:", cpu_id);
+		}
+
+		unlink(dmidecode_result);
+
+		return(!cpu_id.empty());
+	}
+
 	void parse_board_serial(const char* file_name, const char* match_words, std::string& board_serial)
 	{
 		board_serial.c_str();

+ 1 - 0
Module/mod_accessauth/comm.h

@@ -56,6 +56,7 @@ char* Str2Hex(const char* str, int strLen);
 #include <unistd.h>
 int getIPFromLinux(char* ip);
 bool get_cpu_id_by_asm(std::string & cpu_id);
+bool get_cpu_id_by_system(std::string& cpu_id);
 bool get_board_serial_by_system(std::string & board_serial);
 bool get_disk_serial_by_system(std::vector<string> & serial_no);
 bool file_is_exist(string filePath);

+ 28 - 16
Module/mod_accessauth/mod_AccessAuth.cpp

@@ -1273,15 +1273,15 @@ bool CAccessAuthEntity::GetTerminalFingerPrint(BYTE *pBuf, int &nBufLen)
 #ifdef RVC_OS_WIN
 		if (!QueryWMIDevice(Processor, "ProcessorId", szTmp, &nTmpBufLen))
 #else
-		if (!get_cpu_id_by_asm(strTmp))
+		//if (!get_cpu_id_by_asm(strTmp))
+	if (!get_cpu_id_by_system(strTmp))
 #endif // RVC_OS_WIN
 	{
-		strErrMsg = CSimpleStringA::Format("query cpu id fail: %d, 请重启设备", GetLastError());
+		strErrMsg = CSimpleStringA::Format("查询CPU ID失败,请重启机器并重新初始化");
 		SetAuthErrMsg((const char *)strErrMsg);
 		spFunction->SetSysVar("AuthErrMsg", (const char *)strErrMsg, true);
-		//LogError(Severity_Low, Error_Unexpect, ERROR_ACCESSAUTH_GETCPUID, (const char *)strErrMsg);
 		LogWarn(Severity_Middle, Error_Unexpect, ERR_ACCESSAUTH_GET_TERMINAL_FINGERPRINT,
-			GetOutPutStr("%s%s%s%d", "QueryWMIDevice", "False", "Processor", GetLastError()).c_str());
+			GetOutPutStr("%s%s", "Processor", "False").c_str());
 		return false;
 	}
 	
@@ -1298,14 +1298,15 @@ bool CAccessAuthEntity::GetTerminalFingerPrint(BYTE *pBuf, int &nBufLen)
 	if (!get_board_serial_by_system(strTmp))
 #endif // RVC_OS_WIN
 	{
-		strErrMsg = CSimpleStringA::Format("query baseboard sn fail: %d, 请重启设备", GetLastError());
+		strErrMsg = CSimpleStringA::Format("查询主板序列号失败,  请重启机器并重新初始化");
 		SetAuthErrMsg((const char *)strErrMsg);
 		spFunction->SetSysVar("AuthErrMsg", (const char *)strErrMsg, true);
-		//LogError(Severity_Low, Error_Unexpect, ERROR_ACCESSAUTH_GETBASEBOARDSN, (const char *)strErrMsg);
 		LogWarn(Severity_Middle, Error_Unexpect, ERR_ACCESSAUTH_GET_TERMINAL_FINGERPRINT,
-			GetOutPutStr("%s%s%s%d", "QueryWMIDevice", "False", "BaseBoard", GetLastError()).c_str());
+			GetOutPutStr("%s%s", "BaseBoard", "False").c_str());
 		return false;
 	}
+	strRet += "|";
+
 #ifdef RVC_OS_WIN
 	//Dbg("baseboard sn: %s", szTmp);
 	strRet += szTmp;
@@ -1313,24 +1314,35 @@ bool CAccessAuthEntity::GetTerminalFingerPrint(BYTE *pBuf, int &nBufLen)
 	memset(szTmp, 0, sizeof(szTmp));
 	if (!QueryWMIDevice(DiskDrive, "SerialNumber", szTmp, &nTmpBufLen))
 #else
-		Dbg("baseboard sn: %s", strTmp.c_str());
+	Dbg("baseboard sn: %s", strTmp.c_str());
 	strRet += strTmp.c_str();
 	vector<string> disk;
+
 	if (!get_disk_serial_by_system(disk))
 #endif // RVC_OS_WIN
 	{
-		strErrMsg = CSimpleStringA::Format("query harddisk sn fail: %d, 请重启设备", GetLastError());
-		SetAuthErrMsg((const char *)strErrMsg);
-		spFunction->SetSysVar("AuthErrMsg", (const char *)strErrMsg, true);
-		//LogError(Severity_Low, Error_Unexpect, ERROR_ACCESSAUTH_DISKDRIVESN, (const char *)strErrMsg);
-		LogWarn(Severity_Middle, Error_Unexpect, ERR_ACCESSAUTH_GET_TERMINAL_FINGERPRINT,
-			GetOutPutStr("%s%s%s%d", "QueryWMIDevice", "False", "DiskDrive", GetLastError()).c_str());
+		strErrMsg = CSimpleStringA::Format("查询磁盘序列号失败, 请重启机器并重新初始化");
+		SetAuthErrMsg((const char*)strErrMsg);
+		spFunction->SetSysVar("AuthErrMsg", (const char*)strErrMsg, true);
+		LogWarn(Severity_Middle, Error_Unexpect, ERR_INITIALIZER_GET_DISKDRIVE_ID,
+			GetOutPutStr("%s%s", "DiskDrive", "False").c_str());
 		return false;
 	}
-	//Dbg("harddisk sn: %s", szTmp);
-
 	strRet += "|";
+
+#ifdef RVC_OS_WIN
+	//Dbg("harddisk sn: %s", szTmp);
 	strRet += szTmp;
+#else
+	strTmp = "";
+	vector<string>::iterator it = disk.begin();
+	while (it != disk.end()) {
+		strTmp += *it;
+		it++;
+	}
+	Dbg("harddisk sn: %s", strTmp.c_str());
+	strRet += strTmp.c_str();
+#endif // RVC_OS_WIN
 
 	Dbg("device info: [%s]", (const char*)strRet);