x_pool_t *x_create_pool(size_t size) { x_pool_t *p; p = (x_pool_t *)x_alloc(size); if (p == NULL) { return NULL; } p->last = (u_char *) p + sizeof(x_pool_t); p->end = (u_char *) p + size; p->current = p; p->next = NULL; p->large = NULL; p->cleanup = NULL; return p; }
static int print_file(WINDOW *w, int item) { /* int handle, error = 0, i, key, result = 0, r; DjV 033 010203 */ int handle, error = 0, i, result = 0; /* DjV 033 010203 */ char *buffer; const char *name; long l; /* index in buffer[] */ int ll = 0; /* DjV 031 150203 line length counter */ boolean stop = FALSE; if ((name = itm_fullname(w, item)) == NULL) return XFATAL; buffer = x_alloc(PBUFSIZ); if (buffer != NULL) { graf_mouse(HOURGLASS, NULL); if ((handle = x_open(name, O_DENYW | O_RDONLY)) >= 0) { do { if ((l = x_read(handle, PBUFSIZ, buffer)) >= 0) { for (i = 0; i < (int) l; i++) { /* DjV 031 150203 ---vvv--- */ /* * line wrap & new line handling; */ ll++; if ( (buffer[i] == (char)13) || (buffer[i] == (char)10) || (buffer[i] == (char)12) ) ll = 0; /* reset linelength counter at CR, LF or FF */ else if ( ll >= plinelen ) { ll = 0; if (( stop = print_eol() ) == TRUE) break; } /* DjV 031 150203 ---^^^--- */ if ((stop = prtchar(buffer[i])) == TRUE) break; } /* DjV 033 010203 ---vvv--- */ /* if ((r = key_state(&key, TRUE)) > 0) { if (key == ESCAPE) stop = TRUE; } else if (r < 0) stop = TRUE; */ if ( escape_abort(TRUE) ) stop = TRUE; /* DjV 033 010203 ---^^^--- */ } else error = (int) l; } while ((l == PBUFSIZ) && (stop == FALSE)); x_close(handle); print_eol(); /* DjV 031 150203 print cr lf at end of file */ } else error = handle; if (stop == TRUE) result = XABORT; if (error != 0) result = xhndl_error(MEPRINT, error, itm_name(w, item)); graf_mouse(ARROW, NULL); x_free(buffer); } else { xform_error(ENSMEM); result = XFATAL; } free(name); return result; }
INT_PTR CALLBACK DlgProc(HWND hdlg, UINT wmsg, WPARAM wparam, LPARAM lparam){ HANDLE phandle; ULONG index; OPENFILENAME ofn; HICON icon; switch (wmsg){ case WM_INITDIALOG: GlobalList = GetDlgItem(hdlg, IDC_LIST1); icon = ::LoadIconA(GetModuleHandleA(0), (LPSTR)IDI_ICON1); SendMessageA(hdlg, WM_SETICON, ICON_SMALL, (LPARAM)icon); SendMessageA(GlobalList, LB_RESETCONTENT, 0,0); ::EnumProcesses(pids, 4096 * sizeof(DWORD), &needed); num_of_processes = needed / sizeof(DWORD); for (DWORD i = 0; i < num_of_processes; i++){ phandle = ::OpenProcess(PROCESS_ALL_ACCESS, false, pids[i]); if (!phandle){ wsprintf(buffer, "%.04X - process can't be opened", pids[i]); SendMessageA(GlobalList, LB_ADDSTRING, 0, (LPARAM)buffer); continue; } if (!EnumProcessModules(phandle, modules, 4096 * sizeof(HMODULE), &needed)){ ::CloseHandle(phandle); wsprintfA(buffer, "%.04X - can't obtain name", pids[i]); SendMessageA(GlobalList, LB_ADDSTRING, 0, (LPARAM)buffer); continue; } if (!::GetModuleFileNameExA(phandle, modules[0], proc_name, 4096)){ ::CloseHandle(phandle); wsprintfA(buffer, "%.04X - can't obtain name", pids[i]); SendMessageA(GlobalList, LB_ADDSTRING, 0, (LPARAM)buffer); continue; } wsprintfA(buffer, "%.04X - %s", pids[i], proc_name); SendMessageA(GlobalList, LB_ADDSTRING, 0, (LPARAM)buffer); ::CloseHandle(phandle); } return 1; case WM_CLOSE: EndDialog(hdlg, 0); return 1; case WM_COMMAND: if (wparam == ID_DUMP){ index = SendMessageA(GlobalList, LB_GETCURSEL, 0,0); if (index == LB_ERR){ MessageBoxA(hdlg, "select process for dumping...", 0, 0); return 1; } mym(&ofn, 0, sizeof(OPENFILENAME)); ofn.lStructSize = sizeof(OPENFILENAME); ofn.lpstrFilter = "Anyfile\0*.*\0\0"; ofn.lpstrFile = (LPSTR)x_alloc(MAX_PATH); ofn.nMaxFile = MAX_PATH; ofn.hwndOwner = hdlg; if (!GetSaveFileNameA(&ofn)){ MessageBoxA(hdlg, "select some file...", 0, 0); x_free(ofn.lpstrFile); return 1; } char *dir_name = ofn.lpstrFile + ::lstrlenA(ofn.lpstrFile) + 1; while (*dir_name != '\\') dir_name--; dir_name[0] = 0; dump_all(pids[index], ofn.lpstrFile); MessageBoxA(hdlg, "duming done...", "success", 0); x_free(ofn.lpstrFile); return 1; } if (wparam == ID_REFRESH){ SendMessageA(GlobalList, LB_RESETCONTENT, 0,0); ::EnumProcesses(pids, 4096 * sizeof(DWORD), &needed); num_of_processes = needed / sizeof(DWORD); for (DWORD i = 0; i < num_of_processes; i++){ phandle = ::OpenProcess(PROCESS_ALL_ACCESS, false, pids[i]); if (!phandle){ wsprintf(buffer, "%.04X - process can't be opened", pids[i]); SendMessageA(GlobalList, LB_ADDSTRING, 0, (LPARAM)buffer); continue; } if (!EnumProcessModules(phandle, modules, 4096 * sizeof(HMODULE), &needed)){ ::CloseHandle(phandle); wsprintfA(buffer, "%.04X - can't obtain name", pids[i]); SendMessageA(GlobalList, LB_ADDSTRING, 0, (LPARAM)buffer); continue; } if (!::GetModuleFileNameExA(phandle, modules[0], proc_name, 4096)){ ::CloseHandle(phandle); wsprintfA(buffer, "%.04X - can't obtain name", pids[i]); SendMessageA(GlobalList, LB_ADDSTRING, 0, (LPARAM)buffer); continue; } wsprintfA(buffer, "%.04X - %s", pids[i], proc_name); SendMessageA(GlobalList, LB_ADDSTRING, 0, (LPARAM)buffer); ::CloseHandle(phandle); } return 1; } default: return 0; } return 0; }
void *x_palloc(x_pool_t *pool, size_t size) { u_char *m; x_pool_t *p, *n, *current; x_pool_large_t *large; if (size <= (size_t)X_MAX_ALLOC_FROM_POOL && size <= (size_t) (pool->end - (u_char *) pool) - (size_t) x_align_ptr(sizeof(x_pool_t), X_ALIGNMENT)) { p = pool->current; current = p; for ( ;; ) { m = x_align_ptr(p->last, X_ALIGNMENT); if ((size_t) (p->end - m) >= size) { p->last = m + size; return m; } if ((size_t) (p->end - m) < X_ALIGNMENT) { current = p->next; } if (p->next == NULL) { break; } p = p->next; pool->current = current; } n = x_create_pool((size_t) (p->end - (u_char *)p)); if (n == NULL) { return NULL; } pool->current = current ? current : n; p->next = n; m = x_align_ptr(n->last, X_ALIGNMENT); n->last = m + size; return m; } p = x_alloc(size); if (p == NULL) { return NULL; } large = x_palloc(pool, sizeof(x_pool_large_t)); if (large == NULL) { x_free(p); return NULL; } large->alloc = p; large->next = pool->large; pool->large = large; return p; }