Rizin
unix-like reverse engineering framework and cli tools
io_rzk_linux.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2016 Rakholiya Jenish
2 // SPDX-FileCopyrightText: 2016 NighterMan <jpenalbae@gmail.com>
3 // SPDX-FileCopyrightText: 2017-2020 pancake <pancake@nopcode.org>
4 // SPDX-License-Identifier: LGPL-3.0-only
5 
6 #ifndef __IO_RZK_LINUX_H__
7 #define __IO_RZK_LINUX_H__
8 
9 #include <rz_io.h>
10 #include <rz_lib.h>
11 #include <rz_types.h>
12 #include <rz_util.h>
13 #include <rz_util/rz_print.h>
14 #include <sys/types.h>
15 #include <sys/ioctl.h>
16 #include <sys/mman.h>
17 #include <errno.h>
18 
19 #define MAX_PHYS_ADDR 128
20 
21 /*
22  * Backend Id (be_id):
23  * 0: Linear Address
24  * 1: Process Address
25  * 2: Physical Address
26  */
27 struct io_rzk_linux {
28  int beid;
29  int pid;
31 };
32 
33 struct rzk_data {
34  int pid;
35  size_t addr;
36  size_t len;
39 };
40 
42  size_t start_addr;
43  size_t end_addr;
45  int n_pages;
47 };
48 
50  int n_entries;
51  int size;
52 };
53 
55 #if __x86_64__ || __i386__
56  size_t cr0;
57  size_t cr1;
58  size_t cr2;
59  size_t cr3;
60  size_t cr4;
61 #if __x86_64__
62  size_t cr8;
63 #endif
64 #elif __arm__
65  size_t ttbr0;
66  size_t ttbr1;
67  size_t ttbcr;
68  size_t c1;
69  size_t c3;
70 #elif __arm64__ || __aarch64__
71  size_t sctlr_el1;
72  size_t ttbr0_el1;
73  size_t ttbr1_el1;
74  size_t tcr_el1;
75 #endif
76 };
77 
78 struct rzk_proc_info {
79  int pid;
80  char comm[16];
81  size_t vmareastruct[4096];
82  size_t stack;
83  size_t task;
84 };
85 
86 #define RZ_TYPE 0x69
87 
88 #define READ_KERNEL_MEMORY 0x1
89 #define WRITE_KERNEL_MEMORY 0x2
90 #define READ_PROCESS_ADDR 0x3
91 #define WRITE_PROCESS_ADDR 0X4
92 #define READ_PHYSICAL_ADDR 0x5
93 #define WRITE_PHYSICAL_ADDR 0x6
94 #define GET_KERNEL_MAP 0x7
95 #define READ_CONTROL_REG 0x8
96 #define PRINT_PROC_INFO 0x9
97 
98 #ifdef _IOC_TYPECHECK
99 #define rzk_data_size struct rzk_data
100 #define rzk_kernel_maps_size struct rzk_kernel_maps
101 #define rzk_control_reg_size struct rzk_control_reg
102 #define rzk_proc_info_size struct rzk_proc_info
103 #else
104 #define rzk_data_size sizeof(struct rzk_data)
105 #define rzk_kernel_maps_size sizeof(struct rzk_kernel_maps)
106 #define rzk_control_reg_size sizeof(struct rzk_control_reg)
107 #define rzk_proc_info_size sizeof(struct rzk_proc_info)
108 #endif
109 
110 #define IOCTL_READ_KERNEL_MEMORY _IOR(RZ_TYPE, READ_KERNEL_MEMORY, rzk_data_size)
111 #define IOCTL_WRITE_KERNEL_MEMORY _IOR(RZ_TYPE, WRITE_KERNEL_MEMORY, rzk_data_size)
112 #define IOCTL_READ_PROCESS_ADDR _IOR(RZ_TYPE, READ_PROCESS_ADDR, rzk_data_size)
113 #define IOCTL_WRITE_PROCESS_ADDR _IOR(RZ_TYPE, WRITE_PROCESS_ADDR, rzk_data_size)
114 #define IOCTL_READ_PHYSICAL_ADDR _IOR(RZ_TYPE, READ_PHYSICAL_ADDR, rzk_data_size)
115 #define IOCTL_WRITE_PHYSICAL_ADDR _IOR(RZ_TYPE, WRITE_PHYSICAL_ADDR, rzk_data_size)
116 #define IOCTL_GET_KERNEL_MAP _IOR(RZ_TYPE, GET_KERNEL_MAP, rzk_kernel_maps_size)
117 #define IOCTL_READ_CONTROL_REG _IOR(RZ_TYPE, READ_CONTROL_REG, rzk_control_reg_size)
118 #define IOCTL_PRINT_PROC_INFO _IOR(RZ_TYPE, PRINT_PROC_INFO, rzk_data_size) // Bad hack. Incorrect size, but since module does not use _IOC_SIZE, it won't matter if size parameter is wrong
119 
120 #define VM_READ 0x1
121 #define VM_WRITE 0x2
122 #define VM_EXEC 0x4
123 #define VM_MAYSHARE 0x80
124 
125 extern struct io_rzk_linux rzk_struct;
126 
127 int ReadMemory(RzIO *io, RzIODesc *iodesc, int ioctl_n, size_t pid, size_t address, ut8 *buf, int len);
128 int WriteMemory(RzIO *io, RzIODesc *iodesc, int ioctl_n, size_t pid, ut64 address, const ut8 *buf, int len);
129 int run_ioctl_command(RzIO *io, RzIODesc *iodesc, const char *buf);
130 
131 #endif
size_t len
Definition: 6502dis.c:15
lsl lsr asr ror lsl lsr asr ror lsl lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror c1
lsl lsr asr ror lsl lsr asr ror lsl lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror c3
#define MAX_PHYS_ADDR
Definition: io_rzk_linux.h:19
struct io_rzk_linux rzk_struct
int WriteMemory(RzIO *io, RzIODesc *iodesc, int ioctl_n, size_t pid, ut64 address, const ut8 *buf, int len)
Definition: io_rzk_linux.c:351
int ReadMemory(RzIO *io, RzIODesc *iodesc, int ioctl_n, size_t pid, size_t address, ut8 *buf, int len)
Definition: io_rzk_linux.c:272
int run_ioctl_command(RzIO *io, RzIODesc *iodesc, const char *buf)
Definition: io_rzk_linux.c:842
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc pid
Definition: sflib.h:64
Definition: rz_io.h:59
size_t len
Definition: io_rzk_linux.h:36
size_t addr
Definition: io_rzk_linux.h:35
ut8 * buff
Definition: io_rzk_linux.h:37
size_t phys_addr[MAX_PHYS_ADDR]
Definition: io_rzk_linux.h:44
char comm[16]
Definition: io_rzk_linux.h:80
size_t vmareastruct[4096]
Definition: io_rzk_linux.h:81
ut64(WINAPI *w32_GetEnabledXStateFeatures)()