summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJari Vetoniemi <mailroxas@gmail.com>2018-10-23 21:44:38 +0300
committerJari Vetoniemi <mailroxas@gmail.com>2018-10-23 21:46:20 +0300
commit3f066cdd2eb24db34a8332acb653b06ed5c3aed1 (patch)
treea097924f9460c17e53b16ac297a494667b00dea5
parentd29c202985edcaca48000363c4ad83ee8ec25c69 (diff)
memview: add memory write feature
-rw-r--r--src/memview.c53
1 files changed, 39 insertions, 14 deletions
diff --git a/src/memview.c b/src/memview.c
index b326efd..c05b10c 100644
--- a/src/memview.c
+++ b/src/memview.c
@@ -161,6 +161,20 @@ static struct {
struct mem_io io;
} ctx = { .hexview.octects_per_group = 1 };
+static const char*
+basename(const char *path)
+{
+ const char *base = strrchr(path, '/');
+ return (base ? base + 1 : path);
+}
+
+static const char*
+skip_ws(const char *str)
+{
+ const size_t skipped = strspn(str, " \t\n");
+ return str + skipped;
+}
+
const char*
hex_for_byte(unsigned char byte)
{
@@ -722,6 +736,31 @@ goto_offset(void *arg)
}
static void
+write_bytes(void *arg)
+{
+ (void)arg;
+ const char *v;
+ if (!(v = input("bytes")))
+ return;
+
+ unsigned char bytes[255] = {0}, i = 0;
+ for (const char *s = skip_ws(v); i < sizeof(bytes) && *s; s += 2, s += !!isspace(*s)) {
+ unsigned int x;
+ if (!sscanf(s, "%2x", &x)) {
+ error("invalid input `%s`", v);
+ return;
+ }
+ if (i >= sizeof(bytes)) {
+ error("input is too long, sorry :( (max 255 bytes)");
+ return;
+ }
+ bytes[i++] = x;
+ }
+
+ ctx.io.write(&ctx.io, bytes, ctx.hexview.offset, i);
+}
+
+static void
quit(void)
{
for (size_t i = 0; i < ctx.num_regions; ++i)
@@ -773,20 +812,6 @@ init(void)
);
}
-static const char*
-basename(const char *path)
-{
- const char *base = strrchr(path, '/');
- return (base ? base + 1 : path);
-}
-
-static const char*
-skip_ws(const char *str)
-{
- const size_t skipped = strspn(str, " \t\n");
- return str + skipped;
-}
-
static void
region_cb(const char *line, void *data)
{