本文整理汇总了C++中AsmFormatPluginHelper类的典型用法代码示例。如果您正苦于以下问题:C++ AsmFormatPluginHelper类的具体用法?C++ AsmFormatPluginHelper怎么用?C++ AsmFormatPluginHelper使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AsmFormatPluginHelper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _section_32
/* section_32 */
static int _section_32(AsmFormatPlugin * format, char const * name)
{
AsmFormatPluginHelper * helper = format->helper;
Elf * elf = format->priv;
int ss;
Elf32_Shdr * p;
ElfSectionValues * esv;
long offset;
#ifdef DEBUG
fprintf(stderr, "DEBUG: %s(\"%s\")\n", __func__, name);
#endif
if((ss = _elfstrtab_set(format, &shstrtab, name)) < 0)
return -1;
if((p = realloc(elf->es32, sizeof(*p) * (elf->es32_cnt + 1))) == NULL)
return _elf_error(format);
elf->es32 = p;
p = &elf->es32[elf->es32_cnt++];
memset(p, 0, sizeof(*p));
esv = _section_values(name);
p->sh_name = ss;
p->sh_type = esv->type;
p->sh_flags = esv->flags;
if((offset = helper->seek(helper->format, 0, SEEK_CUR)) < 0)
return -1;
#ifdef DEBUG
fprintf(stderr, "DEBUG: %s() offset %ld\n", __func__, offset);
#endif
p->sh_offset = offset;
p->sh_link = SHN_UNDEF; /* FIXME */
return 0;
}
示例2: _elf_detect
/* elf_detect */
static char const * _elf_detect(AsmFormatPlugin * format)
{
AsmFormatPluginHelper * helper = format->helper;
char const * ret;
union
{
Elf32_Ehdr ehdr32;
Elf64_Ehdr ehdr64;
} ehdr;
if(helper->seek(helper->format, 0, SEEK_SET) != 0)
return NULL;
if(helper->read(helper->format, &ehdr, sizeof(ehdr)) != sizeof(ehdr))
return NULL;
switch(ehdr.ehdr32.e_ident[EI_CLASS])
{
case ELFCLASS32:
if((ret = elf32_detect(format, &ehdr.ehdr32)) != NULL)
format->decode = elf32_decode;
break;
case ELFCLASS64:
if((ret = elf64_detect(format, &ehdr.ehdr64)) != NULL)
format->decode = elf64_decode;
break;
default:
ret = NULL;
error_set_code(1, "%s: %s 0x%x\n",
helper->get_filename(helper->format),
"Unsupported ELF class",
ehdr.ehdr32.e_ident[EI_CLASS]);
break;
}
return ret;
}
示例3: _decode64_addr
static int _decode64_addr(AsmFormatPlugin * format, Elf64_Ehdr * ehdr,
Elf64_Addr * addr)
{
AsmFormatPluginHelper * helper = format->helper;
Elf64_Quarter i;
Elf64_Phdr phdr;
if(helper->seek(helper->format, ehdr->e_phoff, SEEK_SET) < 0)
return -1;
for(i = 0; i < ehdr->e_phnum; i++)
{
if(helper->read(helper->format, &phdr, sizeof(phdr))
!= sizeof(phdr))
return -1;
if(ehdr->e_ident[EI_DATA] != elf_arch_native->endian)
_swap_64_phdr(&phdr);
if(phdr.p_type == PT_LOAD && phdr.p_flags & (PF_R | PF_X))
{
*addr = phdr.p_vaddr;
return 0;
}
}
*addr = 0x0;
return 0;
}
示例4: _exit_64_phdr
static int _exit_64_phdr(AsmFormatPlugin * format, Elf64_Off offset)
{
AsmFormatPluginHelper * helper = format->helper;
Elf * elf = format->priv;
ElfArch * ea = elf->arch;
Elf64_Ehdr hdr;
if(elf->es64_cnt == 0)
return 0;
if(helper->seek(helper->format, 0, SEEK_SET) != 0)
return -1;
if(helper->read(helper->format, &hdr, sizeof(hdr)) != sizeof(hdr))
return -1;
if(ea->endian == ELFDATA2MSB)
{
hdr.e_shoff = _htob64(offset);
hdr.e_shnum = _htob16(elf->es64_cnt);
hdr.e_shstrndx = _htob16(elf->es64_cnt - 1);
}
else
{
hdr.e_shoff = _htol64(offset);
hdr.e_shnum = _htol16(elf->es64_cnt);
hdr.e_shstrndx = _htol16(elf->es64_cnt - 1);
}
if(helper->seek(helper->format, 0, SEEK_SET) != 0)
return -1;
if(helper->write(helper->format, &hdr, sizeof(hdr)) != sizeof(hdr))
return -1;
return 0;
}
示例5: _exit_32
static int _exit_32(AsmFormatPlugin * format)
{
int ret = 0;
AsmFormatPluginHelper * helper = format->helper;
long offset;
#ifdef DEBUG
fprintf(stderr, "DEBUG: %s()\n", __func__);
#endif
if(_section_32(format, ".shstrtab") != 0)
ret = -1;
else if(helper->write(helper->format, shstrtab.buf, shstrtab.cnt)
!= (ssize_t)shstrtab.cnt)
ret = -1;
else if((offset = helper->seek(helper->format, 0, SEEK_CUR)) < 0)
ret = -1;
else if(_exit_32_phdr(format, offset) != 0
|| _exit_32_shdr(format, offset) != 0)
ret = -1;
free(shstrtab.buf);
shstrtab.buf = NULL;
shstrtab.cnt = 0;
ret |= _elf_exit(format);
return ret;
}
示例6: _decode64_strtab
static int _decode64_strtab(AsmFormatPlugin * format, Elf64_Shdr * shdr,
size_t shdr_cnt, uint16_t ndx, char ** strtab,
size_t * strtab_cnt)
{
AsmFormatPluginHelper * helper = format->helper;
ssize_t size;
if(ndx >= shdr_cnt)
return -error_set_code(1, "%s: %s",
helper->get_filename(helper->format),
"Unable to read the string table");
shdr = &shdr[ndx];
if(helper->seek(helper->format, shdr->sh_offset, SEEK_SET) < 0)
return -1;
size = sizeof(**strtab) * shdr->sh_size;
if((*strtab = malloc(size)) == NULL)
return -_elf_error(format);
if(helper->read(helper->format, *strtab, size) != size)
{
free(*strtab);
return -1;
}
*strtab_cnt = shdr->sh_size;
return 0;
}
示例7: _exit_32_phdr
static int _exit_32_phdr(AsmFormatPlugin * format, Elf32_Off offset)
{
AsmFormatPluginHelper * helper = format->helper;
Elf * elf = format->priv;
ElfArch * ea = elf->arch;
Elf32_Ehdr hdr;
#ifdef DEBUG
fprintf(stderr, "DEBUG: %s()\n", __func__);
#endif
if(elf->es32_cnt == 0)
return 0;
if(helper->seek(helper->format, 0, SEEK_SET) != 0)
return -1;
if(helper->read(helper->format, &hdr, sizeof(hdr)) != sizeof(hdr))
return _elf_error(format);
if(ea->endian == ELFDATA2MSB)
{
hdr.e_shoff = _htob32(offset);
hdr.e_shnum = _htob16(elf->es32_cnt + 1);
hdr.e_shstrndx = _htob16(elf->es32_cnt);
}
else
{
hdr.e_shoff = _htol32(offset);
hdr.e_shnum = _htol16(elf->es32_cnt + 1);
hdr.e_shstrndx = _htol16(elf->es32_cnt);
}
if(helper->seek(helper->format, 0, SEEK_SET) != 0)
return -1;
if(helper->write(helper->format, &hdr, sizeof(hdr)) != sizeof(hdr))
return -1;
return 0;
}
示例8: _decode64_shdr
static int _decode64_shdr(AsmFormatPlugin * format, Elf64_Ehdr * ehdr,
Elf64_Shdr ** shdr)
{
AsmFormatPluginHelper * helper = format->helper;
ssize_t size;
size_t i;
if(ehdr->e_shentsize == 0)
{
*shdr = NULL;
return 0;
}
if(ehdr->e_shentsize != sizeof(**shdr))
return -error_set_code(1, "%s: %s",
helper->get_filename(helper->format),
"Invalid section header size");
if(helper->seek(helper->format, ehdr->e_shoff, SEEK_SET) < 0)
return -1;
size = sizeof(**shdr) * ehdr->e_shnum;
if((*shdr = malloc(size)) == NULL)
return -_elf_error(format);
if(helper->read(helper->format, *shdr, size) != size)
{
free(*shdr);
return -1;
}
if(ehdr->e_ident[EI_DATA] != elf_arch_native->endian)
for(i = 0; i < ehdr->e_shnum; i++)
_swap_64_shdr(*shdr + i);
return 0;
}
示例9: _elf_decode_section
/* elf_decode_section */
static int _elf_decode_section(AsmFormatPlugin * format, AsmSection * section,
AsmArchInstructionCall ** calls, size_t * calls_cnt)
{
AsmFormatPluginHelper * helper = format->helper;
return helper->decode(helper->format, section->offset, section->size,
section->base, calls, calls_cnt);
}
示例10: _elf_decode_section
/* elf_decode_section */
static int _elf_decode_section(AsmFormatPlugin * format, AsmSection * section,
AsmArchInstructionCall ** calls, size_t * calls_cnt)
{
AsmFormatPluginHelper * helper = format->helper;
#ifdef DEBUG
fprintf(stderr, "DEBUG: %s()\n", __func__);
#endif
return helper->decode(helper->format, section->offset, section->size,
section->base, calls, calls_cnt);
}
示例11: _exit_32_shdr
static int _exit_32_shdr(AsmFormatPlugin * format, Elf32_Off offset)
{
AsmFormatPluginHelper * helper = format->helper;
Elf * elf = format->priv;
ElfArch * ea = elf->arch;
Elf32_Word addralign = ea->addralign;
Elf32_Shdr * es32 = elf->es32;
Elf32_Shdr hdr;
int i;
#ifdef DEBUG
fprintf(stderr, "DEBUG: %s()\n", __func__);
#endif
if(helper->seek(helper->format, 0, SEEK_END) < 0)
return _elf_error(format);
memset(&hdr, 0, sizeof(hdr));
if(ea->endian == ELFDATA2MSB)
{
hdr.sh_type = _htob32(SHT_NULL);
hdr.sh_link = _htob32(SHN_UNDEF);
}
else
{
hdr.sh_type = _htol32(SHT_NULL);
hdr.sh_link = _htol32(SHN_UNDEF);
}
if(helper->write(helper->format, &hdr, sizeof(hdr)) != sizeof(hdr))
return -1;
for(i = 0; i < elf->es32_cnt; i++)
{
#ifdef DEBUG
fprintf(stderr, "DEBUG: %s() %d\n", __func__, i);
#endif
if(i + 1 == elf->es32_cnt)
es32[i].sh_size = offset - es32[i].sh_offset;
else
es32[i].sh_size = es32[i + 1].sh_offset
- es32[i].sh_offset;
es32[i].sh_offset = (ea->endian == ELFDATA2MSB)
? _htob32(es32[i].sh_offset)
: _htol32(es32[i].sh_offset);
es32[i].sh_size = (ea->endian == ELFDATA2MSB)
? _htob32(es32[i].sh_size) : _htol32(es32[i].sh_size);
if(es32[i].sh_type == SHT_PROGBITS)
es32[i].sh_addralign = (ea->endian == ELFDATA2MSB)
? _htob32(addralign) : _htol32(addralign);
es32[i].sh_type = (ea->endian == ELFDATA2MSB)
? _htob32(es32[i].sh_type) : _htol32(es32[i].sh_type);
if(helper->write(helper->format, &es32[i], sizeof(Elf32_Shdr))
!= sizeof(Elf32_Shdr))
return -1;
}
return 0;
}
示例12: _flat_decode
/* flat_decode */
static int _flat_decode(AsmFormatPlugin * format, int raw)
{
AsmFormatPluginHelper * helper = format->helper;
off_t offset;
if((offset = helper->seek(helper->format, 0, SEEK_END)) >= 0
&& helper->set_section(helper->format, 0, 0, ".text", 0,
offset, 0) != NULL)
return 0;
return -1;
}
示例13: _elf_decode32
static int _elf_decode32(AsmFormatPlugin * format, int raw)
{
AsmFormatPluginHelper * helper = format->helper;
Elf32_Ehdr ehdr;
Elf32_Shdr * shdr = NULL;
Elf32_Addr base = 0x0;
char * shstrtab = NULL;
size_t shstrtab_cnt = 0;
size_t i;
#ifdef DEBUG
fprintf(stderr, "DEBUG: %s() \"%s\"\n", __func__,
helper->get_filename(helper->format));
#endif
if(helper->seek(helper->format, 0, SEEK_SET) != 0
|| helper->read(helper->format, &ehdr, sizeof(ehdr))
!= sizeof(ehdr))
return -1;
if(ehdr.e_ident[EI_DATA] != elf_arch_native->endian)
_swap_32_ehdr(&ehdr);
if(_decode32_shdr(format, &ehdr, &shdr) != 0)
return -1;
if(_decode32_addr(format, &ehdr, &base) != 0
|| _decode32_strtab(format, shdr, ehdr.e_shnum,
ehdr.e_shstrndx, &shstrtab, &shstrtab_cnt)
!= 0)
{
free(shdr);
return -1;
}
for(i = 0; i < ehdr.e_shnum; i++)
if(shdr[i].sh_type == SHT_SYMTAB)
{
/* XXX ignore errors? */
_decode32_symtab(format, &ehdr, shdr, ehdr.e_shnum, i);
break;
}
for(i = 0; i < ehdr.e_shnum; i++)
{
if(shdr[i].sh_name >= shstrtab_cnt)
continue;
if((raw || (shdr[i].sh_type == SHT_PROGBITS && shdr[i].sh_flags
& SHF_EXECINSTR))
&& helper->set_section(helper->format, i,
&shstrtab[shdr[i].sh_name],
shdr[i].sh_offset, shdr[i].sh_size,
base + shdr[i].sh_offset) < 0)
break;
}
free(shstrtab);
free(shdr);
return (i == ehdr.e_shnum) ? 0 : -1;
}
示例14: _decode_map_code
static int _decode_map_code(AsmFormatPlugin * format, size_t id, off_t offset,
size_t size)
{
AsmFormatPluginHelper * helper = format->helper;
#ifdef DEBUG
fprintf(stderr, "DEBUG: %s(%lu, %ld, %lu)\n", __func__, id, offset,
size);
#endif
return (helper->set_section(helper->format, id, 0,
".text", offset, size, 0) != NULL) ? 0 : -1;
}
示例15: _decode64_symtab
static int _decode64_symtab(AsmFormatPlugin * format, Elf64_Ehdr * ehdr,
Elf64_Shdr * shdr, size_t shdr_cnt, uint16_t ndx)
{
AsmFormatPluginHelper * helper = format->helper;
char * strtab = NULL;
size_t strtab_cnt = 0;
Elf64_Sym sym;
size_t i;
off_t offset;
#ifdef DEBUG
fprintf(stderr, "DEBUG: %s()\n", __func__);
#endif
if(ndx >= shdr_cnt || shdr[ndx].sh_entsize != sizeof(sym))
return -1;
if(_decode64_strtab(format, shdr, shdr_cnt, shdr[ndx].sh_link, &strtab,
&strtab_cnt) != 0)
return -1;
/* read and process symbols */
if((offset = helper->seek(helper->format, shdr[ndx].sh_offset,
SEEK_SET)) < 0
|| (unsigned long)offset != shdr[ndx].sh_offset)
{
free(strtab);
return -1;
}
for(i = 0; i * sizeof(sym) < shdr[ndx].sh_size; i++)
if(helper->read(helper->format, &sym, sizeof(sym))
!= sizeof(sym))
break;
else if(sym.st_name >= strtab_cnt)
break;
else if(ELF64_ST_TYPE(sym.st_info) == STT_FUNC)
{
offset = -1;
if(ehdr->e_type == ET_REL || ehdr->e_type == ET_EXEC
|| ehdr->e_type == ET_DYN)
offset = sym.st_value;
/* record the function */
helper->set_function(helper->format, i,
&strtab[sym.st_name], offset,
sym.st_size);
}
if(i * sizeof(sym) != shdr[ndx].sh_size)
{
free(strtab);
return -1;
}
return 0;
}