//-------------------------------------------------------------------------- // начало сегмента void N78K_segstart(ea_t ea) { segment_t *Sarea = getseg(ea); const char *SegType= (Sarea->type==SEG_CODE)?"CSEG": ((Sarea->type==SEG_DATA)?"DSEG": "RSEG" ); // Выведем строку вида RSEG <NAME> #if IDP_INTERFACE_VERSION > 37 char sn[MAXNAMELEN]; get_segm_name(Sarea,sn,sizeof(sn)); printf_line(-1,"%s %s ",SegType, sn); #else printf_line(-1,"%s %s ",SegType, get_segm_name(Sarea)); #endif // если смещение не ноль - выведем и его (ORG XXXX) if ( inf.s_org ) { ulong org = ea - get_segm_base(Sarea); if( org != 0 ){ #if IDP_INTERFACE_VERSION > 37 char bufn[MAX_NUMBUF]; btoa(bufn, sizeof(bufn), org); printf_line(-1, "%s %s", ash.origin, bufn); #else printf_line(-1, "%s %s", ash.origin, btoa(org)); #endif } } }
//-------------------------------------------------------------------------- void segstart(ea_t ea) { segment_t *Sarea = getseg(ea); if ( is_spec_segm(Sarea->type) ) return; char sname[MAXNAMELEN]; char sclas[MAXNAMELEN]; get_segm_name(Sarea, sname, sizeof(sname)); get_segm_class(Sarea, sclas, sizeof(sclas)); printf_line(0, COLSTR("%s", SCOLOR_ASMDIR) " " COLSTR("%s %s", SCOLOR_AUTOCMT), strcmp(sclas,"CODE") == 0 ? ".CSEG" : strcmp(sclas,"DATA") == 0 ? ".DSEG" : ".ESEG", ash.cmnt, sname); if ( Sarea->orgbase != 0 ) { char buf[MAX_NUMBUF]; btoa(buf, sizeof(buf), Sarea->orgbase); printf_line(inf.indent, COLSTR("%s %s", SCOLOR_ASMDIR), ash.origin, buf); } }
// Generate a segment header void gen_segm_header(ea_t ea) { segment_t *Sarea = getseg(ea); char sname[MAXNAMELEN]; get_segm_name(Sarea, sname, sizeof(sname)); char *segname = sname; if ( *segname == '_' ) segname++; if ( ash.uflag & UAS_ASW ) { printf_line(inf.indent, COLSTR("SEGMENT %s", SCOLOR_ASMDIR), segname); } else { printf_line(inf.indent, COLSTR(".section .%s", SCOLOR_ASMDIR), segname); } ea_t orgbase = ea - get_segm_para(Sarea); if ( orgbase != 0 ) { char buf[MAX_NUMBUF]; btoa(buf, sizeof(buf), orgbase); printf_line(inf.indent, COLSTR("%s %s", SCOLOR_ASMDIR), ash.origin, buf); } }
//-------------------------------------------------------------------------- void segstart(ea_t ea) { segment_t *Sarea = getseg(ea); if ( is_spec_segm(Sarea->type) ) return; char sname[MAXNAMELEN]; char sclas[MAXNAMELEN]; get_true_segm_name(Sarea, sname, sizeof(sname)); get_segm_class(Sarea, sclas, sizeof(sclas)); if ( ash.uflag & UAS_GNU ) { const char *const predefined[] = { ".text", // Text section ".data", // Data sections ".rdata", ".comm", }; int i; for ( i=0; i < qnumber(predefined); i++ ) if ( strcmp(sname, predefined[i]) == 0 ) break; if ( i != qnumber(predefined) ) printf_line(inf.indent, COLSTR("%s", SCOLOR_ASMDIR), sname); else printf_line(inf.indent, COLSTR(".section %s", SCOLOR_ASMDIR) " " COLSTR("%s %s", SCOLOR_AUTOCMT), sname, ash.cmnt, sclas); } else { if ( strcmp(sname, "XMEM") == 0 ) { char buf[MAX_NUMBUF]; btoa(buf, sizeof(buf), ea-get_segm_base(Sarea)); printf_line(inf.indent, COLSTR("%s %c:%s", SCOLOR_ASMDIR), ash.origin, tolower(sname[0]), buf); } else { printf_line(inf.indent, COLSTR("section %s", SCOLOR_ASMDIR) " " COLSTR("%s %s", SCOLOR_AUTOCMT), sname, ash.cmnt, sclas); } } }
//-------------------------------------------------------------------------- void idaapi footer(void) { char name[MAXSTR]; get_colored_name(BADADDR, inf.beginEA, name, sizeof(name)); const char *end = ash.end; if ( end == NULL ) printf_line(inf.indent,COLSTR("%s end %s",SCOLOR_AUTOCMT), ash.cmnt, name); else printf_line(inf.indent,COLSTR("%s",SCOLOR_ASMDIR) " " COLSTR("%s %s",SCOLOR_AUTOCMT), ash.end, ash.cmnt, name); }
// prints function header static void mits_func_header(func_t *pfn) { std_gen_func_header(pfn); char buf[MAXSTR]; const char *name = mits_get_func_name(pfn, buf, sizeof(buf)); if ( name != NULL ) { printf_line(inf.indent, COLSTR(".FUNC %s", SCOLOR_ASMDIR), name); printf_line(0, COLSTR("%s:", SCOLOR_ASMDIR), name); } }
// prints function header static void idaapi gnu_func_header(func_t *pfn) { std_gen_func_header(pfn); qstring namebuf; if ( fr_get_func_name(&namebuf, pfn) ) { const char *name = namebuf.begin(); if ( is_public_name(pfn->startEA) && ash.a_public != NULL ) printf_line(inf.indent, COLSTR("%s %s", SCOLOR_ASMDIR), ash.a_public, name); printf_line(inf.indent, COLSTR(".type %s, @function", SCOLOR_ASMDIR), name); printf_line(0, COLSTR("%s:", SCOLOR_ASMDIR), name); } }
// prints function header static void idaapi gnu_func_header(func_t *pfn) { std_gen_func_header(pfn); char buf[MAXSTR]; const char *name = fr_get_func_name(pfn, buf, sizeof(buf)); if ( name != NULL ) { if ( is_public_name(pfn->startEA) && ash.a_public != NULL ) printf_line(inf.indent, COLSTR("%s %s", SCOLOR_ASMDIR), ash.a_public, name); printf_line(inf.indent, COLSTR(".type %s, @function", SCOLOR_ASMDIR), name); printf_line(0, COLSTR("%s:", SCOLOR_ASMDIR), name); } }
// prints function header static void gnu_func_header(func_t *pfn) { std_gen_func_header(pfn); char buf[MAXSTR]; const char *name = gnu_get_func_name(pfn, buf, sizeof(buf)); if ( name != NULL ) { printf_line(inf.indent, COLSTR(".desc %s, %s", SCOLOR_ASMDIR), name, pfn->is_far() ? "far" : "near"); printf_line(inf.indent, COLSTR(".proc %s", SCOLOR_ASMDIR), name); } gl_xref = 1; printf_line(0, COLSTR("%s:", SCOLOR_ASMDIR), name); }
//---------------------------------------------------------------------- void out(void) { char buf[MAXSTR]; // output .org for enties without any labels if ( !has_any_name(uFlag) && helper.altval(cmd.ea) ) { btoa(buf, sizeof(buf), cmd.ip); printf_line(inf.indent, COLSTR("%s %s", SCOLOR_ASMDIR), ash.origin, buf); } init_output_buffer(buf, sizeof(buf)); OutMnem(); out_one_operand(0); if ( cmd.Op2.type != o_void ) { out_symbol(','); OutChar(' '); out_one_operand(1); } if ( isVoid(cmd.ea, uFlag, 0) ) OutImmChar(cmd.Op1); if ( isVoid(cmd.ea, uFlag, 1) ) OutImmChar(cmd.Op2); term_output_buffer(); gl_comm = 1; MakeLine(buf); }
// prints function footer static void gnu_func_footer(func_t *pfn) { char buf[MAXSTR]; const char *name = gnu_get_func_name(pfn, buf, sizeof(buf)); if ( name != NULL ) printf_line(inf.indent, COLSTR(".endproc", SCOLOR_ASMDIR)); }
//-------------------------------------------------------------------------- void segend(ea_t) { #if 0 segment_t *s = getseg(ea-1); if ( is_spec_segm(s->type) ) return; printf_line(0,COLSTR(";%-*s ends",SCOLOR_AUTOCMT),inf.indent-2,get_segm_name(s)); #endif }
void printf_formatted_text(FILE * file, char * text, int width, char * prefix) { int length = strlen(text); int pl = prefix ? strlen(prefix):0; char *c; c = text; while(length) { /* go to the end and rewind until we find a space */ char * t = text + width - pl; while((t[0]!=' ') && (t[0]!='\n')) { t--; if(t == text) { /* Too long. Abort */ if(prefix)fprintf(file, "\n%s", prefix); fprintf(file, "%s\n", text); return; } } fprintf(file, "\n%s", prefix?prefix:""); text = printf_line(file, text, t - text); length = strlen(text); } }
// prints function footer static void idaapi gnu_func_footer(func_t *pfn) { char buf[MAXSTR]; const char *name = fr_get_func_name(pfn, buf, sizeof(buf)); if ( name != NULL ) printf_line(inf.indent, COLSTR(".size %s, .-%s", SCOLOR_ASMDIR), name, name); }
//-------------------------------------------------------------------------- void header(void) { gen_cmt_line("Processor : %-8.8s", inf.procName); gen_cmt_line("Target assembler: %s", ash.name); gen_cmt_line("Byte sex : %s, %s", inf.mf ? "big-endian" : "little-endian", inf.wide_high_byte_first ? "high_byte_first" : "high_byte_last"); if ( ash.header != NULL ) for ( const char **ptr=ash.header; *ptr != NULL; ptr++ ) printf_line(0,COLSTR("%s",SCOLOR_ASMDIR),*ptr); MakeNull(); printf_line(0,COLSTR("MY_BYTE .macro BYTE",SCOLOR_ASMDIR)); printf_line(0,COLSTR(" .emsg \"ERROR - Impossible to generate 8bit bytes on this processor. Please convert them to 16bit words.\"",SCOLOR_ASMDIR)); printf_line(0,COLSTR(" .endm",SCOLOR_ASMDIR)); MakeNull(); }
// prints function footer static void mits_func_footer(func_t *pfn) { char buf[MAXSTR]; const char *name = mits_get_func_name(pfn, buf, sizeof(buf)); if ( name != NULL ) printf_line(inf.indent, COLSTR(".ENDFUNC %s", SCOLOR_ASMDIR), name); }
//---------------------------------------------------------------------- static void idaapi func_header(func_t *f) { char buf[256]; char name[64]; printf_line(0, "# =============== S U B R O U T I N E ======================================="); printf_line(0, ""); get_func_name(f->startEA, name, sizeof(name)); init_output_buffer(buf, sizeof(buf)); out_snprintf("def %s(", name); out_snprintf("...):"); term_output_buffer(); printf_line(0, "%s", buf); printf_line(0, ""); }
//-------------------------------------------------------------------------- void footer(void) { char name[MAXSTR]; get_name(BADADDR, inf.beginEA, name, sizeof(name)); printf_line(inf.indent,COLSTR("%s",SCOLOR_ASMDIR) " " COLSTR("%s %s",SCOLOR_AUTOCMT), ash.end, ash.cmnt, name); }
// prints function footer static void idaapi gnu_func_footer(func_t *pfn) { qstring namebuf; if ( fr_get_func_name(&namebuf, pfn) ) { const char *name = namebuf.begin(); printf_line(inf.indent, COLSTR(".size %s, .-%s", SCOLOR_ASMDIR), name, name); } }
//-------------------------------------------------------------------------- void header(void) { gen_cmt_line("Processor : %-8.8s [%s]", inf.procName, device); gen_cmt_line("Target assembler: %s", ash.name); gen_cmt_line("Byte sex : %s", inf.mf ? "Big endian" : "Little endian"); if ( ash.header != NULL ) for ( const char **ptr=ash.header; *ptr != NULL; ptr++ ) printf_line(0, COLSTR("%s",SCOLOR_ASMDIR),*ptr); }
//-------------------------------------------------------------------------- void segstart(ea_t ea) { const char *predefined[] = { ".text", // Text section ".rdata", // Read-only data section ".data", // Data sections ".lit8", // Data sections ".lit4", // Data sections ".sdata", // Small data section, addressed through register $gp ".sbss", // Small bss section, addressed through register $gp ".bss", // bss (block started by storage) section, which loads zero-initialized data }; segment_t *Sarea = getseg(ea); if ( is_spec_segm(Sarea->type) ) return; char sname[MAXNAMELEN]; char sclas[MAXNAMELEN]; get_true_segm_name(Sarea, sname, sizeof(sname)); get_segm_class(Sarea, sclas, sizeof(sclas)); int i; for ( i=0; i < qnumber(predefined); i++ ) if ( strcmp(sname, predefined[i]) == 0 ) break; if ( i != qnumber(predefined) ) printf_line(inf.indent, COLSTR("%s", SCOLOR_ASMDIR), sname); else printf_line(inf.indent, COLSTR("%s", SCOLOR_ASMDIR) "" COLSTR("%s %s", SCOLOR_AUTOCMT), strcmp(sclas,"CODE") == 0 ? ".text" : strcmp(sclas,"BSS") == 0 ? ".bss" : ".data", ash.cmnt, sname); if ( Sarea->orgbase != 0 ) { char buf[MAX_NUMBUF]; btoa(buf, sizeof(buf), Sarea->orgbase); printf_line(inf.indent, COLSTR("%s %s", SCOLOR_ASMDIR), ash.origin, buf); } }
//-------------------------------------------------------------------------- // function to produce start of disassembled text //set as member of LPH struct void idaapi header(void) { printf_line(0,""); printf_line(0,""); printf_line(0,"# CR16C Processor plugin by Andreas Schuler <*****@*****.**>"); printf_line(0,"# "); printf_line(0,"# Based on Simple Python Byte Code Module (Chris Eagle <*****@*****.**>)"); printf_line(0,"# Released under GPL v2"); printf_line(0,"# "); printf_line(0,"# More infos at http://www.codenaschen.de"); }
void segstart(ea_t ea) { char buf[MAXSTR]; segment_t *Sarea = getseg(ea); char name[MAXNAMELEN]; get_segm_name(Sarea, name, sizeof(name)); if ( ash.uflag & UAS_SECT ) { if ( Sarea->type == SEG_IMEM ) { MakeLine(".RSECT", inf.indent); } else { printf_line(0, COLSTR("%s: .section", SCOLOR_ASMDIR), name); } } else { if(ash.uflag & UAS_NOSEG) printf_line(inf.indent, COLSTR("%s.segment %s", SCOLOR_AUTOCMT), ash.cmnt, name); else printf_line(inf.indent, COLSTR("segment %s",SCOLOR_ASMDIR), name); if(ash.uflag & UAS_SELSG) MakeLine(name, inf.indent); if(ash.uflag & UAS_CDSEG) MakeLine(Sarea->type == SEG_IMEM ? COLSTR("DSEG", SCOLOR_ASMDIR) : COLSTR("CSEG", SCOLOR_ASMDIR), inf.indent); // XSEG - eXternal memory } if ( inf.s_org ) { adiff_t org = ea - get_segm_base(Sarea); if ( org != 0 ) { btoa(buf, sizeof(buf), org); gen_cmt_line("%s %s", ash.origin, buf); } } }
static int out_equ(ea_t ea) { char buf[MAXSTR]; char *const end = buf + sizeof(buf); segment_t *s = getseg(ea); if ( s != NULL && s->type == SEG_IMEM && ash.a_equ != NULL) { char nbuf[MAXSTR]; char *name = get_name(BADADDR, ea, nbuf, sizeof(nbuf)); if ( name != NULL && ((ash.uflag & UAS_PBYTNODEF) == 0 || !IsPredefined(name)) ) { get_colored_name(BADADDR, ea, buf, sizeof(buf)); uchar off = uchar(ea - get_segm_base(s)); do_out_equ(buf, ash.a_equ, off); if ( (ash.uflag & UAS_AUBIT) == 0 && (off & 0xF8) == off ) { char *ptr = tag_on(tail(buf), end, COLOR_SYMBOL); APPCHAR(ptr, end, ash.uflag & UAS_NOBIT ? '_' : '.'); APPCHAR(ptr, end, '0'); tag_off(ptr, end, COLOR_SYMBOL); for ( int i=0; i < 8; i++ ) { const ioport_bit_t *b = find_bit(off, i); char *p2 = ptr; if ( b == NULL || b->name == NULL ) ptr[-1] = '0' + i; else p2 = tag_addstr(ptr-1, end, COLOR_HIDNAME, b->name); tag_off(p2, end, COLOR_SYMBOL); do_out_equ(buf, ash.a_equ, off+i); } MakeNull(); } } else { gl_name = 0; MakeLine(""); } return 1; } if ( ash.uflag & UAS_NODS ) { if ( !isLoaded(ea) && s->type == SEG_CODE ) { adiff_t org = ea - get_segm_base(s) + get_item_size(ea); btoa(buf, sizeof(buf), org); printf_line(inf.indent, COLSTR("%s %s", SCOLOR_ASMDIR), ash.origin, buf); return 1; } } return 0; }
//-------------------------------------------------------------------------- void idaapi segstart(ea_t ea) { segment_t *Sarea = getseg(ea); if ( is_spec_segm(Sarea->type) ) return; char sclas[MAXNAMELEN]; get_segm_class(Sarea, sclas, sizeof(sclas)); if ( strcmp(sclas,"CODE") == 0 ) printf_line(inf.indent, COLSTR(".text", SCOLOR_ASMDIR)); else if ( strcmp(sclas,"DATA") == 0 ) printf_line(inf.indent, COLSTR(".data", SCOLOR_ASMDIR)); if ( Sarea->orgbase != 0 ) { char buf[MAX_NUMBUF]; btoa(buf, sizeof(buf), Sarea->orgbase); printf_line(inf.indent, COLSTR("%s %s", SCOLOR_ASMDIR), ash.origin, buf); } }
// generate segment header void idaapi gen_segm_header(ea_t ea) { segment_t *Sarea = getseg(ea); char sname[MAXNAMELEN]; get_segm_name(Sarea, sname, sizeof(sname)); char *segname = sname; if ( ash.uflag & UAS_SEGM ) printf_line(inf.indent, COLSTR("SEGMENT %s", SCOLOR_ASMDIR), segname); else if ( ash.uflag & UAS_RSEG ) printf_line(inf.indent, COLSTR("RSEG %s", SCOLOR_ASMDIR), segname); ea_t orgbase = ea - get_segm_para(Sarea); if ( orgbase != 0 ) { char buf[MAX_NUMBUF]; btoa(buf, sizeof(buf), orgbase); printf_line(inf.indent, COLSTR("%s %s", SCOLOR_ASMDIR), ash.origin, buf); } }
//-------------------------------------------------------------------------- void segend(ea_t ea) { segment_t *Sarea = getseg(ea-1); if ( is_spec_segm(Sarea->type) ) return; if ( (ash.uflag & UAS_GNU) == 0 ) { char sname[MAXNAMELEN]; get_true_segm_name(Sarea, sname, sizeof(sname)); if ( strcmp(sname, "XMEM") != 0 ) printf_line(inf.indent, "endsec"); } }
//-------------------------------------------------------------------------- void idaapi header(void) { gen_cmt_line("Processor : %-8.8s", inf.procName); gen_cmt_line("Target assembler: %s", ash.name); gen_cmt_line("Byte sex : %s, %s", inf.mf ? "big-endian" : "little-endian", inf.wide_high_byte_first ? "high_byte_first" : "high_byte_last"); if ( ash.header != NULL ) for ( const char **ptr=ash.header; *ptr != NULL; ptr++ ) printf_line(0,COLSTR("%s",SCOLOR_ASMDIR),*ptr); MakeNull(); }
// generate segment header void idaapi gen_segm_header(ea_t ea) { segment_t *Sarea = getseg(ea); char sname[MAXNAMELEN]; get_segm_name(Sarea, sname, sizeof(sname)); char *segname = sname; if ( *segname == '_' ) *segname = '.'; printf_line(0, COLSTR(".section %s", SCOLOR_ASMDIR), segname); }
//-------------------------------------------------------------------------- static void print_segment_register(int reg, sel_t value) { if ( reg == ph.regDataSreg ) return; char buf[MAX_NUMBUF]; btoa(buf, sizeof(buf), value); switch (reg) { case ARMS: if (value == -1) break; printf_line(inf.indent,COLSTR(".arms_%s",SCOLOR_ASMDIR), value ? "on":"off"); return; case CPL: if (value == -1) break; printf_line(inf.indent,COLSTR(".cpl_%s",SCOLOR_ASMDIR), value ? "on":"off"); return; case DP: if (value == -1) break; printf_line(inf.indent,COLSTR(".dp %s",SCOLOR_ASMDIR), buf); return; } gen_cmt_line("assume %s = %s", ph.regNames[reg], buf); }