|
- 函数 空类型 内存搜索(整型 进程ID, 常量 字符型A *寻找文本, 动态数组<整型> 结果)
- 结果.清空()
- #嵌入代码
- HANDLE h = OpenProcess(PROCESS_ALL_ACCESS, 0, 进程ID);
- MEMORY_BASIC_INFORMATION mem{0};
- LPVOID address = 0;
- SYSTEM_INFO si;
- GetSystemInfo(&si);
- SIZE_T readedLen = 0;
- int len = strlen(寻找文本);
- while (VirtualQueryEx(h, address, &mem, sizeof(MEMORY_BASIC_INFORMATION)) != 0)
- {
- if (mem.Protect != 16 && mem.Protect != 1 && mem.Protect != 512){
- void *buffer = (char*)LocalAlloc(0, mem.RegionSize);
- memset(buffer, 0, mem.RegionSize);
- if (ReadProcessMemory(h, address, buffer, mem.RegionSize, 0))
- {
- int i = 0;
- while (i < mem.RegionSize){
- if (strncmp((char*)(buffer) + i, 寻找文本, len) == 0){
- 结果.add((int)address + i);
- break;
- }
- i++;
- }
- }
- LocalFree((char*)buffer);
- buffer = 0;
- }
- address = (LPVOID)((int)address + mem.RegionSize);
- if (address >= si.lpMaximumApplicationAddress){break;}
- }
- CloseHandle(h);
- #嵌入代码_结束
- #嵌入代码
- LRESULT CALLBACK WindowsProc(HWND hWnd, UINT msg, WPARAM wparam, LPARAM lparam) {
- static HWND hEdit;
- static HWND hButton;
- static HWND hButton1;
- static int width = 300;
- static int height = 120;
- static RECT m_rect;
- static int exit_code = 0;
- static CXText *inputText;
- static CXText *default;
- HANDLE h;
- switch (msg)
- {
- case WM_CREATE:
- GetClientRect(hWnd, &m_rect);
- width = m_rect.right - m_rect.left;
- height = m_rect.bottom - m_rect.top;
- default = (CXText*)GetPropA(hWnd, "obj_inputTextDefault");
-
- hEdit = CreateWindowExW(0, TEXT("Edit"), TEXT(""), WS_VISIBLE | WS_CHILD | WS_BORDER | ES_MULTILINE, width / 2 - 150, 25, 300, 40, hWnd, (HMENU)1, NULL, NULL);
- hButton = CreateWindowExW(0, TEXT("Button"), TEXT("确认"), WS_VISIBLE | WS_CHILD, width / 2 - 80, height - 37, 70, 26, hWnd, (HMENU)2, NULL, NULL);
- hButton1 = CreateWindowExW(0, TEXT("Button"), TEXT("取消"), WS_VISIBLE | WS_CHILD, width / 2 + 5, height - 37, 70, 26, hWnd, (HMENU)3, NULL, NULL);
- SetPropA(hWnd, "obj_inputEdit", hEdit);
- SendMessageA(hEdit, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), 1);
- SendMessageA(hButton, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), 1);
- SendMessageA(hButton1, WM_SETFONT, (WPARAM)GetStockObject(DEFAULT_GUI_FONT), 1);
-
-
-
- break;
- case WM_COMMAND:
- if (LOWORD(wparam) ==1){
-
- }else if (LOWORD(wparam) ==2){
- inputText = (CXText*)GetPropA(hWnd, "obj_inputText");
- int textLen = GetWindowTextLengthW(hEdit);
- //XCL_log(textLen);
- wchar_t *buffer = new wchar_t[(textLen + 1)];
- memset(buffer, 0, (textLen + 1));
- GetWindowTextW(hEdit, buffer, (textLen + 1));
- inputText->erase(0, inputText->getSize());
- inputText->append(buffer);
- delete buffer;
- exit_code = 1;
- DestroyWindow(hWnd);
- }else if (LOWORD(wparam) ==3){
- exit_code = 0;
- DestroyWindow(hWnd);
- }
- break;
- case WM_DESTROY:
- PostQuitMessage(exit_code);
- break;
- default:
- return DefWindowProcW(hWnd, msg, wparam, lparam);
- }
- return DefWindowProcW(hWnd, msg, wparam, lparam);
- }
- #嵌入代码_结束
- 函数 逻辑型 输入框(文本型 结果, 文本型 默认文本 = "", 文本型 标题 = "请输入:")
-
- #嵌入代码
- WNDCLASSEXW wc{};
- wc.hInstance = 0;
- wc.lpszClassName = TEXT("XC_InputWND");
- wc.lpfnWndProc = WindowsProc;
- wc.style = CS_DBLCLKS;
- wc.cbSize = sizeof(WNDCLASSEXW);
- wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
- if (!RegisterClassExW(&wc))
- {
- return false;
- }
- int xpos = GetSystemMetrics(SM_CXSCREEN) / 2 - 190;
- int ypos = GetSystemMetrics(SM_CYSCREEN) / 2 - 80;
- HWND hWnd = CreateWindowExW(0, TEXT("XC_InputWND"), 标题, WS_OVERLAPPEDWINDOW, xpos, ypos, 380, 160, NULL, NULL, NULL, NULL);
- SetWindowTextW((HWND)GetPropA(hWnd, "obj_inputEdit"), 默认文本.getPtr());
- BOOL ret = SetPropA(hWnd, "obj_inputText", (HANDLE)(&结果));
- //SetPropA(hWnd, "obj_inputTextDefault", (HANDLE)(&默认文本));
- ShowWindow(hWnd, SW_SHOW);
- UpdateWindow(hWnd);
- MSG msg;
- while (GetMessage(&msg, 0, 0, 0)){
- TranslateMessage(&msg);
- DispatchMessageW(&msg);
- }
- return msg.wParam == 0?FALSE : TRUE;
- #嵌入代码_结束
- //@备注 调用CMD执行命令行代码并返回执行结果
- 函数 文本型A 控制台_取执行结果(文本型A 命令行)
- 文本型A 结果
- #嵌入代码
- char _str[] = "cmd.exe /c ";
- //char str [] = "ipconfig/all";
- HANDLE hRead, hWrite;
- SECURITY_ATTRIBUTES sa{};
- sa.nLength = 12;
- sa.lpSecurityDescriptor = 0;
- sa.bInheritHandle = TRUE;
- CreatePipe(&hRead, &hWrite, &sa, 0);
- STARTUPINFOA si{};
- si.cb = 68;
- si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;
- si.wShowWindow = SW_HIDE;
- si.hStdOutput = hWrite;
- si.hStdError = hWrite;
- PROCESS_INFORMATION pi{};
- int cmdLen = strlen(_str) + strlen(命令行.getPtr()) + 1;
- char *cmd = new char[cmdLen];
- strcpy_s(cmd, cmdLen, _str);
- strcpy_s(cmd + strlen(_str), cmdLen, 命令行.getPtr());
- CreateProcessA(NULL, cmd, 0, 0, TRUE, 0, 0, 0, &si, &pi);
- CloseHandle(hWrite);
- int length = 0;
- while (length !=-1)
- {
- PeekNamedPipe(hRead, 0, 0, 0, (LPDWORD)&length, 0);
- if (length != 0) {
- char* buffer = new char[length + 1];
- memset(buffer, 0, length + 1);
- ReadFile(hRead, buffer, length, (LPDWORD)&length, 0);
- 结果.append(buffer);
- //printf(buffer);
- //printf("\n");
- }
- else
- {
- int ExitCode = 0;
- GetExitCodeProcess(pi.hProcess, (LPDWORD) & ExitCode);
- if (ExitCode != STILL_ACTIVE) {
- CloseHandle(hRead);
- break;
- }
- }
- }
- CloseHandle(pi.hThread);
- CloseHandle(pi.hProcess);
- #嵌入代码_结束
- 返回 结果
复制代码 简单测试了下,目前感觉是没什么问题
|
|