static AsmFormatPlugin * _elf_init(AsmFormatPluginHelper * helper, char const * arch) { Elf * elf; #ifdef DEBUG fprintf(stderr, "DEBUG: %s(\"%s\")\n", __func__, arch); #endif if((elf = object_new(sizeof(*elf))) == NULL) return NULL; elf->helper = helper; elf->destroy = NULL; elf->decode = NULL; elf->shstrtab.buf = NULL; elf->shstrtab.cnt = 0; elf->es32 = NULL; elf->es32_cnt = 0; elf->es64 = NULL; elf->es64_cnt = 0; if(arch == NULL) { elf->arch = NULL; return elf; } if((elf->arch = _init_arch(arch)) == NULL) { object_delete(elf); return NULL; } if(elf->arch->capacity == ELFCLASS32) { if(elf32_init(elf) != 0) return NULL; elf->destroy = elf32_destroy; elf->section = elf32_section; elf->decode = elf32_decode; } else if(elf->arch->capacity == ELFCLASS64) { if(elf64_init(elf) != 0) return NULL; elf->destroy = elf64_destroy; elf->section = elf64_section; elf->decode = elf64_decode; } else return NULL; return elf; }
static int _elf_init(AsmFormatPlugin * format, char const * arch) { Elf * elf; #ifdef DEBUG fprintf(stderr, "DEBUG: %s(\"%s\")\n", __func__, arch); #endif if((elf = object_new(sizeof(*elf))) == NULL) return -1; format->priv = elf; elf->es32 = NULL; elf->es32_cnt = 0; elf->es64 = NULL; elf->es64_cnt = 0; if(arch == NULL) { elf->arch = NULL; return 0; } if((elf->arch = _init_arch(arch)) == NULL) { object_delete(elf); return -1; } if(elf->arch->capacity == ELFCLASS32) { if(_init_32(format) != 0) return -1; format->exit = _exit_32; format->section = _section_32; } else if(elf->arch->capacity == ELFCLASS64) { if(_init_64(format) != 0) return -1; format->exit = _exit_64; format->section = _section_64; } else return -1; return 0; }