当前位置: 首页>>代码示例>>C++>>正文


C++ write_memory函数代码示例

本文整理汇总了C++中write_memory函数的典型用法代码示例。如果您正苦于以下问题:C++ write_memory函数的具体用法?C++ write_memory怎么用?C++ write_memory使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了write_memory函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: vax_store_arguments

static CORE_ADDR
vax_store_arguments (struct regcache *regcache, int nargs,
		     struct value **args, CORE_ADDR sp)
{
  struct gdbarch *gdbarch = get_regcache_arch (regcache);
  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  gdb_byte buf[4];
  int count = 0;
  int i;

  /* We create an argument list on the stack, and make the argument
     pointer to it.  */

  /* Push arguments in reverse order.  */
  for (i = nargs - 1; i >= 0; i--)
    {
      int len = TYPE_LENGTH (value_enclosing_type (args[i]));

      sp -= (len + 3) & ~3;
      count += (len + 3) / 4;
      write_memory (sp, value_contents_all (args[i]), len);
    }

  /* Push argument count.  */
  sp -= 4;
  store_unsigned_integer (buf, 4, byte_order, count);
  write_memory (sp, buf, 4);

  /* Update the argument pointer.  */
  store_unsigned_integer (buf, 4, byte_order, sp);
  regcache_cooked_write (regcache, VAX_AP_REGNUM, buf);

  return sp;
}
开发者ID:mbref,项目名称:binutils-gdb-microblaze,代码行数:34,代码来源:vax-tdep.c

示例2: m68k_push_dummy_call

static CORE_ADDR
m68k_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
		      struct regcache *regcache, CORE_ADDR bp_addr, int nargs,
		      struct value **args, CORE_ADDR sp, int struct_return,
		      CORE_ADDR struct_addr)
{
  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  gdb_byte buf[4];
  int i;

  /* Push arguments in reverse order.  */
  for (i = nargs - 1; i >= 0; i--)
    {
      struct type *value_type = value_enclosing_type (args[i]);
      int len = TYPE_LENGTH (value_type);
      int container_len = (len + 3) & ~3;
      int offset;

      /* Non-scalars bigger than 4 bytes are left aligned, others are
	 right aligned.  */
      if ((TYPE_CODE (value_type) == TYPE_CODE_STRUCT
	   || TYPE_CODE (value_type) == TYPE_CODE_UNION
	   || TYPE_CODE (value_type) == TYPE_CODE_ARRAY)
	  && len > 4)
	offset = 0;
      else
	offset = container_len - len;
      sp -= container_len;
      write_memory (sp + offset, value_contents_all (args[i]), len);
    }

  /* Store struct value address.  */
  if (struct_return)
    {
      store_unsigned_integer (buf, 4, byte_order, struct_addr);
      regcache_cooked_write (regcache, tdep->struct_value_regnum, buf);
    }

  /* Store return address.  */
  sp -= 4;
  store_unsigned_integer (buf, 4, byte_order, bp_addr);
  write_memory (sp, buf, 4);

  /* Finally, update the stack pointer...  */
  store_unsigned_integer (buf, 4, byte_order, sp);
  regcache_cooked_write (regcache, M68K_SP_REGNUM, buf);

  /* ...and fake a frame pointer.  */
  regcache_cooked_write (regcache, M68K_FP_REGNUM, buf);

  /* DWARF2/GCC uses the stack address *before* the function call as a
     frame's CFA.  */
  return sp + 8;
}
开发者ID:ChrisG0x20,项目名称:gdb,代码行数:55,代码来源:m68k-tdep.c

示例3: snrom_wram_open

static void snrom_wram_open(usb_dev_handle *handle)
{
	uint8_t t[5];
	t[0] = 0x80;
	write_memory(handle, REQUEST_CPU_WRITE_6502, INDEX_IMPLIED, 0x8000, 1, t);
	t[0] = 0, t[1] = 0, t[2] = 0, t[3] = 1, t[4] = 0;
	write_memory(handle, REQUEST_CPU_WRITE_6502, INDEX_IMPLIED, 0x8000, sizeof(t), t);
	t[0] = 0, t[1] = 0, t[2] = 0, t[3] = 0, t[4] = 0;
	write_memory(handle, REQUEST_CPU_WRITE_6502, INDEX_IMPLIED, 0xe000, sizeof(t), t);
	write_memory(handle, REQUEST_CPU_WRITE_6502, INDEX_IMPLIED, 0xa000, sizeof(t), t);
}
开发者ID:sharkpp,项目名称:unagi_kazzo,代码行数:11,代码来源:hostecho.c

示例4: lem_interrupt

int lem_interrupt(void)
{
	uint16_t cycles = 0;
	uint16_t b = read_register(REG_B);

	switch (read_register(REG_A)) {
	case 0:
		if (b) {
			if (connected == 0) {
				clock_gettime(CLOCK_REALTIME, &tp_prev);
				// TODO don't start up for ~1s
			}
			connected = 1;
			vram = b;
		} else {
			connected = 0;
		}
		break;
	case 1:
		if (b) {
			custom_font = 1;
			font_ram = b;
		} else {
			custom_font = 1;
		}
		break;
	case 2:
		if (b) {
			custom_pal = 1;
			pal_ram = b;
		} else {
			custom_pal = 1;
		}
		break;
	case 3:
		border_col = b;
		break;
	case 4:
		write_memory(b, FONT_LEN, font);
		cycles = 256;
		break;
	case 5:
		write_memory(b, PAL_LEN, pal);
		cycles = 16;
		break;
	default:
		break;
	}

	return cycles;
}
开发者ID:jjonir,项目名称:jpd16s,代码行数:51,代码来源:lem1802.c

示例5: vax_push_dummy_call

static CORE_ADDR
vax_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
		     struct regcache *regcache, CORE_ADDR bp_addr, int nargs,
		     struct value **args, CORE_ADDR sp,
		     function_call_return_method return_method,
		     CORE_ADDR struct_addr)
{
  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  CORE_ADDR fp = sp;
  gdb_byte buf[4];

  /* Set up the function arguments.  */
  sp = vax_store_arguments (regcache, nargs, args, sp);

  /* Store return value address.  */
  if (return_method == return_method_struct)
    regcache_cooked_write_unsigned (regcache, VAX_R1_REGNUM, struct_addr);

  /* Store return address in the PC slot.  */
  sp -= 4;
  store_unsigned_integer (buf, 4, byte_order, bp_addr);
  write_memory (sp, buf, 4);

  /* Store the (fake) frame pointer in the FP slot.  */
  sp -= 4;
  store_unsigned_integer (buf, 4, byte_order, fp);
  write_memory (sp, buf, 4);

  /* Skip the AP slot.  */
  sp -= 4;

  /* Store register save mask and control bits.  */
  sp -= 4;
  store_unsigned_integer (buf, 4, byte_order, 0);
  write_memory (sp, buf, 4);

  /* Store condition handler.  */
  sp -= 4;
  store_unsigned_integer (buf, 4, byte_order, 0);
  write_memory (sp, buf, 4);

  /* Update the stack pointer and frame pointer.  */
  store_unsigned_integer (buf, 4, byte_order, sp);
  regcache->cooked_write (VAX_SP_REGNUM, buf);
  regcache->cooked_write (VAX_FP_REGNUM, buf);

  /* Return the saved (fake) frame pointer.  */
  return fp;
}
开发者ID:mattstock,项目名称:binutils-bexkat1,代码行数:49,代码来源:vax-tdep.c

示例6: add_breakpoint

EXPORT
int add_breakpoint(mach_port_t task, vm_address_t patch_addr, int cont, callback handler) {
    kern_return_t kret;
    char *tmp;
    mach_vm_size_t len = 1;     // number of bytes to write
    uint8_t opcode = 0xcc;      // the CC byte to write
    interface *face;

    face = find_interface(task);
    if(face->registered_exception_handler == 0) {
        DEBUG_PRINT("[+add_breakpoint] HERE IN ADD BREAK\n %d", 0);
        register_(task);
    }

    kret = mach_vm_protect(task, patch_addr, len, FALSE, VM_PROT_READ | VM_PROT_WRITE | VM_PROT_EXECUTE);
    RETURN_ON_MACH_ERROR("[-add_breakpoint] mach_vm_protect()", kret);

    if (patch_addr <= MAX_BREAKS) {
        DEBUG_PRINT("[-add_breakpoint] INVALID BREAKPOINT ADDRESS %lx\n", patch_addr);
        return -1;
    } else if(face->current_break >= MAX_BREAKS) {
        DEBUG_PRINT("[-add_breakpoint] Max %d breaks reached!\n", MAX_BREAKS);
        return -1;
    }

    DEBUG_PRINT("[+add_breakpoint] Breakpoint %u: %lx added\n", face->current_break, patch_addr);
    tmp = (char*) read_memory(task, patch_addr, 1);

    breakpoint_struct *new_break = safe_malloc(sizeof(breakpoint_struct));
    new_break->address = patch_addr;
    new_break->original = tmp[0] & 0xff;
    new_break->handler = handler;
    if(face->single_step) {
        new_break->index = face->single_step_index;
    }
    else {
        new_break->index = face->current_break == 0 ? 0 : face->breaks[face->current_break-1]->index + 1;
    }
    new_break->flags = cont;


    if(face->max_break == 0) {
        face->max_break = 1;
    }

    if(face->current_break >= (face->max_break - 1)) {
        DEBUG_PRINT("[+add_breakpoint] ALLOCATING MORE BP! CURRENTLY: %d\n", face->current_break);
        face->breaks = safe_realloc(face->breaks, sizeof(breakpoint_struct*)  *(face->max_break*2));
        face->max_break *= 2;
    }

    // face->breaks = safe_realloc(face->breaks, sizeof(breakpoint_struct*)  *(face->current_break+1));
    face->breaks[face->current_break++] = new_break;

    write_memory(task, patch_addr, opcode, len); // write the byte
    kret = mach_vm_protect(task, patch_addr, (mach_vm_size_t)1, FALSE, VM_PROT_READ | VM_PROT_EXECUTE);
    RETURN_ON_MACH_ERROR("[-add_breakpoint] RESTORE mach_vm_protect()", kret);

    return 1;
}
开发者ID:UIKit0,项目名称:MacDBG,代码行数:60,代码来源:breakpoint.c

示例7: sparc64obsd_collect_uthread

static void
sparc64obsd_collect_uthread(const struct regcache *regcache,
			    int regnum, CORE_ADDR addr)
{
  CORE_ADDR sp;
  gdb_byte buf[8];

  gdb_assert (regnum >= -1);

  if (regnum == SPARC_SP_REGNUM || regnum == -1)
    {
      CORE_ADDR fp_addr = addr + SPARC64OBSD_UTHREAD_FP_OFFSET;

      regcache_raw_collect (regcache, SPARC_SP_REGNUM, buf);
      write_memory (fp_addr,buf, 8);
    }

  if (regnum == SPARC64_PC_REGNUM || regnum == -1)
    {
      CORE_ADDR i7, i7_addr = addr + SPARC64OBSD_UTHREAD_PC_OFFSET;

      regcache_raw_collect (regcache, SPARC64_PC_REGNUM, buf);
      i7 = extract_unsigned_integer (buf, 8) - 8;
      write_memory_unsigned_integer (i7_addr, 8, i7);

      if (regnum == SPARC64_PC_REGNUM)
	return;
    }

  regcache_raw_collect (regcache, SPARC_SP_REGNUM, buf);
  sp = extract_unsigned_integer (buf, 8);
  sparc_collect_rwindow (regcache, sp, regnum);
}
开发者ID:3125788,项目名称:android_toolchain_gdb,代码行数:33,代码来源:sparc64obsd-tdep.c

示例8: sparc_ravenscar_store_registers

static void
sparc_ravenscar_store_registers (struct regcache *regcache, int regnum)
{
  struct gdbarch *gdbarch = get_regcache_arch (regcache);
  int buf_size = register_size (gdbarch, regnum);
  char buf [buf_size];
  ULONGEST register_address;

  if (register_in_thread_descriptor_p (regnum))
    register_address =
      ptid_get_tid (inferior_ptid) + sparc_register_offsets [regnum];
  else if (register_on_stack_p (regnum))
    {
      regcache_cooked_read_unsigned (regcache, SPARC_SP_REGNUM,
                                     &register_address);
      register_address += sparc_register_offsets [regnum];
    }
  else
    return;

  regcache_raw_collect (regcache, regnum, buf);
  write_memory (register_address,
                buf,
                buf_size);
}
开发者ID:GoldStoneProd2010,项目名称:gdb-7.6,代码行数:25,代码来源:sparc-ravenscar-thread.c

示例9: firmware_update

static void firmware_update(usb_dev_handle *handle, const char *file)
{
	uint8_t *firmware;
	const int firmsize = 0x3800;
	assert(firmsize <= 0x3800);
	firmware = malloc(firmsize);
	memset(firmware, 0xff, firmsize);

	if(hex_load(file, firmsize, firmware) == false){
		puts("image open error!");
		goto end;
	}
	snrom_wram_open(handle);

	int ppu, cpu = 0;
	ppu = cartridge_ram_transform(handle, firmware, REQUEST_PPU_WRITE, REQUEST_PPU_READ, 0x0000, 0x2000, false);
	if(firmsize >= 0x2000){
		cpu = cartridge_ram_transform(handle, firmware + 0x2000, REQUEST_CPU_WRITE_6502, REQUEST_CPU_READ, 0x6000, firmsize - 0x2000, false);
	}
	if((ppu == 0) && (cpu == 0)){
//		write_memory(handle, REQUEST_FIRMWARE_PROGRAM, firmsize, 0x2000, 0, firmware);
		puts("USB connection will be disconnteced. This is normally.");
		puts("Re-turn on kazzo's power.");
		write_memory(handle, REQUEST_FIRMWARE_PROGRAM, firmsize, 0x0000, 0, firmware);
	}else{
		puts("firmware transform error!");
		snrom_wram_close(handle);
	}
end:
	free(firmware);
}
开发者ID:sharkpp,项目名称:unagi_kazzo,代码行数:31,代码来源:hostecho.c

示例10: restore_state

/*!
 * @brief Restores the process state and detaches.
 * @param pid Process identifier to restore.
 * @param s Pointer to \c state with code and registers.
 * @param only_memory Idicates if restore only memory at EIP or also registers
 * @returns Indication of success or failure.
 * @retval 0 Indicates success.
 */
LONG
restore_state(LONG pid, state *s, int only_memory) {
	unsigned long *mem_ptr = NULL;
	LONG i = 0;
	LONG result = 0;

	if (s == NULL)
		return ERROR_INVALID_PARAMETER;

 	mem_ptr = (unsigned long *)(s->memory);

	if (mem_ptr == NULL)
		return ERROR_INVALID_PARAMETER;

	result = write_memory(pid, s->regs.eip, mem_ptr, MMAP_STUB_SIZE);
	if (result != 0)
		return result;

	if (only_memory > 0)
		return 0;

	result = setregs(pid, &(s->regs));
	if (result != 0)
		return result;

	result = detach(pid);
	if (result != 0)
		return result;

	return 0;
}
开发者ID:AnwarMohamed,项目名称:meterpreter,代码行数:39,代码来源:base_inject.c

示例11: amd64_windows_adjust_args_passed_by_pointer

static CORE_ADDR
amd64_windows_adjust_args_passed_by_pointer (struct value **args,
					     int nargs, CORE_ADDR sp)
{
  int i;

  for (i = 0; i < nargs; i++)
    if (amd64_windows_passed_by_pointer (value_type (args[i])))
      {
	struct type *type = value_type (args[i]);
	const gdb_byte *valbuf = value_contents (args[i]);
	const int len = TYPE_LENGTH (type);

	/* Store a copy of that argument on the stack, aligned to
	   a 16 bytes boundary, and then use the copy's address as
	   the argument.  */

	sp -= len;
	sp &= ~0xf;
	write_memory (sp, valbuf, len);

	args[i]
	  = value_addr (value_from_contents_and_address (type, valbuf, sp));
      }

  return sp;
}
开发者ID:CromFr,项目名称:gdb,代码行数:27,代码来源:amd64-windows-tdep.c

示例12: i386_darwin_sstep_at_sigreturn

static int
i386_darwin_sstep_at_sigreturn (x86_thread_state_t *regs)
{
  enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch);
  static const gdb_byte darwin_syscall[] = { 0xcd, 0x80 }; /* int 0x80 */
  gdb_byte buf[sizeof (darwin_syscall)];

  /* Check if PC is at a sigreturn system call.  */
  if (target_read_memory (regs->uts.ts32.__eip, buf, sizeof (buf)) == 0
      && memcmp (buf, darwin_syscall, sizeof (darwin_syscall)) == 0
      && regs->uts.ts32.__eax == 0xb8 /* SYS_sigreturn */)
    {
      ULONGEST uctx_addr;
      ULONGEST mctx_addr;
      ULONGEST flags_addr;
      unsigned int eflags;

      uctx_addr = read_memory_unsigned_integer
		    (regs->uts.ts32.__esp + 4, 4, byte_order);
      mctx_addr = read_memory_unsigned_integer
		    (uctx_addr + 28, 4, byte_order);

      flags_addr = mctx_addr + 12 + 9 * 4;
      read_memory (flags_addr, (gdb_byte *) &eflags, 4);
      eflags |= X86_EFLAGS_T;
      write_memory (flags_addr, (gdb_byte *) &eflags, 4);

      return 1;
    }
  return 0;
}
开发者ID:CyberGrandChallenge,项目名称:gdb,代码行数:31,代码来源:i386-darwin-nat.c

示例13: inject

/* Attach to PID `pid', take a snapshot, modify its state to have it call
 * `dlopen()', restore the previously saved snapshot and detach.
 */
static int inject(pid_t pid, char *filename, char all_thrs)
{
    regs_t regs;
    char buf[PAGE_SIZE];
    ssize_t size;

    int r = -1;

    if(attach(pid, all_thrs) != 0)
        goto ret;

    if(read_registers(pid, &regs) != 0)
        goto ret;

    if((size = read_memory(pid, (void *)SP(regs), buf, sizeof(buf))) < 0)
        goto ret;

    r = 0;

    if(force_dlopen(pid, filename) != 0)
        r = -1;

    if(write_memory(pid, (void *)SP(regs), buf, size) != size)
        r = -1;

    if(write_registers(pid, &regs) != 0)
        r = -1;

    if(detach(pid, all_thrs) != 0)
        r = -1;

ret:
    return r;
}
开发者ID:huku-,项目名称:injectdso,代码行数:37,代码来源:main.c

示例14: change_mem_val

static void change_mem_val (pid_t pid, CfgEntry *cfg_en, T read_val, T value,
			    value_t *buf, ptr_t mem_offs)
{
	list<CheckEntry> *chk_lp = cfg_en->checks;
	ptr_t mem_addr;
	i32 ret;

	if (cfg_en->dynval == DYN_VAL_WATCH)
		goto out;

	if (chk_lp) {
		ret = process_checks(pid, cfg_en->dynmem, chk_lp, mem_offs);
		if (ret)
			goto out;
	}

	ret = check_mem_val(read_val, value, cfg_en->check);
	if (ret)
		goto out;

	memcpy(buf, &value, sizeof(T));
	mem_addr = mem_offs + cfg_en->addr;

	ret = write_memory(pid, mem_addr, buf, "MEMORY");
	if (ret)
		goto out;
out:
	return;
}
开发者ID:Mortezaipo,项目名称:ugtrain,代码行数:29,代码来源:ugtrain.cpp

示例15: remote_buffer

 remote_buffer(const void *data, int dataLen) : remote_buffer(dataLen) {
     if (this->data != 0) {
         // Return value ignored, this is a constructor, we don't
         // have exceptions, and we already printed an error.
         write_memory(this->data, data, dataLen);
     }
 }
开发者ID:jacksisson,项目名称:Halide,代码行数:7,代码来源:sim_host.cpp


注:本文中的write_memory函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。