コード例 #1
0
/*
 * Dump the ELF header, if any.
 */
bool Dmp_elf_header( unsigned long start )
/****************************************/
{
    Wread( &Elf_head, sizeof( Elf32_Ehdr ) );
    if( memcmp( Elf_head.e_ident, ELF_SIGNATURE, ELF_SIGNATURE_LEN ) ) {
        return( 0 );
    }
    Banner( "ELF Header" );
    if( start != 0 ) {
        Wdputs( "File Offset:" );
        Puthex( start, 8 );
        Wdputslc( "\n" );
    }
    Wdputs( "class (1==32-bit objects, 2==64-bit objs)   =       " );
    Puthex( Elf_head.e_ident[EI_CLASS], 2 );
    Wdputslc( "H\ndata  (1==little-endian, 2==big-endian)     =       " );
    Puthex( Elf_head.e_ident[EI_DATA], 2 );
    Wdputslc( "H\nversion                                     =       " );
    Puthex( Elf_head.e_ident[EI_VERSION], 2 );
    Wdputslc( "H\nOS/ABI type (0==unspecified)                =       " );
    Puthex( Elf_head.e_ident[EI_OSABI], 2 );
    Wdputslc( "H\nABI version (0==unspecified)                =       " );
    Puthex( Elf_head.e_ident[EI_ABIVERSION], 2 );
    Wdputslc( "H\n" );
    if( Elf_head.e_ident[EI_DATA] != NATIVE_ENDIAN ) {
        Byte_swap = TRUE;

        /* Byte swap ELF header */
        SWAP_16( Elf_head.e_type );
        SWAP_16( Elf_head.e_machine );
        SWAP_32( Elf_head.e_version );
        SWAP_32( Elf_head.e_entry );
        SWAP_32( Elf_head.e_phoff );
        SWAP_32( Elf_head.e_shoff );
        SWAP_32( Elf_head.e_flags );
        SWAP_16( Elf_head.e_ehsize );
        SWAP_16( Elf_head.e_phentsize );
        SWAP_16( Elf_head.e_phnum );
        SWAP_16( Elf_head.e_shentsize );
        SWAP_16( Elf_head.e_shnum );
        SWAP_16( Elf_head.e_shstrndx );
    }
    dmp_hdr_type( Elf_head.e_type );
    Dump_header( &Elf_head.e_type, elf_exe_msg );
    Wdputslc( "\n" );
    dmp_prog_sec( start );
    return( 1 );
}
コード例 #2
0
ファイル: machoexe.c プロジェクト: bhanug/open-watcom-v2
/*
 * Dump the Mach-O header at offset 'start', if any.
 */
bool Dmp_macho_header( unsigned long start )
/******************************************/
{
    struct mach_header  mhead;
    
    Wread( &mhead, sizeof( mhead ) );
    if( (mhead.magic != MH_MAGIC) && (mhead.magic != MH_CIGAM) ) {
        return( 0 );
    }
    if( mhead.magic == MH_CIGAM ) {
        Byte_swap = true;
        SWAP_32( mhead.cputype );
        SWAP_32( mhead.cpusubtype );
        SWAP_32( mhead.filetype );
        SWAP_32( mhead.ncmds );
        SWAP_32( mhead.sizeofcmds );
        SWAP_32( mhead.flags );
    }

    Banner( "Mach-O Header" );
    if( start != 0 ) {
        Wdputs( "File Offset: " );
        Puthex( start, 8 );
        Wdputslc( "\n" );
    }
    Wdputs( "magic                                       = " );
    Puthex( mhead.magic, 8 );
    Wdputs( "\ncputype                                     = " );
    Puthex( mhead.cputype, 8 );
    Wdputs( "H\ncpusubtype                                  = " );
    Puthex( mhead.cpusubtype, 8 );
    Wdputs( "H\nfiletype                                    = " );
    Puthex( mhead.filetype, 8 );
    Wdputslc( "H\nncmds                                       = " );
    Puthex( mhead.ncmds, 8 );
    Wdputslc( "H\nsizeofcmds                                  = " );
    Puthex( mhead.sizeofcmds, 8 );
    Wdputslc( "H\nflags                                       = " );
    Puthex( mhead.flags, 8 );
    Wdputslc( "H\n" );
    dmp_file_type( mhead.filetype );
    Wdputslc( "\n" );
    dmp_cmd_list( start, mhead.ncmds );
    dmp_prog_sec( start );
    return( 1 );
}