summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/output/pe_output_export_symbols.c25
-rw-r--r--src/output/pe_output_import_libraries.c38
-rw-r--r--src/perk.c21
3 files changed, 47 insertions, 37 deletions
diff --git a/src/output/pe_output_export_symbols.c b/src/output/pe_output_export_symbols.c
index e6f4d5c..4ff8d57 100644
--- a/src/output/pe_output_export_symbols.c
+++ b/src/output/pe_output_export_symbols.c
@@ -8,18 +8,19 @@
#include <perk/perk_output.h>
#include "perk_output_impl.h"
-static void pretty_header(const struct pe_common_ctx * cctx, FILE * fout)
+static int pretty_header(const struct pe_common_ctx * cctx, FILE * fout)
{
- if (cctx->fmtflags & PERK_PRETTY_YAML)
- fputs("exports:\n",fout);
+ return (cctx->fmtflags & PERK_PRETTY_YAML)
+ ? fputs("exports:\n",fout)
+ : 0;
}
-static void pretty_export_item(const struct pe_common_ctx * cctx, const char * name, FILE * fout)
+static int pretty_export_item(const struct pe_common_ctx * cctx, const char * name, FILE * fout)
{
if (cctx->fmtflags & PERK_PRETTY_YAML)
- fprintf(fout,"- %s\n",name);
+ return fprintf(fout,"- %s\n",name);
else
- fprintf(fout,"%s\n",name);
+ return fprintf(fout,"%s\n",name);
}
int pe_output_export_symbols(
@@ -38,16 +39,18 @@ int pe_output_export_symbols(
if (!(fout = pe_output_prolog(cctx,fout,&ftmp)))
return -1;
- pretty_header(cctx,fout);
+ if ((pretty_header(cctx,fout)) < 0)
+ return pe_output_epilog(-1,ftmp);
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));
for (i=0; i<m->edata.num_of_name_ptrs; i++)
- pretty_export_item(
- cctx,
- (char *)((uintptr_t)m->image.addr + symrva[i] - offset),
- fout);
+ if ((pretty_export_item(
+ cctx,
+ (char *)((uintptr_t)m->image.addr + symrva[i] - offset),
+ fout)) < 0)
+ return pe_output_epilog(-1,ftmp);
return pe_output_epilog(0,ftmp);
}
diff --git a/src/output/pe_output_import_libraries.c b/src/output/pe_output_import_libraries.c
index 40d1a08..9a83780 100644
--- a/src/output/pe_output_import_libraries.c
+++ b/src/output/pe_output_import_libraries.c
@@ -8,30 +8,31 @@
#include <perk/perk_output.h>
#include "perk_output_impl.h"
-static void pretty_header(const struct pe_common_ctx * cctx, FILE * fout)
+static int pretty_header(const struct pe_common_ctx * cctx, FILE * fout)
{
- if (cctx->fmtflags & PERK_PRETTY_YAML)
- fputs("imports:\n",fout);
+ return (cctx->fmtflags & PERK_PRETTY_YAML)
+ ? fputs("imports:\n",fout)
+ : 0;
}
-static void pretty_implib_header(const struct pe_common_ctx * cctx, const char * name, FILE * fout)
+static int pretty_implib_header(const struct pe_common_ctx * cctx, const char * name, FILE * fout)
{
if ((cctx->fmtflags & PERK_PRETTY_YAML) && (cctx->fmtflags & PERK_OUTPUT_IMPORT_SYMS))
- fprintf(fout," %s:\n",name);
+ return fprintf(fout," %s:\n",name);
else if (cctx->fmtflags & PERK_PRETTY_YAML)
- fprintf(fout,"- %s:\n",name);
+ return fprintf(fout,"- %s:\n",name);
else if (cctx->fmtflags & PERK_OUTPUT_IMPORT_SYMS)
- fprintf(fout,"%s:\n",name);
+ return fprintf(fout,"%s:\n",name);
else
- fprintf(fout,"%s\n",name);
+ return fprintf(fout,"%s\n",name);
}
-static void pretty_implib_item(const struct pe_common_ctx * cctx, const char * name, FILE * fout)
+static int pretty_implib_item(const struct pe_common_ctx * cctx, const char * name, FILE * fout)
{
if (cctx->fmtflags & PERK_PRETTY_YAML)
- fprintf(fout," - %s\n",name);
+ return fprintf(fout," - %s\n",name);
else
- fprintf(fout,"%s\n",name);
+ return fprintf(fout,"%s\n",name);
}
int pe_output_import_libraries(
@@ -48,18 +49,21 @@ int pe_output_import_libraries(
if (!(fout = pe_output_prolog(cctx,fout,&ftmp)))
return -1;
- pretty_header(cctx,fout);
+ if ((pretty_header(cctx,fout)) < 0)
+ return pe_output_epilog(-1,ftmp);
for (i=0; i<m->summary.num_of_implibs; i++) {
- pretty_implib_header(cctx,m->idata[i].name,fout);
+ if ((pretty_implib_header(cctx,m->idata[i].name,fout)) < 0)
+ return pe_output_epilog(-1,ftmp);
if (cctx->fmtflags & PERK_OUTPUT_IMPORT_SYMS)
for (j=0; j<m->idata[i].count; j++)
if (m->idata[i].items[j].name)
- pretty_implib_item(
- cctx,
- m->idata[i].items[j].name,
- fout);
+ if ((pretty_implib_item(
+ cctx,
+ m->idata[i].items[j].name,
+ fout)) < 0)
+ return pe_output_epilog(-1,ftmp);
}
diff --git a/src/perk.c b/src/perk.c
index 9f40342..652141b 100644
--- a/src/perk.c
+++ b/src/perk.c
@@ -10,27 +10,29 @@
static const char vermsg[] = "%s (git://midipix.org/perk): commit %s.\n";
-static void perk_version(struct pe_driver_ctx * dctx)
+static ssize_t perk_version(struct pe_driver_ctx * dctx)
{
char buf[512];
size_t len;
if (dctx->cctx.fdout >= 0) {
len = sprintf(buf,vermsg,dctx->program,PERK_GIT_VERSION);
- write(dctx->cctx.fdout,buf,len);
+ return write(dctx->cctx.fdout,buf,len);
} else
- fprintf(stdout,vermsg,dctx->program,PERK_GIT_VERSION);
+ return fprintf(stdout,vermsg,dctx->program,PERK_GIT_VERSION);
}
-static void perk_paragraph_break(struct pe_unit_ctx * uctx, int * fpara)
+static ssize_t perk_paragraph_break(struct pe_unit_ctx * uctx, int * fpara)
{
if (*fpara) {
+ *fpara = 0;
+
if (uctx->cctx.fdout >= 0)
- write(uctx->cctx.fdout,"\n",1);
+ return write(uctx->cctx.fdout,"\n",1);
else
- fputc('\n',stdout);
- *fpara = 0;
- }
+ return fputc('\n',stdout);
+ } else
+ return 0;
}
static void perk_perform_unit_actions(struct pe_unit_ctx * uctx)
@@ -67,7 +69,8 @@ static int perk_main(int argc, const char ** argv, const char ** envp)
return (ret == PERK_USAGE) ? !--argc : 2;
if (dctx->cctx.drvflags & PERK_DRIVER_VERSION)
- perk_version(dctx);
+ if ((perk_version(dctx)) < 0)
+ return perk_exit(dctx,2);
for (unit=dctx->units; *unit; unit++) {
if (!(pe_get_unit_ctx(dctx,*unit,&uctx))) {