memzap

replay memory writes
git clone git://git.2f30.org/memzap
Log | Files | Refs | README | LICENSE

commit 03ed1051952b9238cf96d94635cc1af71f7d0e41
parent 8ec52dcb1cf3be497d928893c018767adf7b0492
Author: sin <sin@2f30.org>
Date:   Mon,  4 Mar 2013 13:27:56 +0000

memzap: Dump base image + diffs

Diffstat:
Mmemzap.c | 31++++++++++++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)

diff --git a/memzap.c b/memzap.c @@ -15,6 +15,27 @@ usage(const char *prog) fprintf(stderr, " -h\tThis help screen\n"); } +static void +dump_base_image(const char *name, void *buf, size_t len) +{ + ssize_t ret; + char mem_path[PATH_MAX - 1]; + int fdmem; + + snprintf(mem_path, sizeof(mem_path), + "%s.mem", name); + fdmem = open(mem_path, + O_CREAT | O_RDWR | O_TRUNC, + 0644); + if (fdmem < 0) + errx(1, "%s: %s", mem_path, + strerror(errno)); + ret = write(fdmem, buf, len); + if ((size_t)ret != len) + err(1, "write"); + close(fdmem); +} + int main(int argc, char *argv[]) { @@ -30,6 +51,8 @@ main(int argc, char *argv[]) size_t len = 0; int fd; char *prog = *argv; + char mdiff_path[PATH_MAX - 1]; + bool once = false; while ((c = getopt(argc, argv, "hs:l:r:v")) != -1) { switch (c) { @@ -98,7 +121,9 @@ main(int argc, char *argv[]) if (!WIFSTOPPED(stat)) goto out_mmap; - fd = create_mdiff("test.mdiff"); + snprintf(mdiff_path, sizeof(mdiff_path), + "%s.mdiff", *argv); + fd = create_mdiff(mdiff_path); memset(&hdr, 0, sizeof(hdr)); strncpy((char *)hdr.magic, "MDIFF", 5); hdr.blksize = BLKSIZE; @@ -107,6 +132,10 @@ main(int argc, char *argv[]) mdiff_start_diff(fd); do { readmem(pid, buf, addr, len); + if (!once) { + dump_base_image(*argv, buf, len); + once = true; + } mr_old = build_mem_region(buf, len); if (!mr_old)