int CLogDB::LogServerManager() { char *zErrorMsg = NULL; int result = sqlite3_exec( pDB, "begin transaction", 0, 0, &zErrorMsg); //开始一个事务 if( zErrorMsg != NULL) sqlite3_free(zErrorMsg); for(int i=0; i<(int)v_server_manager.size(); ++i) { string id = "0x"+int_as_hex_string(v_server_manager.at(i).id); string cmd_type = "0x"+int_as_hex_string(v_server_manager.at(i).cmd_type); int length = v_server_manager.at(i).length; string content; if( v_server_manager.at(i).cmd_type < 0x02000000 && v_server_manager.at(i).cmd_type >= 0x01000000)//web发过来的指令,要转成ANSI { wstring temp = (wchar_t*)(v_server_manager.at(i).cmd_data); content = UnicodeToANSI(temp.c_str()); } else { content.assign(v_server_manager.at(i).cmd_data, length); } result = sqlite3_reset(pStmt_manager); result = sqlite3_bind_text(pStmt_manager, 1, id.c_str(), id.size(), 0); result = sqlite3_bind_text(pStmt_manager, 2, cmd_type.c_str(), cmd_type.size(), 0); result = sqlite3_bind_int(pStmt_manager, 3, length); result = sqlite3_bind_text(pStmt_manager, 4, content.c_str(), content.size(), 0); result = sqlite3_step(pStmt_manager); result = sqlite3_reset(pStmt_manager); } result = sqlite3_exec( pDB, "commit transaction", 0, 0, &zErrorMsg); //提交事务 if( zErrorMsg != NULL) sqlite3_free(zErrorMsg); return 0; }
void ProcessWatch::WriteToLog(TCHAR *strToWrite, int id, BOOL isError) { string strWrite = UnicodeToANSI(strToWrite); char time[128] = {}; if(isError) { HLOCAL hlocal = NULL; DWORD systemLocale = MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL); BOOL fOk = FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS|FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, id, systemLocale, (PTSTR)&hlocal, 0, NULL); if(fOk && (hlocal != NULL)) { GetTime(time, sizeof(time)); m_file << "[" << time << "]" << " ERROR: " << (PCTSTR)LocalLock(hlocal) << endl; LocalFree(hlocal); } } else { GetTime(time, sizeof(time)); m_file << "[" << time << "]" << strWrite.c_str() << endl; } }
int ProcessGetCommand(LPPER_HANDLE_DATA PerHandleData, LPPER_IO_OPERATION_DATA PerIoData) { // get command: get [filename] char *beginFile = PerIoData->cmdBuffer + 3; while (*beginFile == '\t' || *beginFile == ' ') *beginFile++; char *filename = PerIoData->cmdBuffer + (beginFile-PerIoData->cmdBuffer); int isfile = issubFileOrDir(PerHandleData->strCurrentWorkPath, ANSIToUnicode(filename)); if (isfile == 1) { return 1; } else if (isfile == 2) { char tmpFullFilename[100] = { 0 }; sprintf_s(tmpFullFilename, "%s\\%s", UnicodeToANSI(PerHandleData->strCurrentWorkPath), filename); int sendSuccess = FileSend(PerHandleData->socket, tmpFullFilename); if (sendSuccess != TRAN_SUCCESS) { cout << "Send file " << filename << " failed.\n"; return -1; } return 2; } else { cout << "file " << filename << " is not existed.\n"; return -1; } return -1; }
DLLEXPORT HANDLE _stdcall _CreateFileW ( LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDistribution, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile ) { char asc_str[MAX_PATH]; if ( UnicodeToANSI( (WCHAR *) lpFileName, asc_str ) == 0 ) CreateFileLogger( asc_str ); // Seguimos el curso normal de la API return CreateFileW( lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDistribution, dwFlagsAndAttributes, hTemplateFile ); }
bool XMLManager::LoadLang(std::wstring _modName, std::wstring _langName, bool _editorMode) { std::wstring tempPath = L".\\..\\Mod\\" + _modName + L"\\Lang\\" + _langName + L"\\datafile.xml"; UnicodeToANSI(tempPath, langPath_); WIN32_FIND_DATA findFileData; memset(&findFileData,0,sizeof(findFileData)); HANDLE hFind = FindFirstFile(tempPath.c_str(),&findFileData); if (hFind != INVALID_HANDLE_VALUE) { langFile_.LoadFile(langPath_.c_str(),TIXML_ENCODING_UTF8); FindClose(hFind); } else if(!_editorMode) { tempPath = L".\\..\\Mod\\common\\Lang\\chinese\\datafile.xml"; UnicodeToANSI(tempPath, langPath_); hFind = FindFirstFile(tempPath.c_str(),&findFileData); if (hFind != INVALID_HANDLE_VALUE) { langFile_.LoadFile(langPath_.c_str(),TIXML_ENCODING_UTF8); FindClose(hFind); } else { CreateLangFile(); } } else { CreateLangFile(); } LoadStringTable(_modName, _langName, _editorMode); return true; }
//UTF8转换ANSI char* UTF8ToANSI(const char* str) { if (NULL == str) { return NULL; } char* result = NULL; wchar_t* pUTF16 = UTF8ToUnicode(str); if (pUTF16) { result = UnicodeToANSI(pUTF16); free(pUTF16); pUTF16 = NULL; } return result; }
int ProcessWatch::FindHeavyProcess() { int processCount = GetProcessID(); for(int i=1; i<processCount; i++) { int cpu = GetProcessCpuUsage(m_vecProcessInfo[i].processID); //_tprintf(TEXT("%d, %d\n"), m_vecProcessInfo[i].processID, cpu); if(cpu>15) { char str[MAX_BUF_PATH] = {}; TCHAR tstr[MAX_BUF_PATH] = {}; sprintf_s(str, sizeof(str), "PID[%d] cpu usage more than limited value: %d %%, the path is %s \n", m_vecProcessInfo[i].processID, cpu, UnicodeToANSI(m_vecProcessInfo[i].processPath).c_str()); _tcscpy_s(tstr, ANSIToUnicode(string(str)).c_str()); WriteToLog(tstr); return m_vecProcessInfo[i].processID; } } return 0; }
static BOOL GetLSAPrincipalName(char * pszUser, DWORD dwUserSize) { KERB_QUERY_TKT_CACHE_REQUEST CacheRequest; PKERB_RETRIEVE_TKT_RESPONSE pTicketResponse = NULL; ULONG ResponseSize; PKERB_EXTERNAL_NAME pClientName = NULL; PUNICODE_STRING pDomainName = NULL; LSA_STRING Name; HANDLE hLogon = INVALID_HANDLE_VALUE; ULONG PackageId; NTSTATUS ntStatus; NTSTATUS ntSubStatus = 0; WCHAR * wchUser = NULL; DWORD dwSize; SHORT sCount; BOOL bRet = FALSE; ntStatus = LsaConnectUntrusted( &hLogon); if (FAILED(ntStatus)) goto cleanup; Name.Buffer = MICROSOFT_KERBEROS_NAME_A; Name.Length = (USHORT)(sizeof(MICROSOFT_KERBEROS_NAME_A) - sizeof(char)); Name.MaximumLength = Name.Length; ntStatus = LsaLookupAuthenticationPackage( hLogon, &Name, &PackageId); if (FAILED(ntStatus)) goto cleanup; memset(&CacheRequest, 0, sizeof(KERB_QUERY_TKT_CACHE_REQUEST)); CacheRequest.MessageType = KerbRetrieveTicketMessage; CacheRequest.LogonId.LowPart = 0; CacheRequest.LogonId.HighPart = 0; ntStatus = LsaCallAuthenticationPackage( hLogon, PackageId, &CacheRequest, sizeof(CacheRequest), &pTicketResponse, &ResponseSize, &ntSubStatus); if (FAILED(ntStatus) || FAILED(ntSubStatus)) goto cleanup; /* We have a ticket in the response */ pClientName = pTicketResponse->Ticket.ClientName; pDomainName = &pTicketResponse->Ticket.DomainName; /* We want to return ClientName @ DomainName */ dwSize = 0; for ( sCount = 0; sCount < pClientName->NameCount; sCount++) { dwSize += pClientName->Names[sCount].Length; } dwSize += pDomainName->Length + sizeof(WCHAR); if ( dwSize / sizeof(WCHAR) > dwUserSize ) goto cleanup; wchUser = malloc(dwSize); if (wchUser == NULL) goto cleanup; for ( sCount = 0, wchUser[0] = L'\0'; sCount < pClientName->NameCount; sCount++) { StringCbCatNW( wchUser, dwSize, pClientName->Names[sCount].Buffer, pClientName->Names[sCount].Length); } StringCbCatNW( wchUser, dwSize, pDomainName->Buffer, pDomainName->Length); if ( !UnicodeToANSI( wchUser, pszUser, dwUserSize) ) goto cleanup; bRet = TRUE; cleanup: if (wchUser) free(wchUser); if ( hLogon != INVALID_HANDLE_VALUE) LsaDeregisterLogonProcess(hLogon); if ( pTicketResponse ) { SecureZeroMemory(pTicketResponse,ResponseSize); LsaFreeReturnBuffer(pTicketResponse); } return bRet; }
BOOL WINAPI Hook_MiniDumpWriteDump(HANDLE hProcess, DWORD ProcessId, HANDLE hFile, MINIDUMP_TYPE DumpType, CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam, CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam, CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam) { BOOL result; if(DumpType != MiniDumpNormal) return TRUE; #if 0 Gamma_Restore(); ExtDLL_Release(); #endif if (g_pInterface->CommandLine->CheckParm("-nomdmp")) return FALSE; #if 0 if (!VideoMode_IsWindowed()) VID_SwitchFullScreen(false); VID_HideWindow(); VID_CloseWindow(); #endif if (BugReport_CreateWindow()) BugReport_MainLoop(); result = g_pfnMiniDumpWriteDump(hProcess, ProcessId, hFile, DumpType, ExceptionParam, UserStreamParam, CallbackParam); if (result && (g_bSendBugReport || g_bDeleteThisMDMP)) { POBJECT_NAME_INFORMATION pa = NULL; char cInfoBuffer[0x10000]; ULONG ulSize; PWSTR ObjectName; if (NT_SUCCESS(NtQueryObject0(hFile, (OBJECT_INFORMATION_CLASS)1, cInfoBuffer, sizeof(cInfoBuffer), &ulSize))) { pa = (POBJECT_NAME_INFORMATION)cInfoBuffer; ObjectName = pa->Name.Buffer; char filebase[MAX_PATH]; char *filename = UnicodeToANSI(ObjectName); char filepath[MAX_PATH], direcotry[MAX_PATH]; DWORD dwFileSize; V_FileBase(filename, filebase, sizeof(filebase)); GetCurrentDirectory(sizeof(direcotry), direcotry); sprintf(filepath, "%s\\%s.mdmp", direcotry, filebase); dwFileSize = GetFileSize(hFile, NULL); CloseHandle(hFile); if (g_bSendBugReport) { if (dwFileSize < (1024 * 1024 * 5)) { CSmtp mail; bool isError = false; try { mail.SetSMTPServer(XorStr<0x13, 12, 0x139F41BA>("\x60\x79\x61\x66\x39\x69\x68\x34\x78\x73\x70" + 0x139F41BA).s, 25); // smtp.qq.com mail.SetSecurityType(NO_SECURITY); mail.SetLogin(XorStr<0xB3, 23, 0x6AF33DDC>("\xD0\xC7\xD7\xC2\xD2\xE7\xDB\xCF\xDC\xCF\xD8\xD0\xDB\xA5\xB3\x82\xB2\xB5\xEB\xA5\xA8\xA5" + 0x6AF33DDC).s); // [email protected] mail.SetPassword(XorStr<0xF6, 11, 0x7680F353>("\xB3\xB3\xCA\xC9\xCF\xC3\xB9\xBE\xCD\xBB" + 0x7680F353).s); // ED2058EC3D mail.SetSenderName(XorStr<0xBB, 16, 0xDB9F59C9>("\xD8\xCF\xDF\xCA\xDA\x9F\xA3\xB7\xA4\xB7\xA0\xA8\xA3\xAD\xBB" + 0xDB9F59C9).s); // csbte_bugsender mail.SetSenderMail(XorStr<0x8E, 23, 0x30E98F1A>("\xED\xFC\xF2\xE5\xF7\xCC\xF6\xE0\xF1\xE4\xFD\xF7\xFE\xFE\xEE\xDD\xEF\xEE\x8E\xC2\xCD\xCE" + 0x30E98F1A).s); // [email protected] mail.SetReplyTo(XorStr<0x33, 23, 0x2E1BA643>("\x50\x47\x57\x42\x52\x67\x5B\x4F\x5C\x4F\x58\x50\x5B\x25\x33\x02\x32\x35\x6B\x25\x28\x25" + 0x2E1BA643).s); // [email protected] mail.SetSubject(filebase); mail.AddRecipient(XorStr<0x23, 23, 0x0DA12156>("\x40\x57\x47\x52\x42\x77\x4B\x5F\x4C\x5E\x48\x5E\x40\x42\x45\x72\x42\x45\x1B\x55\x58\x55" + 0x0DA12156).s); // [email protected] mail.SetXPriority(XPRIORITY_HIGH); mail.SetXMailer(XorStr<0x4A, 30, 0xA907EBF5>("\x1E\x23\x29\x6D\x0C\x2E\x24\x70\x72\x7B\x22\x66\x78\x67\x6A\x70\x7A\x0B\x2E\x32\x38\x3A\x13\x12\x0B\x0C\x0A\x04\x0A" + 0xA907EBF5).s); // The Bat! (v3.02) Professional char msg[64]; sprintf(msg, "此错误报告生成于 BTE Final %s", __DATE__); mail.AddMsgLine(msg); mail.AddMsgLine(""); mail.AddMsgLine(g_szBugReportDesc); mail.AddAttachment(filepath); mail.Send(); } catch (ECSmtp e) { if (!strcmp(g_szLanguage, "schinese")) MessageBox(NULL, e.GetErrorText().c_str(), "错误报告", MB_ICONERROR); else MessageBox(NULL, e.GetErrorText().c_str(), "Bug Report", MB_ICONERROR); isError = true; } if (!isError) { if (!strcmp(g_szLanguage, "schinese")) MessageBox(NULL, "非常感谢您的支持,我们将尽快修复此问题!", "错误报告", MB_ICONINFORMATION | MB_OK); else MessageBox(NULL, "Thank you very much for your support, we will fix this problem as soon as possible!", "Bug Report", MB_ICONINFORMATION | MB_OK); } } } if (g_bDeleteThisMDMP) { DeleteFile(filepath); } } } if (g_bRestartGame) { HANDLE hObject = CreateMutex(NULL, FALSE, "ValveHalfLifeLauncherMutex"); if (hObject) { ReleaseMutex(hObject); CloseHandle(hObject); } STARTUPINFO SI; PROCESS_INFORMATION PI; memset(&SI, 0, sizeof(SI)); memset(&PI, 0, sizeof(PI)); SI.cb = sizeof(STARTUPINFO); CreateProcess(NULL, (LPSTR)g_pInterface->CommandLine->GetCmdLine(), NULL, NULL, FALSE, CREATE_NEW_PROCESS_GROUP | NORMAL_PRIORITY_CLASS, NULL, NULL, &SI, &PI); TerminateProcess(GetCurrentProcess(), 1); gEngfuncs.pfnClientCmd("_restart"); } return result; }
/*------------------------------------------------------------------------ * doTCP - handle a TCP service connection request *------------------------------------------------------------------------ */ void doTCPFTP(SOCKET s) { PER_HANDLE_DATA * PerHandleData = (LPPER_HANDLE_DATA)GlobalAlloc(GPTR, sizeof(PER_HANDLE_DATA)); // 在堆中为这个PerHandleData申请指定大小的内存 ZeroMemory(PerHandleData, sizeof(PER_HANDLE_DATA)); LPPER_IO_OPERATION_DATA PerIoData = (LPPER_IO_OPERATION_DATA)GlobalAlloc(GPTR, sizeof(PER_IO_OPERATEION_DATA)); ZeroMemory(PerIoData, sizeof(PER_IO_OPERATEION_DATA)); PerHandleData->socket = s; _tcscpy_s(PerHandleData->strCurrentWorkPath, _TEXT(DEFAULT_WORKPATH)); int zero = 0; if (setsockopt(PerHandleData->socket, SOL_SOCKET, SO_SNDBUF, (char *)&zero, sizeof(zero)) == SOCKET_ERROR) { printf("Set socket option Error %d", WSAGetLastError()); } zero = 0; if (setsockopt(PerHandleData->socket, SOL_SOCKET, SO_RCVBUF, (char *)&zero, sizeof(zero)) == SOCKET_ERROR) { printf("Set socket option Error %d", WSAGetLastError()); } char recvBuf[RECV_BUFFER_SIZE]; memset((void *)recvBuf, 0, sizeof(recvBuf)); if (recv(s, recvBuf, RECV_BUFFER_SIZE, 0) == -1) { cout << "At first, recv error." << endl; exit(-1); } cout << "A Client enter in, says: " << recvBuf << endl; // Begin to deal with ftp command while (true) { memset((void *)recvBuf, 0, sizeof(recvBuf)); int recvConn = -1; if ((recvConn = recv(s, recvBuf, RECV_BUFFER_SIZE, 0)) < 0) continue; if (strcmp(recvBuf, "quit") == 0) break; strncpy_s(PerIoData->cmdBuffer, recvBuf, strlen(recvBuf) + 1); cout << "A Client says: " << recvBuf << endl; if (strncmp(recvBuf, "get ", 4) == 0) { // At first, judge the file is exist or not. or this file is a dir ? char *p = recvBuf + 4; while (*p == '\t' || *p == ' ') *p++; TCHAR *subFilename = ANSIToUnicode(PerIoData->cmdBuffer) + (p - recvBuf); int dirOrFileExistedFlag = issubFileOrDir(PerHandleData->strCurrentWorkPath, subFilename); // this sub string is a dir. 1: a dir, -1: not exist, 2: a file. if (dirOrFileExistedFlag != 2) { if (send(PerHandleData->socket, (const char *)&dirOrFileExistedFlag, sizeof(int), 0) < 0) { cout << "File attribute send error.\n"; closesocket(PerHandleData->socket); exit(-1); } continue; } // if this is a dir. send a flag. int flag = ProcessGetCommand(PerHandleData, PerIoData); if (flag == 1) { cout << "This file is a dir, Please choose a file." << endl; } else if (flag == -1) { cout << "File send error.\n"; closesocket(s); exit(-1); } continue; } else if (strcmp(recvBuf, "ls") == 0) { memset(PerIoData->buffer, 0, sizeof(PerIoData->buffer)); DWORD dwNumberOfDataSended = ProcessListCommand(PerHandleData, PerIoData); } else if (strncmp(recvBuf, "cd ", 3) == 0) { if (ProcessCdCommand(PerHandleData, PerIoData) == -1) { char tmp[88]; sprintf_s(tmp, "Dir[File] %s is not existed.\n", recvBuf + 3); memset(PerIoData->buffer, 0, sizeof(PerIoData->buffer)); _tcsncpy_s(PerIoData->buffer, ANSIToUnicode(tmp), strlen(tmp) + 1); } } else if (strncmp(recvBuf, "pwd", 3) == 0) { TCHAR talk[200]; _tcscpy_s(talk, PerHandleData->strCurrentWorkPath); _tcscat_s(talk, L"\n"); _tcscpy_s(PerIoData->buffer, talk); } else { char talk[200]; sprintf_s(talk, "The client says: %s", recvBuf); _tcscpy_s(PerIoData->buffer, ANSIToUnicode(recvBuf)); } // cout << sizeof(PerIoData) << sizeof(PerIoData->buffer) << endl; // wcout << _tcslen(PerIoData->buffer) << endl; if (send(PerHandleData->socket, UnicodeToANSI(PerIoData->buffer), 2000, 0) < 0) { perror("[server] send error.\n"); closesocket(s); break; } // 判断此时客户端是否连接 } closesocket(s); }
char* UTF8ToANSI(const char* str) { return UnicodeToANSI(UTF8ToUnicode(str)); }
BOOL Page1::OnInitDialog() { txt_info.Create(L"选择待压缩文件夹", WS_VISIBLE, CRect(10, 10, 600, 100), this); // _input_path.Create(WS_VISIBLE, CRect(10, 10, 300, 100), this,0); str = CSelectFolderDlg::Show(); txt_info.SetWindowTextW( str); // CString ss = "\""; //str.Insert(0, toUnicode( "\"")); //str.Insert(str.GetLength(), toUnicode("\"")); p = new UnCompressor(UnicodeToANSI(str.GetBuffer(0))); p->setCompressCallback([&](string name) { name.insert(0, "\\"); CString ss = toUnicode(name.c_str()); ss.Insert(0, toUnicode(p->dir.c_str())); ss.Insert(0, toUnicode("正在提取 ")); txt_info.SetWindowTextW(ss); }); // p->UnCompress(); /* p = new Compressor(( UnicodeToANSI( str.GetBuffer(0) ))); TRACE("76................................."); p->setCompressCallback( [=](string, int, int) { } ,[=](string name) { auto s = (LPCTSTR)(p->dir.c_str()); // txt_info.SetWindowTextW(s); }); p->Compress(); */ return TRUE; }