|
|
153cea |
/***************************************************************/
|
|
|
153cea |
/* perk: PE Resource Kit */
|
|
|
153cea |
/* Copyright (C) 2015--2017 Z. Gilboa */
|
|
|
153cea |
/* Released under GPLv2 and GPLv3; see COPYING.PERK. */
|
|
|
153cea |
/***************************************************************/
|
|
|
153cea |
|
|
|
153cea |
#include <stdio.h>
|
|
|
153cea |
|
|
|
153cea |
#include <perk/perk.h>
|
|
|
153cea |
#include <perk/perk_output.h>
|
|
|
153cea |
#include "perk_driver_impl.h"
|
|
|
153cea |
#include "perk_hdrdump_impl.h"
|
|
|
153cea |
#include "perk_dprintf_impl.h"
|
|
|
153cea |
#include "perk_errinfo_impl.h"
|
|
|
153cea |
|
|
|
153cea |
#define PE_ADDR meta->r_coff
|
|
|
153cea |
#define PE_RAW_STRUCT coff_image_hdr
|
|
|
153cea |
#define PE_OUTPUT(x) PE_OUTPUT_TABLE(x)
|
|
|
153cea |
|
|
|
153cea |
int pe_hdrdump_coff_image_hdr(
|
|
|
153cea |
const struct pe_driver_ctx * dctx,
|
|
|
153cea |
const struct pe_image_meta * meta)
|
|
|
153cea |
{
|
|
|
153cea |
int bits;
|
|
|
153cea |
uint64_t faddr;
|
|
|
153cea |
uint64_t vaddr;
|
|
|
153cea |
char * ch;
|
|
|
153cea |
char buf[8192];
|
|
|
153cea |
|
|
|
153cea |
if (!PE_ADDR)
|
|
|
153cea |
return 0;
|
|
|
153cea |
|
|
|
153cea |
if ((bits = pe_image_bits(meta)) < 0)
|
|
|
153cea |
return PERK_CUSTOM_ERROR(
|
|
|
153cea |
dctx,PERK_ERR_UNSUPPORTED_ABI);
|
|
|
153cea |
|
|
|
153cea |
faddr = (char *)(PE_ADDR) - (char *)meta->r_image.map_addr;
|
|
|
153cea |
vaddr = meta->m_opt.oh_mem.coh_image_base + faddr;
|
|
|
153cea |
|
|
|
153cea |
ch = buf;
|
|
|
153cea |
ch += pe_output_hex_header(
|
|
|
153cea |
ch,
|
|
|
153cea |
"struct pe_raw_coff_image_hdr",
|
|
|
153cea |
faddr,vaddr,bits);
|
|
|
153cea |
|
|
|
153cea |
ch += PE_OUTPUT(cfh_signature);
|
|
|
153cea |
ch += PE_OUTPUT(cfh_machine);
|
|
|
153cea |
ch += PE_OUTPUT(cfh_num_of_sections);
|
|
|
153cea |
ch += PE_OUTPUT(cfh_time_date_stamp);
|
|
|
153cea |
ch += PE_OUTPUT(cfh_ptr_to_sym_tbl);
|
|
|
153cea |
ch += PE_OUTPUT(cfh_num_of_syms);
|
|
|
153cea |
ch += PE_OUTPUT(cfh_size_of_opt_hdr);
|
|
|
153cea |
ch += PE_OUTPUT(cfh_characteristics);
|
|
|
153cea |
|
|
|
153cea |
ch += pe_output_hex_footer(ch);
|
|
|
153cea |
|
|
|
153cea |
*ch = 0;
|
|
|
153cea |
|
|
|
153cea |
if (pe_dprintf(pe_driver_fdout(dctx),"%s",buf) < 0)
|
|
|
153cea |
return PERK_FILE_ERROR(dctx);
|
|
|
153cea |
|
|
|
153cea |
return 0;
|
|
|
153cea |
}
|