// Checks if szArg is an option, and if it is, returns which option it is // We return the first match, so g_Switches should be ordered appropriately __CommandLineSwitch ParseArgument(_In_z_ LPCSTR szArg) { if (!szArg || !szArg[0]) return switchNoSwitch; ULONG i = 0; LPCSTR szSwitch = NULL; // Check if this is a switch at all switch (szArg[0]) { case '-': case '/': case '\\': if (szArg[1] != 0) szSwitch = &szArg[1]; break; default: return switchNoSwitch; break; } for (i = 0; i < g_ulSwitches; i++) { // If we have a match if (StrStrIA(g_Switches[i].szSwitch, szSwitch) == g_Switches[i].szSwitch) { return g_Switches[i].iSwitch; } } return switchUnknown; } // ParseArgument
HWND SearchWindow(CHAR *pLikeTitle) { //EnumWindows((WNDENUMPROC)&EnumCallback,(LPARAM)pLikeTitle); //暴力找窗口 DWORD cnt=0; HWND hwnd,newhw; DWORD pid; CHAR cname[MAX_PATH]; for(cnt=0;cnt<0x00FFFFFF;cnt++) { newhw=(HWND)cnt; if(!IsWindow(newhw))continue; pid=0; GetWindowThreadProcessId(newhw,&pid); if(!pid)continue; hwnd = newhw; ::GetWindowTextA(hwnd,cname,MAX_PATH); if(StrStrIA(cname,pLikeTitle)) { // if(FindWindowEx((HWND)newhw,0,_T("wtlStatic"),_T("输入AK频道号快速进入"))) return hwnd; } } return 0; }
HANDLE GetProcHandle(__in LPSTR strProcName, __in DWORD dwFlags) { HANDLE hSnapshot, hProcess; PROCESSENTRY32 pProcEntry; hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (hSnapshot == INVALID_HANDLE_VALUE) exit(printf("[!!] CreateToolhelp32Snapshot: %08x\n", GetLastError())); pProcEntry.dwSize = sizeof(PROCESSENTRY32); if (!Process32First(hSnapshot, &pProcEntry)) exit(printf("[!!] Process32First: %08x\n", GetLastError())); do { if (StrStrIA(pProcEntry.szExeFile, strProcName)) { hProcess = OpenProcess(dwFlags, FALSE, pProcEntry.th32ProcessID); if (!hProcess) exit(printf("[!!] OpenProcess: %08x\n", GetLastError())); else return hProcess; } } while(Process32Next(hSnapshot, &pProcEntry)); return INVALID_HANDLE_VALUE; }
static void test_StrStrIA(void) { static const char *deadbeefA = "DeAdBeEf"; const struct { const char *search; const char *expect; } StrStrIA_cases[] = { {"", NULL}, {"DeAd", deadbeefA}, {"dead", deadbeefA}, {"AdBe", deadbeefA + 2}, {"adbe", deadbeefA + 2}, {"BeEf", deadbeefA + 4}, {"beef", deadbeefA + 4}, {"cafe", NULL}, }; LPSTR ret; int i; /* Tests crash on Win2k */ if (0) { ret = StrStrIA(NULL, NULL); ok(!ret, "Expected StrStrIA to return NULL, got %p\n", ret); ret = StrStrIA(NULL, ""); ok(!ret, "Expected StrStrIA to return NULL, got %p\n", ret); ret = StrStrIA("", NULL); ok(!ret, "Expected StrStrIA to return NULL, got %p\n", ret); } ret = StrStrIA("", ""); ok(!ret, "Expected StrStrIA to return NULL, got %p\n", ret); for (i = 0; i < sizeof(StrStrIA_cases)/sizeof(StrStrIA_cases[0]); i++) { ret = StrStrIA(deadbeefA, StrStrIA_cases[i].search); ok(ret == StrStrIA_cases[i].expect, "[%d] Expected StrStrIA to return %p, got %p\n", i, StrStrIA_cases[i].expect, ret); } }
int FindMatchA(const char *text, char *search, int options) { if (!search[0] && (!(options & F_EXACT) || !text[0])) return 1; if (options & F_EXACT) return (options & F_CASE) ? !strcmp(text, search) : !stricmp(text, search); // on empty string strstr() returns full string while StrStrI() returns NULL return (options & F_CASE) ? (int)strstr(text, search) : (int)StrStrIA(text, search); }
void CEditorRoot::SetMasterFolder() { CHAR sFolder[_MAX_PATH]; GetModuleFileNameA( GetModuleHandle(NULL), sFolder, sizeof(sFolder)); PathRemoveFileSpecA(sFolder); CHAR *lpPath = StrStrIA(sFolder,"\\Bin32"); if (lpPath) *lpPath = 0; lpPath = StrStrIA(sFolder,"\\Bin64"); if (lpPath) *lpPath = 0; m_masterFolder = sFolder; if (!m_masterFolder.IsEmpty()) { if (m_masterFolder[m_masterFolder.GetLength()-1] != '\\') m_masterFolder += '\\'; } SetCurrentDirectoryA( sFolder ); }
/// <summary>Determines whether file is a legacy project</summary> /// <param name="path">The path.</param> /// <returns></returns> bool ProjectDocTemplate::IsLegacyProject(Path path) const { try { StreamPtr s(XFileInfo(path).OpenRead()); ByteArrayPtr buf(new BYTE[1024]); // Peek first 1024 bytes DWORD count = s->Read(buf.get(), 1024); buf.get()[min(count,1023)] = '\0'; // Check for 'version=1' attribute return StrStrIA((char*)buf.get(), "<project version=\"1\"") != nullptr; } catch (ExceptionBase& e) { Console.Log(HERE, e, VString(L"Unable to identify project file '%s'", path.c_str())); return false; } }
char* multiReplaceA(const char *value, const char *search, const char *replace, int cs) { int slen = (int)mir_strlen(search); int rlen = (int)mir_strlen(replace); int vlen = (int)mir_strlen(value); int ci = slen ? cs : 1; // on empty string strstr() returns full string while StrStrI() returns NULL // let's try to calculate maximum length for result string int newlen = (!slen) ? rlen + 1 : ( ( rlen <= slen ) ? vlen + 1 : vlen * rlen / slen + 1 ); char *head; char *in = (char*)value; char *out = (char*)mir_alloc(newlen * sizeof(char)); out[0] = 0; while (head = ci ? strstr(in, search) : StrStrIA(in, search)) { if (head != in) mir_strncat(out, in, head - in + 1); in = head + slen; mir_strcat(out, replace); } mir_strcat(out, in); return out; }
unsigned char* web_page::load_utf8_file( LPCWSTR path, bool is_html, LPCWSTR defEncoding ) { unsigned char* ret = NULL; HANDLE fl = CreateFile(path, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if(fl != INVALID_HANDLE_VALUE) { DWORD size = GetFileSize(fl, NULL); ret = new unsigned char[size + 1]; DWORD cbRead = 0; if(size >= 3) { ReadFile(fl, ret, 3, &cbRead, NULL); if(ret[0] == '\xEF' && ret[1] == '\xBB' && ret[2] == '\xBF') { ReadFile(fl, ret, size - 3, &cbRead, NULL); ret[cbRead] = 0; } else { ReadFile(fl, ret + 3, size - 3, &cbRead, NULL); ret[cbRead + 3] = 0; } } CloseHandle(fl); } // try to convert encoding if(is_html) { std::wstring encoding; char* begin = StrStrIA((LPSTR) ret, "<meta"); while(begin && encoding.empty()) { char* end = StrStrIA(begin, ">"); char* s1 = StrStrIA(begin, "Content-Type"); if(s1 && s1 < end) { s1 = StrStrIA(begin, "charset"); if(s1) { s1 += strlen("charset"); while(!isalnum(s1[0]) && s1 < end) { s1++; } while((isalnum(s1[0]) || s1[0] == '-') && s1 < end) { encoding += s1[0]; s1++; } } } if(encoding.empty()) { begin = StrStrIA(begin + strlen("<meta"), "<meta"); } } if(encoding.empty() && defEncoding) { encoding = defEncoding; } if(!encoding.empty()) { if(!StrCmpI(encoding.c_str(), L"UTF-8")) { encoding.clear(); } } if(!encoding.empty()) { CoInitialize(NULL); IMultiLanguage* ml = NULL; HRESULT hr = CoCreateInstance(CLSID_CMultiLanguage, NULL, CLSCTX_INPROC_SERVER, IID_IMultiLanguage, (LPVOID*) &ml); MIMECSETINFO charset_src = {0}; MIMECSETINFO charset_dst = {0}; BSTR bstrCharSet = SysAllocString(encoding.c_str()); ml->GetCharsetInfo(bstrCharSet, &charset_src); SysFreeString(bstrCharSet); bstrCharSet = SysAllocString(L"utf-8"); ml->GetCharsetInfo(bstrCharSet, &charset_dst); SysFreeString(bstrCharSet); DWORD dwMode = 0; UINT szDst = (UINT) strlen((LPSTR) ret) * 4; LPSTR dst = new char[szDst]; if(ml->ConvertString(&dwMode, charset_src.uiInternetEncoding, charset_dst.uiInternetEncoding, (LPBYTE) ret, NULL, (LPBYTE) dst, &szDst) == S_OK) { dst[szDst] = 0; delete ret; ret = (unsigned char*) dst; } else { delete dst; } CoUninitialize(); } } return ret; }
static void test_loadlibraryshim(void) { const WCHAR v2_0[] = {'v','2','.','0','.','5','0','7','2','7',0}; const WCHAR v1_1[] = {'v','1','.','1','.','4','3','2','2',0}; const WCHAR vbogus[] = {'v','b','o','g','u','s',0}; const WCHAR fusion[] = {'f','u','s','i','o','n',0}; const WCHAR fusiondll[] = {'f','u','s','i','o','n','.','d','l','l',0}; const WCHAR nosuchdll[] = {'j','n','v','n','l','.','d','l','l',0}; const WCHAR gdidll[] = {'g','d','i','3','2','.','d','l','l',0}; HRESULT hr; const WCHAR *latest = NULL; CHAR latestA[MAX_PATH]; HMODULE hdll; CHAR dllpath[MAX_PATH]; if (no_legacy_runtimes) { win_skip("No legacy .NET runtimes are installed\n"); return; } hr = pLoadLibraryShim(fusion, v1_1, NULL, &hdll); ok(hr == S_OK || hr == E_HANDLE, "LoadLibraryShim failed, hr=%x\n", hr); if (SUCCEEDED(hr)) { latest = v1_1; GetModuleFileNameA(hdll, dllpath, MAX_PATH); todo_wine ok(StrStrIA(dllpath, "v1.1.4322") != 0, "incorrect fusion.dll path %s\n", dllpath); ok(StrStrIA(dllpath, "fusion.dll") != 0, "incorrect fusion.dll path %s\n", dllpath); FreeLibrary(hdll); } hr = pLoadLibraryShim(fusion, v2_0, NULL, &hdll); ok(hr == S_OK || hr == E_HANDLE, "LoadLibraryShim failed, hr=%x\n", hr); if (SUCCEEDED(hr)) { latest = v2_0; GetModuleFileNameA(hdll, dllpath, MAX_PATH); todo_wine ok(StrStrIA(dllpath, "v2.0.50727") != 0, "incorrect fusion.dll path %s\n", dllpath); ok(StrStrIA(dllpath, "fusion.dll") != 0, "incorrect fusion.dll path %s\n", dllpath); FreeLibrary(hdll); } hr = pLoadLibraryShim(fusion, v4_0, NULL, &hdll); ok(hr == S_OK || hr == E_HANDLE, "LoadLibraryShim failed, hr=%x\n", hr); if (SUCCEEDED(hr)) { /* LoadLibraryShim with a NULL version prefers 2.0 and earlier */ if (!latest) latest = v4_0; GetModuleFileNameA(hdll, dllpath, MAX_PATH); todo_wine ok(StrStrIA(dllpath, "v4.0.30319") != 0, "incorrect fusion.dll path %s\n", dllpath); ok(StrStrIA(dllpath, "fusion.dll") != 0, "incorrect fusion.dll path %s\n", dllpath); FreeLibrary(hdll); } hr = pLoadLibraryShim(fusion, vbogus, NULL, &hdll); todo_wine ok(hr == E_HANDLE, "LoadLibraryShim failed, hr=%x\n", hr); if (SUCCEEDED(hr)) FreeLibrary(hdll); WideCharToMultiByte(CP_ACP, 0, latest, -1, latestA, MAX_PATH, NULL, NULL); hr = pLoadLibraryShim(fusion, NULL, NULL, &hdll); ok(hr == S_OK, "LoadLibraryShim failed, hr=%x\n", hr); if (SUCCEEDED(hr)) { GetModuleFileNameA(hdll, dllpath, MAX_PATH); if (latest) todo_wine ok(StrStrIA(dllpath, latestA) != 0, "incorrect fusion.dll path %s\n", dllpath); ok(StrStrIA(dllpath, "fusion.dll") != 0, "incorrect fusion.dll path %s\n", dllpath); FreeLibrary(hdll); } hr = pLoadLibraryShim(fusiondll, NULL, NULL, &hdll); ok(hr == S_OK, "LoadLibraryShim failed, hr=%x\n", hr); if (SUCCEEDED(hr)) { GetModuleFileNameA(hdll, dllpath, MAX_PATH); if (latest) todo_wine ok(StrStrIA(dllpath, latestA) != 0, "incorrect fusion.dll path %s\n", dllpath); ok(StrStrIA(dllpath, "fusion.dll") != 0, "incorrect fusion.dll path %s\n", dllpath); FreeLibrary(hdll); } hr = pLoadLibraryShim(nosuchdll, latest, NULL, &hdll); ok(hr == E_HANDLE, "LoadLibraryShim failed, hr=%x\n", hr); if (SUCCEEDED(hr)) FreeLibrary(hdll); hr = pLoadLibraryShim(gdidll, latest, NULL, &hdll); todo_wine ok(hr == E_HANDLE, "LoadLibraryShim failed, hr=%x\n", hr); if (SUCCEEDED(hr)) FreeLibrary(hdll); }
void CImportDlg::import( LPCWSTR fileName ) { vcard::reader vcf; if(vcf.open(fileName)) { CRecord* rec = NULL; int phoneid = 1; vcard::card* crd = vcf.next(); while(crd) { rec = new CRecord; phoneid = 1; for(int i=0; i < crd->count(); i++) { vcard::field fld = crd->getField(i); struct { LPSTR vcardName; LPWSTR recName; } defNames[] = { {"NICKNAME", L"nickname"}, {"FN", L"displayname"}, {"TITLE", L"title"}, {"ROLE", L"role"}, {"CATEGORIES", L"category"}, {"NOTE", L"notes"}, {"URL", L"url"}, {"X-ICQ", L"icq"}, {"X-GTALK", L"gtalk"}, {"X-AIM", L"aim"}, {"X-YAHOO", L"yahoo"}, {"X-SKYPE", L"skype"}, {"X-MSN", L"msn"}, {"X-JABBER", L"jabber"}, {"X-QQ", L"qq"}, {NULL, NULL} }; BOOL found = FALSE; for(int j=0; defNames[j].vcardName; j++) { if(defNames[j].vcardName == fld.getType()) { rec->SetFieldValue(defNames[j].recName, fld.getConvertedStringValue(crd->version()).c_str()); found = TRUE; break; } } if(!found) { if(fld.getType() == "TEL") { if(phoneid <= 7) { WCHAR recFldName[100]; wsprintf(recFldName, L"phone%d", phoneid); rec->SetFieldValue(recFldName, fld.getConvertedStringValue(crd->version()).c_str()); wsprintf(recFldName, L"phonetype%d", phoneid); if(fld.haveParam("HOME")) { rec->SetFieldValue(recFldName, L"homephone"); } else if(fld.haveParam("WORK")) { rec->SetFieldValue(recFldName, L"workphone"); } else if(fld.haveParam("FAX")) { rec->SetFieldValue(recFldName, L"fax"); } else if(fld.haveParam("CELL")) { rec->SetFieldValue(recFldName, L"mobile"); } else if(fld.haveParam("PAGER")) { rec->SetFieldValue(recFldName, L"pager"); } else { rec->SetFieldValue(recFldName, L"primaryphone"); } phoneid++; } } else if(fld.getType() == "N") { LPWSTR names[] = { L"lastname", L"firstname", L"middlename", L"prefixname", L"suffixname", NULL }; std::vector<std::wstring> values = fld.getStructuredText(crd->version()); for(size_t j = 0; j < values.size() && names[j]; j++) { rec->SetFieldValue(names[j], values[j].c_str()); } } else if(fld.getType() == "ORG") { LPWSTR names[] = { L"organization", L"department", NULL }; std::vector<std::wstring> values = fld.getStructuredText(crd->version()); for(size_t j = 0; j < values.size() && names[j]; j++) { rec->SetFieldValue(names[j], values[j].c_str()); } } else if(fld.getType() == "PHOTO") { UINT photoSize = 0; LPBYTE photo = fld.getBinaryValue(photoSize); if(photo) { rec->InitImage(photo, photoSize, TRUE); delete photo; } } else if(fld.getType() == "EMAIL") { if(fld.haveParam("INTERNET") || fld.haveParam("TYPE", "INTERNET")) { rec->SetFieldValue(L"email", fld.getConvertedStringValue(crd->version()).c_str()); } } else if(fld.getType() == "ADR") { LPWSTR adrComponentsW[] = { L"work_pobox", L"work_address2", L"work_address", L"work_city", L"work_state", L"work_zip", L"work_country", NULL }; LPWSTR adrComponentsH[] = { L"home_pobox", L"home_address2", L"home_address", L"home_city", L"home_state", L"home_zip", L"home_country", NULL }; LPWSTR* adrComponents = NULL; if(fld.haveParam("HOME")) { adrComponents = adrComponentsH; } else { if(fld.haveParam("WORK")) { adrComponents = adrComponentsW; } else { std::string type = fld.getParamValue("TYPE"); if(StrStrIA(type.c_str(), "work")) { adrComponents = adrComponentsW; } else { adrComponents = adrComponentsH; } } } std::vector<std::wstring> values = fld.getStructuredText(crd->version()); for(size_t j = 0; j < values.size() && adrComponents[j]; j++) { rec->SetFieldValue(adrComponents[j], values[j].c_str()); } } } } if(rec->GetFieldValue(L"displayname").empty()) { std::wstring fname = rec->GetFieldValue(L"firstname"); std::wstring lname = rec->GetFieldValue(L"lastname"); if(fname.empty() && lname.empty()) { std::wstring org = rec->GetFieldValue(L"organization"); std::wstring dep = rec->GetFieldValue(L"department"); if(org.empty() && dep.empty()) { std::wstring nickname = rec->GetFieldValue(L"nickname"); if(!nickname.empty()) { rec->SetFieldValue(L"displayname", nickname.c_str()); } } else { std::wstring str; if(!org.empty()) { str = org; } if(!dep.empty()) { if(!org.empty()) str += L", "; str += dep; } rec->SetFieldValue(L"displayname", str.c_str()); } } else { std::wstring str; if(!fname.empty()) { str = fname; } if(!lname.empty()) { if(!fname.empty()) str += L" "; str += lname; } rec->SetFieldValue(L"displayname", str.c_str()); } } rec->m_ID = m_btn->FindSimilarRecord(*rec); m_records.push_back(rec); UINT action = IMPORT_ACT_IMPORT; if(rec->m_ID) { action = IMPORT_ACT_NONE; } m_actions.push_back(action); crd = vcf.next(); } vcf.close(); } }
//--------------------------------------------------------------------------- int ProcessDataThread::Handle_SSL(PDATA_BLOCK dataBlock) { // SSL DATA TIME hKey ProcName ProcID ThreadID FinalFlag EncryptFlag DataLen\r\n // 0 1 2 3 4 5 6 7 8 9 10 11 std::vector<std::string> & args = dataBlock->args; assert(dataBlock->dataLen > 0); if (dataBlock->dataLen == 0) { return 0; } Target * tarBlock = GetTargetFromGlobalMap(dataBlock->targetId); if (tarBlock == NULL) { return 0; } LONG time = strtoul(args[2].c_str(), NULL, 10); ULONG hKey = strtoul(args[3].c_str(), NULL, 10); int encryptFlag = atoi(args[8].c_str()); ULONG procId = strtoul(args[5].c_str(), NULL, 10); ULONG threadId = strtoul(args[6].c_str(), NULL, 10); int finalFlag = atoi(args[7].c_str()); DWORD dwPackageType = 0; DWORD dwPassFlag = 0; std::string procNameBase64 = args[4].c_str(); std::wstring widProcName = GetWideFromBase64(procNameBase64); std::wstring widHttpsDirName = tarBlock->widHttpsDataDir + L"\\" + widProcName + L"\\"; AdkCreateDirectoryW(widHttpsDirName.c_str()); // 写到本地数据目录中 // 文件名的 日期_send.dat 或 日期_recv.dat // std::string opTimeStr = GetDateString(time); std::wstring widFileName; std::string sslData = dataBlock->data; std::string sslHost = ""; // 针对下行数据,进行进一步处理 // if (encryptFlag == 1) { widFileName = widHttpsDirName + AnsiToWide(opTimeStr) + L"_send.txt"; if (strnicmp(sslData.c_str(), "Get", 3) == 0) { dwPackageType = 1; } if (strnicmp(sslData.c_str(), "Post", 4) == 0) { dwPackageType = 2; } if (dwPackageType > 0) { // 去除尾部的多余字符 // const char * lpEnd = strstr(sslData.c_str(), "\r\n\r\n"); if (lpEnd) { lpEnd += 4; UINT index = lpEnd - sslData.c_str(); sslData = dataBlock->data.substr(0, index); } // 定位Host // int indexBeg = sslData.find("Host:"); if (indexBeg != std::string::npos) { indexBeg += 5; int indexEnd = sslData.find("\r\n", indexBeg); sslHost = sslData.substr(indexBeg, indexEnd - indexBeg); } } // 密码识别 // if ( StrStrIA(sslData.c_str(), "password") || StrStrIA(sslData.c_str(), "passwd") || StrStrIA(sslData.c_str(), "pwd") ) { dwPassFlag = 1; } if (StrStrIA(sslData.c_str(), "subject") && StrStrIA(sslData.c_str(), "body")) { if (strchr(sslData.c_str(), '@') || StrStrIA(sslData.c_str(), "%40")) { dwPassFlag = 2; } } } else { widFileName = widHttpsDirName + AnsiToWide(opTimeStr) + L"_recv.txt"; if (strnicmp(sslData.c_str(), "Http/", 5) == 0) { dwPackageType = 3; int index = sslData.find("\r\n"); sslHost = sslData.substr(0, index); // 去除尾部的多余字符 // const char * lpEnd = strstr(sslData.c_str(), "\r\n\r\n"); if (lpEnd) { lpEnd += 4; UINT index = lpEnd - sslData.c_str(); sslData = dataBlock->data.substr(0, index); } } } DWORD dwByteWritten = 0; HANDLE hFile = CreateFileW(widFileName.c_str(), GENERIC_ALL, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) { return 0; } SetFilePointer(hFile, 0, NULL, FILE_END); // [时间] ProcessID ThreadID CryptHandle // char buf[1024]; std::string aniTime = GetTimeString(time); if (dwPassFlag == 0) { sprintf(buf, "\r\n----------------------------------------------------------------------------------\r\n"); } else { sprintf(buf, "\r\n**********************************************************************************\r\n"); } WriteFile(hFile, buf, strlen(buf),&dwByteWritten, 0); sprintf(buf, "[%s] ProcessID: %d ThreadID: %d CryptHandle: %d\r\n", aniTime.c_str(), procId, threadId, hKey); WriteFile(hFile, buf, strlen(buf),&dwByteWritten, 0); WriteFile(hFile, sslData.c_str(), sslData.size(), &dwByteWritten, 0); CloseHandle(hFile); if (dwPassFlag == 0) { return 0; } // 当前只关注发送数据 // if (encryptFlag == 1) { // 只有密码信息才填入到数据库中 // std::string opTimeStr = GetTimeString(time); int httpId = DM->InsertSSLInfo(dataBlock->targetId, opTimeStr.c_str(), hKey, widProcName, procId, threadId, dwPackageType, encryptFlag, dwPassFlag, finalFlag, sslHost.c_str(), sslData.c_str(), sslData.size()); // 更新界面, 只有界面显示的时候才回进行更新 // Target *tar = GetTargetFromGlobalMap(dataBlock->targetId); if (tar) { if (tar->frmTarControl) { if (tar->frmTarControl->bShowFlag) { std::string aniTitle; switch(dwPackageType) { case 0: aniTitle = std::string("[") + opTimeStr + "] DATA"; break; case 1: // Get aniTitle = std::string("[") + opTimeStr + "] GET :" + sslHost.c_str(); break; case 2: // Post aniTitle = std::string("[") + opTimeStr + "] POST :" + sslHost.c_str(); break; } QStringList *sl = new QStringList(); sl->append(QString::fromStdWString(widProcName)); sl->append(QString::fromLocal8Bit(aniTitle.c_str())); SendMessage(tar->frmTarControl->Handle, WM_UPDATE_HTTPS, httpId, (LONG)(sl)); delete sl; } } } } return 0; }
LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { static HWND hEdit1, hEdit2, hEdit3, hButton; static HWND hStatic1, hStatic2; static HWND hCheck; switch (msg) { case WM_CREATE: hStatic1 = CreateWindow(TEXT("Static"), TEXT("対象リスト"), WS_VISIBLE | WS_CHILD, 0, 0, 0, 0, hWnd, 0, ((LPCREATESTRUCT)lParam)->hInstance, 0); hEdit1 = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("EDIT"), TEXT(""), WS_VISIBLE | WS_CHILD | WS_TABSTOP | WS_VSCROLL | WS_HSCROLL | ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_MULTILINE | ES_WANTRETURN, 0, 0, 0, 0, hWnd, 0, ((LPCREATESTRUCT)lParam)->hInstance, 0); SendMessage(hEdit1, EM_LIMITTEXT, 0, 0); hCheck = CreateWindow(TEXT("Button"), TEXT("HTMLエスケープ"), WS_VISIBLE | WS_CHILD | WS_TABSTOP | BS_AUTOCHECKBOX, 0, 0, 0, 0, hWnd, 0, ((LPCREATESTRUCT)lParam)->hInstance, 0); hEdit3 = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("EDIT"), TEXT(""), WS_VISIBLE | WS_CHILD | WS_TABSTOP | ES_AUTOHSCROLL, 0, 0, 0, 0, hWnd, 0, ((LPCREATESTRUCT)lParam)->hInstance, 0); hButton = CreateWindow(TEXT("Button"), TEXT(">変換>"), WS_VISIBLE | WS_CHILD | WS_TABSTOP | BS_DEFPUSHBUTTON, 0, 0, 0, 0, hWnd, (HMENU)IDOK, ((LPCREATESTRUCT)lParam)->hInstance, 0); hStatic2 = CreateWindow(TEXT("Static"), TEXT("結果リスト"), WS_VISIBLE | WS_CHILD, 0, 0, 0, 0, hWnd, 0, ((LPCREATESTRUCT)lParam)->hInstance, 0); hEdit2 = CreateWindowEx(WS_EX_CLIENTEDGE, TEXT("EDIT"), TEXT(""), WS_VISIBLE | WS_CHILD | WS_TABSTOP | WS_VSCROLL | WS_HSCROLL | ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_MULTILINE | ES_READONLY, 0, 0, 0, 0, hWnd, 0, ((LPCREATESTRUCT)lParam)->hInstance, 0); SendMessage(hEdit2, EM_LIMITTEXT, 0, 0); DragAcceptFiles(hWnd, TRUE); break; case WM_DROPFILES: { const HDROP hDrop = (HDROP)wParam; const UINT nFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0); if (nFiles == 1) { TCHAR szFileName[MAX_PATH]; DragQueryFile(hDrop, 0, szFileName, sizeof(szFileName)); const HANDLE hFile = CreateFile(szFileName, GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (hFile != INVALID_HANDLE_VALUE) { const DWORD dwFileSize = GetFileSize(hFile, 0); DWORD dwReadSize; LPSTR lpszText = (LPSTR)GlobalAlloc(0, dwFileSize + 1); ReadFile(hFile, lpszText, dwFileSize, &dwReadSize, 0); lpszText[dwReadSize] = 0; SetWindowTextA(hEdit1, lpszText); GlobalFree(lpszText); CloseHandle(hFile); } } DragFinish(hDrop); } break; case WM_SIZE: { const int button_width = 128; const int width = (LOWORD(lParam) - button_width - 20) / 2; MoveWindow(hStatic1, 0, 0, width, 32, TRUE); MoveWindow(hEdit1, 0, 32, width, HIWORD(lParam) - 32, TRUE); MoveWindow(hCheck, width + 10, HIWORD(lParam) / 2 - 16 - 10 - 32, button_width, 32, TRUE); MoveWindow(hEdit3, width + 10, HIWORD(lParam) / 2 - 16, button_width, 32, TRUE); MoveWindow(hButton, width + 10, HIWORD(lParam) / 2 + 16 + 10, button_width, 32, TRUE); MoveWindow(hStatic2, width + button_width + 20, 0, width, 32, TRUE); MoveWindow(hEdit2, width + button_width + 20, 32, width, HIWORD(lParam) - 32, TRUE); } break; case WM_COMMAND: if (LOWORD(wParam) == IDOK) { EnableWindow(hButton, FALSE); SetWindowTextA(hEdit2, 0); const INT_PTR nEditLineCount1 = SendMessageA(hEdit1, EM_GETLINECOUNT, 0, 0); const INT_PTR bHtmlEscape = SendMessageA(hCheck, BM_GETCHECK, 0, 0); LPSTR lpszEdit3 = 0; const int nEditLenght3 = GetWindowTextLengthA(hEdit3); if (nEditLenght3) { lpszEdit3 = (LPSTR)GlobalAlloc(0, sizeof(CHAR) * (nEditLenght3 + 1)); GetWindowTextA(hEdit3, lpszEdit3, nEditLenght3 + 1); } BOOL bIsFound; for (INT_PTR i = 0; i < nEditLineCount1; ++i) { bIsFound = FALSE; const INT_PTR nEditLineIndex1 = SendMessageA(hEdit1, EM_LINEINDEX, i, 0); const INT_PTR nEditLineLength1 = SendMessageA(hEdit1, EM_LINELENGTH, nEditLineIndex1, 0); if (!nEditLineLength1) continue; LPSTR lpszEditLine1 = (LPSTR)GlobalAlloc(0, sizeof(CHAR)* (nEditLineLength1 + 1 + 2)); // 改行文字2文字分追加 *(WORD *)lpszEditLine1 = (WORD)nEditLineLength1; SendMessageA(hEdit1, EM_GETLINE, i, (LPARAM)lpszEditLine1); lpszEditLine1[nEditLineLength1] = 0; { const std::string target(lpszEditLine1); std::regex re(R"(https?://[-_.!~*\'()a-zA-Z0-9;/?:@&=+$,%#]+)"); std::smatch match; for (auto it = target.begin(); regex_search(it, target.end(), match, re); it += match.position(0) + match.length(0)) { std::string str(match.str(0)); if (bHtmlEscape) { str = Replace(str, "&", "&"); str = Replace(str, "%3D", "="); str = Replace(str, "%22", "\""); str = Replace(str, "%20", " "); } if (!lpszEdit3 || StrStrIA(str.c_str(), lpszEdit3)) { INT_PTR dwEditTextLength = SendMessageA(hEdit2, WM_GETTEXTLENGTH, 0, 0); SendMessageA(hEdit2, EM_SETSEL, dwEditTextLength, dwEditTextLength); SendMessageA(hEdit2, EM_REPLACESEL, 0, (LPARAM)str.c_str()); SendMessageA(hEdit2, EM_REPLACESEL, 0, (LPARAM)"\r\n"); } } } GlobalFree(lpszEditLine1); } if (lpszEdit3) { GlobalFree(lpszEdit3); } SendMessageA(hEdit2, EM_SETSEL, 0, -1); SetFocus(hEdit2); EnableWindow(hButton, TRUE); } break; case WM_CLOSE: DestroyWindow(hWnd); break; case WM_DESTROY: PostQuitMessage(0); break; default: return DefDlgProc(hWnd, msg, wParam, lParam); } return 0; }