|
|
c0fbae |
#include <stdint.h>
|
|
|
c0fbae |
#include <stdlib.h>
|
|
|
c0fbae |
#include <stdio.h>
|
|
|
c0fbae |
#include <string.h>
|
|
|
c0fbae |
#include <errno.h>
|
|
|
c0fbae |
|
|
|
c0fbae |
#include <perk/perk.h>
|
|
|
e343a6 |
#include <perk/perk_output.h>
|
|
|
bd5676 |
#include "perk_output_impl.h"
|
|
|
c0fbae |
|
|
|
6025fb |
static int pretty_header(const struct pe_common_ctx * cctx, FILE * fout)
|
|
|
e343a6 |
{
|
|
|
6025fb |
return (cctx->fmtflags & PERK_PRETTY_YAML)
|
|
|
6025fb |
? fputs("exports:\n",fout)
|
|
|
6025fb |
: 0;
|
|
|
e343a6 |
}
|
|
|
e343a6 |
|
|
|
6025fb |
static int pretty_export_item(const struct pe_common_ctx * cctx, const char * name, FILE * fout)
|
|
|
e343a6 |
{
|
|
|
e343a6 |
if (cctx->fmtflags & PERK_PRETTY_YAML)
|
|
|
6025fb |
return fprintf(fout,"- %s\n",name);
|
|
|
e343a6 |
else
|
|
|
6025fb |
return fprintf(fout,"%s\n",name);
|
|
|
e343a6 |
}
|
|
|
e343a6 |
|
|
|
2b7f36 |
int pe_output_export_symbols(
|
|
|
2b7f36 |
const struct pe_image_meta * m,
|
|
|
2b7f36 |
const struct pe_common_ctx * cctx,
|
|
|
2b7f36 |
FILE * fout)
|
|
|
c0fbae |
{
|
|
|
7cd8bc |
FILE * ftmp;
|
|
|
c0fbae |
uint32_t offset;
|
|
|
c0fbae |
uint32_t * symrva;
|
|
|
c0fbae |
int i;
|
|
|
c0fbae |
|
|
|
ab024a |
if (!m->hedata)
|
|
|
ab024a |
return 0;
|
|
|
7cd8bc |
|
|
|
7cd8bc |
if (!(fout = pe_output_prolog(cctx,fout,&ftmp)))
|
|
|
ab024a |
return -1;
|
|
|
c0fbae |
|
|
|
6025fb |
if ((pretty_header(cctx,fout)) < 0)
|
|
|
6025fb |
return pe_output_epilog(-1,ftmp);
|
|
|
e343a6 |
|
|
|
c0fbae |
offset = m->hedata->virtual_addr - m->hedata->ptr_to_raw_data;
|
|
|
664d5b |
symrva = (uint32_t *)((uintptr_t)m->image.addr + (m->edata.name_ptr_rva - offset));
|
|
|
c0fbae |
|
|
|
c0fbae |
for (i=0; i<m->edata.num_of_name_ptrs; i++)
|
|
|
6025fb |
if ((pretty_export_item(
|
|
|
6025fb |
cctx,
|
|
|
6025fb |
(char *)((uintptr_t)m->image.addr + symrva[i] - offset),
|
|
|
6025fb |
fout)) < 0)
|
|
|
6025fb |
return pe_output_epilog(-1,ftmp);
|
|
|
ab024a |
|
|
|
7cd8bc |
return pe_output_epilog(0,ftmp);
|
|
|
c0fbae |
}
|