static int disassemble_file( const char * name, opdis_off_t offset ) { int rv; FILE * f; opdis_t o; opdis_buf_t buf; opdis_insn_tree_t tree; f = fopen( name, "r" ); if (! f ) { printf( "Unable to open file %s: %s\n", name, strerror(errno) ); return -1; } buf = opdis_buf_read( f, 0, 0 ); fclose( f ); o = opdis_init(); tree = opdis_insn_tree_init( 1 ); opdis_set_display( o, store_insn, tree ); rv = opdis_disasm_cflow( o, buf, (opdis_vma_t) offset ); opdis_insn_tree_foreach( tree, print_insn, (void *) name ); opdis_insn_tree_free( tree ); opdis_term( o ); return (rv > 0) ? 0 : -2; }
static void output_disassembly( struct opdis_options * opts ) { asm_fprintf_header( opts->output_file, opts->fmt ); // TODO: print targets and maps opdis_insn_tree_foreach( opts->insn_tree, print_insn, opts ); asm_fprintf_footer( opts->output_file, opts->fmt ); }