C *copy_cell(C *c) { switch (c->type) { case LABEL: return makecell(LABEL, (V){ scpy(c->val.label) }, copy_cell(c->next)); case LIST: return makecell(LIST, (V){ .list = copy_cell(c->val.list) }, copy_cell(c->next)); case BUILTIN: return makecell(BUILTIN, (V){ .func = { scpy(c->val.func.name), c->val.func.addr} }, copy_cell(c->next));
int readConfig(SdFatFs& fat, Config_t& cfg){ char buf[128]; char *parts[2]; int rd; int res = 0; if(fat.isFile(CONFIG) != 1){ res = fat.mkdir(CONFIG_DIR); if (res < 0){ return res; } SdFatFile file = fat.open(CONFIG,"w"); file.write(config0 ,sizeof(config0) - 1); file.write(config1 ,sizeof(config1) - 1); file.write(config2 ,sizeof(config2) - 1); file.write(config3 ,sizeof(config3) - 1); file.close(); } SdFatFile file = fat.open(CONFIG,"r"); //memset(buf, 0, sizeof(buf)); cfg.ap = false; cfg.channel[0] = '1'; cfg.channel[1] = '\0'; do{ rd = file.readline(buf,sizeof(buf)); //int c = getlen(buf); int c = split(buf,parts,'='); if (c != 2) continue; if(streq(strip(parts[0]),"mode")){ if(streq(strip(parts[1]),"ap")){ cfg.ap = true; } } if(streq(strip(parts[0]),"channel")){ scpy(strip(parts[1]), cfg.channel,sizeof(cfg.channel)); } if(streq(strip(parts[0]),"ssid")){ scpy(strip(parts[1]), cfg.ssid,sizeof(cfg.ssid)); } if(streq(strip(parts[0]),"passwd")){ scpy(strip(parts[1]), cfg.passwd, sizeof(cfg.passwd)); } /*if (c == 2){ printf(">>>%s<<< >>>%s<<<<\n", strip(parts[0]),strip(parts[1])); }*/ }while (rd != -1); file.close(); return res; }
int main(){ char s[10]="hello"; printf("%s: %d\n",s,slen(s)); //testing for slen char cpy[15]="aba"; printf("After scpy, %s became: ",cpy); scpy(cpy,s); printf("%s\n",cpy); char ncpy[15]="abalaba"; printf("After sncpy (n=3), %s became: ",ncpy); sncpy(ncpy,s,3); printf("%s\n",ncpy); char cat[15]="AddOn"; printf("After scat, %s became: ",cpy); scat(cpy,cat); printf("%s\n",cpy); char s2[18]="hello"; char s3[5]="po"; char s4[5]="bao"; printf("scmp %s and %s: %d\n",s,s2,scmp(s,s2)); printf("scmp %s and %s: %d\n",s,cpy,scmp(s,cpy)); printf("scmp %s and %s: %d\n",s,s3,scmp(s,s3)); printf("scmp %s and %s: %d\n",s,s4,scmp(s,s4)); printf("schr %s and %c: %s\n",s,'l',schr(s,'l')); printf("schr %s and %c: %s\n",s,'t',schr(s,'t')); char s5[5]="el"; printf("sstr %s and %s: %s\n",s,s5,sstr(s,s5)); printf("sstr %s and %s: %s\n",s,s3,sstr(s,s3)); return 0; }
String& String::operator+=(const String &str) { if(!str.curLength) return *this; curLength += str.curLength; if(curLength) { if(lpString) { lpString = (TSTR)ReAllocate(lpString, (curLength+1)*sizeof(TCHAR)); scat(lpString, str.lpString); } else { lpString = (TSTR)Allocate((curLength+1)*sizeof(TCHAR)); scpy(lpString, str.lpString); } } else { if(lpString) Free(lpString); lpString = NULL; } return *this; }
BOOL STDCALL OSFindNextFile(HANDLE hFind, OSFindData &findData) { WIN32_FIND_DATA wfd; BOOL bSuccess = FindNextFile(hFind, &wfd); if (bSuccess) { BOOL bFoundDumbDir; do { bFoundDumbDir = FALSE; if( (scmp(wfd.cFileName, TEXT("..")) == 0) || (scmp(wfd.cFileName, TEXT(".")) == 0) ) { if(!FindNextFile(hFind, &wfd)) { bSuccess = FALSE; break; } bFoundDumbDir = TRUE; } }while(bFoundDumbDir); } if(bSuccess) { scpy(findData.fileName, wfd.cFileName); findData.bDirectory = (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; findData.bHidden = (wfd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) != 0; } else *findData.fileName = 0; return bSuccess; }
HANDLE STDCALL OSFindFirstFile(CTSTR lpFileName, OSFindData &findData) { WIN32_FIND_DATA wfd; HANDLE hFind = FindFirstFile(lpFileName, &wfd); if(hFind == INVALID_HANDLE_VALUE) hFind = NULL; else { BOOL bFoundDumbDir; do { bFoundDumbDir = FALSE; if( (scmp(wfd.cFileName, TEXT("..")) == 0) || (scmp(wfd.cFileName, TEXT(".")) == 0) ) { if(!FindNextFile(hFind, &wfd)) { FindClose(hFind); return NULL; } bFoundDumbDir = TRUE; } }while(bFoundDumbDir); scpy(findData.fileName, wfd.cFileName); findData.bDirectory = (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; findData.bHidden = (wfd.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) != 0; } return hFind; }
node *sym(char *val) { node *ptr = newnode(SYM); namestr *name = name_malloc(); scpy(name->s, val); ptr->name = name; return ptr; }
HANDLE STDCALL OSLoadLibrary(CTSTR lpFile) { TCHAR FullFileName[250]; scpy(FullFileName, lpFile); scat(FullFileName, TEXT(".dll")); return (HANDLE)LoadLibrary(FullFileName); }
static char *trim(char const *s, char c) { char *str; int i; i = ft_strlen(s); if (!(str = ft_strnew(i))) return (NULL); str = scpy(str, s, c); return (str); }
String::String(const String &str) { curLength = str.curLength; if(curLength) { lpString = (TSTR)Allocate((curLength+1)*sizeof(TCHAR)); scpy(lpString, str.lpString); } else lpString = NULL; }
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ char *ltod (char *buffer, long l) /* long to decimal (returns end-of-number) */ { char *p1, lbuf[12]; short i; if (l < 0) { l= -l; *buffer++ = '-'; } p1 = lbuf+12; *(--p1) = 0; i = 11; do { *(--p1) = l%10 + '0'; } while((l = l/10) != 0 && --i); return scpy(p1, buffer); }
String XConfig::ProcessString(TSTR &lpTemp) { TSTR lpStart = lpTemp; BOOL bFoundEnd = FALSE; BOOL bPreviousWasEscaped = FALSE; while(*++lpTemp) { if (*lpTemp == '\\' && lpTemp[-1] == '\\') { bPreviousWasEscaped = TRUE; continue; } if(*lpTemp == '"' && (bPreviousWasEscaped || lpTemp[-1] != '\\')) { bFoundEnd = TRUE; break; } bPreviousWasEscaped = FALSE; } if(!bFoundEnd) return String(); ++lpTemp; TCHAR backupChar = *lpTemp; *lpTemp = 0; String string = lpStart; *lpTemp = backupChar; if (string.Length() == 2) return String(); String stringOut = string.Mid(1, string.Length()-1); if (stringOut.IsEmpty()) return String(); TSTR lpStringOut = stringOut; while(*lpStringOut != 0 && (lpStringOut = schr(lpStringOut, '\\')) != 0) { switch(lpStringOut[1]) { case 0: *lpStringOut = 0; break; case '"': *lpStringOut = '"'; scpy(lpStringOut+1, lpStringOut+2); break; case 't': *lpStringOut = '\t'; scpy(lpStringOut+1, lpStringOut+2); break; case 'r': *lpStringOut = '\r'; scpy(lpStringOut+1, lpStringOut+2); break; case 'n': *lpStringOut = '\n'; scpy(lpStringOut+1, lpStringOut+2); break; case '/': *lpStringOut = '/'; scpy(lpStringOut+1, lpStringOut+2); break; case '\\': scpy(lpStringOut+1, lpStringOut+2); break; } lpStringOut++; } stringOut.SetLength(slen(stringOut)); return stringOut; }
// // Save global variables // void saveGlobals(char *message) { edata *data = &memory->data[id]; scpy(data->message, message); data->id = id; data->ememory_size = sizeof(ememory); data->node_size = sizeof(node); data->nnodes = nnodes; data->nodemem = nodemem; data->nnames = nnames; data->namemem = namemem; data->nstrings = nstrings; data->stringmem = stringmem; }
void * __restrict DebugAlloc::_Allocate(size_t dwSize) { if(!dwSize) return NULL; OSEnterMutex(hDebugMutex); LPVOID lpRet; if(bEnableTracking) { ++allocationCounter; ++totalAllocations; } if(bEnableTracking && allocationCounter == memoryBreakID) ProgramBreak(); if((lpRet=FastAlloc::_Allocate(dwSize)) && bEnableTracking) { Allocation allocTemp; Allocation *new_array = (Allocation*)FastAlloc::_Allocate(sizeof(Allocation)*++numAllocations); zero(new_array, sizeof(Allocation)*numAllocations); allocTemp.Address = lpRet; if(lpAllocCurFile) scpy(allocTemp.lpFile, lpAllocCurFile); allocTemp.dwLine = dwAllocCurLine; if(bEnableTracking) allocTemp.allocationID = allocationCounter; else allocTemp.allocationID = INVALID; if(AllocationList) mcpy(new_array, AllocationList, sizeof(Allocation)*(numAllocations-1)); FastAlloc::_Free(AllocationList); AllocationList = new_array; mcpy(&AllocationList[numAllocations-1], &allocTemp, sizeof(Allocation)); } OSLeaveMutex(hDebugMutex); return lpRet; }
BOOL STDCALL InitXT(CTSTR logFile, CTSTR allocatorName) { if(!bBaseLoaded) { if(logFile) scpy(lpLogFileName, logFile); OSInit(); ResetXTAllocator(allocatorName); bBaseLoaded = 1; } return TRUE; }
int main() { char s1[] = "ABCDEFGHabcdefgh123456"; char s2[] = "ABCDEFGHabcdefgh123456 "; char dest[100]; char dest2[STR_MAX_SIZE+1]; int i, j, c; memset(dest, 0, sizeof(dest)); strcpy(dest, s1); strncpy(dest2, s1, STR_MAX_SIZE); dest2[STR_MAX_SIZE] = '\0'; printf("dest2 = %s\n", dest2); printf("scmp(s1, dest) = %d\n", scmp(s1, dest)); printf("scmp(s2, dest) = %d\n", scmp(s2, dest)); printf("before reverse: \"%s\"\n", dest); for (i = 0, j = strlen(dest)-1; i < j; i++, j--) { c = dest[i]; dest[i] = dest[j]; dest[j] = c; } printf("after reverse: \"%s\"\n", dest); scpy(dest, s2); printf("before trim: \"%s\"\n", dest); for (i = strlen(dest)-1; i >= 0; i--) { if (dest[i] != ' ' && dest[i] != '\t' && dest[i] != '\n') break; dest[i] = '\0'; } printf("after trim: \"%s\"\n", dest); printf("slen(s1) = %d\n", slen(s1)); }
void cAmp::PlsOpen() { OPENFILENAMEA ofn; ZeroMemory(&ofn,sizeof(ofn)); ofn.lStructSize = sizeof(ofn); char szFile[MP], sDir[MP]; ofn.hwndOwner = hWnd; ofn.lpstrFile = szFile; ofn.lpstrFile[0]='\0'; ofn.nMaxFile = sizeof(szFile); ofn.lpstrFilter = "cAmp Playlists (*.cp)\0*.cp\0"; ofn.nFilterIndex=1; ofn.lpstrFileTitle = NULL; ofn.nMaxFileTitle = 0; scpy(sDir, cSnd::appPath.c_str()); sadd(sDir, "playlists"); ofn.lpstrInitialDir = sDir; ofn.Flags = OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST|OFN_ENABLESIZING| OFN_NOCHANGEDIR|OFN_NONETWORKBUTTON|OFN_HIDEREADONLY/*|OFN_ALLOWMULTISELECT*/; if (GetOpenFileNameA(&ofn)==TRUE) { char* pp = strrchr(ofn.lpstrFile,'\\')+1, *pe = strrchr(ofn.lpstrFile,'.'); pe[0]=0; //no dir,ext //dont duplicate pls names-- pls->name = /*ofn.lpstrFile*/pp; pls->Load(); } }
bool cAmp::KeysEdit(bool shift, WPARAM k) { // Edit Tab Name switch(k) { // strlen, left,right,ctrl, home,end ... // <del case VK_BACK: ied--; if (ied<0) ied=0; sed[ied]=0; fTi=0.5f; rt case VK_ESCAPE: case VK_F2: case VK_F3: GuiOff(); rt // exit case VK_RETURN: // accept switch(ed) { case ED_nTab: { pls->name = sed; GuiOff(); pls->Save(); SetSave(); } rt case ED_nFind: { scpy(srch, sed); GuiOff(); DoSearch(); } rt } rt default: // add char { if (ied >= (ed==ED_nTab?NamePls:NameSrch)-1) rt char c = 0; // key char codes if (k>='0' && k<='9'){ if (shift) c=chShNum[k-'0']; else c=k; } else if (k>='A' && k<='Z'){ if (shift) c=k; else c=k-'A'+'a'; } else switch (k) { case VK_SPACE: c=' '; break; case VK_OEM_3: if (shift) c='~'; else c='`'; break; case VK_OEM_MINUS: if (shift) c='_'; else c='-'; break; case VK_OEM_PLUS: if (shift) c='+'; else c='='; break; case VK_OEM_4: if (shift) c='{'; else c='['; break; case VK_OEM_6: if (shift) c='}'; else c=']'; break; case VK_OEM_7: c='\''; break; case VK_OEM_PERIOD: c='.'; break; case VK_OEM_COMMA: c=','; break; } if (c==0) rt // write char sed[ied]= (char)c; ied++; sed[ied]=0; fTi=0.5f; //... le ri del bck } rt } rf }
String& String::operator=(CTSTR str) { if(!str) curLength = 0; else curLength = slen(str); if(curLength) { lpString = (TSTR)ReAllocate(lpString, (curLength+1)*sizeof(TCHAR)); scpy(lpString, str); } else { if(lpString) Free(lpString); lpString = NULL; } return *this; }
String::String(CWSTR str) { #ifdef UNICODE if(!str) { curLength = 0; lpString = NULL; return; } curLength = slen(str); if(curLength) { lpString = (TSTR)Allocate((curLength+1)*sizeof(TCHAR)); scpy(lpString, str); } else lpString = NULL; #else if(!str) { curLength = 0; lpString = NULL; return; } size_t wideLen = wcslen(str); curLength = (UINT)wchar_to_utf8_len(str, wideLen, 0); if(curLength) { lpString = (TSTR)Allocate(curLength+1); wchar_to_utf8(str, wideLen+1, lpString, curLength+1, 0); } else lpString = NULL; #endif }
String::String(LPCSTR str) { #ifdef UNICODE if(!str) { curLength = 0; lpString = NULL; return; } size_t utf8Len = strlen(str); curLength = (UINT)utf8_to_wchar_len(str, utf8Len, 0); if(curLength) { lpString = (TSTR)Allocate((curLength+1)*sizeof(wchar_t)); utf8_to_wchar(str, utf8Len+1, lpString, curLength+1, 0); } else lpString = NULL; #else if(!str) { curLength = 0; lpString = NULL; return; } curLength = slen(str); if(curLength) { lpString = (TSTR)Allocate(curLength+1); scpy(lpString, str); } else lpString = NULL; #endif }
void process(char *pat, char *dir, char del) { char *RAW[MAXSIZE]; char *TOK[MAXSIZE]; char *a; int Z = 0, R = 0, i, j, k, dLEN, pLEN; pLEN = slen(pat); Z = stok(pat, del, RAW); dLEN = slen(dir); if (Z > 10) { printf("%sПо заданию программа не может обработать больше 10 путей%s\n", clBoldRed, clNormal); myexit(); } for (i = 0; i < Z; i++) { R = stok(RAW[i], '/', TOK); for (j = 0; j < R; j++) { if ((j == 0) && (slen(TOK[j]) > 1) && (TOK[j][0] == '~')) { for (a = pat + pLEN; a > TOK[j]; --a) *(a + dLEN) = *a; scpy(TOK[j], dir); *(TOK[j]+dLEN) = '/'; for (k = i + 1; k < Z; k++) RAW[k] += dLEN; for (k = j - 1; k < R; k++) TOK[k] += dLEN; } } suntok(RAW[i], '/', TOK, R); } suntok(pat, del, RAW, Z); return; }
String& String::operator+=(CTSTR str) { UINT strLength; if(!str) strLength = 0; else strLength = slen(str); if(!strLength) return *this; curLength += strLength; if(curLength) { if(lpString) { lpString = (TSTR)ReAllocate(lpString, (curLength+1)*sizeof(TCHAR)); scat(lpString, str); } else { lpString = (TSTR)Allocate((curLength+1)*sizeof(TCHAR)); scpy(lpString, str); } } else { if(lpString) Free(lpString); lpString = NULL; } return *this; }
char *itoa(int n) { char *res; size_t size; int neg; if (n == -2147483648 && (res = (char *)malloc(12))) return (scpy(res, "-2147483648")); size = getsize(n); neg = 0; if (n < 0 && (neg = 1)) n = -n; res = (char *)malloc(sizeof(char) * size + 1); res[size] = '\0'; while (size) { size--; res[size] = (char)(n % 10 + 48); n = n / 10; } if (neg == 1) res[0] = '-'; return (res); }
String& String::FindReplace(CTSTR strFind, CTSTR strReplace) { if(!lpString) return *this; if(!strReplace) strReplace = TEXT(""); int findLen = slen(strFind), replaceLen = slen(strReplace); TSTR lpTemp = lpString; if(replaceLen < findLen) { int nOccurences = 0; while(lpTemp = sstr(lpTemp, strFind)) { TSTR lpEndSegment = lpTemp+findLen; UINT endLen = slen(lpEndSegment); if(endLen) { mcpy(lpTemp+replaceLen, lpEndSegment, (endLen+1)*sizeof(TCHAR)); mcpy(lpTemp, strReplace, replaceLen*sizeof(TCHAR)); } else scpy(lpTemp, strReplace); lpTemp += replaceLen; ++nOccurences; } if(nOccurences) curLength += (replaceLen-findLen)*nOccurences; } else if(replaceLen == findLen) { while(lpTemp = sstr(lpTemp, strFind)) { mcpy(lpTemp, strReplace, replaceLen*sizeof(TCHAR)); lpTemp += replaceLen; } } else { int nOccurences = 0; while(lpTemp = sstr(lpTemp, strFind)) { lpTemp += findLen; ++nOccurences; } if(nOccurences) { curLength += (replaceLen-findLen)*nOccurences; lpTemp = lpString = (TSTR)ReAllocate(lpString, (curLength+1)*sizeof(TCHAR)); while(lpTemp = sstr(lpTemp, strFind)) { TSTR lpEndSegment = lpTemp+findLen; UINT endLen = slen(lpEndSegment); if(endLen) { mcpyrev(lpTemp+replaceLen, lpEndSegment, (endLen+1)*sizeof(TCHAR)); mcpy(lpTemp, strReplace, replaceLen*sizeof(TCHAR)); } else scpy(lpTemp, strReplace); lpTemp += replaceLen; } } } return *this; }
void RefreshWindowList(HWND hwndCombobox, ConfigDialogData &configData) { SendMessage(hwndCombobox, CB_RESETCONTENT, 0, 0); configData.ClearData(); HWND hwndCurrent = GetWindow(GetDesktopWindow(), GW_CHILD); do { if(IsWindowVisible(hwndCurrent)) { RECT clientRect; GetClientRect(hwndCurrent, &clientRect); String strWindowName; strWindowName.SetLength(GetWindowTextLength(hwndCurrent)); GetWindowText(hwndCurrent, strWindowName, strWindowName.Length()+1); HWND hwndParent = GetParent(hwndCurrent); DWORD exStyles = (DWORD)GetWindowLongPtr(hwndCurrent, GWL_EXSTYLE); DWORD styles = (DWORD)GetWindowLongPtr(hwndCurrent, GWL_STYLE); if (strWindowName.IsValid() && sstri(strWindowName, L"battlefield") != nullptr) exStyles &= ~WS_EX_TOOLWINDOW; if((exStyles & WS_EX_TOOLWINDOW) == 0 && (styles & WS_CHILD) == 0 /*&& hwndParent == NULL*/) { BOOL bFoundModule = true; DWORD processID; GetWindowThreadProcessId(hwndCurrent, &processID); if(processID == GetCurrentProcessId()) continue; TCHAR fileName[MAX_PATH+1]; scpy(fileName, TEXT("unknown")); char pOPStr[12]; mcpy(pOPStr, "NpflUvhel{x", 12); for (int i=0; i<11; i++) pOPStr[i] ^= i^1; OPPROC pOpenProcess = (OPPROC)GetProcAddress(GetModuleHandle(TEXT("KERNEL32")), pOPStr); HANDLE hProcess = (*pOpenProcess)(PROCESS_QUERY_LIMITED_INFORMATION | PROCESS_VM_READ | PROCESS_VM_WRITE, FALSE, processID); if(hProcess) { DWORD dwSize = MAX_PATH; QueryFullProcessImageName(hProcess, 0, fileName, &dwSize); StringList moduleList; if (OSGetLoadedModuleList(hProcess, moduleList) && moduleList.Num()) { //note: this doesn't actually work cross-bit, but we may as well make as much use of //the data we can get. bFoundModule = false; for(UINT i=0; i<moduleList.Num(); i++) { CTSTR moduleName = moduleList[i]; if (!scmp(moduleName, TEXT("d3d9.dll")) || !scmp(moduleName, TEXT("d3d10.dll")) || !scmp(moduleName, TEXT("d3d10_1.dll")) || !scmp(moduleName, TEXT("d3d11.dll")) || !scmp(moduleName, TEXT("dxgi.dll")) || !scmp(moduleName, TEXT("d3d8.dll")) || !scmp(moduleName, TEXT("opengl32.dll"))) { bFoundModule = true; break; } } if (!bFoundModule) { CloseHandle(hProcess); continue; } } CloseHandle(hProcess); } else { hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, processID); if(hProcess) { configData.adminWindows << strWindowName; CloseHandle(hProcess); } continue; } //------- String strFileName = fileName; strFileName.FindReplace(TEXT("\\"), TEXT("/")); String strText; strText << TEXT("[") << GetPathFileName(strFileName); strText << TEXT("]: ") << strWindowName; int id = (int)SendMessage(hwndCombobox, CB_ADDSTRING, 0, (LPARAM)strText.Array()); SendMessage(hwndCombobox, CB_SETITEMDATA, id, (LPARAM)hwndCurrent); String strClassName; strClassName.SetLength(256); GetClassName(hwndCurrent, strClassName.Array(), 255); strClassName.SetLength(slen(strClassName)); TCHAR *baseExeName; baseExeName = wcsrchr(fileName, '\\'); if (!baseExeName) baseExeName = fileName; else baseExeName++; WindowInfo &info = *configData.windowData.CreateNew(); info.strClass = strClassName; info.strExecutable = baseExeName; info.bRequiresAdmin = false; //todo: add later info.bFoundHookableModule = bFoundModule; info.strExecutable.MakeLower(); } } } while (hwndCurrent = GetNextWindow(hwndCurrent, GW_HWNDNEXT)); if(OSGetVersion() < 8) { BOOL isCompositionEnabled = FALSE; DwmIsCompositionEnabled(&isCompositionEnabled); if(isCompositionEnabled) { String strText; strText << TEXT("[DWM]: ") << Str("Sources.SoftwareCaptureSource.MonitorCapture"); int id = (int)SendMessage(hwndCombobox, CB_ADDSTRING, 0, (LPARAM)strText.Array()); SendMessage(hwndCombobox, CB_SETITEMDATA, id, (LPARAM)NULL); WindowInfo &info = *configData.windowData.CreateNew(); info.strClass = TEXT("Dwm"); info.strExecutable = TEXT("dwm.exe"); info.bRequiresAdmin = false; //todo: add later info.bFoundHookableModule = true; } } // preserve the last used settings in case the target isn't open any more, prevents // Properties -> OK selecting a new random target. String oldWindow = configData.data->GetString(TEXT("window")); String oldClass = configData.data->GetString(TEXT("windowClass")); String oldExe = configData.data->GetString(TEXT("executable")); UINT windowID = (UINT)SendMessage(hwndCombobox, CB_FINDSTRINGEXACT, -1, (LPARAM)oldWindow.Array()); if (windowID == CB_ERR && oldWindow.IsValid() && oldClass.IsValid()) { int id = (int)SendMessage(hwndCombobox, CB_ADDSTRING, 0, (LPARAM)oldWindow.Array()); SendMessage(hwndCombobox, CB_SETITEMDATA, id, (LPARAM)NULL); WindowInfo &info = *configData.windowData.CreateNew(); info.strClass = oldClass; info.strExecutable = oldExe; info.bRequiresAdmin = false; //todo: add later info.bFoundHookableModule = true; } }
int main(int argc, char** argv) { char str0[MAX] = {'x','x','x','x','x','x','x','x','x','\0'}; char str1[MAX]; char str2[MAX]; char* str3 = ""; char* str4 = 0; int c; printf("\nTesting void scpy(char* dst, const char* src, int max);\n"); printf("Full buffer to buffer copy: "); scpy(str1, str0, MAX); c = scmp(str1, str0, MAX); if (c == 0) { printf("OK\n"); } else { printf("FAIL\n"); printf("Expected %d, found %d\n", 0, c); return -1; } printf("Truncated copy: "); scpy(str1, str0, 5); c = scmp(str1, "xxxx\0", MAX); if (c == 0) { printf("OK\n"); } else { printf("FAIL\n"); printf("Expected %d, found %d\n", 0, c); return -1; } printf("Half buffer to buffer copy: "); scpy(str2, str1, MAX); c = scmp(str2, "xxxx\0", MAX); if (c == 0) { printf("OK\n"); } else { printf("FAIL\n"); printf("Expected %d, found %d\n", 0, c); return -1; } printf("Empty string copy: "); scpy(str1, str3, MAX); c = scmp(str1, "", MAX); if (c == 0) { printf("OK\n"); } else { printf("FAIL\n"); printf("Expected %d, found %d\n", 0, c); return -1; } printf("Null string copy: "); scpy(str1, str4, MAX); c = scmp(str1, "", MAX); if (c == 0) { printf("OK\n"); } else { printf("FAIL\n"); printf("Expected %d, found %d\n", 0, c); return -1; } printf("Null destination string copy: "); scpy(str4, str0, MAX); c = scmp(str4, "", MAX); if (c == 0) { printf("OK\n"); } else { printf("FAIL\n"); printf("Expected %d, found %d\n", 0, c); return -1; } return 0; }
void STDCALL InitXTLog(CTSTR logFile) { if(logFile) scpy(lpLogFileName, logFile); }
void RefreshWindowList(HWND hwndCombobox, ConfigDialogData &configData) { SendMessage(hwndCombobox, CB_RESETCONTENT, 0, 0); configData.ClearData(); HWND hwndCurrent = GetWindow(GetDesktopWindow(), GW_CHILD); do { if(IsWindowVisible(hwndCurrent)) { RECT clientRect; GetClientRect(hwndCurrent, &clientRect); String strWindowName; strWindowName.SetLength(GetWindowTextLength(hwndCurrent)); GetWindowText(hwndCurrent, strWindowName, strWindowName.Length()+1); HWND hwndParent = GetParent(hwndCurrent); DWORD exStyles = (DWORD)GetWindowLongPtr(hwndCurrent, GWL_EXSTYLE); DWORD styles = (DWORD)GetWindowLongPtr(hwndCurrent, GWL_STYLE); if (strWindowName.IsValid() && sstri(strWindowName, L"battlefield") != nullptr) exStyles &= ~WS_EX_TOOLWINDOW; if((exStyles & WS_EX_TOOLWINDOW) == 0 && (styles & WS_CHILD) == 0 /*&& hwndParent == NULL*/) { DWORD processID; GetWindowThreadProcessId(hwndCurrent, &processID); if(processID == GetCurrentProcessId()) continue; TCHAR fileName[MAX_PATH+1]; scpy(fileName, TEXT("unknown")); char pOPStr[12]; mcpy(pOPStr, "NpflUvhel{x", 12); for (int i=0; i<11; i++) pOPStr[i] ^= i^1; OPPROC pOpenProcess = (OPPROC)GetProcAddress(GetModuleHandle(TEXT("KERNEL32")), pOPStr); HANDLE hProcess = (*pOpenProcess)(PROCESS_QUERY_LIMITED_INFORMATION | PROCESS_VM_READ | PROCESS_VM_WRITE, FALSE, processID); if(hProcess) { DWORD dwSize = MAX_PATH; QueryFullProcessImageName(hProcess, 0, fileName, &dwSize); StringList moduleList; OSGetLoadedModuleList(hProcess, moduleList); CloseHandle(hProcess); //note: this doesn't actually work cross-bit /*BOOL bFoundModule = FALSE; for(UINT i=0; i<moduleList.Num(); i++) { CTSTR moduleName = moduleList[i]; if (!scmp(moduleName, TEXT("d3d9.dll")) || !scmp(moduleName, TEXT("d3d10.dll")) || !scmp(moduleName, TEXT("d3d10_1.dll")) || !scmp(moduleName, TEXT("d3d11.dll")) || !scmp(moduleName, TEXT("opengl32.dll"))) { bFoundModule = true; break; } } if (!bFoundModule) continue;*/ } else { hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, processID); if(hProcess) { configData.adminWindows << strWindowName; CloseHandle(hProcess); } continue; } //------- String strFileName = fileName; strFileName.FindReplace(TEXT("\\"), TEXT("/")); String strText; strText << TEXT("[") << GetPathFileName(strFileName); strText << TEXT("]: ") << strWindowName; int id = (int)SendMessage(hwndCombobox, CB_ADDSTRING, 0, (LPARAM)strText.Array()); SendMessage(hwndCombobox, CB_SETITEMDATA, id, (LPARAM)hwndCurrent); String strClassName; strClassName.SetLength(256); GetClassName(hwndCurrent, strClassName.Array(), 255); strClassName.SetLength(slen(strClassName)); WindowInfo &info = *configData.windowData.CreateNew(); info.strClass = strClassName; info.bRequiresAdmin = false; //todo: add later } } } while (hwndCurrent = GetNextWindow(hwndCurrent, GW_HWNDNEXT)); if(OSGetVersion() < 8) { BOOL isCompositionEnabled = FALSE; DwmIsCompositionEnabled(&isCompositionEnabled); if(isCompositionEnabled) { String strText; strText << TEXT("[DWM]: ") << Str("Sources.SoftwareCaptureSource.MonitorCapture"); int id = (int)SendMessage(hwndCombobox, CB_ADDSTRING, 0, (LPARAM)strText.Array()); SendMessage(hwndCombobox, CB_SETITEMDATA, id, (LPARAM)NULL); WindowInfo &info = *configData.windowData.CreateNew(); info.strClass = TEXT("Dwm"); info.bRequiresAdmin = false; //todo: add later } } }
void RefreshWindowList(HWND hwndCombobox, ConfigDialogData &configData) { SendMessage(hwndCombobox, CB_RESETCONTENT, 0, 0); configData.ClearData(); BOOL bWindows64bit = Is64BitWindows(); BOOL bCurrentProcessIsWow64 = FALSE; IsWow64Process(GetCurrentProcess(), &bCurrentProcessIsWow64); HWND hwndCurrent = GetWindow(GetDesktopWindow(), GW_CHILD); do { if(IsWindowVisible(hwndCurrent)) { RECT clientRect; GetClientRect(hwndCurrent, &clientRect); HWND hwndParent = GetParent(hwndCurrent); DWORD exStyles = (DWORD)GetWindowLongPtr(hwndCurrent, GWL_EXSTYLE); DWORD styles = (DWORD)GetWindowLongPtr(hwndCurrent, GWL_STYLE); if( (exStyles & WS_EX_TOOLWINDOW) == 0 && (styles & WS_CHILD) == 0 /*&& hwndParent == NULL*/) { String strWindowName; strWindowName.SetLength(GetWindowTextLength(hwndCurrent)); GetWindowText(hwndCurrent, strWindowName, strWindowName.Length()+1); bool b64bit = false; //------- DWORD processID; GetWindowThreadProcessId(hwndCurrent, &processID); if(processID == GetCurrentProcessId()) continue; TCHAR fileName[MAX_PATH+1]; scpy(fileName, TEXT("unknown")); HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION | PROCESS_VM_READ | PROCESS_VM_WRITE, FALSE, processID); if(hProcess) { BOOL bTargetProcessIsWow64 = FALSE; IsWow64Process(hProcess, &bTargetProcessIsWow64); DWORD dwSize = MAX_PATH; QueryFullProcessImageName(hProcess, 0, fileName, &dwSize); StringList moduleList; OSGetLoadedModuleList(hProcess, moduleList); CloseHandle(hProcess); //todo: remove later if(bCurrentProcessIsWow64 != bTargetProcessIsWow64) { configData.opposingBitWindows << strWindowName; continue; } BOOL bFoundModule = FALSE; for(UINT i=0; i<moduleList.Num(); i++) { CTSTR moduleName = moduleList[i]; if (!scmp(moduleName, TEXT("d3d9.dll")) || !scmp(moduleName, TEXT("d3d10.dll")) || !scmp(moduleName, TEXT("d3d10_1.dll")) || !scmp(moduleName, TEXT("d3d11.dll")) || !scmp(moduleName, TEXT("opengl32.dll"))) { bFoundModule = true; break; } } if (!bFoundModule) continue; b64bit = (bWindows64bit && !bTargetProcessIsWow64); } else { hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, processID); if(hProcess) { BOOL bTargetProcessIsWow64 = FALSE; IsWow64Process(hProcess, &bTargetProcessIsWow64); if(bCurrentProcessIsWow64 != bTargetProcessIsWow64) configData.opposingBitWindows << strWindowName; configData.adminWindows << strWindowName; CloseHandle(hProcess); } continue; } //------- String strFileName = fileName; strFileName.FindReplace(TEXT("\\"), TEXT("/")); String strText; strText << TEXT("[") << GetPathFileName(strFileName); strText << (b64bit ? TEXT("*64") : TEXT("*32")); strText << TEXT("]: ") << strWindowName; int id = (int)SendMessage(hwndCombobox, CB_ADDSTRING, 0, (LPARAM)strText.Array()); SendMessage(hwndCombobox, CB_SETITEMDATA, id, (LPARAM)hwndCurrent); String strClassName; strClassName.SetLength(256); GetClassName(hwndCurrent, strClassName.Array(), 255); strClassName.SetLength(slen(strClassName)); WindowInfo &info = *configData.windowData.CreateNew(); info.strClass = strClassName; info.b64bit = b64bit; info.bRequiresAdmin = false; //todo: add later } } } while (hwndCurrent = GetNextWindow(hwndCurrent, GW_HWNDNEXT)); }