Beispiel #1
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;
}
Beispiel #2
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;
}
Beispiel #3
0
/*
 * parse the executable
 */
static void dmp_exe( void )
/*************************/
{
    bool            dos_dmp;
    unsigned long   len;

    Form = FORM_NE;
    Data_count = 0;
    Sizeleft = 0;
    Num_buff = -1;
    Byte_swap = false;
    if( Options_dmp & EXE_INFO ) {
        dos_dmp = Dmp_dos_head();
        if( dos_dmp == 2 ) {
            Options_dmp |= HAS_NEW_EXE;
            if( Dmp_os2_head() ) {
                /* done */
            } else if( Dmp_386_head() ) {
                /* done */
            } else if( Dmp_pe_head() ) {
                /* done */
            } else {
                Wdputslc( "Invalid OS/2, PE header\n" );
            }
        } else if( dos_dmp == 3 ) {
            if( Dmp_d16m_head() ) {
                /* done */
            } else if( Dmp_phar_head() ) {
                /* done */
            } else {
                Wdputslc( "No protected mode executable found\n" );
            }
        } else if( !dos_dmp ) {
            if( Dmp_os2_head() ) {
                /* done */
            } else if( Dmp_386_head() ) {
                /* done */
            } else if( Dmp_pe_head() ) {
                /* done */
            } else if( Dmp_dwarf() ) {
                /* done */
            } else if( Dmp_qnx_head() ) {
                /* done */
            } else if( Dmp_macho_head() ) {
                /* done */
            } else if( Dmp_elf_head() ) {
                /* done */
                // elf debug info has already been handled
                Options_dmp &= ~DEBUG_INFO;
            } else if( Dmp_phar_head() ) {
                /* done */
            } else if( Dmp_nlm_head() ) {
                /* done */
            } else if( Dmp_ar_head() ) {
                /* done */
            } else if( Dmp_lib_head() ) {
                /* done */
            } else if( Dmp_coff_head() ) {
                /* done */
            } else if( Dmp_d16m_head() ) {
                /* done */
            } else {
                Wdputs( Name );
                Wdputslc( " does not have recognized format\n" );
            }
        }
    }
    if( Options_dmp & DEBUG_INFO ) {
        Wdputslc( "\n" );
        if( Dmp_cv_head() ) {
            /* done */
        } else if( Dmp_hll_head() ) {
            /* done */
        } else if( !Dmp_mdbg_head() ) {
            Wdputslc( "No debugging information found\n" );
        }
    }
    if( Options_dmp & IMPORT_LIB ) {
        if( !Dmp_pe_tab() ) {
            Wdputslc( "Invalid PE file\n" );
        }
    }
    if( Options_dmp & IMPORT_DEF ) {
        if( !Dmp_os2_exports() ) {
            Wdputslc( "No exports found\n" );
        }
    }
    if( Options_dmp & BINARY_DMP ) {
        len = WFileSize();
        if( len > Hexoff ) {
            len -= Hexoff;
            Wdputs( "offset = " );
            Puthex( Hexoff, 8 );
            Wdputs( ",  length = " );
            Puthex( len, 8 );
            Wdputslc( "\n" );
            Dmp_seg_data( Hexoff, len );
        }
    }
    if( WSize ) {
        write( Lhandle, Write_buff, WSize );
    }
}