示例#1
0
/* Load the PE file in the bin->mlist */
static void pe_load_mlist(r_binfmt_s *bin) {
  uint32_t flags;
  IMAGE_COFF_HEADER *coff;
  IMAGE_SECTION_HEADER *shdr;
  WORD sections_addr;
  int i;

  bin->mlist = r_binfmt_mlist_new();

  /* Get sections table */
  coff = (IMAGE_COFF_HEADER*)(pe_get_addr_coff(bin) + bin->mapped);
  sections_addr = pe_get_addr_sections(bin);
  shdr = (IMAGE_SECTION_HEADER*)(bin->mapped + sections_addr);


  /* Load each section */
  for(i = 0; i < coff->NumberOfSections; i++) {
    flags = 0;

    if(shdr[i].Characteristics & IMAGE_SCN_MEM_EXECUTE)
      flags |= R_BINFMT_MEM_FLAG_PROT_X;
    if(shdr[i].Characteristics & IMAGE_SCN_MEM_WRITE)
      flags |= R_BINFMT_MEM_FLAG_PROT_W;
    if(shdr[i].Characteristics & IMAGE_SCN_MEM_READ)
      flags |= R_BINFMT_MEM_FLAG_PROT_R;

    if(flags)
      r_binfmt_mlist_add(bin->mlist, shdr[i].VirtualAddress,
			 bin->mapped + shdr[i].PointerToRawData,
			 shdr[i].SizeOfRawData,
			 flags);
  }

}
示例#2
0
/* Load the ELF binary in the bin->mlist */
static void elf64_load_mlist(r_binfmt_s *bin) {
  Elf64_Ehdr *ehdr = (Elf64_Ehdr*)bin->mapped;
  Elf64_Phdr *phdr;
  int i;
  uint64_t flags;
  uint64_t p_vaddr, p_offset, p_filesz;
  uint32_t p_type, p_flags;
  uint16_t e_phnum;

  bin->mlist = r_binfmt_mlist_new();

  phdr = (Elf64_Phdr*)(bin->mapped + r_binfmt_get_int64((byte_t*)&ehdr->e_phoff, bin->endian));

  e_phnum = r_binfmt_get_int16((byte_t*)&ehdr->e_phnum, bin->endian);

  for(i = 0; i < e_phnum; i++) {
    p_type = r_binfmt_get_int32((byte_t*)&phdr[i].p_type, bin->endian);
    p_flags = r_binfmt_get_int32((byte_t*)&phdr[i].p_flags, bin->endian);
    p_vaddr = r_binfmt_get_int64((byte_t*)&phdr[i].p_vaddr, bin->endian);
    p_offset = r_binfmt_get_int64((byte_t*)&phdr[i].p_offset, bin->endian);
    p_filesz = r_binfmt_get_int64((byte_t*)&phdr[i].p_filesz, bin->endian);

    if(p_type == PT_LOAD) {

      flags = 0;
      if(p_flags & PF_X)
	flags |= R_BINFMT_MEM_FLAG_PROT_X;
      if(p_flags & PF_R)
	flags |= R_BINFMT_MEM_FLAG_PROT_R;
      if(p_flags & PF_W)
	flags |= R_BINFMT_MEM_FLAG_PROT_W;

      r_binfmt_mlist_add(bin->mlist,
			p_vaddr,
			bin->mapped + p_offset,
			p_filesz,
			flags);
    }
  }
}
示例#3
0
static void r_binfmt_macho64_load_mlist(r_binfmt_s *bin) {
  r_binfmt_macho64_header_s *hdr;
  r_binfmt_macho_cmd_s *cmd;
  u32 i, cmd_num, type, off;

  bin->mlist = r_binfmt_mlist_new();

  hdr = (r_binfmt_macho64_header_s*)(bin->mapped);
  cmd_num = r_binfmt_get_int32((byte_t*)&hdr->h_cmd_num, bin->endian);


  off = 0;
  for(i = 0; i < cmd_num; i++) {
    cmd = (r_binfmt_macho_cmd_s*)(bin->mapped + sizeof(*hdr) + off);
    type = r_binfmt_get_int32((byte_t*)&cmd->type, bin->endian);
    if(type == R_BINFMT_MACHO_CMD_TYPE_SEGMENT64) {
      r_binfmt_macho64_load_segment(bin, (r_binfmt_macho64_segment_s*)cmd);
    }

    off += r_binfmt_get_int32((byte_t*)&cmd->size, bin->endian);
  }
}