size_t DIPIMPENTRY( SymName )( imp_image_handle *ii, imp_sym_handle *is, location_context *lc, symbol_name sn, char *buff, size_t buff_size ) { byte *sp; byte *ep; byte curr; size_t len; char *mangled_name; location_list ll; imp_sym_handle gbl_is; switch( sn ) { case SN_EXPRESSION: sp = (byte *)is; ++is; len = 0; #define STUFF_IT( c ) if( (len+1) < buff_size ) *ep++ = (c); ++len ep = (byte *)buff; STUFF_IT( SH_ESCAPE ); while( sp < (byte *)is ) { curr = *sp++; switch( curr ) { case SH_ESCAPE: curr = 1; STUFF_IT( SH_ESCAPE ); break; case '\0': curr = 2; STUFF_IT( SH_ESCAPE ); break; case '`': curr = 3; STUFF_IT( SH_ESCAPE ); break; } STUFF_IT( curr ); } if( buff_size > 0 ) *ep++ = '\0'; return( len ); case SN_DEMANGLED: len = ImpInterface.SymName( ii, is, lc, SN_OBJECT, NULL, 0 ); if( len == 0 ) return( len ); mangled_name = __alloca( len + 1 ); ImpInterface.SymName( ii, is, lc, SN_OBJECT, mangled_name, len + 1 ); if( !__is_mangled( mangled_name, len ) ) return( 0 ); return( __demangle_l( mangled_name, len, buff, buff_size ) ); case SN_OBJECT: switch( is->type ) { case SH_LCL: if( Lcl2GblHdl( ii, is, &gbl_is ) != DS_OK ) break; return( SymHdl2ObjGblName( ii, &gbl_is, buff, buff_size ) ); case SH_MBR: if( ImpInterface.SymLocation( ii, is, lc, &ll ) != DS_OK ) break; if( ll.num != 1 || ll.e[0].type != LT_ADDR ) break; if( ImpInterface.AddrMod( ii, ll.e[0].u.addr, &gbl_is.im ) == SR_NONE ) break; if( LookupGblAddr(ii,ll.e[0].u.addr,&gbl_is) != SR_EXACT ) break; is = &gbl_is; /* fall through */ case SH_GBL: return( SymHdl2ObjGblName( ii, is, buff, buff_size ) ); } /* fall through */ case SN_SOURCE: switch( is->type ) { case SH_GBL: return( SymHdl2GblName( ii, is, buff, buff_size ) ); case SH_LCL: return( SymHdl2LclName( ii, is, buff, buff_size ) ); case SH_MBR: return( SymHdl2MbrName( ii, is, buff, buff_size ) ); case SH_TYP: return( SymHdl2TypName( ii, is, buff, buff_size ) ); case SH_CST: return( SymHdl2CstName( ii, is, buff, buff_size ) ); } break; } return( 0 ); }
unsigned DoFmtStr( char *buff, unsigned len, char *src, va_list *args ) /****************************************************************************/ /* quick vsprintf routine */ /* assumptions - format string does not end in '%' */ /* - only use of '%' is as follows */ /* %s : string */ /* %tn : n character string (%ns) */ /* %c : character */ /* %x : 4 digit hex number (%4x) */ /* %h : 8 digit hex number (%8x) */ /* %d : decimal */ /* %l : long decimal */ /* %a : address ( %x:%x or 32 bit, depends on format) */ /* %A : address ( %x:%h or 32 bit, depends on format) */ /* %S : symbol name */ /* %f : an executable format name */ /********************************************************************/ { char ch; char *dest; char *str; unsigned_16 num; unsigned_32 num2; unsigned size; targ_addr * addr; unsigned int i; static char hexchar[] = "0123456789abcdef"; int temp; dest = buff; for(;;) { ch = *src++; if( ch == '\0' || len == 1 ) break; if( ch != '%' ) { *dest++ = ch; len--; } else { ch = *src++; switch( ch ) { case 'S' : if( UseArgInfo() ) { str = MsgArgInfo.arg[MsgArgInfo.index].symb->name; IncremIndex(); } else { str = va_arg( *args, symbol * )->name; } if( !(LinkFlags & DONT_UNMANGLE) ) { size = __demangle_l( str, 0, dest, len ); if( size > (len-1) ) size = len - 1; CurrSymName = dest; } else { size = strlen( str ); if( size > len ) size = len; memcpy( dest, str, size ); CurrSymName = str; } len -= size; dest += size; break; case 's' : if( UseArgInfo() ) { str = MsgArgInfo.arg[MsgArgInfo.index].string; IncremIndex(); } else { str = va_arg( *args, char * ); } size = strlen( str ); if( size > len ) size = len; memcpy( dest, str, size ); len -= size; dest += size; break; case 't' : str = va_arg( *args, char * ); num = *src++ - '0'; num = num * 10 + *src++ - '0'; if( num > len ) num = len; for( ; (*str != '\0') && (num > 0); --num ) { *dest++ = *str++; } while( num-- > 0 ) { *dest++ = ' '; } len -= num; break; case 'c' : *dest++ = va_arg( *args, int ); len--; break; case 'x' : if( UseArgInfo() ) { num = MsgArgInfo.arg[MsgArgInfo.index].int_16; IncremIndex(); } else { num = va_arg( *args, unsigned int ); } if( len < 4 ) return( dest - buff ); //NOTE: premature return dest += 4; len -= 4; str = dest; for( i = 4; i > 0; i-- ) { *--str = hexchar[num & 0x0f]; num >>= 4; } break; case 'h' : num2 = va_arg( *args, unsigned_32 ); if( len < 8) return( dest - buff ); //NOTE: premature return dest += 8; len -= 8; str = dest; for( i = 8; i > 0; i-- ) { *--str = hexchar[num2 & 0x0f]; num2 >>= 4; } break; case 'd' : if( len < 5 ) return( dest - buff ); // NOTE: premature return if( UseArgInfo() ) { num = MsgArgInfo.arg[MsgArgInfo.index].int_16; IncremIndex(); } else { num = va_arg( *args, unsigned int ); } ultoa( num, dest, 10 ); size = strlen( dest ); dest += size; len -= size; break; case 'l' : if( len < 10 ) return( dest - buff ); //NOTE: premature return if( UseArgInfo() ) { num2 = MsgArgInfo.arg[MsgArgInfo.index].int_32; IncremIndex(); } else { num2 = va_arg( *args, unsigned_32 ); } ultoa( num2, dest, 10 ); size = strlen( dest ); dest += size; len -= size; break; case 'a': case 'A': if( UseArgInfo() ) { addr = MsgArgInfo.arg[MsgArgInfo.index].address; IncremIndex(); } else { addr = va_arg( *args, targ_addr * ); } temp = MsgArgInfo.index; MsgArgInfo.index = -1; if( FmtData.type & MK_FLAT ) { size = FmtStr( dest, len, "%h", addr->off ); } else if( FmtData.type & MK_QNX_FLAT) { size = FmtStr( dest, len, "%h", FindLinearAddr( addr ) ); } else if( FmtData.type & (MK_ELF|MK_PE) ) { size = FmtStr( dest, len, "%h", FindLinearAddr2( addr ) ); } else if( FmtData.type & MK_ID_SPLIT ) { if( addr->seg == CODE_SEGMENT ) { size = FmtStr( dest, len, "CODE:%h", addr->off ); } else { size = FmtStr( dest, len, "DATA:%h", addr->off ); } } else if( (FmtData.type & MK_32BIT) || ch == 'A' ) { size = FmtStr( dest, len, "%x:%h", addr->seg, addr->off ); } else { size = FmtStr( dest, len, "%x:%x", addr->seg, (unsigned short)addr->off ); } dest += size; len -= size; MsgArgInfo.index = temp; break; case 'f': num = MakeExeName( dest, len ); dest += num; len -= num; break; } } } MsgArgInfo.index = -1; *dest = '\0'; return( dest - buff ); }
orl_return CreateNamedLabel( orl_symbol_handle sym_hnd ) { hash_data * data_ptr; label_list sec_label_list; label_entry entry; orl_symbol_type type; orl_symbol_type primary_type; orl_sec_handle sec; char * SourceName; char * LabName; unsigned_64 val64; type = ORLSymbolGetType( sym_hnd ); primary_type = type & 0xFF; switch( primary_type ) { // No harm in including these since elf generates relocs to these. // case ORL_SYM_TYPE_NONE: // case ORL_SYM_TYPE_FUNC_INFO: // return( ORL_OKAY ); case ORL_SYM_TYPE_FILE: SourceName = ORLSymbolGetName( sym_hnd ); if( (SourceName != NULL) && (SourceFileInObject == NULL) ) { SourceFileInObject = SourceName; } return( ORL_OKAY ); } entry = MemAlloc( sizeof( label_entry_struct ) ); if( !entry ) return( ORL_OUT_OF_MEMORY ); val64 = ORLSymbolGetValue( sym_hnd ); entry->offset = val64.u._32[I64LO32]; // all symbols from the object file will have names entry->shnd = ORLSymbolGetSecHandle( sym_hnd ); if( primary_type == ORL_SYM_TYPE_SECTION ) { entry->type = LTYP_SECTION; } else if( primary_type == ORL_SYM_TYPE_GROUP ) { entry->type = LTYP_GROUP; } else if( entry->shnd == 0 ) { entry->type = LTYP_EXTERNAL_NAMED; } else if( primary_type == ORL_SYM_TYPE_FUNC_INFO ){ entry->type = LTYP_FUNC_INFO; } else { entry->type = LTYP_NAMED; } entry->binding = ORLSymbolGetBinding( sym_hnd ); LabName = ORLSymbolGetName( sym_hnd ); if( LabName == NULL ) { sec = ORLSymbolGetSecHandle( sym_hnd ); if( sec ) { LabName = ORLSecGetName( sec ); } else { MemFree( entry ); return( ORL_OKAY ); } } // Demangle the name, if necessary if( !((Options & NODEMANGLE_NAMES) || (DFormat & DFF_ASM)) ) { entry->label.name = MemAlloc( MAX_LINE_LEN + 3 ); __demangle_l( LabName, 0, &(entry->label.name[2]), MAX_LINE_LEN ); } else { entry->label.name = MemAlloc( strlen( LabName )+8 ); strcpy( &(entry->label.name[2]), LabName ); } entry->label.name[0]=0; entry->label.name[1]=0; LabName = &(entry->label.name[2]); if( NeedsQuoting( LabName ) ) { // entry->label.name[-1] will be 1 if we have added a quote, // 0 otherwise. This is helpful when freeing the memory. entry->label.name[0] = 1; entry->label.name[1] = '`'; entry->label.name += 1; LabName += strlen( LabName ); LabName[0] = '`'; LabName[1] = '\0'; } else { entry->label.name += 2; } data_ptr = HashTableQuery( HandleToLabelListTable, (hash_value) entry->shnd ); if( data_ptr ) { sec_label_list = (label_list) *data_ptr; entry = addLabel( sec_label_list, entry, sym_hnd ); if( Options & PRINT_PUBLICS && entry->shnd != 0 && primary_type != ORL_SYM_TYPE_SECTION && entry->binding != ORL_SYM_BINDING_LOCAL ) { Publics.number++; } } else { // error!!!! the label list should have been created MemFree( entry ); return( ORL_ERROR ); } return( ORL_OKAY ); }