summaryrefslogtreecommitdiffhomepage
path: root/src/internal
diff options
context:
space:
mode:
Diffstat (limited to 'src/internal')
-rw-r--r--src/internal/argv/argv.h131
-rw-r--r--src/internal/mdso_driver_impl.h1
-rw-r--r--src/internal/mdso_errinfo_impl.c2
-rw-r--r--src/internal/mdso_errinfo_impl.h2
-rw-r--r--src/internal/mdso_hexfmt_impl.c35
-rw-r--r--src/internal/mdso_hexfmt_impl.h14
-rw-r--r--src/internal/mdso_object_impl.h16
-rw-r--r--src/internal/perk/perk_structs.h4
8 files changed, 175 insertions, 30 deletions
diff --git a/src/internal/argv/argv.h b/src/internal/argv/argv.h
index 8f43ed8..0be1d0e 100644
--- a/src/internal/argv/argv.h
+++ b/src/internal/argv/argv.h
@@ -1,6 +1,6 @@
/****************************************************************************/
/* argv.h: a thread-safe argument vector parser and usage screen generator */
-/* Copyright (C) 2015--2017 Z. Gilboa */
+/* Copyright (C) 2015--2024 SysDeer Technologies, LLC */
/* Released under GPLv2 and GPLv3; see COPYING.MDSO. */
/****************************************************************************/
@@ -83,6 +83,7 @@ enum argv_error {
ARGV_ERROR_INTERNAL,
ARGV_ERROR_SHORT_OPTION,
ARGV_ERROR_LONG_OPTION,
+ ARGV_ERROR_VENDOR_OPTION,
ARGV_ERROR_OPTARG_NONE,
ARGV_ERROR_OPTARG_REQUIRED,
ARGV_ERROR_OPTARG_PARADIGM,
@@ -150,6 +151,12 @@ static void argv_usage(
const struct argv_option **,
const char * mode);
+static void argv_usage_plain(
+ int fd,
+ const char * header,
+ const struct argv_option **,
+ const char * mode);
+
static struct argv_meta * argv_get(
char **,
const struct argv_option **,
@@ -392,7 +399,11 @@ static void argv_scan(
fval = ch;
}
} else {
- ferr = ARGV_ERROR_SHORT_OPTION;
+ if ((ch == &parg[0][1]) && (ch[0] == 'W') && ch[1]) {
+ ferr = ARGV_ERROR_VENDOR_OPTION;
+ } else {
+ ferr = ARGV_ERROR_SHORT_OPTION;
+ }
}
} else if (!fnoscan && (fhybrid || is_long_option(ch))) {
@@ -407,49 +418,72 @@ static void argv_scan(
ch = *parg;
}
- if (fhybrid && !(option->flags & ARGV_OPTION_HYBRID_SWITCH))
+ /* now verify the proper setting of option values */
+ if (fhybrid && !(option->flags & ARGV_OPTION_HYBRID_SWITCH)) {
ferr = ARGV_ERROR_HYBRID_NONE;
- else if (!fhybrid && (option->flags & ARGV_OPTION_HYBRID_ONLY))
+
+ } else if (!fhybrid && (option->flags & ARGV_OPTION_HYBRID_ONLY)) {
ferr = ARGV_ERROR_HYBRID_ONLY;
- else if (option->optarg == ARGV_OPTARG_NONE) {
+
+ } else if (option->optarg == ARGV_OPTARG_NONE) {
if (val[0]) {
ferr = ARGV_ERROR_OPTARG_NONE;
ctx->errch = val + 1;
- } else
+ } else {
fval = false;
+ }
+
} else if (val[0] && (option->flags & ARGV_OPTION_HYBRID_JOINED)) {
fval = true;
ch = val;
- } else if (fhybrid && !val[0] && !(option->flags & ARGV_OPTION_HYBRID_SPACE))
- ferr = ARGV_ERROR_HYBRID_SPACE;
- else if (fhybrid && (val[0]=='=') && !(option->flags & ARGV_OPTION_HYBRID_EQUAL))
+
+ } else if (fhybrid && !val[0] && !(option->flags & ARGV_OPTION_HYBRID_SPACE)) {
+ if (option->optarg == ARGV_OPTARG_OPTIONAL) {
+ fval = false;
+
+ } else {
+ ferr = ARGV_ERROR_HYBRID_SPACE;
+ }
+
+ } else if (fhybrid && (val[0]=='=') && !(option->flags & ARGV_OPTION_HYBRID_EQUAL)) {
ferr = ARGV_ERROR_HYBRID_EQUAL;
- else if (fhybrid && (val[0]==',') && !(option->flags & ARGV_OPTION_HYBRID_COMMA))
+
+ } else if (fhybrid && (val[0]==',') && !(option->flags & ARGV_OPTION_HYBRID_COMMA)) {
ferr = ARGV_ERROR_HYBRID_COMMA;
- else if (!fhybrid && (val[0]==','))
+
+ } else if (!fhybrid && (val[0]==',')) {
ferr = ARGV_ERROR_HYBRID_COMMA;
- else if (val[0] && !val[1])
+
+ } else if (val[0] && !val[1]) {
ferr = ARGV_ERROR_OPTARG_REQUIRED;
- else if (val[0] && val[1]) {
+
+ } else if (val[0] && val[1]) {
fval = true;
ch = ++val;
+
} else if (option->optarg == ARGV_OPTARG_REQUIRED) {
- if (!val[0] && !*parg)
+ if (!val[0] && !*parg) {
ferr = ARGV_ERROR_OPTARG_REQUIRED;
- else if (*parg && is_short_option(*parg))
+
+ } else if (*parg && is_short_option(*parg)) {
ferr = ARGV_ERROR_OPTARG_REQUIRED;
- else if (*parg && is_long_option(*parg))
+
+ } else if (*parg && is_long_option(*parg)) {
ferr = ARGV_ERROR_OPTARG_REQUIRED;
- else if (*parg && is_last_option(*parg))
+
+ } else if (*parg && is_last_option(*parg)) {
ferr = ARGV_ERROR_OPTARG_REQUIRED;
- else
+
+ } else {
fval = true;
+ }
} else {
/* ARGV_OPTARG_OPTIONAL */
fval = val[0];
}
- } else
+ } else {
ferr = ARGV_ERROR_LONG_OPTION;
+ }
}
if (ferr == ARGV_ERROR_OK)
@@ -525,7 +559,11 @@ static const char * argv_program_name(const char * program_path)
static void argv_show_error(int fd, struct argv_ctx * ctx)
{
- char opt_short_name[2] = {0,0};
+ const char * src;
+ char * dst;
+ char * cap;
+ char opt_vendor_buf[256];
+ char opt_short_name[2] = {0,0};
if (ctx->erropt && ctx->erropt->short_name)
opt_short_name[0] = ctx->erropt->short_name;
@@ -541,6 +579,27 @@ static void argv_show_error(int fd, struct argv_ctx * ctx)
argv_dprintf(fd,"'--%s' is not a valid long option\n",ctx->errch);
break;
+ case ARGV_ERROR_VENDOR_OPTION:
+ src = ctx->errch;
+ dst = opt_vendor_buf;
+ cap = &opt_vendor_buf[sizeof(opt_vendor_buf)];
+
+ for (; src && *src && dst<cap; ) {
+ if ((*src == '=') || (*src == ',') || (*src == ':')) {
+ src = 0;
+ } else {
+ *dst++ = *src++;
+ }
+ }
+
+ if (dst == cap)
+ dst--;
+
+ *dst = '\0';
+
+ argv_dprintf(fd,"'-%s' is not a valid vendor option\n",opt_vendor_buf);
+ break;
+
case ARGV_ERROR_OPTARG_NONE:
argv_dprintf(fd,"'%s' is not a valid option value for [%s%s%s%s%s] "
"(option values may not be specified)\n",
@@ -557,7 +616,9 @@ static void argv_show_error(int fd, struct argv_ctx * ctx)
opt_short_name[0] ? "-" : "",
opt_short_name,
opt_short_name[0] ? "," : "",
- ctx->erropt->long_name ? "--" : "",
+ ctx->erropt->long_name
+ ? (ctx->erropt->flags & ARGV_OPTION_HYBRID_ONLY) ? "-" : "--"
+ : "",
ctx->erropt->long_name,
ctx->erropt->paradigm ? "one of the following values:" : "a value",
ctx->erropt->paradigm ? "{" : "",
@@ -763,11 +824,12 @@ static void argv_free(struct argv_meta * xmeta)
}
}
-static void argv_usage(
+static void argv_usage_impl(
int fd,
const char * header,
const struct argv_option ** options,
- const char * mode)
+ const char * mode,
+ int fcolor)
{
const struct argv_option ** optv;
const struct argv_option * option;
@@ -789,12 +851,13 @@ static void argv_usage(
const char cblue [] = "\x1b[34m";
const char ccyan [] = "\x1b[36m";
const char * color = ccyan;
- bool fcolor;
+
+ (void)argv_usage;
+ (void)argv_usage_plain;
fshort = mode ? !strcmp(mode,"short") : 0;
flong = fshort ? 0 : mode && !strcmp(mode,"long");
fboth = !fshort && !flong;
- fcolor = isatty(fd);
if (fcolor)
argv_dprintf(fd,"%s%s",cbold,cgreen);
@@ -936,6 +999,24 @@ static void argv_usage(
argv_dprintf(fd,creset);
}
+static void argv_usage(
+ int fd,
+ const char * header,
+ const struct argv_option ** options,
+ const char * mode)
+{
+ argv_usage_impl(fd,header,options,mode,isatty(fd));
+}
+
+static void argv_usage_plain(
+ int fd,
+ const char * header,
+ const struct argv_option ** options,
+ const char * mode)
+{
+ argv_usage_impl(fd,header,options,mode,0);
+}
+
#endif
#endif
diff --git a/src/internal/mdso_driver_impl.h b/src/internal/mdso_driver_impl.h
index dc37a66..02234f7 100644
--- a/src/internal/mdso_driver_impl.h
+++ b/src/internal/mdso_driver_impl.h
@@ -59,6 +59,7 @@ struct mdso_driver_ctx_impl {
struct mdso_error_info** erricap;
struct mdso_error_info * erriptr[64];
struct mdso_error_info erribuf[64];
+ char tmpname[32];
};
struct mdso_unit_ctx_impl {
diff --git a/src/internal/mdso_errinfo_impl.c b/src/internal/mdso_errinfo_impl.c
index 37ef64a..28a663c 100644
--- a/src/internal/mdso_errinfo_impl.c
+++ b/src/internal/mdso_errinfo_impl.c
@@ -1,6 +1,6 @@
/****************************************************************/
/* mdso: midipix dso scavenger */
-/* Copyright (C) 2015--2017 Z. Gilboa */
+/* Copyright (C) 2015--2024 SysDeer Technologies, LLC */
/* Released under GPLv2 and GPLv3; see COPYING.MDSO. */
/****************************************************************/
diff --git a/src/internal/mdso_errinfo_impl.h b/src/internal/mdso_errinfo_impl.h
index 13aa0c3..6c83033 100644
--- a/src/internal/mdso_errinfo_impl.h
+++ b/src/internal/mdso_errinfo_impl.h
@@ -1,6 +1,6 @@
/****************************************************************/
/* mdso: midipix dso scavenger */
-/* Copyright (C) 2015--2017 Z. Gilboa */
+/* Copyright (C) 2015--2024 SysDeer Technologies, LLC */
/* Released under GPLv2 and GPLv3; see COPYING.MDSO. */
/****************************************************************/
diff --git a/src/internal/mdso_hexfmt_impl.c b/src/internal/mdso_hexfmt_impl.c
new file mode 100644
index 0000000..33d337b
--- /dev/null
+++ b/src/internal/mdso_hexfmt_impl.c
@@ -0,0 +1,35 @@
+/****************************************************************/
+/* mdso: midipix dso scavenger */
+/* Copyright (C) 2015--2024 SysDeer Technologies, LLC */
+/* Released under GPLv2 and GPLv3; see COPYING.MDSO. */
+/****************************************************************/
+
+#include <stdint.h>
+
+char buf[256] = {0};
+
+static unsigned char mdso_hexfmt[16] = {
+ '0','1','2','3','4','5','6','7',
+ '8','9','a','b','c','d','e','f',
+};
+
+void mdso_write_hex_64(char * ch, uint64_t val)
+{
+ ch[0xf] = mdso_hexfmt[val % 16]; val >>= 4;
+ ch[0xe] = mdso_hexfmt[val % 16]; val >>= 4;
+ ch[0xd] = mdso_hexfmt[val % 16]; val >>= 4;
+ ch[0xc] = mdso_hexfmt[val % 16]; val >>= 4;
+ ch[0xb] = mdso_hexfmt[val % 16]; val >>= 4;
+ ch[0xa] = mdso_hexfmt[val % 16]; val >>= 4;
+ ch[0x9] = mdso_hexfmt[val % 16]; val >>= 4;
+ ch[0x8] = mdso_hexfmt[val % 16]; val >>= 4;
+
+ ch[0x7] = mdso_hexfmt[val % 16]; val >>= 4;
+ ch[0x6] = mdso_hexfmt[val % 16]; val >>= 4;
+ ch[0x5] = mdso_hexfmt[val % 16]; val >>= 4;
+ ch[0x4] = mdso_hexfmt[val % 16]; val >>= 4;
+ ch[0x3] = mdso_hexfmt[val % 16]; val >>= 4;
+ ch[0x2] = mdso_hexfmt[val % 16]; val >>= 4;
+ ch[0x1] = mdso_hexfmt[val % 16]; val >>= 4;
+ ch[0x0] = mdso_hexfmt[val % 16]; val >>= 4;
+}
diff --git a/src/internal/mdso_hexfmt_impl.h b/src/internal/mdso_hexfmt_impl.h
new file mode 100644
index 0000000..1ad74d1
--- /dev/null
+++ b/src/internal/mdso_hexfmt_impl.h
@@ -0,0 +1,14 @@
+/****************************************************************/
+/* mdso: midipix dso scavenger */
+/* Copyright (C) 2015--2024 SysDeer Technologies, LLC */
+/* Released under GPLv2 and GPLv3; see COPYING.MDSO. */
+/****************************************************************/
+
+#ifndef MDSO_HEXFMT_IMPL_H
+#define MDSO_HEXFMT_IMPL_H
+
+#include <stdint.h>
+
+void mdso_write_hex_64(char * ch, uint64_t val);
+
+#endif
diff --git a/src/internal/mdso_object_impl.h b/src/internal/mdso_object_impl.h
index b329ef9..539a77d 100644
--- a/src/internal/mdso_object_impl.h
+++ b/src/internal/mdso_object_impl.h
@@ -1,6 +1,6 @@
/****************************************************************/
/* mdso: midipix dso scavenger */
-/* Copyright (C) 2015--2017 Z. Gilboa */
+/* Copyright (C) 2015--2024 SysDeer Technologies, LLC */
/* Released under GPLv2 and GPLv3; see COPYING.MDSO. */
/****************************************************************/
@@ -31,3 +31,17 @@ static inline void mdso_obj_write_quad(unsigned char * ch, uint64_t val)
ch[6] = val >> 48;
ch[7] = val >> 56;
}
+
+static inline void mdso_obj_write_dec(unsigned char * ch, uint64_t dec)
+{
+ int digits;
+ uint64_t val;
+
+ *ch = '0';
+
+ for (digits=0,val=dec; val; digits++)
+ val /= 10;
+
+ for (val=dec; val; val/=10)
+ ch[--digits] = (val % 10) + '0';
+}
diff --git a/src/internal/perk/perk_structs.h b/src/internal/perk/perk_structs.h
index 4dd2ffc..9ffb480 100644
--- a/src/internal/perk/perk_structs.h
+++ b/src/internal/perk/perk_structs.h
@@ -326,13 +326,13 @@ struct pe_raw_coff_symbol_name {
unsigned char cs_zeroes [0x04]; /* 0x00 */
unsigned char cs_offset [0x04]; /* 0x04 */
} long_name;
- };
+ } cs_u;
};
struct pe_raw_coff_strtbl {
unsigned char cst_size [0x04]; /* 0x00 */
- unsigned char cst_data[]; /* 0x04 */
+ unsigned char cst_data []; /* 0x04 */
};