static size_t tryDUP( unsigned_8 *bytes, size_t i, size_t size ) { size_t d; size_t dup; if( i >= ( size - ( 8 * MIN_DUP_LINES ) ) ) return( 0 ); for( d = i + 8; d < ( size - 8 ); d += 8 ) { if( memcmp( &bytes[i], &bytes[d], 8 ) ) { return( 0 ); } } d -= i; dup = d / 8; if( dup < MIN_DUP_LINES ) return( 0 ); BufferStore( "0%XH DUP(", dup ); for( dup = 0; dup < 7; dup++ ) { BufferHex( 2, bytes[i + dup] ); BufferConcat( "," ); } BufferHex( 2, bytes[i + 7] ); BufferConcat( ")" ); return( d ); }
static size_t tryDUP( unsigned_8 *bytes, size_t i, size_t size ) { size_t d; size_t dup; dis_value value; if( i >= ( size - ( 8 * MIN_DUP_LINES ) ) ) return( 0 ); for( d = i + 8; d < ( size - 8 ); d += 8 ) { if( memcmp( &bytes[i], &bytes[d], 8 ) ) { return( 0 ); } } d -= i; dup = d / 8; if( dup < MIN_DUP_LINES ) return( 0 ); BufferStore( "0%XH DUP(", dup ); value.u._32[I64HI32] = 0; for( dup = 0; dup < 7; dup++ ) { value.u._32[I64LO32] = bytes[i + dup]; BufferHex( 2, value ); BufferConcat( "," ); } value.u._32[I64LO32] = bytes[i + 7]; BufferHex( 2, value ); BufferConcat( ")" ); return( d ); }
static return_val bssMasmASMSection( section_ptr section, dis_sec_size size, label_entry l_entry ) { size_t offset = OFFSET_UNDEF; dis_value value; PrintHeader( section ); value.u._32[I64HI32] = 0; for( ; l_entry != NULL; l_entry = l_entry->next ) { if( l_entry->type != LTYP_SECTION ) { if( offset != l_entry->offset ) { BufferStore( " ORG " ); value.u._32[I64LO32] = l_entry->offset; BufferHex( 8, value ); offset = l_entry->offset; BufferConcatNL(); BufferPrint(); } switch( l_entry->type ) { case LTYP_UNNAMED: BufferStore( "%c$%d", LabelChar, l_entry->label.number ); break; case LTYP_SECTION: case LTYP_NAMED: BufferStore( "%s", l_entry->label.name ); break; } BufferConcat( " LABEL\tBYTE" ); BufferConcatNL(); BufferPrint(); } } if( offset == OFFSET_UNDEF ) { if( size > 0 ) { BufferStore( " ORG 0" ); BufferConcatNL(); BufferPrint(); } offset = 0; } if( size > offset ) { BufferStore( " ORG " ); value.u._32[I64LO32] = size; BufferHex( 8, value ); BufferConcatNL(); BufferPrint(); } PrintTail( section ); BufferConcatNL(); BufferPrint(); return( RC_OKAY ); }
static void printRest( unsigned_8 *bytes, size_t size ) { size_t i; size_t d; const char *btype; bool is_masm; dis_value value; is_masm = IsMasmOutput(); if( is_masm ) { btype = " DB\t"; } else { btype = " .byte\t"; } BufferConcat( btype ); value.u._32[I64HI32] = 0; for( i = 0; i < size; ) { // see if we can replace large chunks of homogenous // segment space by using the DUP macro if( is_masm && (i % 8) == 0 ) { d = tryDUP( bytes, i, size ); if( d > 0 ) { i += d; if( i < size ) { BufferConcatNL(); BufferConcat( btype ); BufferPrint(); } continue; } } value.u._32[I64LO32] = bytes[i]; BufferHex( 2, value ); if( i < size - 1 ) { if( (i % 8) == 7 ) { BufferConcatNL(); BufferConcat( btype ); BufferPrint(); } else { BufferConcat( ", " ); } } i++; } BufferConcatNL(); BufferPrint(); }