1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
|
/**
* @namespace biew_plugins_auto
* @file plugins/bin/aout.c
* @brief This file contains implementation of a.out file format decoder.
* @version -
* @remark this source file is part of Binary vIEW project (BIEW).
* The Binary vIEW (BIEW) is copyright (C) 1995 Nick Kurshev.
* All rights reserved. This software is redistributable under the
* licence given in the file "Licence.en" ("Licence.ru" in russian
* translation) distributed in the BIEW archive.
* @note Requires POSIX compatible development system
*
* @author Nick Kurshev
* @since 1999
* @note Development, fixes and improvements
**/
#include <stdio.h>
#include <string.h>
#include "colorset.h"
#include "bmfile.h"
#include "biewutil.h"
#include "bin_util.h"
#include "biewhelp.h"
#include "bconsole.h"
#include "reg_form.h"
#include "plugins/disasm.h"
#define ARCH_SIZE 32
#include "plugins/bin/aout64.h"
#include "biewlib/kbd_code.h"
#include "biewlib/biewlib.h"
static const char * __NEAR__ __FASTCALL__ aout_encode_hdr(unsigned long info)
{
switch(info & 0x0000FFFFUL)
{
case OMAGIC: return " a.out: Object file ";
case NMAGIC: return " a.out: Pure executable ";
case ZMAGIC: return " a.out: Demand-paged executable ";
case BMAGIC: return " b.out: Object file ";
case QMAGIC: return " a.out: 386BSD demand-paged executable ";
default: return " Unknow a.out or b.out format ";
}
}
static unsigned long __FASTCALL__ ShowAOutHeader( void )
{
struct external_exec aout;
unsigned long fpos;
unsigned keycode;
TWindow *w;
fpos = BMGetCurrFilePos();
bmReadBufferEx(&aout,sizeof(struct external_exec),0,SEEKF_START);
w = CrtDlgWndnls(aout_encode_hdr(*((unsigned long *)&aout.e_info)),54,7);
twGotoXY(1,1);
twPrintF("Length of text section = %08lXH\n"
"Length of data section = %08lXH\n"
"Length of bss area = %08lXH\n"
"Length of symbol table = %08lXH\n"
,*((unsigned long *)&aout.e_text)
,*((unsigned long *)&aout.e_data)
,*((unsigned long *)&aout.e_bss)
,*((unsigned long *)&aout.e_syms));
twSetColorAttr(dialog_cset.entry);
twPrintF("Start address = %08lXH"
,*((unsigned long *)&aout.e_entry));
twClrEOL(); twPrintF("\n");
twSetColorAttr(dialog_cset.main);
twPrintF("Length of text relocation = %08lXH\n"
"Length of data relocation = %08lXH"
,*((unsigned long *)&aout.e_trsize)
,*((unsigned long *)&aout.e_drsize));
while(1)
{
keycode = GetEvent(drawEmptyPrompt,w);
if(keycode == KE_ENTER) { fpos = *((unsigned long *)&aout.e_entry); break; }
else
if(keycode == KE_ESCAPE || keycode == KE_F(10)) break;
}
CloseWnd(w);
return fpos;
}
static tBool __FASTCALL__ aout_check_fmt( void )
{
unsigned short id;
id = bmReadWordEx(0,SEEKF_START);
return !(N_BADMAG(id));
}
static void __FASTCALL__ aout_init_fmt( void ) {}
static void __FASTCALL__ aout_destroy_fmt( void ) {}
static int __FASTCALL__ aout_bitness(unsigned long off)
{
UNUSED(off);
return DAB_USE32;
}
static tBool __FASTCALL__ aout_AddrResolv(char *addr,unsigned long fpos)
{
/* Since this function is used in references resolving of disassembler
it must be seriously optimized for speed. */
tBool bret = True;
if(fpos < sizeof(struct external_exec))
{
strcpy(addr,"a.outh:");
strcpy(&addr[7],Get2Digit(fpos));
}
else bret = False;
return bret;
}
static unsigned long __FASTCALL__ aout_help( void )
{
hlpDisplay(10000);
return BMGetCurrFilePos();
}
static int __FASTCALL__ aout_platform( void ) { return DISASM_CPU_IX86; }
REGISTRY_BIN aoutTable =
{
"a.out (Assembler and link Output)",
{ "AOutHl", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL },
{ aout_help, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL },
aout_check_fmt,
aout_init_fmt,
aout_destroy_fmt,
ShowAOutHeader,
NULL,
NULL,
aout_platform,
aout_bitness,
aout_AddrResolv,
NULL,
NULL,
NULL,
NULL,
NULL,
NULL
};
|