Beispiel #1
0
//--------------------------------------------------------------------------
// начало сегмента
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
		}
	}
}
Beispiel #2
0
// 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);
    }
}
Beispiel #3
0
void IdaFrontend::createSections(core::image::Image *image) {
    for (int i = 0; i < get_segm_qty(); i++) {
        segment_t *idaSegment = getnseg(i);

        assert(idaSegment != NULL);

        char segName[MAXSTR];
        ssize_t segNameSize = get_segm_name(idaSegment, segName, sizeof(segName) - 1);
        if(segNameSize < 0) {
            segName[0] = '\0';
        } else if(segNameSize > 0 && segName[0] == '_') {
            segName[0] = '.';
        }

        auto section = std::make_unique<core::image::Section>(
            segName,
            checked_cast<ByteAddr>(idaSegment->startEA),
            checked_cast<ByteSize>(idaSegment->size())
        );

        section->setReadable(idaSegment->perm & SEGPERM_READ);
        section->setWritable(idaSegment->perm & SEGPERM_WRITE);
        section->setExecutable(idaSegment->perm & SEGPERM_EXEC);
        section->setCode(idaSegment->type == SEG_CODE);
        section->setData(idaSegment->type == SEG_DATA);
        section->setBss(idaSegment->type == SEG_BSS);
        section->setAllocated(section->isCode() || section->isData() || section->isBss());
        section->setExternalByteSource(std::make_unique<IdaByteSource>());

        image->addSection(std::move(section));
    }
}
Beispiel #4
0
//--------------------------------------------------------------------------
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);
  }
}
Beispiel #5
0
//--------------------------------------------------------------------------
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
}
Beispiel #6
0
// 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);
}
Beispiel #7
0
void segstart( ea_t ea )
{
    segment_t *Sarea = getseg( ea );

    char name[MAXNAMELEN];
    get_segm_name(Sarea, name, sizeof(name));
    gen_cmt_line( COLSTR("segment %s", SCOLOR_AUTOCMT), name );

    ea_t org = ea - get_segm_base( Sarea );
    if ( org != 0 )
    {
        char buf[MAX_NUMBUF];
        btoa(buf, sizeof(buf), org);
        gen_cmt_line("%s %s", ash.origin, buf);
    }
}
Beispiel #8
0
bool IsBlacklistedSegEA( const ea_t ea )
{
	// Skip none-code segment
	segment_t *seg = getseg(ea);
	if( seg->type != SEG_CODE ) return true;

	// Skip "_init", "_fini" and "_plt" segments
	char segname[MAXSTR];
	get_segm_name(seg->startEA, segname, sizeof(segname)-1 );
	if( strcmp(segname, "_init")  == 0 ||
	strcmp(segname, "_fini") == 0 ||
	strcmp(segname, "_plt") == 0 )
		return true;

	return false;

}
Beispiel #9
0
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);
    }
  }
}
Beispiel #10
0
// 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);
    }
}
Beispiel #11
0
//saves a segment to harddisk
bool dump_seg_to_disk(ulong n)
{
	segment_t *curseg;
	uchar *segdata;
	char *answer;
	FILE *file;

	curseg = getnseg(n);
	
	//show "save file" dialog
	answer = askfile_cv(1,get_segm_name(curseg),"Enter a filename for the segment:",0);
	if(answer == NULL)
	{
		return false;
	}

	//get copy of segment and save it to disk
	segdata = get_segment_data(curseg->startEA, curseg->endEA, getsegsize(curseg));
	file = fopenWB(answer);
	ewrite(file, segdata, getsegsize(curseg));
	eclose(file);
	free(segdata);
	return true;
}
Beispiel #12
0
void segend( ea_t ea )
{
    char name[MAXNAMELEN];
    get_segm_name(getseg(ea-1), name, sizeof(name));
    gen_cmt_line( "end of '%s'", name );
}
Beispiel #13
0
//--------------------------------------------------------------------------
void idaapi segend(ea_t ea)
{
  char sname[MAXNAMELEN];
  get_segm_name(getseg(ea-1), sname, sizeof(sname));
  gen_cmt_line("end of '%s'", sname);
}