From c9cbeced5b3f2bdd7407e29c0811e65954132540 Mon Sep 17 00:00:00 2001 From: Root THC Date: Tue, 24 Feb 2026 12:42:47 +0000 Subject: initial --- other/Kermit/lib/rwKernel.cpp | 107 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) create mode 100644 other/Kermit/lib/rwKernel.cpp (limited to 'other/Kermit/lib/rwKernel.cpp') diff --git a/other/Kermit/lib/rwKernel.cpp b/other/Kermit/lib/rwKernel.cpp new file mode 100644 index 0000000..4077ff5 --- /dev/null +++ b/other/Kermit/lib/rwKernel.cpp @@ -0,0 +1,107 @@ +/* + * rwKernel.cpp: + * written by palmers / teso + */ +#include +#include +#include +#include +#include +#include +#include + + + bool rwKernel::openFile (int w) + { + int a = 0; + void *tmp = NULL; + char *file = NULL; + + if (w == DEVMEM) + file = "/dev/mem"; + else if (w == PROCKCORE) + file = "/proc/kcore"; + + if ((a = open (file, O_RDWR)) <= 0) + { + cerr << "open error" << endl; + abort (); + } + + if ((tmp = mmap (NULL, 0x40000000, PROT_READ | \ + PROT_WRITE, MAP_SHARED, a, 0xc0000000 - mem_conf)) == (void *) -1) + { + cerr << "mmap failed" << endl; + abort (); + } + fd = (char *) tmp; + return true; + } + + + void rwKernel::setOffset (int x) + { + switch (x) + { + case CONF_1GB: + mem_conf = 0xC0000000; + break; + case CONF_2GB: + mem_conf = 0x80000000; + break; + case CONF_3GB: + mem_conf = 0x40000000; + break; + case IGNORE: + mem_conf = 0xC0000000; + break; + default: + mem_conf = 0xC0000000; + break; + } + } + + + void rwKernel::closeFile () + { + munmap (fd, 0x40000000); + } + + + rwKernel::rwKernel () + { + setOffset (CONF_1GB); + openFile (DEVMEM); + } + + + rwKernel::rwKernel (int file, int off) + { + if (file == PROCKCORE) + off = IGNORE; + setOffset (off); + openFile (file); + } + + + rwKernel::~rwKernel () + { + closeFile (); + } + + + void rwKernel::read (unsigned char *dest, unsigned int len, \ + unsigned int offset) + { + offset -= mem_conf; + copy (fd + offset, fd + offset + len, dest); + } + + + void rwKernel::write (unsigned char *src, unsigned int len, \ + unsigned int offset) + { + offset -= mem_conf; + copy (src, src + len, fd + offset); + } + -- cgit v1.3