Exemple #1
0
/*
 * Dump The Resource Table for Windows NE module
 */
static void dmp_resrc_tab_win( void )
/***********************************/
{
    unsigned_16                             res_type;
    auto struct resource_type_record        res_group;
    unsigned_32                             offset;

    Resrc_end = 0ul;
    Wread( &Resrc_shift_cnt, sizeof( unsigned_16 ) );
    offset = New_exe_off + Os2_head.resource_off + sizeof( unsigned_16 );
    Wdputs( "resource shift count: " );
    Putdec( Resrc_shift_cnt );
    Wdputslc( "\n" );
    for( ;; ) {
        Wlseek( offset );
        Wread( &res_group, sizeof( resource_type_record ) );
        offset += sizeof( resource_type_record );
        res_type = res_group.type;
        if( res_type == 0 ) {
            return;
        }
        dmp_resrc_type_nam( res_type );
        Wlseek( offset );
        dmp_resrc_ent( res_group.num_resources );
        offset += res_group.num_resources * sizeof( resource_record );
        Wdputslc( "\n" );
    }
}
Exemple #2
0
/*
 * Dump the Mach-O command list.
 */
static void dmp_cmd_list( unsigned_32 start, int n )
{
    int                         i;
    unsigned_32                 offset;
    uint32_t                    cmd, cmdsize;
    struct segment_command      seg;

    offset = start + sizeof( struct mach_header );
    for( i = 0; i < n; ++i ) {
        Wlseek( offset );
        Wread( &cmd, sizeof( cmd ) );
        Wread( &cmdsize, sizeof( cmdsize ) );
        Wlseek( offset );

        switch( cmd ) {
        case LC_SEGMENT:
            Wread( &seg, sizeof( seg ) );
            Dump_header( &seg, m_segment_msg );
            break;
        default:
            Wdputs( "\ncmd       = " );
            Puthex( cmd, 8 );
            Wdputs( "H\ncmdsize   = " );
            Puthex( cmdsize, 8 );
            Wdputs( "H" );
        }
        Wdputslc( "\n" );
        offset += cmdsize;
        Wlseek( offset );
    }
}
Exemple #3
0
/*
 * Dump the coff object, if any.
 */
bool Dmp_coff_head( void )
/************************/
{
    coff_file_header    header;

    Wlseek( Coff_off );
    Wread( &header, sizeof( coff_file_header ) );
    if( header.cpu_type != IMAGE_FILE_MACHINE_I386
        && header.cpu_type != IMAGE_FILE_MACHINE_ALPHA
        && header.cpu_type != IMAGE_FILE_MACHINE_UNKNOWN
        && header.cpu_type != IMAGE_FILE_MACHINE_POWERPC ) {
        return 0;
    }
    Banner( "COFF object file" );
    Wdputs( "file offset = " );
    Puthex( Coff_off, 8 );
    Wdputslc( "H\n" );
    Wdputslc( "\n" );
    Dump_header( (char *)&header, coff_hdr_msg );
    DumpCoffHdrFlags( header.flags );
    load_string_table( &header );
    Wlseek( Coff_off + sizeof(coff_file_header) + header.opt_hdr_size );
    dmp_objects( header.num_sections );
    unload_string_table();
    dmp_symtab( header.sym_table, header.num_symbols );
    return 1;
}
Exemple #4
0
/*
 * dump_hll - dump HLL data at offset 'base' from start of file
 */
static void dump_hll( unsigned_32 base )
/**************************************/
{
    hll_trailer                 header;
    hll_dirinfo                 dir_info;
    hll_dir_entry               dir_entry;
    int                         i;

    Wlseek( base );
    Wread( &header, sizeof( header ) );
    if( memcmp( header.sig, HLL_NB04, HLL_SIG_SIZE ) != 0 ) {
        return;
    }
    Wlseek( base + header.offset );
    Wread( &dir_info, sizeof( dir_info ) );
    Dump_header( &dir_info , hll_dir_info_msg );
    Wdputslc( "\n" );
    for( i = 0; i < dir_info.cDir; ++i ) {
        Wlseek( base + header.offset + dir_info.cbDirHeader + i * dir_info.cbDirEntry );
        Wread( &dir_entry, sizeof( dir_entry ) );
        Dump_header( &dir_entry, hll_dir_entry_msg );
        Wdputslc( "\n" );
        dump_hll_subsection( base, &dir_entry );
    }
}
Exemple #5
0
static void set_dwarf( unsigned_32 start )
/****************************************/
{
    Elf32_Shdr      elf_sec;
    unsigned_32     offset;
    char            *string_table;
    int             i;
    uint            sect;
    unsigned_32     sectsizes[DR_DEBUG_NUM_SECTS];
    unsigned_32     sections[DR_DEBUG_NUM_SECTS];

    // grab the string table, if it exists
    if( !Elf_head.e_shstrndx ) {
        return; // no strings no dwarf
    }
    if( Elf_head.e_shnum == 0 ) {
        return; // no sections no dwarf
    }
    memset( sections, 0, DR_DEBUG_NUM_SECTS * sizeof( unsigned_32 ) );
    memset( sectsizes, 0, DR_DEBUG_NUM_SECTS * sizeof( unsigned_32 ) );
    offset = Elf_head.e_shoff
           + Elf_head.e_shstrndx * Elf_head.e_shentsize+start;
    Wlseek( offset );
    Wread( &elf_sec, sizeof( Elf32_Shdr ) );
    swap_shdr( &elf_sec );
    string_table = Wmalloc( elf_sec.sh_size );
    Wlseek( elf_sec.sh_offset + start );
    Wread( string_table, elf_sec.sh_size );
    for( i = 0; i < Elf_head.e_shnum; i++ ) {
        Wlseek( Elf_head.e_shoff + i * Elf_head.e_shentsize + start );
        Wread( &elf_sec, sizeof( Elf32_Shdr ) );
        swap_shdr( &elf_sec );
        if( elf_sec.sh_type == SHT_PROGBITS ) {
            sect = Lookup_section_name( &string_table[elf_sec.sh_name] );
            if ( sect < DW_DEBUG_MAX ) {
                sections[sect] = elf_sec.sh_offset + start;
                sectsizes[sect] = elf_sec.sh_size;
            }
        }
    }
    free( string_table );
    for( i = 0; i < DR_DEBUG_NUM_SECTS; i += 1 ) {
        Sections[i].cur_offset = 0;
        Sections[i].max_offset = sectsizes[i];

        if( sectsizes[i] != 0 ) {
            Wlseek( sections[i] );
            Sections[i].data = Wmalloc( sectsizes[i] );
            if( Sections[i].data == NULL ) {
                Wdputslc( "Not enough memory\n" );
                exit( 1 );
            }
            Wread( Sections[i].data, sectsizes[i] );
        }
    }
}
Exemple #6
0
/*
 * Dump a note section.
 */
static void dmp_sec_note( unsigned_32 offset, unsigned_32 size )
/**************************************************************/
{
    Elf_Note        note;
    unsigned_32     read = 0;
    unsigned_32     skip;
    char            *ptr;

    Wlseek( offset );
    while( read < size ) {
        Wdputslc( "\n" );
        Wread( &note, sizeof( note ) );
        read += sizeof( note );
        if( Byte_swap ) {
            SWAP_32( note.n_namesz );
            SWAP_32( note.n_descsz );
            SWAP_32( note.n_type );
        }
        ptr = Wmalloc( note.n_namesz );
        Wread( ptr, note.n_namesz );
        Wdputs( "    note name:                              " );
        Wdputs( ptr );
        Wdputslc( "\n" );
        Wdputs( "    descriptor length:                      " );
        Puthex( note.n_descsz, 8 );
        Wdputslc( "H\n" );
        Wdputs( "    note type:                              " );
        switch( note.n_type ) {
        case NT_PRSTATUS:
            Wdputs( "process status" );
            break;
        case NT_FPREGSET:
            Wdputs( "floating-point registers" );
            break;
        case NT_PRPSINFO:
            Wdputs( "process info" );
            break;
        default:
            Wdputs( "unknown (" );
            Puthex( note.n_type, 8 );
            Wdputs( "H)" );
        }
        Wdputslc( "\n" );
        free( ptr );

        /* Calculate rounded up note name length */
        skip = (note.n_namesz + ELF_ROUND) & ~ELF_ROUND;
        read += skip;
        Wlseek( offset + read );
        /* Calculate rounded up note descriptor length */
        skip = (note.n_descsz + ELF_ROUND) & ~ELF_ROUND;
        read += skip;
        Wlseek( offset + read );
    }
}
Exemple #7
0
/*
 * dump_cv_sstTypes - dump CV sstTypes at 'offset'
 * from 'base 'containing 'size' bytes
 */
static void dump_cv_sstTypes( unsigned_32 base, unsigned_32 offset,
                                                unsigned_32 size )
/*****************************************************************/
{
    cv3_lf_common       typ;
    cv3_lf_all          type;
    unsigned_32         read = 0;
    unsigned            idx = 0;

    Wlseek( base + offset );
    Wdputs( "==== sstTypes at offset " );
    Puthex( offset, 8 );
    Wdputslc( "\n" );
    Wdputslc( " index: len  id type\n" );
    while( read < size ) {
        /* seek to start of next type record */
        Wlseek( base + offset + read );
        Wread( &typ, sizeof( cv3_lf_common ) );
        Wdputs( "  " );
        Puthex( idx, 4 );
        Wdputs( ": " );
        Puthex( typ.length, 4 );
        Wdputs( " " );
        Puthex( typ.type, 2 );
        read += typ.length + sizeof( unsigned_8 ) + sizeof( unsigned_16 );
        switch( typ.type ) {
        case HLF_SKIP:
            Wdputslc( " SKIP\n" );
            break;
        case HLF_NULL:
            Wdputslc( " NULL\n" );
            break;
        case HLF_BITFIELD:
            Wread( &type, sizeof( cv3_lf_bitfield ) );
            Wdputs( " BITFIELD: size=" );
            Puthex( type.bitfield.length, 2 );
            Wdputs( " basetype=" );
            Puthex( type.bitfield.type, 2 );
            Wdputs( " offset=" );
            Puthex( type.bitfield.position, 2 );
            Wdputslc( "\n" );
            break;
        default:
            Wdputs( " unknown type code " );
            Puthex( typ.type, 2 );
            Wdputslc( "!\n" );
        }
        ++idx;
    }
    Wdputslc( "\n" );
}
/*
 * dump_addr_info - dump out address info
 */
static void dump_addr_info( section_dbg_header *sdh )
/***************************************************/
{
    unsigned_32 total_bytes;
    unsigned_32 bytes_read;
    seg_info    *si;
    long        cpos;
    long        basepos;
    unsigned_32 len;
    int         i;
    unsigned_32 seg_off;

    total_bytes = sdh->section_size - sdh->addr_offset;
    print_info_title( "Addr" );

    bytes_read = 0;
    si = (seg_info *) Wbuff;
    basepos = cpos = Curr_sectoff + sdh->addr_offset;
    while( bytes_read < total_bytes ) {
        Wlseek( cpos );
        Wread( Wbuff, sizeof( seg_info ) );
        Wlseek( cpos );
        len = sizeof( seg_info ) + (si->num-1) * sizeof( addr_info );
        Wread( Wbuff, len );
        Wdputs( " Base:  fileoff = " );
        Puthex( cpos-basepos, 8 );
        Wdputs( "H   seg = " );
        Puthex( si->base.segment, 4 );
        Wdputs( "H,  off = " );
        Puthex( si->base.offset, 8 );
        Wdputslc( "H\n" );
        seg_off = si->base.offset;
        for( i = 0; i < si->num; i++ ) {
            Putdecl( i, 6 );
            Wdputs( ") fileoff = " );
            Puthex( (long) cpos - basepos + sizeof( seg_info) +
                        i * sizeof( addr_info ) - sizeof( addr_info ), 8 );
            Wdputs( "H,  Size = " );
            Puthex( si->addr[i].size, 8 );
            Wdputs( "H @" );
            Puthex( seg_off, 8 );
            Wdputs( "H,  mod_index = " );
            Putdec( si->addr[i].mod );
            Wdputslc( "\n" );
            seg_off += si->addr[i].size;
        }
        cpos += len;
        bytes_read += len;
    }
} /* dump_addr_info */
Exemple #9
0
/*
 * Dump Segment Table
 */
void Dmp_seg_tab( void )
/**********************/
{
    unsigned_16                     num_segs;
    struct segment_record           *segtab;
    unsigned_16                     segtabsize;
    unsigned_16                     segnum;

    Banner( "Segment Table" );
    num_segs = Os2_head.segments;
    if( num_segs == 0 ) {
        return;
    }
    Wlseek( New_exe_off + Os2_head.segment_off );
    segtabsize = sizeof( struct segment_record ) * num_segs;
    segtab = Wmalloc( segtabsize );
    Wread( segtab, segtabsize );
    Int_seg_tab = segtab;
    ++num_segs;
    Wdputslc( "seg  fileoff  len  alloc prior priv flag\n" );
    Wdputslc( "==== ======== ==== ====  ====  ==== ====\n" );
    for( segnum = 1; segnum != num_segs; segnum++ ) {
        Puthex( segnum, 4 );
        dmp_seg_ent( segtab++ );
    }
    Wdputslc( "\n" );
}
Exemple #10
0
/*
 * Dump the Resource Data.
 */
static void dmp_res_data( void )
/******************************/
{
    resource_entry          res_data;
    unsigned_16             i;

    Wdputslc( "\n" );
    Wdputslc( "       data rva     data size    codepage     reserved\n" );
    Wdputslc( "       ========     ========     ========     ========\n" );
    Wlseek( Data_off );
    for( i = 0; ; i++ ) {
        Wread( &res_data, sizeof( resource_entry ) );
        if( res_data.rsvd != 0 ) break;
        Putdecl( i, 3 );
        Wdputs( ":   " );
        Puthex( res_data.data_rva, 8 );
        Wdputs( "     " );
        Puthex( res_data.size, 8 );
        Wdputs( "     " );
        Puthex( res_data.code_page, 8 );
        Wdputs( "     " );
        Puthex( res_data.rsvd, 8 );
        Wdputslc( "\n" );
    }
}
Exemple #11
0
/*
 * Dump the Resource Directory.
 */
static void dmp_res_dir( void )
/*****************************/
{
    resource_dir_header     res_head;
    resource_dir_entry      res_dir;
    unsigned_16             count, i;

    Wdputslc( "\n" );
    Wdputslc( "80000000H = name rva,        else integer id\n" );
    Wdputslc( "80000000H = sudirectory rva, else data entry rva\n" );
    Wdputslc( "  #id ents    #name ents    name rva/id    data/subdir rva\n" );
    Wdputslc( "    ====         ====         ========        ========\n" );
    Wlseek( Res_off );
    for( ;; ) {
        Wread( &res_head, sizeof( resource_dir_header ) );
        count = res_head.num_name_entries + res_head.num_id_entries;
        if( count == 0 ) break;
        Wdputs( "    " );
        Puthex( res_head.num_id_entries, 4 );
        Wdputs( "         " );
        Puthex( res_head.num_name_entries, 4 );
        Wdputs( "         " );
        for( i = 0; i < count; i++ ) {
            Wread( &res_dir, sizeof( resource_dir_entry ) );
            if( i != 0 ) {
                Wdputs( "                              " );
            }
            Puthex( res_dir.id_name, 8 );
            Wdputs( "        " );
            Puthex( res_dir.entry_rva, 8 );
            Wdputslc( "\n" );
        }
    }
}
Exemple #12
0
/*
 * Dmp_hll_head - dump IBM HLL or MS CodeView debugging information
 */
bool Dmp_hll_head( void )
/**********************/
{
    off_t           end_off;
    off_t           dbg_off;
    hll_trailer     trailer;

    end_off = lseek( Handle, 0, SEEK_END );
    Wlseek( end_off - sizeof( trailer ) );
    Wread( &trailer, sizeof( trailer ) );
    dbg_off = end_off - trailer.offset;
    if( memcmp( trailer.sig, HLL_NB04, HLL_SIG_SIZE ) == 0 ) {
        Banner( "HLL NB04 debugging information" );
        Wdputs( "debugging information base  = " );
        Puthex( dbg_off, 8 );
        Wdputslc( "H\n" );
        Wdputs( "subsection directory offset = " );
        Puthex( trailer.offset, 8 );
        Wdputslc( "H\n\n" );
        dump_hll( dbg_off );
        return( true );
    } else if( memcmp( trailer.sig, HLL_NB02, HLL_SIG_SIZE ) == 0 ) {
        Banner( "CodeView NB02 debugging information" );
        Wdputs( "debugging information base  = " );
        Puthex( dbg_off, 8 );
        Wdputslc( "H\n" );
        Wdputs( "subsection directory offset = " );
        Puthex( trailer.offset, 8 );
        Wdputslc( "H\n\n" );
        dump_cv( dbg_off );
        return( true );
    }
    return( false );
} /* Dmp_hll_head */
Exemple #13
0
/*
 * Dump relocation fixup table.
 */
static void dmp_reloc_fixup( void )
/*********************************/
{
    unsigned_32     i;
    unsigned_32     reloc;

    if( Nlm_head.numberOfRelocationFixups == 0 ) {
        return;
    }
    Wdputslc( "\n" );
    Wlseek( Nlm_head.relocationFixupOffset );
    Banner( "Relocation Fixup Table" );
    Wdputslc( "80000000H = target is in code segment\n" );
    Wdputslc( "40000000H = source of fixup is in code segment\n" );
    for( i = 0; i < Nlm_head.numberOfRelocationFixups; i++ ) {
        Wread( &reloc, sizeof( unsigned_32 ) );
        if( i != 0 ) {
            if( (i) % 6 == 0 ) {
                Wdputslc( "\n" );
            } else {
                Wdputs( "      " );
            }
        }
        Puthex( reloc, 8 );
    }
    Wdputslc( "\n" );
}
Exemple #14
0
/*
 * dump_cv_sstModules - dump CV sstModules at 'offset' from 'base'
 */
static void dump_cv_sstModules( unsigned_32 base, unsigned_32 offset )
/********************************************************************/
{
    cv3_module_16       mod;
    cv3_seginfo_16      seg;
    bool                first = true;

    Wlseek( base + offset );
    Wdputs( "==== sstModules at offset " );
    Puthex( offset, 8 );
    Wdputslc( "\n" );
    Wread( &mod, offsetof( cv3_module_16, name_len ) );
    Dump_header( &mod, cv_sstModules_msg );
    Wdputs( "  module name: \"" );
    dump_name( 0 );
    Wdputslc( "\"\n" );
    if( mod.cSeg ) {
        while( --mod.cSeg ) {
            if( !first ) {
                Wdputslc( "    ====\n" );
            }
            Wread( &seg, sizeof( seg ) );
            Dump_header( &seg, cv_seg_msg );
            first = false;
        }
    }
    Wdputslc( "\n" );
}
Exemple #15
0
/*
 * dump_hll_sstModules - dump HLL sstModules at 'offset' from 'base'
 */
static void dump_hll_sstModules( unsigned_32 base, unsigned_32 offset )
/*********************************************************************/
{
    hll_module          mod;
    hll_seginfo         seg;
    bool                first = true;

    Wlseek( base + offset );
    Wdputs( "==== sstModules at offset " );
    Puthex( offset, 8 );
    Wdputslc( "\n" );
    Wread( &mod, offsetof( hll_module, name_len ) );
    Dump_header( &mod, hll_sstModules_msg );
    hll_level = mod.Version >> 8;
    Wdputs( "  module name: \"" );
    dump_name( 0 );
    Wdputslc( "\"\n" );
    if( mod.cSeg ) {
        while( --mod.cSeg ) {
            if( !first ) {
                Wdputslc( "    ====\n" );
            }
            Wread( &seg, sizeof( seg ) );
            Dump_header( &seg, hll_seg_msg );
            first = false;
        }
    }
    Wdputslc( "\n" );
}
Exemple #16
0
/*
 * dump_hll_sstPublics - dump HLL sstPublics at 'offset'
 * from 'base 'containing 'size' bytes
 */
static void dump_hll_sstPublics( unsigned_32 base, unsigned_32 offset,
                                                   unsigned_32 size )
/********************************************************************/
{
    hll_public_32       pub32;
    unsigned_32         read = 0;
    unsigned_8          name_len;
    char                name[256];

    Wlseek( base + offset );
    Wdputs( "==== sstPublics at offset " );
    Puthex( offset, 8 );
    Wdputslc( "\n" );
    while( read < size ) {
        Wread( &pub32, sizeof( pub32 ) );
        name_len = pub32.name_len;
        Dump_header( &pub32, hll_sstPublics_msg );
        read += sizeof( pub32 );
        Wread( name, name_len );
        name[name_len] = '\0';
        Wdputs( "  symbol name: \"" );
        Wdputs( name );
        read += name_len;
        Wdputslc( "\"\n" );
    }
    Wdputslc( "\n" );
}
Exemple #17
0
/*
 * Dump public entry (export) table.
 */
static void dmp_public_entry( void )
/**********************************/
{
    unsigned_32     i;
    unsigned_8      len;
    char            *name;
    unsigned_32     addr;

    if( Nlm_head.numberOfPublics == 0 ) {
        return;
    }
    Wdputslc( "\n" );
    Wlseek( Nlm_head.publicsOffset );
    Banner( "Public Entry (Export) Table" );
    Wdputslc( "80000000H = symbol is in code\n" );
    Wdputslc( "      Address         Name\n" );
    Wdputslc( "      =======         ====\n" );
    for( i = 0; i < Nlm_head.numberOfPublics; i++ ) {
        Wread( &len, sizeof( unsigned_8 ) );
        name = Wmalloc( len );
        Wread( name, len );
        name[len] = '\0';
        Wread( &addr, sizeof( unsigned_32 ) );
        Wdputs( "      " );
        Puthex( addr, 8 );
        Wdputs( "        " );
        Wdputs( name );
        Wdputslc( "\n" );
    }
}
Exemple #18
0
/*
 * Dump the Resource Id's.
 */
static void dmp_res_name_id( unsigned_16 count, bool is_name )
/***********************************************************/
{
    unsigned_16             i, j, cnt;
    unsigned_32             offset, tmp_off;
    resource_dir_header     pe_res_name;
    resource_dir_entry      pe_res_dir;
    res_name                name;

    if( count == 0 ) return;
    offset = Res_off + sizeof( resource_dir_header );
    for( i = 0; i < count; i++ ) {
        Wlseek( offset );
        Wread( &pe_res_dir, sizeof( resource_dir_entry ) );
        offset += sizeof( resource_dir_entry );
        tmp_off = Res_off +( pe_res_dir.id_name & PE_RESOURCE_MASK );
        if( is_name ) {
            name = get_name( tmp_off );
        } else {
            name.len = 0;
            name.rname = NULL;
        }
        tmp_off = Res_off +( pe_res_dir.entry_rva & PE_RESOURCE_MASK );
        Wlseek( tmp_off );
        Wread( &pe_res_name, sizeof( resource_dir_header ) );
        tmp_off += sizeof( resource_dir_header );
        cnt = pe_res_name.num_name_entries + pe_res_name.num_id_entries;
        for( j = 0; j < cnt; j++ ) {
            if( is_name ) {
                Wdputs( name.rname );
                for( j = name.len; j <= SLEN; j++ ) {
                    Wdputc( ' ' );
                }
            } else {
                Puthex( pe_res_dir.id_name, 8 );
                Wdputs( "                       " );
            }
            if( j >= pe_res_name.num_name_entries ) {
                dmp_name_id( tmp_off, FALSE );
            } else {
                dmp_name_id( tmp_off, TRUE );
            }
            tmp_off += sizeof( resource_dir_entry );
            Wdputslc( "\n" );
        }
    }
}
Exemple #19
0
bool Dmp_ar_head( void )
/**********************/
{
    char                sig[AR_IDENT_LEN];
    ar_header           hdr;
    unsigned long       filesize;
    unsigned long       size;

    Wlseek( 0 );
    Wread( sig, AR_IDENT_LEN );
    if( memcmp( sig, AR_IDENT, AR_IDENT_LEN ) != 0 ) return 0;
    filesize = WFileSize();
    Coff_off = AR_IDENT_LEN;
    for(;;) {
        if( Coff_off + sizeof(ar_header) >= filesize ) break;
        Wread( &hdr, sizeof(ar_header) );
        Coff_off += sizeof(ar_header);
        hdr.date[0]='\0';
        Wdputs( "ar name = " );
        Wdputs( hdr.name );
        Wdputslc( "\n" );
        hdr.header_ident[0] = '\0';
        size = strtoul( hdr.size, NULL, 10 );
        if( strcmp( hdr.name, "/               " ) == 0 ||
                        strcmp( hdr.name, "//              " ) == 0 ) {
            Dmp_seg_data( Coff_off, size );
        } else if( !Dmp_coff_head() ) {
            // then try and see if it's ELF
            Wlseek( Coff_off );
            if( !Dmp_elf_header( Coff_off ) ) {
                Wdputslc( "archive entry not identified\n" );
                Dmp_seg_data( Coff_off, size );
                Wdputslc( "\n" );
            }
        }
        if( size & 1 ) {
            size++;
        }
        Coff_off += size;
        Wlseek( Coff_off );
    }
    return 1;
}
Exemple #20
0
bool Dmp_lib_head( void )
/***********************/
{
    char                sig[LIBMAG_LEN];
    Lib32_Hdr           hdr;
    long                filesize;
    unsigned long       size;
    unsigned long       Elf_off;

    Wlseek( 0 );
    Wread( sig, LIBMAG_LEN );
    if( memcmp( sig, LIBMAG, LIBMAG_LEN ) != 0 ) return 0;
    filesize = WFileSize();
    Elf_off = LIBMAG_LEN + LIB_CLASS_LEN + LIB_DATA_LEN;
    Wlseek( Elf_off );
    for( ;; ) {
        if( Elf_off + LIB_HEADER_SIZE >= filesize ) break;
        Wread( &hdr, LIB_HEADER_SIZE );
        Elf_off += LIB_HEADER_SIZE;
        hdr.lib_date[0]='\0';
        Wdputs( "lib name = " );
        Wdputs( hdr.lib_name );
        Wdputslc( "\n" );
        hdr.lib_fmag[0] = '\0';
        size = strtoul( hdr.lib_size, NULL, 10 );
        if( !Dmp_elf_header( Elf_off ) ) {
            if( strcmp( hdr.lib_name, LIB_SYMTAB_NAME ) &&
                strcmp( hdr.lib_name, LIB_LFTAB_NAME ) &&
                strcmp( hdr.lib_name, LIB_FFTAB_NAME ) ) {
                Wdputslc( "archive entry not identified\n" );
            }
            Dmp_seg_data( Elf_off, size );
            Wdputslc( "\n" );
        }
        if( size & 1 ) {
            size++;
        }
        Elf_off += size;
        Wlseek( Elf_off );
    }
    return 1;
}
Exemple #21
0
/*
 * Dump the Resource Names.
 */
static void dmp_name_id( unsigned_32 offset, bool is_name )
/*********************************************************/
{
    unsigned_16             i, j, cnt;
    resource_dir_entry      pe_res_dir, tmp_dir;
    resource_dir_header     pe_res_lang;
    res_name                name;

    Wlseek( offset );
    Wread( &pe_res_dir, sizeof( resource_dir_entry ) );
    offset = Res_off +( pe_res_dir.id_name & PE_RESOURCE_MASK );
    if( is_name ) {
        name = get_name( offset );
        Wdputs( name.rname );
        for( j = name.len; j <= SLEN; j++ ) {
            Wdputc( ' ' );
        }
    } else {
        Puthex( pe_res_dir.id_name, 8 );
        Wdputs( "                       " );
    }
    offset = Res_off +( pe_res_dir.entry_rva & PE_RESOURCE_MASK );
    if( pe_res_dir.entry_rva & PE_RESOURCE_MASK_ON ) {
        Wlseek( offset );
        Wread( &pe_res_lang, sizeof( resource_dir_header ) );
        offset += sizeof( resource_dir_header );
        Wlseek( offset );
        cnt = pe_res_lang.num_id_entries;
        for( i = 0; i < cnt; i++ ) {
            Wread( &tmp_dir, sizeof( resource_dir_entry ) );
            Puthex( tmp_dir.id_name, 8 );
            if( i != cnt - 1 ) {
                Wdputslc( "\n                                                             " );
            }
        }
        offset = Res_off +( tmp_dir.entry_rva & PE_RESOURCE_MASK );
    }
    if( Data_off == 0 ) {
        Data_off = offset;
    }
}
Exemple #22
0
/*
 * Dump The Resource Table for NE module
 */
void Dmp_resrc_tab( void )
/************************/
{
    if( Os2_head.resource_off == Os2_head.resident_off ) {
        return;
    }
    Banner( "Resource Table" );
    Wlseek( New_exe_off + Os2_head.resource_off );
    if( Os2_head.target == TARGET_OS2 )
        dmp_resrc_tab_os2();
    else
        dmp_resrc_tab_win();
}
Exemple #23
0
/*
 * get a resource type name
 */
static char *get_resrc_nam( unsigned_16 offset )
/**********************************************/
{
    unsigned_8      num_chars;
    char            *name;

    Wlseek( New_exe_off + Os2_head.resource_off + offset );
    Wread( &num_chars, sizeof( unsigned_8 ) );
    name = Wmalloc( num_chars + 1 );
    Wread( name, num_chars );
    name[ num_chars ] = '\0';
    return( name );
}
Exemple #24
0
/*
 * dump_cv - dump CV data at offset 'base' from start of file
 */
static void dump_cv( unsigned_32 base )
/*************************************/
{
    hll_trailer                 header;
    cv3_dir_entry               sst_dir_entry;
    unsigned_16                 num_entries;
    int                         i;

    Wlseek( base );
    Wread( &header, sizeof( header ) );
    if( memcmp( header.sig, HLL_NB02, HLL_SIG_SIZE ) != 0 ) {
        return;
    }
    Wlseek( base + header.offset );
    Wread( &num_entries, sizeof( num_entries ) );
    for( i = 0; i < num_entries; ++i ) {
        Wlseek( base + header.offset + 2 + i * sizeof( sst_dir_entry ) );
        Wread( &sst_dir_entry, sizeof( sst_dir_entry ) );
        Dump_header( &sst_dir_entry, cv_dir_entry_msg );
        Wdputslc( "\n" );
        dump_cv_subsection( base, &sst_dir_entry );
    }
}
Exemple #25
0
/*
 * dump_global_info - dump out global info
 */
static void dump_global_info( section_dbg_header *sdh )
/*****************************************************/
{
    unsigned_32 total_bytes;
    unsigned_32 bytes_read;
    v3_gbl_info *gi;
    long        cpos;
    char        name[256];

    total_bytes = sdh->addr_offset - sdh->gbl_offset;
    print_info_title( "Global" );

    bytes_read = 0;
    gi = (v3_gbl_info *) Wbuff;
    cpos = Curr_sectoff + sdh->gbl_offset;
    while( bytes_read < total_bytes ) {
        Wlseek( cpos );
        Wread( Wbuff, sizeof( v3_gbl_info ) + 255 );
        bytes_read += sizeof( v3_gbl_info ) + gi->name[0];
        cpos += sizeof( v3_gbl_info ) + gi->name[0];
        get_len_prefix_string( name, gi->name );
        Wdputs( "  Name:  " );
        Wdputs(  name );
        Wdputslc( "\n" );
        Wdputs( "    address      = " );
        Puthex( gi->addr.segment, 4 );
        Wdputc( ':' );
        Puthex( gi->addr.offset, 8 );
        Wdputslc( "\n" );
        Wdputs( "    module index = " );
        Putdec( gi->mod );
        Wdputslc( "\n" );
        Wdputs( "    kind:         " );
        if( gi->kind & GBL_KIND_STATIC ) {
            Wdputs( " (static pubdef)" );
        }
        if( gi->kind & GBL_KIND_CODE ) {
            Wdputs( " (code)" );
        }
        if( gi->kind & GBL_KIND_DATA ) {
            Wdputs( " (data)" );
        }
        Wdputslc( "\n" );
    }
    Wdputslc( "\n" );

} /* dump_global_info */
Exemple #26
0
/*
 * Dump a progbits section.
 */
static void dmp_sec_progbits( char *name,
    unsigned_32 offset, unsigned_32 size )
/****************************************/
{
    const uint_8    *ptr;
    uint            sect;

    if( name == NULL ) {
        Dmp_seg_data( offset, size );
    } else {
        ptr = Wmalloc( size );
        Wlseek( offset );
        Wread( (char *)ptr, size );
        sect = Lookup_section_name( name );
        Dump_specific_section( sect, ptr, size );
        free( (void *)ptr );
    }
}
Exemple #27
0
static void load_string_table( coff_file_header *header )
/*******************************************************/
{
    unsigned_32 string_pos;
    unsigned_32 table_size;

    string_pos = Coff_off + header->sym_table
                        + header->num_symbols * sizeof( coff_symbol );
    Wlseek( string_pos );
    Wread( &table_size, sizeof( table_size ) );
    if( table_size > 4 ){
        table_size -= sizeof(unsigned_32);
        String_table = Wmalloc( table_size );
        Wread( String_table, table_size );
    } else {
        String_table = NULL;
    }
}
Exemple #28
0
/*
 * Dump external reference (import) table.
 */
static void dmp_external_ref( void )
/**********************************/
{
    unsigned_32     i,j;
    unsigned_8      len;
    char            *name;
    unsigned_32     num;
    unsigned_32     reloc;

    if( Nlm_head.numberOfExternalReferences  == 0 ) {
        return;
    }
    Wdputslc( "\n" );
    Wlseek( Nlm_head.externalReferencesOffset );
    Banner( "External Reference (Import) Table" );
    Wdputslc( "80000000H = relocation not relative to current position\n" );
    Wdputslc( "40000000H = relocation to code segment\n" );
    for( i = 0; i < Nlm_head.numberOfExternalReferences; i++ ) {
        Wread( &len, sizeof( unsigned_8 ) );
        name = Wmalloc( len );
        Wread( name, len );
        name[len] = '\0';
        Wdputs( name );
        Wdputs( ",  relocations:" );
        Wdputslc( "\n" );
        Wread( &num, sizeof( unsigned_32 ) );
        Wdputs( "        " );
        for( j = 0; j < num; j++ ) {
            Wread( &reloc, sizeof( unsigned_32 ) );
            if( j != 0 ) {
                if( (j) % 4 == 0 ) {
                    Wdputslc( "\n        " );
                } else {
                    Wdputs( "      " );
                }
            }
            Putdecl( j, 2 );
            Wdputc( ':' );
            Puthex( reloc, 8 );
        }
        Wdputslc( "\n" );
    }
}
Exemple #29
0
/*
 * Dump the Resource Table.
 */
void Dmp_resources( void )
/************************/
{
    resource_dir_header             pe_res_type;

    Data_off = 0;
    Wlseek( Res_off );
    Wread( &pe_res_type, sizeof( resource_dir_header ) );
    Banner( "Resource Directory Table" );
    Dump_header( (char *)&pe_res_type.flags, pe_resource_msg );
    Wdputslc( "\n" );
    Wdputslc( "type id/string                 name id/string                 language id\n" );
    Wdputslc( "==============                 ==============                 ===========\n" );
    dmp_res_name_id( pe_res_type.num_name_entries, TRUE );
    dmp_res_name_id( pe_res_type.num_id_entries, FALSE );
    if( Options_dmp & RESRC_DMP ) {
        dmp_res_dir();
        dmp_res_data();
    }
}
Exemple #30
0
/*
 * dump_cv_sstSrcLnSeg - dump sstSrcLnSeg at 'offset' from 'base'
 */
static void dump_cv_sstSrcLnSeg( unsigned_32 base, unsigned_32 offset )
/*********************************************************************/
{
    cv_linnum_seg       src_ln;
    cv3_linnum_entry_16 lo_16;

    Wlseek( base + offset );
    Wdputs( "==== sstSrcLnSeg at offset " );
    Puthex( offset, 8 );
    Wdputslc( "\n" );
    Wdputs( "  source file: \"" );
    dump_name( 2 );
    Wdputslc( "\"\n" );
    Wread( &src_ln, sizeof( src_ln ) );
    Dump_header( &src_ln, cv_sstSrcLnSeg_msg );
    while( src_ln.cPair-- ) {
        Wread( &lo_16, sizeof( lo_16 ) );
        Dump_header( &lo_16, cv_lnoff16_msg );
    }
    Wdputslc( "\n" );
}