Пример #1
0
bool SpoofHDSN(const HDSNInfo& originSN, const HDSNInfo& newSN)
{
	HKEY key;
	LONG rst = RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("SYSTEM\\CurrentControlSet\\services\\snspoofer")
		, 0, KEY_WOW64_64KEY | KEY_WRITE, &key);
	if (ERROR_SUCCESS != rst) {
		return false;
	}

	bool ret = false;
	do
	{
		TCHAR str[4];
		str[0] = 's';
		str[1] = 'n';
		str[2] = '0';
		str[3] = 0;

		TCHAR buf[82 + 1];
		TCHAR* ptr;
		DWORD cb = 82 * sizeof(TCHAR);
		int i = 0;
		for (; i < newSN.count; i++)
		{
			str[2] = '0' + i;
			ptr = buf;
			ToHexStr(originSN.sn[i], SN_MAX_LEN, ptr);
			ptr += (SN_MAX_LEN * 2);
			*ptr++ = '|';
			ToHexStr(newSN.sn[i], SN_MAX_LEN, ptr);
			ptr += (SN_MAX_LEN * 2);
			*ptr++ = 0;

			rst = RegSetValueEx(key, str, 0, REG_SZ, (const BYTE*)buf, cb);
			if (rst != ERROR_SUCCESS) {
				break;
			}
		}
		if (i == newSN.count) {
			ret = true;
		}
	} while (0);

	if (key) {
		RegCloseKey(key);
	}
	return ret;
}
Пример #2
0
	std::string TransformSpecial (char c)
	{
		if (IsAscii (c))
		{
			switch (c)
			{
			case 34:
				return Quot;
			case 38:
				return Amp;
			case 39:
				return Apos;
			case 60:
				return Lt;
			case 62:
				return Gt;
			default:
				Assert (!"Character is not special!");
				return Quot;
			};
		}
		else
		{
			std::string encodedUpperAscii ("&#x");
			encodedUpperAscii += ToHexStr (c);
			
			encodedUpperAscii += ';';
			return encodedUpperAscii;
		}
	}
Пример #3
0
//将数据写入文件
void CIOCPModel::WriteDataToFile(char *pData, DWORD dwLen)
{
	EnterCriticalSection(&m_csDataFile);
	string strFilePath = "C:\\IOServer日志\\";
	//判断文件是否存在
	if (_access(strFilePath.c_str(), 0) == -1)
	{
		//目录不存在,创建目录
		if (_mkdir(strFilePath.c_str()) == -1)
		{
			LeaveCriticalSection(&m_csDataFile);
			MessageBox(NULL, L"无法创建日志文件", L"错误", MB_OK | MB_ICONERROR);
			return;
		}
	}

	SYSTEMTIME st;
	GetLocalTime(&st);
	char szTime[20] = { 0 };
	sprintf_s(szTime, "大表%d_%02d_%02d.data", st.wYear, st.wMonth, st.wDay);
	strFilePath += szTime;
	//追加只写
	FILE *fe = NULL;
	fopen_s(&fe, strFilePath.c_str(), "ab");
	if (fe == NULL)
	{
		m_log.LogMsgToFile(L"打开文件失败:室温数据");
		LeaveCriticalSection(&m_csDataFile);
		return;
	}
	//写入时间
	memset(szTime, 0, 20);
	sprintf_s(szTime, "\r\n%02d:%02d:%02d:", st.wHour, st.wMinute, st.wSecond);
	fwrite(szTime, 1, strlen(szTime), fe);
	//转换数据格式
	string strHexData = ToHexStr(pData, dwLen);
	if (fwrite(strHexData.c_str(), strHexData.size(), 1, fe) < 1)
	{
		m_log.LogMsgToFile(L"写入文件失败:室温数据");
		fclose(fe);
		LeaveCriticalSection(&m_csDataFile);
		return;
	}

	fclose(fe);
	LeaveCriticalSection(&m_csDataFile);
}