//-------------------------------------------------------------------------- bool win32_debmod_t::set_debug_hook(ea_t base) { // the debug hook for borland is located at the very beginning of // the program's text segment, with a clear signature before peheader_t pe; ea_t peoff = get_pe_header(base, &pe); if ( peoff == BADADDR ) return false; ea_t text = base + pe.text_start; uchar buf[4096]; if ( _read_memory(text, buf, sizeof(buf)) != sizeof(buf) ) return false; ssize_t bcc_hook_off = find_bcc_sign(buf, sizeof(buf)); if ( bcc_hook_off == -1 ) return false; uint32 bcc_hook; if ( _read_memory(text+bcc_hook_off, &bcc_hook, 4) != 4 ) return false; // now the bcc_hook might be already relocated or not. // it seems that vista loads files without relocating them for // the 'open file' dialog box. This is an heuristic rule: if ( bcc_hook < base + pe.text_start || bcc_hook > base + pe.imagesize ) return false; const uint32 active_hook = 2; // borland seems to want this number return _write_memory(bcc_hook, &active_hook, 4) == 4; }
static void restore_breakpoint_data(unsigned char breakpoint_num) { unsigned char* inst_data = breakpoints[breakpoint_num].saved_data; /*? me.from_instance.name ?*/_write_memory(reg_pc, BREAKPOINT_INSTRUCTION_SIZE, inst_data); for (int i = 0; i < BREAKPOINT_INSTRUCTION_SIZE; i++) { breakpoints[breakpoint_num].saved_data[i] = 0; } breakpoints[free_breakpoint_tail].saved_data[0] = breakpoint_num; }
static void GDB_insert_sw_breakpoint(char* command) { char *addr_string = strtok(command + 2, ",#"); seL4_Word addr = (seL4_Word) strtol(addr_string, NULL, 16); unsigned char breakpoint_index = save_breakpoint_data(addr); unsigned char breakpoint[2] = {0xCC, breakpoint_index}; seL4_Word error = /*? me.from_instance.name ?*/_write_memory(addr, 2, (unsigned char *)&breakpoint); if (!error) { send_message("OK", 0); } }
int _write(int file, char *ptr, int len) { // TODO: for (int i = 0; i < len; i++) { _write_memory(ptr[i]); } return len; /* int r; */ /* for (r = 0; r < len; r++) { */ /* uart0_putc(ptr[r]); */ /* } */ /* return len; */ }
static gboolean arv_gv_device_write_memory (ArvDevice *device, guint32 address, guint32 size, void *buffer, GError **error) { ArvGvDevice *gv_device = ARV_GV_DEVICE (device); int i; gint32 block_size; for (i = 0; i < (size + ARV_GVCP_DATA_SIZE_MAX - 1) / ARV_GVCP_DATA_SIZE_MAX; i++) { block_size = MIN (ARV_GVCP_DATA_SIZE_MAX, size - i * ARV_GVCP_DATA_SIZE_MAX); if (!_write_memory (gv_device->priv->io_data, address + i * ARV_GVCP_DATA_SIZE_MAX, block_size, buffer + i * ARV_GVCP_DATA_SIZE_MAX, error)) return FALSE; } return TRUE; }
static gboolean arv_uv_device_write_memory (ArvDevice *device, guint64 address, guint32 size, void *buffer, GError **error) { ArvUvDevice *uv_device = ARV_UV_DEVICE (device); int i; gint32 block_size; guint data_size_max; data_size_max = uv_device->priv->ack_packet_size_max - sizeof (ArvUvcpHeader); for (i = 0; i < (size + data_size_max - 1) / data_size_max; i++) { block_size = MIN (data_size_max, size - i * data_size_max); if (!_write_memory (uv_device, address + i * data_size_max, block_size, ((char *) buffer) + i * data_size_max, error)) return FALSE; } return TRUE; }
// GDB write memory format: // M[addr],[length]:[data] static void GDB_write_memory(char* command) { // Get address to write to from command char *addr_string = strtok(command, "M,"); // Get num of bytes to write from command char *length_string = strtok(NULL, ",:"); // Get data from command char *data_string = strtok(NULL, ":"); // Convert strings to values seL4_Word addr = (seL4_Word) strtol(addr_string, NULL, HEX_STRING); seL4_Word length = (seL4_Word) strtol(length_string, NULL, DEC_STRING); // Buffer for data to be written unsigned char data[length]; memset(data, 0, length); // Parse data to be written as raw hex for (int i = 0; i < length; i++) { sscanf(data_string, "%2hhx", &data[i]); data_string += CHAR_HEX_SIZE; } // Do a write call to the GDB delegate who will write to the process on our behalf seL4_Word error = /*? me.from_instance.name ?*/_write_memory(addr, length, data); if (!error) { send_message("OK", 0); } }