wdtab.c

来自「开放源码的编译器open watcom 1.6.0版的源代码」· C语言 代码 · 共 611 行 · 第 1/2 页

C
611
字号
/****************************************************************************
*
*                            Open Watcom Project
*
*    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
*  ========================================================================
*
*    This file contains Original Code and/or Modifications of Original
*    Code as defined in and that are subject to the Sybase Open Watcom
*    Public License version 1.0 (the 'License'). You may not use this file
*    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
*    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
*    provided with the Original Code and Modifications, and is also
*    available at www.sybase.com/developer/opensource.
*
*    The Original Code and all software distributed under the License are
*    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
*    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
*    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
*    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
*    NON-INFRINGEMENT. Please see the License for the specific language
*    governing rights and limitations under the License.
*
*  ========================================================================
*
* Description:  NE/LE/LX name tables processing.
*
****************************************************************************/


#include <stdio.h>
#include <setjmp.h>
#include <unistd.h>
#include "walloca.h"

#include "wdglb.h"
#include "wdfunc.h"


extern struct int_entry_pnt     *Entry_pnts = NULL;

/*
 * Read a resident/nonresident name and ordinal
 */
static unsigned_8 read_res_nonres_nam( char *name, unsigned_16 *ordinal )
/***********************************************************************/
{
    unsigned_8              string_len;

    Wread( &string_len, sizeof( string_len ) );
    if( string_len ) {
        Wread( name, string_len );
        Wread( ordinal, sizeof( unsigned_16 ) );
    }
    name[ string_len ] = '\0';
    return( string_len );
}

/*
 * Dump a resident/nonresident name
 */
static unsigned_8 dmp_res_nonres_nam( void )
/******************************************/
{
    char                    resident[256];
    unsigned_16             entry_index;
    unsigned_8              len;

    len = read_res_nonres_nam( resident, &entry_index );
    if( len ) {
        if( Form == FORM_NE ) {
            Wdputs( resident );
            Dmp_ordinal( entry_index );
        } else {
            Wdputs( "ordinal " );
            Puthex( entry_index, 4 );
            Wdputs( ": " );
            Wdputs( resident );
        }
        Wdputslc( "\n" );
    }
    return( len );
}

/*
 * Dump the Resident or Nonresident Names Tables
 */
static void dmp_res_nonres_tab( unsigned_32 res_nam_tab )
/*******************************************************/
{
    if( res_nam_tab <= New_exe_off ) return;
    Wlseek( res_nam_tab );
    while( dmp_res_nonres_nam() )
        ;
}

/*
 * Dump the module reference table
 */
static void dmp_imp_tab( unsigned_32 proc_off, unsigned_32 size_proc )
/********************************************************************/
{
    unsigned_8              string_len;
    unsigned_16             size;
    char                    *imp_nam;

    Wlseek( proc_off );
    for( size = 0; size < size_proc; size += string_len + 1 ) {
        Wread( &string_len, sizeof( unsigned_8 ) );
        imp_nam = Wmalloc( string_len + 1 );
        Wread( imp_nam, string_len );
        imp_nam[ string_len ] = '\0';
        Wdputs( imp_nam );
        Wdputslc( "\n" );
    }
}

/*
 * Dump the module reference table
 */
static void dmp_mod_ref_tab( unsigned_32 mod_ref, unsigned_16 num_mod_ref )
/*************************************************************************/
{
    unsigned_16                     *mod_ref_tab;
    unsigned_16                     size_mod_ref;
    unsigned_16                     ref_num;
    char                            *imp_nam;
    unsigned_32                     imp_off;
    unsigned_8                      string_len;

    if( num_mod_ref == 0 ) {
        return;
    }
    Wdputslc( "\n" );
    Banner( "Module Reference Table" );
    Wlseek( mod_ref );
    size_mod_ref = num_mod_ref * sizeof( unsigned_16 );
    mod_ref_tab = Wmalloc( size_mod_ref );
    Wread( mod_ref_tab, size_mod_ref );
    Int_mod_ref_tab = Wmalloc( num_mod_ref * sizeof( unsigned_8 * ) );
    for( ref_num = 0; ref_num != num_mod_ref; ++ref_num ) {
        imp_off = New_exe_off + mod_ref_tab[ ref_num ] + Os2_head.import_off;
        Wlseek( imp_off );
        Wread( &string_len, sizeof( unsigned_8 ) );
        imp_nam = Wmalloc( string_len + 1 );
        Wread( imp_nam, string_len );
        imp_nam[ string_len ] = '\0';
        Wdputs( imp_nam );
        Wdputslc( "\n" );
        Int_mod_ref_tab[ ref_num ] = imp_nam;
    }
    free( mod_ref_tab );
}

/*
 * Dump the Imported Names Tables
 */
static void dmp_import_tab( unsigned_32 imp_nam_tab )
/***************************************************/
{
    unsigned_8                      string_len;
    char                            *resident;

    Wlseek( imp_nam_tab );
    Wread( &string_len, sizeof( unsigned_8 ) );
    if( string_len == 0 ) {
        return;
    }
    Wdputslc( "\n" );
    Banner( "Imported Name Table" );
    for( ;; ) {
        resident = alloca( string_len );
        if( resident == NULL ) {
            Wdputslc( "Error! Dynamic memory exausted.\n" );
            longjmp( Se_env, 1 );
        }
        Wread( resident, string_len );
        resident[ string_len ] = '\0';
        Wdputs( resident );
        Wdputslc( "\n" );
        Wread( &string_len, sizeof( unsigned_8 ) );
        if( string_len == 0 ) {
            return;
        }
    }
}

/*
 * Dump the Entry Table
 */
static void dmp_ent_type( unsigned_8 type, unsigned ordinal )
/***********************************************************/
{
    flat_bundle_entry32     ent_bund32;
    flat_bundle_entry16     ent_bund16;
    flat_bundle_gate16      gate_bund;
    flat_bundle_entryfwd    ent_bund_fwd;

    switch( type ) {
    case FLT_BNDL_EMPTY:
        break;
    case FLT_BNDL_ENTRY16:
        Wread( &ent_bund16, sizeof( flat_bundle_entry16 ) );
        Wdputslc( "\nordinal = " );
        Puthex( ordinal, 4 );
        Wdputs( "   flags = " );
        Puthex( ent_bund16.e32_flags, 2 );
        Wdputs( "   offset = " );
        Puthex( ent_bund16.e32_offset, 4 );
        if( ent_bund16.e32_flags & ENTRY_EXPORTED ) {
            Wdputs( "  EXPORTED" );
        }
        if( ent_bund16.e32_flags & ENTRY_SHARED ) {
            Wdputs( "  SHARED DATA" );
        }
        break;
    case FLT_BNDL_GATE16:
        Wread( &gate_bund, sizeof( flat_bundle_gate16 ) );
        Wdputslc( "\nordinal = " );
        Puthex( ordinal, 4 );
        Wdputs( "   flags = " );
        Puthex( gate_bund.e32_flags, 2 );
        Wdputs( "   offset = " );
        Puthex( gate_bund.offset, 4 );
        Wdputs( "   callgate = " );
        Puthex( gate_bund.callgate, 4 );
        if( gate_bund.e32_flags & ENTRY_EXPORTED ) {
            Wdputs( "  EXPORTED" );
        }
        if( gate_bund.e32_flags & ENTRY_SHARED ) {
            Wdputs( "  SHARED DATA" );
        }
        break;
    case FLT_BNDL_ENTRY32:
        Wread( &ent_bund32, sizeof( flat_bundle_entry32 ) );
        Wdputslc( "\nordinal = " );
        Puthex( ordinal, 4 );
        Wdputs( "   flags = " );
        Puthex( ent_bund32.e32_flags, 2 );
        Wdputs( "   offset = " );
        Puthex( ent_bund32.e32_offset, 8 );
        if( ent_bund32.e32_flags & ENTRY_EXPORTED ) {
            Wdputs( "  EXPORTED" );
        }
        if( ent_bund32.e32_flags & ENTRY_SHARED ) {
            Wdputs( "  SHARED DATA" );
        }
        break;
    case FLT_BNDL_ENTRYFWD:
        Wread( &ent_bund_fwd, sizeof( flat_bundle_entryfwd ) );
        Wdputslc( "\nordinal = " );
        Puthex( ordinal, 4 );
        Wdputs( "   flags = " );
        Puthex( ent_bund_fwd.e32_flags, 2 );
        Wdputs( "   module ordinal = " );
        Puthex( ent_bund_fwd.modord, 4 );
        Wdputs( "   offset or ordinal = " );
        Puthex( ent_bund_fwd.value, 8 );
        if( ent_bund_fwd.e32_flags & ENTRY_EXPORTED ) {
            Wdputs( "  EXPORTED" );
        }
        if( ent_bund_fwd.e32_flags & ENTRY_SHARED ) {
            Wdputs( "  SHARED DATA" );
        }
        break;
    }
}

/*
 * Dump the Entry Table
 */
static void dmp_ent_tab( unsigned_32 ent_tab )
/********************************************/
{
    flat_null_prefix        ent_bund_pfx;
    unsigned                ordinal = 1;
    unsigned_16             object;
    unsigned                i;

    Wlseek( ent_tab );
    Wread( &ent_bund_pfx, sizeof( ent_bund_pfx ) );
    if( !ent_bund_pfx.b32_cnt ) {
        return;
    }
    Wdputslc( "\n" );
    Banner( "Entry Point Table" );
    for( ; ent_bund_pfx.b32_cnt != 0; ) {
        Wdputs( "\nnumber of entries in bundle = " );
        Puthex( ent_bund_pfx.b32_cnt, 2 );
        Wdputslc( "\ntype = " );
        Puthex( ent_bund_pfx.b32_type, 2 );
        if( ent_bund_pfx.b32_type != FLT_BNDL_EMPTY ) {
            Wread( &object, sizeof( object ) );
            Wdputslc( "\nobject number = " );
            Puthex( object, 4 );
        }
        Wdputslc( "\n" );
        for( i = 0; i < ent_bund_pfx.b32_cnt; ++i ) {
            dmp_ent_type( ent_bund_pfx.b32_type, ordinal++ );
        }
        Wdputslc( "\n" );
        Wread( &ent_bund_pfx, sizeof( ent_bund_pfx ) );
    }
    Wdputslc( "\n" );
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?