10 #define fset(num, shift) ((((num) & (((ut64)1) << (shift))) == 0) ? 0 : 1)
12 #if __i386__ || __x86_64__
26 fset(ctrl.cr0, 31),
fset(ctrl.cr0, 30),
fset(ctrl.cr0, 29),
fset(ctrl.cr0, 18),
28 fset(ctrl.cr0, 2),
fset(ctrl.cr0, 1),
fset(ctrl.cr0, 1));
39 (((
ut64)ctrl.cr3) & 0xfffffffffffff000),
fset(ctrl.cr3, 4),
fset(ctrl.cr3, 3));
52 " [*] OSXMMEXCPT: %d\n"
63 fset(ctrl.cr4, 22),
fset(ctrl.cr4, 21),
fset(ctrl.cr4, 20),
fset(ctrl.cr4, 18),
64 fset(ctrl.cr4, 17),
fset(ctrl.cr4, 16),
fset(ctrl.cr4, 14),
fset(ctrl.cr4, 13),
65 fset(ctrl.cr4, 11),
fset(ctrl.cr4, 10),
fset(ctrl.cr4, 9),
fset(ctrl.cr4, 8),
72 io->
cb_printf(
" [*] TPL: %zu\n", ctrl.cr8 & 0xf);
80 " [*] UNP/SBZ: 0x%" PFMT64x "\n"
85 (
ut64)((ctrl.ttbr0 & (0xffffffff << (14 - (ctrl.ttbcr & 7)))) >> (14 - (ctrl.ttbcr & 7))),
86 (
ut64)((ctrl.ttbr0 & ((1 << (13 - (ctrl.ttbcr & 7) + 1)) - (1 << 5))) >> 6),
87 (
ut64)((ctrl.ttbr0 & 0x18) >> 3),
fset(ctrl.ttbr0, 2),
fset(ctrl.ttbr0, 1),
fset(ctrl.ttbr0, 0));
92 " [*] UNP/SBZ: 0x%" PFMT64x "\n"
97 (
ut64)((ctrl.ttbr1 & (0xffffffff << 14)) >> 14), (
ut64)((ctrl.ttbr1 & ((1 << (13 + 1)) - (1 << 5))) >> 6),
98 (
ut64)((ctrl.ttbr1 & 0x18) >> 3),
fset(ctrl.ttbr1, 2),
fset(ctrl.ttbr1, 1),
fset(ctrl.ttbr1, 0));
102 io->
cb_printf(
" [*] N: %d\n", ctrl.ttbcr & 7);
133 fset(ctrl.c1, 1),
fset(ctrl.c1, 0));
139 #elif __arm64__ || __aarch64__
162 fset(ctrl.sctlr_el1, 26),
fset(ctrl.sctlr_el1, 25),
fset(ctrl.sctlr_el1, 24),
fset(ctrl.sctlr_el1, 19),
163 fset(ctrl.sctlr_el1, 18),
fset(ctrl.sctlr_el1, 16),
fset(ctrl.sctlr_el1, 15),
fset(ctrl.sctlr_el1, 14),
164 fset(ctrl.sctlr_el1, 12),
fset(ctrl.sctlr_el1, 9),
fset(ctrl.sctlr_el1, 8),
fset(ctrl.sctlr_el1, 7),
165 fset(ctrl.sctlr_el1, 6),
fset(ctrl.sctlr_el1, 5),
fset(ctrl.sctlr_el1, 4),
fset(ctrl.sctlr_el1, 3),
166 fset(ctrl.sctlr_el1, 2),
fset(ctrl.sctlr_el1, 1),
fset(ctrl.sctlr_el1, 0));
171 " [*] BADDR [47:10]: 0x%" PFMT64x "\n",
172 (ctrl.ttbr0_el1 & 0xffff000000000000LLU) >> 48, (ctrl.ttbr0_el1 & ((((
ut64)1) << (47 + 1)) - (1 << 10))) >> 10);
177 " [*] BADDR [47:10]: 0x%" PFMT64x "\n",
178 (ctrl.ttbr1_el1 & 0xffff000000000000LLU) >> 48, (ctrl.ttbr1_el1 & ((((
ut64)1) << (47 + 1)) - (1 << 10))) >> 10);
199 fset(ctrl.tcr_el1, 38),
fset(ctrl.tcr_el1, 37),
fset(ctrl.tcr_el1, 36),
200 (
int)(ctrl.tcr_el1 >> 32) & 0x7,
fset(ctrl.tcr_el1, 30), (
int)(ctrl.tcr_el1 >> 28) & 0x3,
201 (
int)(ctrl.tcr_el1 >> 26) & 0x3, (
int)(ctrl.tcr_el1 >> 24) & 0x3,
fset(ctrl.tcr_el1, 23),
202 fset(ctrl.tcr_el1, 22), (
int)(ctrl.tcr_el1 >> 16) & 0x3f,
fset(ctrl.tcr_el1, 14),
203 (
int)(ctrl.tcr_el1 >> 12) & 0x3, (
int)(ctrl.tcr_el1 >> 10) & 0x3, (
int)(ctrl.tcr_el1 >> 8) & 0x3,
204 fset(ctrl.tcr_el1, 7), (
int)ctrl.tcr_el1 & 0x3f);
224 ret = strtoul(
buf, 0, 0);
233 int cmd_len =
cmd ? strlen(
cmd) : 0;
234 const char *
usage =
"Usage: \\[MprRw][lpP] [args...]";
235 const char *help_msg[] = {
236 "\\dm Print kernel memory map (or process if rzk.io==1)",
237 "\\dr Print control registers",
238 "\\dR Print control registers in detailed mode",
239 "\\dp [pid] Print current selected pid or change it",
240 "\\e rzk.io=[012] Read/Write from 0: Linear, 1: Process, 2: Physical addresses"
242 const char *help_msg_old[] = {
243 "\\M Print kernel memory map",
244 "\\b beid [pid] Change rzk backend. pid is required when beid is 1.",
245 " 0: linear address; 1: process address; 2: physical address",
246 "\\p pid Print process information",
247 "\\rl addr len Read from linear address",
248 "\\rp pid addr len Read from process address",
249 "\\rP addr len Read physical address",
250 "\\R[p] Print control registers. Use R!Rp for detailed description",
251 "\\wl[x] addr input Write at linear address. Use R!wlx for input in hex",
252 "\\wp[x] pid addr input Write at process address. Use R!wpx for input in hex",
253 "\\wP[x] addr input Write at physical address. Use R!wPx for input in hex",
254 "\\W 1|0 Honor arch write protect (1 enable WP, 0 disable WP)"
259 for (
i = 0;
i < (
sizeof(help_msg) /
sizeof(
char *));
i++) {
260 if (!
cmd || !strncmp(
cmd, help_msg[
i] + 1, cmd_len)) {
264 io->
cb_printf(
"\nOld Commands: (deprecated)\n");
265 for (
i = 0;
i < (
sizeof(help_msg_old) /
sizeof(
char *));
i++) {
266 if (!
cmd || !strncmp(
cmd, help_msg_old[
i] + 1, cmd_len)) {
274 int pagesize, newlen;
279 if (iodesc && iodesc->
data > 0 &&
buf) {
290 ret =
ioctl((
int)(
size_t)iodesc->
data, ioctl_n, &data);
298 pagesize = getpagesize();
299 pageaddr = address + pagesize;
300 pageaddr -= (pageaddr % pagesize);
301 if ((
len - (
int)(pageaddr - address)) > 0) {
302 data.
len = pageaddr - address;
303 ret =
ioctl((
int)(
size_t)iodesc->
data, ioctl_n, &data);
311 offset = pageaddr - address;
313 while (newlen >= pagesize) {
314 data.
addr = pageaddr;
317 ret =
ioctl((
int)(
size_t)iodesc->
data, ioctl_n, &data);
324 pageaddr += pagesize;
329 data.
addr = pageaddr;
331 ret =
ioctl((
int)(
size_t)iodesc->
data, ioctl_n, &data);
339 ret = flag ?
len : -1;
344 io->
cb_printf(
"Invalid input buffer.\n");
346 io->
cb_printf(
"IOCTL device not initialized.\n");
354 if (iodesc && iodesc->
data > 0 &&
buf) {
368 ret =
ioctl((
int)(
size_t)iodesc->
data, ioctl_n, &data);
372 io->
cb_printf(
"Write failed. ioctl err: %s\n", strerror(errno));
378 io->
cb_printf(
"Invalid input buffer.\n");
380 io->
cb_printf(
"IOCTL device not initialized.\n");
386 int ret, inphex, ioctl_n;
399 if (wp < 0 || wp > 1) {
417 if (beid < 0 || beid > 2) {
422 if (beid == 1 &&
pid < 0) {
432 io->
cb_printf(
"io_rzk_linux : Malloc failed. Seeking to 0x0\n");
454 io->
cb_printf(
"Invalid number of arguments.\n");
471 io->
cb_printf(
"Invalid number of arguments.\n");
489 io->
cb_printf(
"Invalid number of arguments.\n");
509 io->
cb_printf(
"Failed to allocate buffer\n");
514 inphex = (
buf[2] ==
'x') ? 1 : 0;
519 if ((inphex &&
buf[3] !=
' ') || (!inphex &&
buf[2] !=
' ')) {
527 io->
cb_printf(
"Invalid number of arguments.\n");
536 if ((inphex &&
buf[3] !=
' ') || (!inphex &&
buf[2] !=
' ')) {
544 io->
cb_printf(
"Invalid number of arguments.\n");
553 if ((inphex &&
buf[3] !=
' ') || (!inphex &&
buf[2] !=
' ')) {
561 io->
cb_printf(
"Invalid number of arguments.\n");
586 eprintf(
"Failed to allocate buffer.\n");
595 long page_size = sysconf(_SC_PAGESIZE);
598 ret =
ioctl((
int)(
size_t)iodesc->
data, ioctl_n, &map_data);
601 io->
cb_printf(
"ioctl err: %s\n", strerror(errno));
607 if (
info == MAP_FAILED) {
608 io->
cb_printf(
"mmap err: %s\n", strerror(errno));
616 io->
cb_printf(
"n_pages: %d (%ld Kbytes)\n",
in->n_pages, (
in->n_pages * page_size) / 1024);
617 io->
cb_printf(
"n_phys_addr: %d\n",
in->n_phys_addr);
618 for (j = 0; j <
in->n_phys_addr; j++) {
633 ret =
ioctl((
int)(
size_t)iodesc->
data, ioctl_n, ®_data);
636 io->
cb_printf(
"ioctl err: %s\n", strerror(errno));
640 #if __i386__ || __x86_64__
643 if (
buf[1] != 0 &&
buf[1] ==
'p') {
644 x86_ctrl_reg_pretty_print(io, reg_data);
656 if (
buf[1] != 0 &&
buf[1] ==
'p') {
657 arm_ctrl_reg_pretty_print(io, reg_data);
665 #elif __arm64__ || __aarch64__
666 if (
buf[1] != 0 &&
buf[1] ==
'p') {
667 arm64_ctrl_reg_pretty_print(io, reg_data);
685 if (*(
buf + 1) ==
'*') {
688 switch (*(
buf + 1)) {
691 if (*(
buf + 2) !=
' ') {
705 io->
cb_printf(
"Invalid number of arguments.\n");
712 ret =
ioctl((
int)(
size_t)iodesc->
data, ioctl_n, &proc_data);
714 io->
cb_printf(
"ioctl err: %s\n", strerror(errno));
721 for (
i = 0;
i + 1 < buffsize;) {
723 if (
i + 7 < buffsize) {
728 nextstart > 0 && nextstart - 1 < buffsize) {
736 io->
cb_printf(
"f pid.%d.task_struct @ 0x%08zu\n", proc_data.
pid, proc_data.
task);
738 io->
cb_printf(
"pid = %d\nprocess name = %s\n", proc_data.
pid, proc_data.
comm);
740 for (
i = 0;
i < buffsize;) {
742 if (
i + 7 < buffsize) {
746 nextstart > 0 && nextstart - 1 < buffsize) {
807 if (strchr(
buf,
'?')) {
813 const char *
eq = strchr(
buf,
'=');
815 int v = atoi(
eq + 1);
826 if (strchr(
buf,
'?')) {
827 io->
cb_printf(
"<bool> enable write protection (disabled by default)\n");
830 const char *
eq = strchr(
buf,
'=');
832 int v = atoi(
eq + 1);
RzBinInfo * info(RzBinFile *bf)
const lzma_allocator const uint8_t * in
void usage(const char *message)
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags cmd
static static sync static getppid static getegid const char static filename ioctl
RZ_API void Ht_() free(HtName_(Ht) *ht)
static void print_help(RzIO *io, char *cmd, int p_usage)
int run_new_command(RzIO *io, RzIODesc *iodesc, const char *buf)
int run_old_command(RzIO *io, RzIODesc *iodesc, const char *buf)
static size_t getvalue(const char *buf, int pos)
int WriteMemory(RzIO *io, RzIODesc *iodesc, int ioctl_n, size_t pid, ut64 address, const ut8 *buf, int len)
static const char * getargpos(const char *buf, int pos)
int ReadMemory(RzIO *io, RzIODesc *iodesc, int ioctl_n, size_t pid, size_t address, ut8 *buf, int len)
int run_ioctl_command(RzIO *io, RzIODesc *iodesc, const char *buf)
#define IOCTL_READ_KERNEL_MEMORY
#define IOCTL_GET_KERNEL_MAP
#define IOCTL_READ_PHYSICAL_ADDR
struct io_rzk_linux rzk_struct
#define IOCTL_WRITE_PHYSICAL_ADDR
#define IOCTL_WRITE_PROCESS_ADDR
#define IOCTL_WRITE_KERNEL_MEMORY
#define IOCTL_READ_CONTROL_REG
#define IOCTL_PRINT_PROC_INFO
#define IOCTL_READ_PROCESS_ADDR
return memset(p, 0, total)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
void * malloc(size_t size)
void * calloc(size_t number, size_t size)
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
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 static sig const char static mode static oldfd struct tms static buf static getgid static geteuid const char static filename static arg static mask struct ustat static ubuf static getppid static setsid static egid sigset_t static set struct timeval struct timezone static tz fd_set fd_set fd_set struct timeval static timeout const char char static bufsiz const char static swapflags mmap
static const void static count static fd struct stat static buf struct pollfd unsigned static timeout void static offset munmap
RZ_API RzPrint * rz_print_new(void)
RZ_API RzPrint * rz_print_free(RzPrint *p)
RZ_API RZ_OWN char * rz_print_hexdump_str(RZ_NONNULL RzPrint *p, ut64 addr, RZ_NONNULL const ut8 *buf, int len, int base, int step, size_t zoomsz)
Prints a hexdump of buf at addr.
RZ_API int rz_hex_str2bin(const char *in, ut8 *out)
Convert an input string in into the binary form in out.
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API const char * rz_str_bool(int b)
RZ_API char * rz_str_ichr(char *str, char chr)
RZ_API bool rz_str_startswith(RZ_NONNULL const char *str, RZ_NONNULL const char *needle)
Checks if a string starts with a specifc sequence of characters (case sensitive)
RZ_API int rz_str_unescape(char *buf)
size_t vmareastruct[4096]
ut64(WINAPI *w32_GetEnabledXStateFeatures)()