summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2015-11-21 21:17:19 -0500
committermidipix <writeonce@midipix.org>2016-11-10 23:35:25 -0500
commitbbf9e9debd761b5c5024d8417ad38e1cadc70d5b (patch)
tree7a5b208769256db03f1888a6f9be02dd85108d78 /src
parent1b12c372a5e411176d2c6e8ece9019de63f6bb5e (diff)
downloadperk-bbf9e9debd761b5c5024d8417ad38e1cadc70d5b.tar.bz2
perk-bbf9e9debd761b5c5024d8417ad38e1cadc70d5b.tar.xz
driver integration 1/9: remove old (ad-hoc) driver, prepare source tree.
Diffstat (limited to 'src')
-rw-r--r--src/internal/perk_impl.h14
-rw-r--r--src/logic/pe_get_image_meta.c (renamed from src/main/pe_get_image_meta.c)0
-rw-r--r--src/logic/pe_map_raw_image.c (renamed from src/main/pe_map_raw_image.c)0
-rw-r--r--src/main/perk.c116
-rw-r--r--src/perk.c11
5 files changed, 11 insertions, 130 deletions
diff --git a/src/internal/perk_impl.h b/src/internal/perk_impl.h
index a47391c..bda7581 100644
--- a/src/internal/perk_impl.h
+++ b/src/internal/perk_impl.h
@@ -4,20 +4,6 @@
#include <stdint.h>
#include <endian.h>
-/* internal structures */
-struct perk_ctx {
- int argc;
- char ** argv;
- char ** envp;
- const char * fname;
- int status;
- int flags;
- int fd;
- FILE * fout;
- FILE * tmp;
- struct pe_raw_image map;
-};
-
#if (BYTE_ORDER == LITTLE_ENDIAN)
static inline uint16_t pe_read_short(const unsigned char * raw)
diff --git a/src/main/pe_get_image_meta.c b/src/logic/pe_get_image_meta.c
index 350abe3..350abe3 100644
--- a/src/main/pe_get_image_meta.c
+++ b/src/logic/pe_get_image_meta.c
diff --git a/src/main/pe_map_raw_image.c b/src/logic/pe_map_raw_image.c
index caf14b9..caf14b9 100644
--- a/src/main/pe_map_raw_image.c
+++ b/src/logic/pe_map_raw_image.c
diff --git a/src/main/perk.c b/src/main/perk.c
deleted file mode 100644
index 0382186..0000000
--- a/src/main/perk.c
+++ /dev/null
@@ -1,116 +0,0 @@
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <limits.h>
-#include <errno.h>
-#include <sys/mman.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#include <perk/perk.h>
-#include "perk_impl.h"
-
-static int perk_parse_opts(struct perk_ctx * ctx)
-{
- int i;
- char * ch;
- const char ** popt;
-
- for (i=1; i<ctx->argc; i++) {
- ch = ctx->argv[i];
-
- if (*ch == '-') {
- switch (*++ch) {
- case 'i':
- popt = &ctx->fname;
- break;
- case 'h':
- ctx->flags = PERK_HELP;
- return 0;
- default:
- ctx->status = PERK_BAD_OPT;
- return ctx->status;
- }
-
- while ((*++ch == '\t') || (*ch == ' '));
-
- if (!*ch) {
- if (++i < ctx->argc)
- *popt = ctx->argv[i];
- else
- ctx->status = PERK_BAD_OPT_VAL;
- } else
- *popt = ch;
- } else if (!ctx->fname)
- ctx->fname = ch;
- else
- ctx->status = PERK_BAD_OPT;
-
- }
-
- return ctx->status;
-}
-
-
-static int perk_map_input(struct perk_ctx * ctx)
-{
- ctx->fd = open(ctx->fname,O_RDONLY | O_CLOEXEC);
-
- if (ctx->fd < 0) {
- ctx->status = PERK_IO_ERROR;
- return ctx->status;
- }
-
- ctx->status = pe_map_raw_image(ctx->fd,0,PROT_READ,&ctx->map);
-
- return ctx->status;
-}
-
-
-static int perk_exit(struct perk_ctx * ctx)
-{
- if (ctx->map.addr)
- pe_unmap_raw_image(&ctx->map);
-
- return ctx->status;
-}
-
-
-static int perk_run(struct perk_ctx * ctx)
-{
- struct pe_image_meta * meta;
-
- if (perk_map_input(ctx))
- return perk_exit(ctx);
-
- if ((ctx->status = pe_get_image_meta(&ctx->map,&meta)))
- return perk_exit(ctx);
-
- /* pre-alpha default output */
- pe_output_export_symbols(
- meta,
- PERK_OUTPUT_FORMAT_LIST | PERK_OUTPUT_FIELD_NAME,
- stdout);
-
- ctx->status = pe_free_image_meta(meta);
-
- return perk_exit(ctx);
-}
-
-static int perk_main(int argc, char ** argv, char ** envp)
-{
- struct perk_ctx ctx = {argc,argv,envp};
-
- if (perk_parse_opts(&ctx))
- return ctx.status;
- else
- return perk_run(&ctx);
-}
-
-int main(int argc, char ** argv, char ** envp)
-{
- return perk_main(argc,argv,envp);
-}
diff --git a/src/perk.c b/src/perk.c
new file mode 100644
index 0000000..983c130
--- /dev/null
+++ b/src/perk.c
@@ -0,0 +1,11 @@
+#include <perk/perk.h>
+
+static int perk_main(int argc, char ** argv, char ** envp)
+{
+ return -1;
+}
+
+int main(int argc, char ** argv, char ** envp)
+{
+ return perk_main(argc,argv,envp);
+}