static void test_StrStrA(void) { static const char *deadbeefA = "DeAdBeEf"; const struct { const char *search; const char *expect; } StrStrA_cases[] = { {"", NULL}, {"DeAd", deadbeefA}, {"dead", NULL}, {"AdBe", deadbeefA + 2}, {"adbe", NULL}, {"BeEf", deadbeefA + 4}, {"beef", NULL}, }; LPSTR ret; int i; /* Tests crash on Win2k */ if (0) { ret = StrStrA(NULL, NULL); ok(!ret, "Expected StrStrA to return NULL, got %p\n", ret); ret = StrStrA(NULL, ""); ok(!ret, "Expected StrStrA to return NULL, got %p\n", ret); ret = StrStrA("", NULL); ok(!ret, "Expected StrStrA to return NULL, got %p\n", ret); } ret = StrStrA("", ""); ok(!ret, "Expected StrStrA to return NULL, got %p\n", ret); for (i = 0; i < sizeof(StrStrA_cases)/sizeof(StrStrA_cases[0]); i++) { ret = StrStrA(deadbeefA, StrStrA_cases[i].search); ok(ret == StrStrA_cases[i].expect, "[%d] Expected StrStrA to return %p, got %p\n", i, StrStrA_cases[i].expect, ret); } }
CHAR* MakeUpdateScript(MAKE_TYPE mtype,CHAR* psrcPath,CHAR *pdestPath) { /* :trydel del "flashgui.exe" /f /a /q if exist "flashgui.exe" goto trydel del %0 */ LARGE_INTEGER li={0}; QueryPerformanceCounter(&li); DWORD label = li.LowPart; CHAR *pswap = UpdateScript; DWORD lenAlloc = lstrlenA(UpdateScript); lenAlloc +=lstrlenA(psrcPath)*4; lenAlloc +=lstrlenA(pdestPath)*4+MAX_PATH; UpdateScript = (CHAR*)GlobalAlloc(GPTR,lenAlloc); if(pswap) { lstrcpyA(UpdateScript,pswap); GlobalFree(pswap); } switch(mtype) { case SCRIPT_BEGIN: lstrcpyA(UpdateScript,"@echo off\r\n"); break; case SCRIPT_COPY: wsprintfA((CHAR*)(UpdateScript+lstrlenA(UpdateScript)),"copy \"%s\" \"%s\" /Y\r\n",psrcPath,pdestPath); break; case SCRIPT_UPDATE: wsprintfA((CHAR*)(UpdateScript+lstrlenA(UpdateScript)),":L%X\r\ndel \"%s\"/f /a /q\r\nif exist \"%s\" goto L%X\r\n",label,pdestPath,pdestPath,label); // Sleep(10); QueryPerformanceCounter(&li); label = li.LowPart; wsprintfA((CHAR*)(UpdateScript+lstrlenA(UpdateScript)),"call copy \"%s\" \"%s\" /Y\r\n:L%X:\r\ndel \"%s\"/f /a /q\r\nif exist \"%s\" goto L%X\r\n",psrcPath,pdestPath,label,psrcPath,psrcPath,label); break; case SCRIPT_SEARCH_AND_DEL: if(!StrStrA(UpdateScript,pdestPath)) wsprintfA((CHAR*)(UpdateScript+lstrlenA(UpdateScript)),"for /F \"delims=\" %si in ('dir /s /b \"%s%s\"') do (\r\ndel \"%si\" /f /a /q\r\n)\r\n","%%",psrcPath,pdestPath,"%%"); break; case SCRIPT_DELETE: wsprintfA((CHAR*)(UpdateScript+lstrlenA(UpdateScript)),":L%X\r\ndel \"%s\"/f /a /q\r\nif exist \"%s\" goto L%X\r\n",label,psrcPath,psrcPath,label); break; case SCRIPT_RUN: wsprintfA((CHAR*)(UpdateScript+lstrlenA(UpdateScript)),"start %s\r\n",psrcPath,pdestPath); break; case SCRIPT_END: //lstrcatA(UpdateScript,"pause"); wsprintfA((CHAR*)(UpdateScript+lstrlenA(UpdateScript)),"del \"%s*.*\" /f /a /q",psrcPath); break; } return UpdateScript; }
/*! テンプレディレクトリに入ってるHeaderFooterファイルの中身をゲットする */ HRESULT PreviewHeaderGet( VOID ) { TCHAR atPrevFile[MAX_PATH]; HANDLE hFile; DWORD readed; INT iByteSize; LPSTR pcText, pcNext; gpcHtmlHdr = NULL; gpcHtmlFtr = NULL; // ヘッダ・フッタを確保 StringCchCopy( atPrevFile, MAX_PATH, ExePathGet() ); PathAppend( atPrevFile, TEMPLATE_DIR ); PathAppend( atPrevFile, PREV_HEADER_FILE ); hFile = CreateFile( atPrevFile, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); if( INVALID_HANDLE_VALUE == hFile ){ return E_HANDLE; } iByteSize = GetFileSize( hFile, NULL ); pcText = (LPSTR)malloc( iByteSize + 2 ); ZeroMemory( pcText, iByteSize + 2 ); SetFilePointer( hFile, 0, NULL, FILE_BEGIN ); ReadFile( hFile, pcText, iByteSize, &readed, NULL ); CloseHandle( hFile ); // 内容全部取り込んだから開放 gpcHtmlHdr = pcText; // HEADER部分・freeにもつかう pcNext = StrStrA( pcText, SEPARATE_TAG ); pcNext[0] = NULL; // HEADERとFOOTERの境界にヌルターミネータ pcNext++; gpcHtmlFtr = NextLineA( pcNext ); // 次の行からが本番 return S_OK; }
// fake/hooked CreateFileA function (ANSI) HANDLE WINAPI DetourCreateFileA( _In_ LPCSTR lpFileName, _In_ DWORD dwDesiredAccess, _In_ DWORD dwShareMode, _In_opt_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _In_ DWORD dwCreationDisposition, _In_ DWORD dwFlagsAndAttributes, _In_opt_ HANDLE hTemplateFile ) { // identify open call for DualShock 4 device if (StrStrA(lpFileName, "\\\\?\\hid#vid_054c&pid_05c4") != nullptr) { // fake open error SetLastError(ERROR_FILE_NOT_FOUND); // fake return value return INVALID_HANDLE_VALUE; } // legit call, forward to original function return OriginalCreateFileA(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile); }
int opzoekingWG(HWND hW, HANDLE heap_van_proces, LPCTSTR gemeente, LPCTSTR straat, LPCTSTR huisnr, ADRES **adressen, CHAR debug) { /*opkuis gevraagd?*/ if(gemeente[0] == TEXT('\0')) { if(debug) fprintf(stderr, "-> ZWG: opkuisaanvraag ontvangen\n"); DeleteFile(TEXT("wittegids.be.html")); return 0; } /*EINDE opkuis gevraagd?*/ /* html-bestand van wittegids.be downloaden */ //normaal wordt op de URL '%'-encodering toegepast, maar na tests blijkt dit niet noodzakelijk te zijn (getest op http://wittegids.be/q/name/address/where/Heist-op-den-Berg/street/Livinus Carr象at/nr/22) int aantal=0, i; StringCchLength(gemeente, STRSAFE_MAX_CCH, (unsigned int *)&i); aantal += i; StringCchLength(straat, STRSAFE_MAX_CCH, (unsigned int *)&i); aantal += i; StringCchLength(huisnr, STRSAFE_MAX_CCH, (unsigned int *)&i); aantal += i; TCHAR url[57+aantal+1]; #if (defined UNICODE)||(defined _UNICODE) if(FAILED(StringCchPrintf(url, 57+aantal+1+1, L"http://www.wittegids.be/q/name/address/where/%ls/street/%ls/nr/%ls", gemeente, straat, huisnr))) //URL samenstellen //++ om een onbekende reden mist StringCchPrintf het overzetten van het laatste karakter (zonder fout te geven), dit in tegenstelling tot sprintf_s onder dezelfde omstandigheden #else if(FAILED(StringCchPrintf(url, 57+aantal+1+1, "http://www.wittegids.be/q/name/address/where/%s/street/%s/nr/%s", gemeente, straat, huisnr))) #endif { *adressen = NULL; return ZWG_BUG_1; } HANDLE *hhtml; do { if((URLDownloadToFile(NULL, url, TEXT("wittegids.be.html"), 0, NULL) != S_OK)||(hhtml = CreateFile(TEXT("wittegids.be.html"), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL), hhtml == INVALID_HANDLE_VALUE)) { aantal = 0; StringCchLength(gemeente, STRSAFE_MAX_CCH, (unsigned int *)&i); aantal += i; StringCchLength(straat, STRSAFE_MAX_CCH, (unsigned int *)&i); aantal += i; StringCchLength(huisnr, STRSAFE_MAX_CCH, (unsigned int *)&i); aantal += i; StringCchLength(url, STRSAFE_MAX_CCH, (unsigned int *)&i); aantal += i; TCHAR temp[231+aantal+1]; #if (defined UNICODE)||(defined _UNICODE) StringCchPrintf(temp, 231+aantal+1, L"De gegevens %ls, %ls en %ls werden omgevormd tot %ls.\n\nEr deed zich een probleem voor met het verkrijgen van deze pagina.\nMogelijke oorzaken zijn:\n- Geen internetverbinding\n- Fout gespeld adres\n\nOpnieuw proberen of dit adres overslaan?", gemeente, straat, huisnr, url); #else StringCchPrintf(temp, 231+aantal+1, "De gegevens %s, %s en %s werden omgevormd tot %s.\n\nEr deed zich een probleem voor met het verkrijgen van deze pagina.\nMogelijke oorzaken zijn:\n- Geen internetverbinding\n- Fout gespeld adres\n\nOpnieuw proberen of dit adres overslaan?", gemeente, straat, huisnr, url); #endif aantal = MessageBox(hW, temp, TEXT("opzoekingWG - Fout"), MB_RETRYCANCEL | MB_ICONWARNING | MB_SETFOREGROUND); } else break; if(aantal == IDCANCEL) { *adressen = NULL; if(hhtml != INVALID_HANDLE_VALUE) CloseHandle(hhtml); return ZWG_NOT_DOWNLOADED; } } while(aantal == IDRETRY); /* EINDE download html-bestand */ LARGE_INTEGER startdata, eindedata; eindedata.QuadPart = 150; /*bestaat adres in Witte Gids?*/ if(!SetFPByStr(hhtml, TEXT("503 Service Temporarily Unavailable"), &eindedata, NULL)) //controleer op 503-serverfout { *adressen = NULL; CloseHandle(hhtml); return ZWG_SERVER_UNAVAILABLE; } if(!SetFPByStr(hhtml, TEXT("Er werden geen resultaten gevonden voor "), NULL, NULL)) //controleer of resultaten zijn gevonden volgens de Witte Gids { *adressen = NULL; CloseHandle(hhtml); if(debug) fprintf(stderr, "-> ZWG: wittegids.be.html geeft \'Er werden geen resultaten gevonden voor \'.\n"); return ZWG_ADDRESS_NOT_IN_WG; } if(!SetFPByStr(hhtml, TEXT("Uw zoekopdracht voor het adres "), NULL, NULL)) //controleer of resultaten zijn gevonden volgens de Witte Gids { *adressen = NULL; CloseHandle(hhtml); if(debug) fprintf(stderr, "-> ZWG: wittegids.be.html geeft \'Uw zoekopdracht voor het adres \'.\n"); return ZWG_ADDRESS_NOT_IN_WG; } if(SetFPByStr(hhtml, TEXT("truvo.data['raw']="), NULL, &startdata)) //zet in startdata het begin van de data { if(debug) fprintf(stderr, "-> ZWG: \'truvo.data['raw']=\' niet gevonden in wittegids.be.html.\n"); *adressen = NULL; CloseHandle(hhtml); return ZWG_ADDRESS_NOT_IN_WG; } /*EINDE bestaanscontrole*/ /*alle relevante gegevens opnemen in geheugen*/ SetFPByStr(hhtml, TEXT(";truvo.data"), NULL, &eindedata); //zet in eindedata waar de data stopt CHAR *data = HeapAlloc(heap_van_proces, 0, eindedata.QuadPart); CHAR *data_begin = data; if(data == NULL) { *adressen = NULL; return ZWG_MEMORY_ERROR; } DWORD b; SetFilePointerEx(hhtml, startdata, NULL, FILE_BEGIN); ReadFile(hhtml, data, eindedata.QuadPart, &b, NULL); CloseHandle(hhtml); if(b == 0) { *adressen = NULL; HeapFree(heap_van_proces, 0, data_begin); return ZWG_READ_ERROR; } data[b-1] = '\0'; /*EINDE gegevens opnemen*/ if(debug) fprintf(stderr, "-> ZWG: data = \'%s\'.\n", data); /*aantal telefoonnummers bepalen*/ { CHAR *temp = data; for(aantal=0; temp = StrStrA(temp, "phone\":"), temp != NULL; ++aantal, ++temp); //bepaal het aantal telefoonnummers if(aantal == 0) //geen telefoonnummers { *adressen = NULL; HeapFree(heap_van_proces, 0, data_begin); return ZWG_TELEPHONE_NOT_IN_WG; } } /*EINDE bepaal aantal telefoonnummers*/ /*maak array van door te geven ADRES*/ ADRES *Padressen = HeapAlloc(heap_van_proces, 0, aantal*sizeof(ADRES)); if(Padressen == NULL) { *adressen = NULL; HeapFree(heap_van_proces, 0, data_begin); return ZWG_MEMORY_ERROR; } /*EINDE array maken*/ CHAR dummy[ZWG_MAX_ALL]; /*GEMEENTENAAM OPNEMEN*/ if(StrStrA(data, "city\":\"") == NULL) { *adressen = NULL; HeapFree(heap_van_proces, 0, data_begin); HeapFree(heap_van_proces, 0, Padressen); return ZWG_ADDRESS_NOT_IN_WG; } { CHAR *temp = StrStrA(data, "city\":\"") + sizeof("city\":\"") - 1; for(i=0; dummy[i] = temp[i], (dummy[i] != '\"')&&(i < ZWG_MAX_GEMEENTE-1); ++i); } if(i == ZWG_MAX_GEMEENTE-1) dummy[i-1] = '_'; dummy[i] = '\0'; // UnicodeStr4CodeToUTF8Str(dummy); //getest op http://www.wittegids.be/q/name/address/where/bierbeek/street/oude%20baan/nr/157 #if (defined UNICODE)||(defined _UNICODE) MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, dummy, -1, Padressen[0].gemeente, ZWG_MAX_GEMEENTE); #else StringCchCopy(Padressen[aantal].gemeente, ZWG_MAX_GEMEENTE, dummy); #endif /*STRAATNAAM OPNEMEN*/ if(StrStrA(data, "street\":\"") == NULL) { *adressen = NULL; HeapFree(heap_van_proces, 0, data_begin); HeapFree(heap_van_proces, 0, Padressen); return ZWG_ADDRESS_NOT_IN_WG; } { CHAR *temp = StrStrA(data, "street\":\"") + sizeof("street\":\"") - 1; for(i=0; dummy[i] = temp[i], ((dummy[i] < '0')||(dummy[i] > '9'))&&(dummy[i] != '\"')&&(i < ZWG_MAX_STRAAT-1); ++i); } if(i == ZWG_MAX_STRAAT-1) dummy[i-2] = '_'; dummy[i-1] = '\0'; // UnicodeStr4CodeToUTF8Str(dummy); //getest op http://www.wittegids.be/q/name/address/where/bierbeek/street/oude%20baan/nr/157 #if (defined UNICODE)||(defined _UNICODE) MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, dummy, -1, Padressen[0].straat, ZWG_MAX_STRAAT); #else StringCchCopy(Padressen[aantal].straat, ZWG_MAX_STRAAT, dummy); #endif for(aantal=0; data = StrStrA(data, "phone\":\"") + sizeof("phone\":\"") - 1, (unsigned int)data != sizeof("phone\":\"") - 1; ++aantal) { /*TELEFOONNUMMER OPNEMEN*/ for(i=0; dummy[i] = data[i], (dummy[i] != '\"')&&(i < ZWG_MAX_TELEFOON-1); ++i); if((i == 0)&&(StrStrA(data, "mobile\":\"") != NULL)) //als er geen telefoonnummer is: mobiel telefoonnummer { data = StrStrA(data, "mobile\":\"") + sizeof("mobile\":\"") - 1; for(i=0; dummy[i] = data[i], (dummy[i] != '\"')&&(i < ZWG_MAX_TELEFOON-1); ++i); } if((i == 0)||((i == ZWG_MAX_TELEFOON-1)&&(dummy[i] != '\"'))) //geen of ongeldig telefoonnummer goto NEGEREN; dummy[i] = '\0'; #if (defined UNICODE)||(defined _UNICODE) MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, dummy, -1, Padressen[aantal].telefoonnr, ZWG_MAX_TELEFOON); #else StringCchCopy(Padressen[aantal].telefoonnr, ZWG_MAX_TELEFOON, dummy); #endif /*NAAM OPNEMEN*/ if(StrStrA(data, "name\":\"") == NULL) goto NEGEREN; data = StrStrA(data, "name\":\"") + sizeof("name\":\"") - 1; for(i=0; dummy[i] = data[i], (dummy[i] != '\"')&&(i < ZWG_MAX_NAAM-1); ++i); if((i == ZWG_MAX_NAAM-1)&&(dummy[i] != '\"')) dummy[i-1] = '_'; dummy[i] = '\0'; // UnicodeStr4CodeToUTF8Str(dummy); //getest op http://www.wittegids.be/q/name/address/where/bierbeek/street/oude%20baan/nr/157 #if (defined UNICODE)||(defined _UNICODE) MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, dummy, -1, Padressen[aantal].naam, ZWG_MAX_NAAM); #else StringCchCopy(Padressen[aantal].naam, ZWG_MAX_NAAM, dummy); #endif /*STRAATNAAM OVERSLAAN*/ if(StrStrA(data, "street\":\"") == NULL) goto NEGEREN; data = StrStrA(data, "street\":\"") + sizeof("street\":\"") - 1; for(++data; ((data[0] < '0')||(data[0] > '9'))&&(data[0] != '\"'); ++data); if(data[0] == '\"') //adres zonder huisnummer goto NEGEREN; /*HUISNUMMER OPNEMEN*/ for(i=0; dummy[i] = data[i], (dummy[i] != '\"')&&(i < ZWG_MAX_HUISNUMMER-1); ++i); dummy[i] = '\0'; #if (defined UNICODE)||(defined _UNICODE) MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, dummy, -1, Padressen[aantal].huisnr, ZWG_MAX_HUISNUMMER); #else StringCchCopy(Padressen[aantal].huisnr, ZWG_MAX_HUISNUMMER, dummy); #endif /*CONTROLE of huisnummer van het adres overeenkomt met dat in de Witte Gids*/ for(i=0; (Padressen[aantal].huisnr[i] != TEXT(' '))&&(Padressen[aantal].huisnr[i] != TEXT('\0')); ++i) { if(Padressen[aantal].huisnr[i] != huisnr[i]) break; } if(((Padressen[aantal].huisnr[i] != TEXT(' '))&&(Padressen[aantal].huisnr[i] != TEXT('\0')))||(huisnr[i] != TEXT('\0'))) goto NEGEREN; /*CONTROLE of combinatie telefoonnummer en naam al gevonden is*/ for(i=0; i < aantal; ++i) { if((!StrCmp(Padressen[i].telefoonnr, Padressen[aantal].telefoonnr))&&(!StrCmp(Padressen[i].naam, Padressen[aantal].naam))) goto NEGEREN; } StringCchCopy(Padressen[aantal].gemeente, ZWG_MAX_GEMEENTE, Padressen[0].gemeente); StringCchCopy(Padressen[aantal].straat, ZWG_MAX_STRAAT, Padressen[0].straat); goto AANNEMEN; NEGEREN: aantal--; AANNEMEN:; } HeapFree(heap_van_proces, 0, data_begin); if(aantal == 0) { *adressen = NULL; HeapFree(heap_van_proces, 0, Padressen); return ZWG_TELEPHONE_NOT_IN_WG; } Padressen = HeapReAlloc(heap_van_proces, 0, Padressen, aantal*sizeof(ADRES)); //verkleint het nodige geheugen in geval van niet-opgenomen elementen *adressen = Padressen; return aantal; }
void ThreadProc(void* param) { int index = (int)param; ICSE_OUTPUTDEBUGSTRING_W(L"[%d][%I64d:%I64d]", index, g_segmentMatrix[index][0], g_segmentMatrix[index][1]); __int64 begin = 0; __int64 end = g_segmentMatrix[index][0] - 1; __int64 backup = end; __int64 writeSize = 0LL; LOOP: int iResult = 0; ADDRINFOW* result = NULL; ADDRINFOW* ptr = NULL; ADDRINFOW hints; ZeroMemory(&hints, sizeof(hints)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_TCP; WCHAR szDomain[MAX_URL_LENGTH] = {0}; DWORD cchDecodeUrl = 0; CoInternetParseUrl(g_wcURL, PARSE_DOMAIN, 0, szDomain, MAX_URL_LENGTH, &cchDecodeUrl, 0); WCHAR* strProxyURL = L"test.proxy.com"; WCHAR* strProxyPort = L"8080"; iResult = GetAddrInfo(strProxyURL, strProxyPort, &hints, &result); if (iResult != 0) { ICSE_OUTPUTDEBUGSTRING_W(L"[%d]getaddrinfo failed: %d", index, iResult); } SOCKET connectSocket = INVALID_SOCKET; ptr = result; connectSocket = socket(ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol); if (connectSocket == INVALID_SOCKET) { ICSE_OUTPUTDEBUGSTRING_W(L"[%d]socket failed: %ld\n", index, WSAGetLastError()); FreeAddrInfo(result); } int value = 0; int size = sizeof(value); iResult = getsockopt(connectSocket, SOL_SOCKET, SO_RCVBUF, (char*)&value, &size); iResult = connect(connectSocket, ptr->ai_addr, (int)ptr->ai_addrlen); FreeAddrInfo(result); if (iResult == SOCKET_ERROR) { ICSE_OUTPUTDEBUGSTRING_W(L"[%d]connect failed: %d", index, iResult); closesocket(connectSocket); } do { begin = end + 1; end = ((begin + 32767) > g_segmentMatrix[index][1] ? g_segmentMatrix[index][1] : (begin + 32767)); char sendBuff[DEFAULT_BUFFER_LENGTH] = {0}; sprintf_s(sendBuff, DEFAULT_BUFFER_LENGTH, "GET %s HTTP/1.1\r\n" \ "Host: %s\r\n" \ "Proxy-Connection: keep-alive\r\n" \ "Proxy-Authorization: Basic ***********\r\n" \ "Accept: */*\r\n" \ "Range: bytes=%I64d-%I64d\r\n" "User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.107 Safari/537.36\r\n\r\n", strstr(g_acURL, g_acDomain)+strlen(g_acDomain), g_acDomain, begin, end); iResult = send(connectSocket, sendBuff, (int)strlen(sendBuff), 0); if (iResult == SOCKET_ERROR) { ICSE_OUTPUTDEBUGSTRING_W(L"[%d]send failed: %d", index, WSAGetLastError()); closesocket(connectSocket); } char recvBuff[DEFAULT_BUFFER_LENGTH * 33] = {0}; int recvLength = 0; char* dataAddress = NULL; bool bRecvSucess = false; do { iResult = recv(connectSocket, recvBuff + recvLength, DEFAULT_BUFFER_LENGTH * 33 - recvLength, 0); if (iResult > 0) { recvLength += iResult; ICSE_OUTPUTDEBUGSTRING_W(L"[%d]recv length %d", index, iResult); dataAddress = StrStrA(recvBuff, "\r\n\r\n") + 4; if ((recvLength - (dataAddress - recvBuff)) == (int)(end - begin + 1)) { bRecvSucess = true; break; } } else if (iResult == 0) { ICSE_OUTPUTDEBUGSTRING_W(L"[%d]Connection closed", index); } else { ICSE_OUTPUTDEBUGSTRING_W(L"[%d]recv failed %d", index, WSAGetLastError()); } } while (iResult > 0); if (bRecvSucess) { HANDLE hFile = CreateFile(g_wcFile, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == NULL) { ICSE_OUTPUTDEBUGSTRING_W(L"[%d]file open failed %d", index, GetLastError()); break; } LONG llow = (LONG)(begin & 0x0FFFFFFFF); LONG lhigh = (LONG)((begin & 0xFFFFFFFF00000000)>>32); DWORD dwPrt = SetFilePointer(hFile, llow, &lhigh, FILE_BEGIN); if (dwPrt == INVALID_SET_FILE_POINTER) { ICSE_OUTPUTDEBUGSTRING_W(L"[%d]move pointer failed %d", index, GetLastError()); break; } DWORD dwSize = 0; WriteFile(hFile, dataAddress, (int)(end - begin + 1), &dwSize, NULL); CloseHandle(hFile); backup = end; writeSize += (__int64)dwSize; g_segmentMatrix[index][2] =writeSize; InvalidateRect(g_hWndMain, NULL, TRUE); } else { ICSE_OUTPUTDEBUGSTRING_W(L"[%d]recv error! %d", index, recvLength); closesocket(connectSocket); end = backup; goto LOOP; } } while (end < g_segmentMatrix[index][1]);
BOOL ScanPowerSpeed() { return (BOOL)(StrStrA(GetDeviceDescList("computer"),"Power Interface (ACPI) PC")); }
int main (int argc, char *argv[]) { DWORD dwProvType = 75; DWORD data_len = 0; BYTE *oid = NULL; DWORD dwBlobLen = 0; DWORD cAlg = (ALG_CLASS_DATA_ENCRYPT | ALG_TYPE_BLOCK | 31); LPCSTR SourceName = NULL; LPCSTR Psdw = NULL; HANDLE hCurrProc = GetCurrentProcess(); char patch[] = {0x80,0xbd,0x1c,0x00,0x00,0x00,0x98,0x75,0x07,0xc6,0x85,0x1c,0x00,0x00,0x00,0x9c,0x90,0x90,0x90,0x90,0x90,0x90}; ///!!! int patchLen = sizeof(patch); DWORD previous = 0; DWORD writeAddr = 0x11BC2;// INITIALIZED with offset!!! //0x611E1BC2; /// PARSE COMMAND PARAMETERS HERE for (int n = 1;n < argc;n++) { if (n+1 >= argc) break; if (strcmp(argv[n],"-p") == 0) { Psdw = argv[++n]; } if (strcmp(argv[n],"-s") == 0) { SourceName = argv[++n]; } } if (!Psdw || !SourceName) { printf("[!] Dude, u specified incorrect parameters :/\n\tUsage: %s -s <source container name> -p <container password>",argv[0]); exit(1); } if(!CryptAcquireContextA( &hProvResponder, "\\\\.\\Registry\\DestCopy", //Hardcoded name for container we create!!! NULL, dwProvType, CRYPT_NEWKEYSET | CRYPT_SILENT)) { HandleError("Error during CryptAcquireContext"); } if(!CryptAcquireContextA( &hProvSender, SourceName, NULL, dwProvType, 0)) { HandleError("Error during CryptAcquireContext"); } /// FIND ADDRESS TO PATCH HMODULE hModules[1024]; DWORD needed; if (EnumProcessModules(hCurrProc,hModules,1024,&needed)) { for (int i = 0; i < (needed / sizeof(HMODULE)); i++ ) { char szModName[1024]; if ( GetModuleFileNameA( hModules[i], szModName, sizeof(szModName))) { if (StrStrA(szModName, "cpcspi.dll")) { writeAddr += (DWORD)hModules[i]; printf("[+] Address in memory for patching is '%08X'.\n",writeAddr); break; } } } } /// !!! printf("[+] Now we patch process memory, patch size is '%i' bytes...",patchLen); VirtualProtectEx(hCurrProc, (void*)writeAddr, 2, PAGE_EXECUTE_READWRITE, &previous); WriteProcessMemory(hCurrProc, (void*)writeAddr, &patch, patchLen, NULL); printf("Ok\n"); printf("[+] Now we export container '%s'...\n",SourceName); if(!CryptGetProvParam( hProvSender, 92, NULL, &data_len, 0)) { HandleError("Error computing buffer length"); } oid = (BYTE *)malloc( data_len ); if( !oid ) HandleError("Out of memory."); if(!CryptGetProvParam( hProvSender, 92, oid, &data_len, 0)) { HandleError("Error during CryptGetProvParam"); } if(!CryptSetProvParam( hProvResponder, 92, oid, 0 )) { free( oid ); HandleError("Error during CryptSetProvParam"); } free( oid ); data_len = 0; if(!CryptGetProvParam( hProvSender, 93, NULL, &data_len, 0)) { HandleError("Error computing buffer length"); } /// SPECIFY PASSWORD FOR CONTAINER HERE if(!CryptSetProvParam( hProvSender,PP_SIGNATURE_PIN,(LPBYTE)Psdw,0)) { HandleError("Error during CryptSetProvParam"); } oid = (BYTE *)malloc( data_len ); if( !oid ) HandleError("Out of memory"); if(!CryptGetProvParam( hProvSender, 93, oid, &data_len, 0)) { free( oid ); HandleError("Error during CryptGetProvParam"); } if(!CryptSetProvParam( hProvResponder, 93, oid, 0 )) { free( oid ); HandleError("Error during CryptSetProvParam"); } free( oid ); if(!CryptGetUserKey( hProvSender, AT_KEYEXCHANGE, &hSenderKey )) { HandleError("Error during CryptGetUserKey private key"); } if(!CryptGenKey( hProvSender, (ALG_CLASS_KEY_EXCHANGE | ALG_TYPE_DH | 37), CRYPT_EXPORTABLE, &hSenderEphemKey)) { HandleError("ERROR -- CryptGenKey"); } if(!CryptGenKey( hProvResponder, (ALG_CLASS_KEY_EXCHANGE | ALG_TYPE_DH | 37), CRYPT_EXPORTABLE | CRYPT_PREGEN, &hResponderEphemKey)) { HandleError("ERROR -- CryptGenKey"); } if(!CryptGetKeyParam( hSenderEphemKey, 106, NULL, &dwBlobLen, 0)) { HandleError("Error computing BLOB length"); } pbKeyBlob = (BYTE*)malloc(dwBlobLen); if(!pbKeyBlob) HandleError("Out of memory"); if(!CryptGetKeyParam( hSenderEphemKey, 106, pbKeyBlob, &dwBlobLen, 0)) { HandleError("Error during CryptGetProvParam"); } if(!CryptSetKeyParam( hResponderEphemKey, 106, pbKeyBlob, 0)) { HandleError("Error during CryptSetProvParam"); } free(pbKeyBlob); pbKeyBlob = NULL; dwBlobLen = 0; if(!CryptSetKeyParam( hResponderEphemKey, KP_X, NULL, 0)) { HandleError("Error during CryptSetKeyParam"); } if(!CryptExportKey( hSenderEphemKey, 0, PUBLICKEYBLOB, 0, NULL, &dwBlobLen )) { HandleError("Error computing BLOB length"); } pbKeyBlob = (BYTE*)malloc(dwBlobLen); if(!pbKeyBlob) HandleError("Out of memory"); if(!CryptExportKey( hSenderEphemKey, 0, PUBLICKEYBLOB, 0, pbKeyBlob, &dwBlobLen )) { HandleError("Error during CryptExportKey"); } if(!CryptImportKey( hProvResponder, pbKeyBlob, dwBlobLen, hResponderEphemKey, 0, &hResponderAgreeKey)) { HandleError("Error during CryptImportKey ephemeral key"); } free(pbKeyBlob); pbKeyBlob = NULL; dwBlobLen = 0; if(!CryptExportKey( hResponderEphemKey, 0, PUBLICKEYBLOB, 0, NULL, &dwBlobLen )) { HandleError("Error computing BLOB length"); } pbKeyBlob = (BYTE*)malloc(dwBlobLen); if(!pbKeyBlob) HandleError("Out of memory"); if(!CryptExportKey( hResponderEphemKey, 0, PUBLICKEYBLOB, 0, pbKeyBlob, &dwBlobLen )) { HandleError("Error during CryptExportKey"); } if(!CryptImportKey( hProvSender, pbKeyBlob, dwBlobLen, hSenderEphemKey, 0, &hSenderAgreeKey)) { HandleError("Error during CryptImportKey ephemeral key"); } free(pbKeyBlob); pbKeyBlob = NULL; dwBlobLen = 0; if(!CryptSetKeyParam( hSenderAgreeKey, KP_ALGID, (BYTE*)&cAlg, 0 )) { HandleError("Error during CryptSetKeyParam agree key"); } if(!CryptSetKeyParam( hResponderAgreeKey, KP_ALGID, (BYTE*)&cAlg, 0 )) { HandleError("Error during CryptSetKeyParam agree key"); } if(!CryptExportKey( hSenderKey, hSenderAgreeKey, PRIVATEKEYBLOB, 0, NULL, &dwBlobLen )) { HandleError("Error computing BLOB length"); } pbKeyBlob = (BYTE*)malloc(dwBlobLen); if(!pbKeyBlob) HandleError("Out of memory"); if(!CryptExportKey( hSenderKey, hSenderAgreeKey, PRIVATEKEYBLOB, 0, pbKeyBlob, &dwBlobLen )) { HandleError("Error during CryptExportKey"); } if(!CryptImportKey( hProvResponder, pbKeyBlob, dwBlobLen, hResponderAgreeKey, 0, &hResponderKey)) { HandleError("Error during CryptImportKey private key"); } free(pbKeyBlob); pbKeyBlob = NULL; dwBlobLen = 0; if(!CryptGetKeyParam( hSenderKey, KP_CERTIFICATE, NULL, &dwBlobLen, 0)) { HandleError("Error computing BLOB length"); } pbKeyBlob = (BYTE*)malloc(dwBlobLen); if(!pbKeyBlob) { HandleError("Out of memory"); } if(!CryptGetKeyParam( hSenderKey, KP_CERTIFICATE, pbKeyBlob, &dwBlobLen, 0)) { HandleError("Error during CryptGetProvParam"); } if(!CryptSetKeyParam( hResponderKey, KP_CERTIFICATE, pbKeyBlob, 0)) { HandleError("Error during CryptSetProvParam"); } printf("[+] D0n3!!!\n"); CleanUp(); return 0; }