summaryrefslogtreecommitdiff
path: root/other/Kermit/include/rwKernel.hpp
blob: 3b577502468fa4334edd7bca7306216ef4a8c761 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
 * rwKernel.hpp:
 * access to kernel memory.
 * written by palmers / teso
 */
#ifndef __RW_KERNEL_C
#define __RW_KERNEL_C

#include <algorithm>

#define PROCKCORE	213
#define DEVMEM		23846

#define CONF_1GB	34
#define CONF_2GB	33
#define CONF_3GB	32
#define IGNORE		31

/**
 * Wrapper around kernel memory access. It lets you read from
 * and write to the kernel without taking care of offsets or file access.
 */
class rwKernel
{
private:

  char *fd;
  int which;
  unsigned int mem_conf;

  bool openFile (int);
  void closeFile ();
  void setOffset (int);


public:

/**
 * Create the object with a fairly standard configuration. This constructor will assume
 * that you want to use /dev/mem and a standard offset (as used by any 2.4.x and any
 * 2.2.x kernel not defined to use more than 1GB of ram).
 */
  rwKernel ();

/**
 * Create a rwKernel object with the defined parameters.
 * @param file sets the file to use. This must be either
 * PROCKCORE (to use /proc/kcore as the memory device) or
 * DEVMEM (to use /dev/mem as the memory device).
 * @param offset sets the offset from real memory addresses
 * to virtual (kernel-) addresses. This is only needed if
 * (file == DEVMEM), otherways supply IGNORE.
 */
  rwKernel (int file, int offset);

/**
 * Destructor. Will unmap the used device.
 */
  ~rwKernel ();

/**
 * read from kernel.
 * @param dest read data to this address.
 * @param len amount of bytes to read.
 * @param addr read data from this address.
 */
  void read (unsigned char *dest, unsigned int len, unsigned int addr);

/**
 * write to kernel.
 * @param src read data from this address.
 * @param len amount of bytes to write.
 * @param addr write data to this address.
 */
  void write (unsigned char *src, unsigned int len, unsigned int addr);

/**
 * Foo.
 */
  void read (char *a, unsigned int b, unsigned int c)
  {
    read ((unsigned char *) a, b, c);
  }

/**
 * Foo.
 */
  void write (char *a, unsigned int b, unsigned int c)
  {
    write ((unsigned char *) a, b, c);
  }
};

#endif /* __RW_KERNEL_C */