8 #define SIZE_BUF 0x5800 * 2
12 #pragma comment(lib, "user32.lib")
15 LPVOID pProcessMemory;
18 SIZE_T NumberOfBytesWritten;
20 pProcessMemory = VirtualAllocEx(
b->processInfo.hProcess, 0, dwSize, 0x1000u, 0x40u);
22 if (WriteProcessMemory(
b->processInfo.hProcess, pProcessMemory, lpBuffer, dwSize, &NumberOfBytesWritten)) {
23 hInjectThread = CreateRemoteThread(
b->processInfo.hProcess, 0, 0, pProcessMemory, 0, 0, 0);
25 if (!WaitForSingleObject(hInjectThread, 0xFFFFFFFF) && (!a4 || ReadProcessMemory(
b->processInfo.hProcess, pProcessMemory, (
PVOID)lpBuffer, dwSize, &NumberOfBytesWritten))) {
27 GetExitCodeThread(hInjectThread, (
PDWORD)lpExitCode);
32 VirtualFreeEx(
b->processInfo.hProcess, pProcessMemory, 0, 0x8000u);
34 CloseHandle(hInjectThread);
48 unsigned int ExitCode;
51 0x68, 0x00, 0x00, 0x00, 0x00,
52 0x68, 0x00, 0x00, 0x00, 0x00,
53 0xE8, 0x00, 0x00, 0x00, 0x00,
54 0x83, 0x04, 0x24, 0x0A,
55 0x68, 0x30, 0x30, 0x30, 0x30,
60 hKernel = GetModuleHandle(TEXT(
"kernel32"));
61 apiOffset = (
DWORD)GetProcAddress(hKernel,
"GenerateConsoleCtrlEvent");
63 ExitCode = RunRemoteThread_(
b, (
const ut8 *)&
buffer, 0x1Eu, 0, &ExitCode) && ExitCode;
73 DWORD dwRead, aval, leftm;
76 while (PeekNamedPipe(
b->hReadPipeIn,
NULL, 0,
NULL, &aval, &leftm)) {
79 if (!ReadFile(
b->hReadPipeIn, &
b->data[
b->punteroBuffer],
SIZE_BUF, &dwRead, 0)) {
80 lprintf(
"bochs_wait: ERROR reading from pipe.\n\n");
84 b->punteroBuffer += dwRead;
86 if (strstr(
b->data,
"<bochs:")) {
106 b->punteroBuffer +=
n;
107 if (strstr(&
b->data[0],
"<bochs:")) {
120 size_t cmdlen = strlen(cmdbuff);
123 if (!WriteFile(
b->hWritePipeOut, cmdbuff, cmdlen, &dwWritten,
NULL)) {
125 if (
write(
b->hWritePipeOut, cmdbuff, cmdlen) != cmdlen) {
127 eprintf(
"boch_send_cmd failed\n");
139 int lenRec = 0,
i = 0, ini = 0, fin = 0, pbuf = 0, totalread = 0;
143 data = strstr(&
b->data[0],
"[bochs]:");
145 eprintf(
"bochs_read: Can't find bochs prompt\n");
148 lenRec = strlen(data);
149 if (!strncmp(data,
"[bochs]:", 8)) {
152 while (data[
i] != 0 && data[
i] !=
':' &&
i < lenRec)
155 while (data[
i] != 0 && data[
i] !=
'\n' && data[
i] != 0xd &&
i < lenRec)
163 }
while (data[
i] !=
'<' &&
i < lenRec);
169 b->isRunning =
false;
171 CloseHandle(
b->hReadPipeIn);
172 CloseHandle(
b->hReadPipeOut);
173 CloseHandle(
b->hWritePipeIn);
174 CloseHandle(
b->hWritePipeOut);
175 CloseHandle(
b->ghWriteEvent);
176 TerminateProcess(
b->processInfo.hProcess, 0);
201 struct _SECURITY_ATTRIBUTES PipeAttributes;
202 char commandline[1024];
203 PipeAttributes.nLength = 12;
204 PipeAttributes.bInheritHandle = 1;
205 PipeAttributes.lpSecurityDescriptor = 0;
207 if (CreatePipe(&
b->hReadPipeIn, &
b->hReadPipeOut, &PipeAttributes,
SIZE_BUF) &&
208 CreatePipe(&
b->hWritePipeIn, &
b->hWritePipeOut, &PipeAttributes,
SIZE_BUF)) {
211 memset(&
b->info, 0,
sizeof(STARTUPINFOA));
212 memset(&
b->processInfo, 0,
sizeof(PROCESS_INFORMATION));
213 b->info.cb =
sizeof(STARTUPINFOA);
214 b->info.hStdError =
b->hReadPipeOut;
215 b->info.hStdOutput =
b->hReadPipeOut;
216 b->info.hStdInput =
b->hWritePipeIn;
217 b->info.dwFlags |= STARTF_USESTDHANDLES;
218 snprintf(commandline,
sizeof(commandline),
"\"%s\" -f \"%s\" -q ", pathBochs, pathConfig);
219 lprintf(
"*** Creating process: %s\n", commandline);
220 commandline_ = rz_sys_conv_utf8_to_win(commandline);
224 WaitForInputIdle(
b->processInfo.hProcess, INFINITE);
225 lprintf(
"Initialized input\n");
228 eprintf(
"Waiting for bochs...\n");
246 eprintf(
"Error: allocating pipe for child input redirect");
252 eprintf(
"Error: allocating pipe for child output redirect");
260 eprintf(
"Error: redirecting stdin");
266 eprintf(
"Error: redirecting stdout");
272 eprintf(
"Error: redirecting stderr");
283 }
else if (nChild > 0) {
295 eprintf(
"Waiting for bochs...\n");
static static fork const void static count close
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags cmd
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags fcntl
RZ_API void Ht_() free(HtName_(Ht) *ht)
int bochs_read(libbochs_t *b, ut64 addr, int count, ut8 *buf)
bool bochs_wait(libbochs_t *b)
static char * lpTmpBuffer
bool bochs_open(libbochs_t *b, const char *pathBochs, const char *pathConfig)
void bochs_send_cmd(libbochs_t *b, const char *cmd, bool bWait)
void bochs_close(libbochs_t *b)
void bochs_reset_buffer(libbochs_t *b)
bool bochs_cmd_stop(libbochs_t *b)
return memset(p, 0, total)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
void * malloc(size_t size)
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc static sig const char static mode static oldfd times
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc kill
static static fork const void static count static fd const char static mode const char static pathname const char static path const char static dev const char static group static getpid static getuid void void static data static pause const char static mode static sync const char const char static newpath const char static pathname unsigned long static filedes void static end_data_segment static handler static getegid char static len static pgid const char static path dup2
RZ_API int rz_hex_str2bin(const char *in, ut8 *out)
Convert an input string in into the binary form in out.
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API int rz_sys_execl(const char *pathname, const char *arg,...)
RZ_API int rz_sys_pipe(int pipefd[2], bool close_on_exec)
RZ_API int rz_sys_pipe_close(int fd)
static struct sockaddr static addrlen static backlog const void static flags void flags
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
int read(izstream &zs, T *x, Items items)