summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/driver/pe_amain.c10
-rw-r--r--src/driver/pe_driver_ctx.c21
-rw-r--r--src/driver/pe_unit_ctx.c4
-rw-r--r--src/internal/perk_driver_impl.h2
-rw-r--r--src/internal/perk_output_impl.h46
-rw-r--r--src/output/pe_output_export_symbols.c16
-rw-r--r--src/output/pe_output_image_type.c18
-rw-r--r--src/output/pe_output_import_libraries.c20
8 files changed, 21 insertions, 116 deletions
diff --git a/src/driver/pe_amain.c b/src/driver/pe_amain.c
index cd345d9..d23e9fe 100644
--- a/src/driver/pe_amain.c
+++ b/src/driver/pe_amain.c
@@ -46,15 +46,11 @@ static ssize_t pe_version(struct pe_driver_ctx * dctx)
verclr[4],verinfo->commit,verclr[5]);
}
-static ssize_t pe_paragraph_break(const struct pe_driver_ctx * dctx, int * fpara)
+static ssize_t pe_paragraph_break(int * fpara)
{
if (*fpara) {
*fpara = 0;
-
- if (dctx->cctx->ioctx->fdout >= 0)
- return write(dctx->cctx->ioctx->fdout,"\n",1);
- else
- return fputc('\n',stdout);
+ return fputc('\n',stdout);
} else
return 0;
}
@@ -75,7 +71,7 @@ static void pe_perform_unit_actions(
}
if ((flags & PERK_OUTPUT_IMPORT_LIBS) || (flags & PERK_OUTPUT_IMPORT_SYMS)) {
- pe_paragraph_break(dctx,&fpara);
+ pe_paragraph_break(&fpara);
pe_output_import_libraries(dctx,uctx->meta,0);
fpara += (uctx->meta->summary.nimplibs > 0);
}
diff --git a/src/driver/pe_driver_ctx.c b/src/driver/pe_driver_ctx.c
index 3622fa8..021a7fb 100644
--- a/src/driver/pe_driver_ctx.c
+++ b/src/driver/pe_driver_ctx.c
@@ -90,8 +90,7 @@ static struct pe_driver_ctx_impl * pe_driver_ctx_alloc(
ictx->ctx.errinfp = &ictx->ctx.erriptr[0];
ictx->ctx.erricap = &ictx->ctx.erriptr[--elements];
- ictx->meta = meta;
- ictx->ctx.cctx.ioctx = &ictx->ctx.ioctx;
+ ictx->meta = meta;
for (entry=meta->entries,units=ictx->units; entry->fopt || entry->arg; entry++)
if (!entry->fopt)
@@ -200,30 +199,12 @@ int pe_get_driver_ctx(
ctx->ctx.program = program;
ctx->ctx.cctx = &ctx->cctx;
- ctx->ioctx.fdout = cctx.output ? fdout : -1;
- ctx->ioctx.fdin = -1;
- ctx->ioctx.fderr = -1;
- ctx->ioctx.fdlog = -1;
- ctx->ioctx.fdsrc = AT_FDCWD;
- ctx->ioctx.fddst = AT_FDCWD;
- ctx->ioctx.fdtmp = AT_FDCWD;
-
*pctx = &ctx->ctx;
return PERK_OK;
}
-static void pe_driver_close_fds(struct pe_common_ctx * cctx)
-{
- if (cctx->ioctx->status && cctx->output)
- unlinkat(cctx->ioctx->fddst,cctx->output,0);
-
- if (cctx->ioctx->fdout >= 0)
- close(cctx->ioctx->fdout);
-}
-
static void pe_free_driver_ctx_impl(struct pe_driver_ctx_alloc * ictx)
{
- pe_driver_close_fds(&ictx->ctx.cctx);
argv_free(ictx->meta);
free(ictx);
}
diff --git a/src/driver/pe_unit_ctx.c b/src/driver/pe_unit_ctx.c
index b3dae71..26fb8a7 100644
--- a/src/driver/pe_unit_ctx.c
+++ b/src/driver/pe_unit_ctx.c
@@ -47,7 +47,7 @@ int pe_get_unit_ctx(
? PROT_READ | PROT_WRITE
: PROT_READ;
- if (pe_map_raw_image(dctx,dctx->cctx->ioctx->fdin,path,prot,&ctx->map))
+ if (pe_map_raw_image(dctx,-1,path,prot,&ctx->map))
return pe_free_unit_ctx_impl(ctx,
PERK_NESTED_ERROR(dctx));
@@ -56,8 +56,6 @@ int pe_get_unit_ctx(
PERK_NESTED_ERROR(dctx));
ctx->path = path;
- ctx->ioctx.prot = prot;
-
ctx->uctx.path = &ctx->path;
ctx->uctx.map = &ctx->map;
ctx->uctx.meta = ctx->meta;
diff --git a/src/internal/perk_driver_impl.h b/src/internal/perk_driver_impl.h
index 3c0d15d..9581210 100644
--- a/src/internal/perk_driver_impl.h
+++ b/src/internal/perk_driver_impl.h
@@ -23,7 +23,6 @@ enum app_tags {
};
struct pe_driver_ctx_impl {
- struct pe_io_ctx ioctx;
struct pe_common_ctx cctx;
struct pe_driver_ctx ctx;
const struct pe_unit_ctx * euctx;
@@ -38,7 +37,6 @@ struct pe_unit_ctx_impl {
const char * path;
struct pe_raw_image map;
struct pe_image_meta * meta;
- struct pe_io_ctx ioctx;
struct pe_unit_ctx uctx;
};
diff --git a/src/internal/perk_output_impl.h b/src/internal/perk_output_impl.h
deleted file mode 100644
index cb8b304..0000000
--- a/src/internal/perk_output_impl.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/***************************************************************/
-/* perk: PE Resource Kit */
-/* Copyright (C) 2015--2016 Z. Gilboa */
-/* Released under GPLv2 and GPLv3; see COPYING.PERK. */
-/***************************************************************/
-
-#ifndef PE_OUTPUT_IMPL_H
-#define PE_OUTPUT_IMPL_H
-
-#include <unistd.h>
-#include <perk/perk.h>
-
-static inline FILE * pe_output_prolog(
- const struct pe_common_ctx * cctx,
- FILE * fout,
- FILE ** ftmp)
-{
- int fdout;
-
- *ftmp = (FILE *)0;
-
- if (fout)
- return fout;
- else if (!cctx)
- return 0;
- else if (cctx->ioctx->fdout < 0)
- return stdout;
-
- if ((fdout = dup(cctx->ioctx->fdout)) < 0)
- return 0;
-
- if ((*ftmp = fdopen(fdout,"a")))
- return *ftmp;
-
- close(fdout);
- return 0;
-}
-
-static inline int pe_output_epilog(int ret, FILE * f)
-{
- if (f)
- fclose(f);
- return ret;
-}
-
-#endif
diff --git a/src/output/pe_output_export_symbols.c b/src/output/pe_output_export_symbols.c
index d47cb7a..ee48b0e 100644
--- a/src/output/pe_output_export_symbols.c
+++ b/src/output/pe_output_export_symbols.c
@@ -12,7 +12,6 @@
#include <perk/perk.h>
#include <perk/perk_output.h>
-#include "perk_output_impl.h"
#include "perk_errinfo_impl.h"
static int pretty_header(const struct pe_common_ctx * cctx, FILE * fout)
@@ -37,7 +36,6 @@ int pe_output_export_symbols(
const struct pe_image_meta * m,
FILE * fout)
{
- FILE * ftmp;
uint32_t offset;
uint32_t * symrva;
unsigned i;
@@ -46,13 +44,11 @@ int pe_output_export_symbols(
if (!m->hedata)
return 0;
- if (!(fout = pe_output_prolog(cctx,fout,&ftmp)))
- return PERK_SYSTEM_ERROR(dctx);
+ if (!fout)
+ fout = stdout;
if ((pretty_header(cctx,fout)) < 0)
- return pe_output_epilog(
- PERK_FILE_ERROR(dctx),
- ftmp);
+ return PERK_FILE_ERROR(dctx);
offset = m->hedata->virtual_addr - m->hedata->ptr_to_raw_data;
symrva = (uint32_t *)((uintptr_t)m->image.addr + (m->edata.name_ptr_rva - offset));
@@ -62,9 +58,7 @@ int pe_output_export_symbols(
cctx,
(char *)((uintptr_t)m->image.addr + symrva[i] - offset),
fout)) < 0)
- return pe_output_epilog(
- PERK_FILE_ERROR(dctx),
- ftmp);
+ return PERK_FILE_ERROR(dctx);
- return pe_output_epilog(0,ftmp);
+ return 0;
}
diff --git a/src/output/pe_output_image_type.c b/src/output/pe_output_image_type.c
index 15bcabc..1d0ff59 100644
--- a/src/output/pe_output_image_type.c
+++ b/src/output/pe_output_image_type.c
@@ -13,7 +13,6 @@
#include <perk/perk.h>
#include <perk/perk_output.h>
-#include "perk_output_impl.h"
#include "perk_errinfo_impl.h"
static const char const * pe_subsystem_name[0x10] = {
@@ -141,11 +140,8 @@ int pe_output_image_type(
const struct pe_unit_ctx * uctx,
FILE * fout)
{
- FILE * ftmp;
- const struct pe_common_ctx * cctx = dctx->cctx;
-
- if (!(fout = pe_output_prolog(cctx,fout,&ftmp)))
- return PERK_SYSTEM_ERROR(dctx);
+ if (!fout)
+ fout = stdout;
if (dctx->cctx->fmtflags & PERK_PRETTY_YAML) {
if (fprintf(fout,"%s:\n- %s:\n- %s:\n- %s:\n- %s:\n",
@@ -154,19 +150,15 @@ int pe_output_image_type(
pretty_type(uctx),
pretty_subsystem(uctx),
pretty_framework(uctx)) < 0)
- return pe_output_epilog(
- PERK_FILE_ERROR(dctx),
- ftmp);
+ return PERK_FILE_ERROR(dctx);
} else {
if (fprintf(fout,"%s-%s-%s-%s\n",
pretty_abi(uctx),
pretty_type(uctx),
pretty_subsystem(uctx),
pretty_framework(uctx)) < 0)
- return pe_output_epilog(
- PERK_FILE_ERROR(dctx),
- ftmp);
+ return PERK_FILE_ERROR(dctx);
}
- return pe_output_epilog(0,ftmp);
+ return 0;
}
diff --git a/src/output/pe_output_import_libraries.c b/src/output/pe_output_import_libraries.c
index 95920ab..54b7b48 100644
--- a/src/output/pe_output_import_libraries.c
+++ b/src/output/pe_output_import_libraries.c
@@ -12,7 +12,6 @@
#include <perk/perk.h>
#include <perk/perk_output.h>
-#include "perk_output_impl.h"
#include "perk_errinfo_impl.h"
static int pretty_header(const struct pe_common_ctx * cctx, FILE * fout)
@@ -47,7 +46,6 @@ int pe_output_import_libraries(
const struct pe_image_meta * m,
FILE * fout)
{
- FILE * ftmp;
int i;
unsigned j;
const struct pe_common_ctx * cctx = dctx->cctx;
@@ -55,19 +53,15 @@ int pe_output_import_libraries(
if (!m->summary.nimplibs)
return 0;
- if (!(fout = pe_output_prolog(cctx,fout,&ftmp)))
- return PERK_SYSTEM_ERROR(dctx);
+ if (!fout)
+ fout = stdout;
if ((pretty_header(cctx,fout)) < 0)
- return pe_output_epilog(
- PERK_FILE_ERROR(dctx),
- ftmp);
+ return PERK_FILE_ERROR(dctx);
for (i=0; i<m->summary.nimplibs; i++) {
if ((pretty_implib_header(cctx,m->idata[i].name,fout)) < 0)
- return pe_output_epilog(
- PERK_FILE_ERROR(dctx),
- ftmp);
+ return PERK_FILE_ERROR(dctx);
if (cctx->fmtflags & PERK_OUTPUT_IMPORT_SYMS)
for (j=0; j<m->idata[i].count; j++)
@@ -76,10 +70,8 @@ int pe_output_import_libraries(
cctx,
m->idata[i].items[j].name,
fout)) < 0)
- return pe_output_epilog(
- PERK_FILE_ERROR(dctx),
- ftmp);
+ return PERK_FILE_ERROR(dctx);
}
- return pe_output_epilog(0,ftmp);
+ return 0;
}