diff options
| author | Root THC | 2026-02-24 12:42:47 +0000 |
|---|---|---|
| committer | Root THC | 2026-02-24 12:42:47 +0000 |
| commit | c9cbeced5b3f2bdd7407e29c0811e65954132540 (patch) | |
| tree | aefc355416b561111819de159ccbd86c3004cf88 /other/Kermit/include/rwKernel.hpp | |
| parent | 073fe4bf9fca6bf40cef2886d75df832ef4b6fca (diff) | |
initial
Diffstat (limited to 'other/Kermit/include/rwKernel.hpp')
| -rw-r--r-- | other/Kermit/include/rwKernel.hpp | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/other/Kermit/include/rwKernel.hpp b/other/Kermit/include/rwKernel.hpp new file mode 100644 index 0000000..3b57750 --- /dev/null +++ b/other/Kermit/include/rwKernel.hpp | |||
| @@ -0,0 +1,94 @@ | |||
| 1 | /* | ||
| 2 | * rwKernel.hpp: | ||
| 3 | * access to kernel memory. | ||
| 4 | * written by palmers / teso | ||
| 5 | */ | ||
| 6 | #ifndef __RW_KERNEL_C | ||
| 7 | #define __RW_KERNEL_C | ||
| 8 | |||
| 9 | #include <algorithm> | ||
| 10 | |||
| 11 | #define PROCKCORE 213 | ||
| 12 | #define DEVMEM 23846 | ||
| 13 | |||
| 14 | #define CONF_1GB 34 | ||
| 15 | #define CONF_2GB 33 | ||
| 16 | #define CONF_3GB 32 | ||
| 17 | #define IGNORE 31 | ||
| 18 | |||
| 19 | /** | ||
| 20 | * Wrapper around kernel memory access. It lets you read from | ||
| 21 | * and write to the kernel without taking care of offsets or file access. | ||
| 22 | */ | ||
| 23 | class rwKernel | ||
| 24 | { | ||
| 25 | private: | ||
| 26 | |||
| 27 | char *fd; | ||
| 28 | int which; | ||
| 29 | unsigned int mem_conf; | ||
| 30 | |||
| 31 | bool openFile (int); | ||
| 32 | void closeFile (); | ||
| 33 | void setOffset (int); | ||
| 34 | |||
| 35 | |||
| 36 | public: | ||
| 37 | |||
| 38 | /** | ||
| 39 | * Create the object with a fairly standard configuration. This constructor will assume | ||
| 40 | * that you want to use /dev/mem and a standard offset (as used by any 2.4.x and any | ||
| 41 | * 2.2.x kernel not defined to use more than 1GB of ram). | ||
| 42 | */ | ||
| 43 | rwKernel (); | ||
| 44 | |||
| 45 | /** | ||
| 46 | * Create a rwKernel object with the defined parameters. | ||
| 47 | * @param file sets the file to use. This must be either | ||
| 48 | * PROCKCORE (to use /proc/kcore as the memory device) or | ||
| 49 | * DEVMEM (to use /dev/mem as the memory device). | ||
| 50 | * @param offset sets the offset from real memory addresses | ||
| 51 | * to virtual (kernel-) addresses. This is only needed if | ||
| 52 | * (file == DEVMEM), otherways supply IGNORE. | ||
| 53 | */ | ||
| 54 | rwKernel (int file, int offset); | ||
| 55 | |||
| 56 | /** | ||
| 57 | * Destructor. Will unmap the used device. | ||
| 58 | */ | ||
| 59 | ~rwKernel (); | ||
| 60 | |||
| 61 | /** | ||
| 62 | * read from kernel. | ||
| 63 | * @param dest read data to this address. | ||
| 64 | * @param len amount of bytes to read. | ||
| 65 | * @param addr read data from this address. | ||
| 66 | */ | ||
| 67 | void read (unsigned char *dest, unsigned int len, unsigned int addr); | ||
| 68 | |||
| 69 | /** | ||
| 70 | * write to kernel. | ||
| 71 | * @param src read data from this address. | ||
| 72 | * @param len amount of bytes to write. | ||
| 73 | * @param addr write data to this address. | ||
| 74 | */ | ||
| 75 | void write (unsigned char *src, unsigned int len, unsigned int addr); | ||
| 76 | |||
| 77 | /** | ||
| 78 | * Foo. | ||
| 79 | */ | ||
| 80 | void read (char *a, unsigned int b, unsigned int c) | ||
| 81 | { | ||
| 82 | read ((unsigned char *) a, b, c); | ||
| 83 | } | ||
| 84 | |||
| 85 | /** | ||
| 86 | * Foo. | ||
| 87 | */ | ||
| 88 | void write (char *a, unsigned int b, unsigned int c) | ||
| 89 | { | ||
| 90 | write ((unsigned char *) a, b, c); | ||
| 91 | } | ||
| 92 | }; | ||
| 93 | |||
| 94 | #endif /* __RW_KERNEL_C */ | ||
