13 #define MAX_PID_CHARS (5)
16 ut64 retlen = 0, retmax = 0,
off = 0,
len =
g->stub_features.pkt_sz - 2,
17 blksz =
g->data_max, subret_space = 0, subret_len = 0;
18 char *
tmp, *tmp2, *tmp3, *ret =
NULL, *subret =
NULL,
msg[128] = { 0 },
25 if (
g->data_len == 0) {
28 if (
g->data_len == 1 &&
g->data[0] ==
'l') {
32 if (retmax - retlen < g->data_len) {
39 strcpy(ret + retlen,
g->data + 1);
40 retlen +=
g->data_len - 1;
53 tmp = strstr(ret,
"<xi:include");
56 if (!(tmp2 = strstr(
tmp,
"/>"))) {
59 subret_space = tmp2 + 2 -
tmp;
60 if (!(tmp2 = strstr(
tmp,
"href="))) {
64 if (!(tmp3 = strchr(tmp2,
'"'))) {
72 if (subret_len <= subret_space) {
75 retlen - (
tmp + subret_space - ret));
76 retlen -= subret_space - subret_len;
78 tmp = strstr(tmp3,
"<xi:include");
82 if (subret_len > retmax - retlen - 1) {
84 if (!(tmp3 =
realloc(ret, retmax + subret_len))) {
90 retmax += subret_len + 1;
92 memmove(
tmp + subret_len,
tmp + subret_space,
93 retlen - (
tmp + subret_space - ret));
95 retlen += subret_len - subret_space;
99 tmp = strstr(tmp3,
"<xi:include");
110 ut64 retlen = 0, retmax = 0,
off = 0,
len =
g->stub_features.pkt_sz - 2,
118 if (
g->data_len == 0) {
121 if (
g->data_len == 1 &&
g->data[0] ==
'l') {
125 if (retmax - retlen < g->data_len) {
132 strcpy(ret + retlen,
g->data + 1);
133 retlen +=
g->data_len - 1;
176 char *regstr, *flagstr, *
tmp, *profile =
NULL, pc_alias[64], flag_bits[65];
182 ut64 profile_len = 0, profile_max_len, regnum = 0, regoff = 0;
188 if (!(flagstr = strstr(xml_data,
"<feature"))) {
204 if (!(profile =
malloc(profile_max_len))) {
207 rz_list_foreach (
regs,
iter, tmpreg) {
212 arch_regs[regnum].
size = tmpreg->
size;
213 arch_regs[regnum].
offset = regoff;
214 if (profile_len + 128 >= profile_max_len) {
215 if (!(
tmp =
realloc(profile, profile_max_len + 512))) {
219 profile_max_len += 512;
228 if (tmpreg->
size >= 64 &&
229 (strstr(tmpreg->
type,
"fpu") ||
230 strstr(tmpreg->
type,
"mmx") ||
231 strstr(tmpreg->
type,
"xmm") ||
232 strstr(tmpreg->
type,
"ymm"))) {
233 packed_size = tmpreg->
size / 8;
235 profile_len +=
snprintf(profile + profile_len, 128,
236 "%s\t%s\t.%u\t.%" PFMT64d "\t%d\t%s\n", tmpreg->
type,
244 if (profile_len + 128 >= profile_max_len) {
245 if (!(
tmp =
realloc(profile, profile_max_len + 512))) {
249 profile_max_len += 512;
251 profile_len +=
snprintf(profile + profile_len, 128,
"gpr\t%s\t"
258 regoff += tmpreg->
size;
261 switch (
g->target.arch) {
263 switch (
g->target.bits) {
294 switch (
g->target.bits) {
329 if (arch_regs && arch_regs[0].
size == 8) {
337 g->target.regprofile =
strdup(profile);
340 g->target.valid =
true;
341 g->registers = arch_regs;
364 char *itemstr, *column, *column_end, *proc_filename;
365 int ret = -1, ipid, column_data_len;
375 while ((itemstr = strstr(column,
"<item>"))) {
376 if (!strstr(itemstr,
"</item>")) {
381 if (!(column = strstr(itemstr,
"<column name=\"pid\">"))) {
385 if (!(column_end = strstr(column,
"</column>"))) {
390 column +=
sizeof(
"<column name=\"pid\">") - 1;
391 column_data_len = column_end - column;
393 memcpy(pidstr, column, column_data_len);
394 pidstr[column_data_len] =
'\0';
399 if (!(column = strstr(itemstr,
"<column name=\"command\">"))) {
403 if (!(column_end = strstr(column,
"</column>"))) {
408 column +=
sizeof(
"<column name=\"command\">") - 1;
409 column_data_len = column_end - column;
411 memcpy(cmdline, column, column_data_len);
412 cmdline[column_data_len] =
'\0';
416 proc_filename =
rz_str_newf(
"/proc/%d/status", ipid);
421 eprintf(
"Failed to read from data from procfs file of pid (%d)\n", ipid);
424 eprintf(
"Failed to close procfs file of pid (%d)\n", ipid);
427 eprintf(
"Failed to open procfs file of pid (%d)\n", ipid);
432 pid_info->
pid = ipid;
434 pid_info->
uid = pid_info->
gid = -1;
461 if (!
g->stub_features.qXfer_features_read) {
475 if (!
g->stub_features.qXfer_features_read) {
502 bool fc[26] = {
false };
506 for (
i = 0;
i <
flags->num_fields;
i++) {
508 if (
flags->fields[
i].sz != 1) {
527 if ((
arch = strstr(xml_data,
"<architecture"))) {
552 if (strstr(xml_data,
"com.apple.debugserver.arm64")) {
555 }
else if (strstr(xml_data,
"org.gnu.gdb.riscv")) {
558 }
else if (strstr(xml_data,
"org.gnu.gdb.mips")) {
562 }
else if (strstr(xml_data,
"com.apple.debugserver.x86_64")) {
566 eprintf(
"Warning: Unknown architecture parsing XML (%s)\n", xml_data);
573 char *tmp1, *tmp2, *flagsend, *field_start, *field_end;
574 ut64 num_fields, type_sz, name_sz;
581 while ((flagstr = strstr(flagstr,
"<flags"))) {
582 if (!(flagsend = strstr(flagstr,
"</flags>"))) {
590 if (!(tmp1 = strstr(flagstr,
"id="))) {
594 if (!(tmp2 = strchr(tmp1,
'"'))) {
598 type_sz =
sizeof(tmpflag->
type);
599 strncpy(tmpflag->
type, tmp1, type_sz - 1);
600 tmpflag->
type[type_sz - 1] =
'\0';
603 if (!(tmp1 = strstr(flagstr,
"size="))) {
613 field_start = flagstr;
614 while ((field_start = strstr(field_start,
"<field"))) {
616 if (num_fields >= 64) {
619 if (!(field_end = strstr(field_start,
"/>"))) {
624 if (!(tmp1 = strstr(field_start,
"name="))) {
628 if (!(tmp2 = strchr(tmp1,
'"'))) {
632 if (tmp2 - tmp1 <= 1) {
634 field_start = field_end + 1;
638 name_sz =
sizeof(tmpflag->
fields[num_fields].
name);
639 strncpy(tmpflag->
fields[num_fields].
name, tmp1, name_sz - 1);
640 tmpflag->
fields[num_fields].
name[name_sz - 1] =
'\0';
643 if (!(tmp1 = strstr(field_start,
"start="))) {
652 if (!(tmp1 = strstr(field_start,
"end="))) {
663 field_start = field_end + 1;
668 flagstr = flagsend + 1;
684 char *ptr = strstr(
info,
"State:");
686 switch (*(ptr + 7)) {
708 ptr = strstr(
info,
"PPid:");
710 pid_info->
ppid = atoi(ptr + 5);
712 ptr = strstr(
info,
"Uid:");
714 pid_info->
uid = atoi(ptr + 5);
716 ptr = strstr(
info,
"Gid:");
718 pid_info->
gid = atoi(ptr + 5);
728 char *regstr_end, *
regname, *regtype, *tmp1, *tmpregstr, *feature_end, *typegroup, *feature_start;
729 ut32 flagnum, regname_len, regsize, regnum;
739 while ((tmpregstr = strstr(regstr,
"<reg"))) {
740 if (!(regstr_end = strchr(tmpregstr,
'/'))) {
746 if ((feature_start = strstr(regstr,
"<feature")) && feature_start < tmpregstr) {
748 regstr = feature_start;
749 feature_end = strchr(regstr,
'>');
753 if ((tmp1 = strstr(regstr,
"core")) !=
NULL && tmp1 < feature_end) {
755 }
else if ((tmp1 = strstr(regstr,
"segments")) !=
NULL && tmp1 < feature_end) {
757 }
else if ((tmp1 = strstr(regstr,
"linux")) !=
NULL && tmp1 < feature_end) {
760 }
else if ((tmp1 = strstr(regstr,
"avx")) !=
NULL && tmp1 < feature_end) {
762 }
else if ((tmp1 = strstr(regstr,
"mpx")) !=
NULL && tmp1 < feature_end) {
765 }
else if ((tmp1 = strstr(regstr,
"m-profile")) !=
NULL && tmp1 < feature_end) {
767 }
else if ((tmp1 = strstr(regstr,
"pfe")) !=
NULL && tmp1 < feature_end) {
769 }
else if ((tmp1 = strstr(regstr,
"vfp")) !=
NULL && tmp1 < feature_end) {
771 }
else if ((tmp1 = strstr(regstr,
"iwmmxt")) !=
NULL && tmp1 < feature_end) {
774 }
else if ((tmp1 = strstr(regstr,
"sve")) !=
NULL && tmp1 < feature_end) {
776 }
else if ((tmp1 = strstr(regstr,
"pauth")) !=
NULL && tmp1 < feature_end) {
778 }
else if ((tmp1 = strstr(regstr,
"qemu")) !=
NULL && tmp1 < feature_end) {
792 if (!(
regname = strstr(regstr,
"name="))) {
796 if (!(tmp1 = strchr(
regname,
'"'))) {
801 if (!(tmp1 = strstr(regstr,
"bitsize="))) {
808 regsize = strtoul(tmp1,
NULL, 10);
811 if ((tmp1 = strstr(regstr,
"regnum="))) {
816 regnum = strtoul(tmp1,
NULL, 10);
819 if ((tmp1 = strstr(regstr,
"group="))) {
834 if ((tmp1 = strstr(regstr,
"type="))) {
839 strcpy(pc_alias,
"=PC ");
840 strncpy(pc_alias + 4,
regname, regname_len);
841 strcpy(pc_alias + 4 + regname_len,
"\n");
860 if (regsize > 64 && !strcmp(regtype,
"gpr")) {
864 if (regsize == 128 && !strcmp(regtype,
"fpu")) {
871 if (regname_len >
sizeof(tmpreg->
name) - 1) {
875 tmpreg->
name[
sizeof(tmpreg->
name) - 1] =
'\0';
877 strncpy(tmpreg->
type, regtype,
sizeof(tmpreg->
type) - 1);
878 tmpreg->
type[
sizeof(tmpreg->
type) - 1] =
'\0';
879 tmpreg->
size = regsize;
896 regstr = regstr_end + 3;
898 regstr +=
sizeof(
"</feature>");
const aarch64_field fields[]
RzBinInfo * info(RzBinFile *bf)
int gdbr_open_file(libgdbr_t *g, const char *filename, int flags, int mode)
int gdbr_read_file(libgdbr_t *g, ut8 *buf, ut64 max_len)
int gdbr_close_file(libgdbr_t *g)
static static fork const void static count static fd const char const char static newpath const char static path const char path
int send_ack(libgdbr_t *g)
Functions sends a single ack ('+')
RZ_API void Ht_() free(HtName_(Ht) *ht)
int read_packet(libgdbr_t *instance, bool vcont)
int send_msg(libgdbr_t *g, const char *command)
return memset(p, 0, total)
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
static void list(RzEgg *egg)
RZ_API RZ_OWN RzList * rz_list_new(void)
Returns a new initialized RzList pointer (free method is not initialized)
RZ_API ut32 rz_list_set_n(RZ_NONNULL RzList *list, ut32 n, void *p)
Sets the N-th element of the list.
RZ_API RZ_BORROW void * rz_list_get_n(RZ_NONNULL const RzList *list, ut32 n)
Returns the N-th element of the list.
RZ_API RZ_BORROW RzListIter * rz_list_push(RZ_NONNULL RzList *list, void *item)
Alias for rz_list_append.
RZ_API ut32 rz_list_length(RZ_NONNULL const RzList *list)
Returns the length of the list.
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
void * realloc(void *ptr, size_t 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
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
static const char struct stat static buf struct stat static buf static vhangup int status
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API char * rz_str_prepend(char *ptr, const char *string)
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)
static struct sockaddr static addrlen static backlog const void static flags void flags
static struct sockaddr static addrlen static backlog const void msg
struct gdbr_xml_flags_t::@444 fields[64]
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static char * regname(int reg)
static RzDebugPid * _extract_pid_info(const char *info, const char *path, int tid)
static RzList * _extract_flags(char *flagstr)
int gdbr_read_processes_xml(libgdbr_t *g, int pid, RzList *list)
int gdbr_read_target_xml(libgdbr_t *g)
static void _write_flag_bits(char *buf, const gdbr_xml_flags_t *flags)
static char * gdbr_read_osdata(libgdbr_t *g, const char *file, ut64 *tot_len)
static char * gdbr_read_feature(libgdbr_t *g, const char *file, ut64 *tot_len)
static int gdbr_parse_target_xml(libgdbr_t *g, char *xml_data, ut64 len)
static int _resolve_arch(libgdbr_t *g, char *xml_data)
static RzList * _extract_regs(char *regstr, RzList *flags, char *pc_alias)
static int gdbr_parse_processes_xml(libgdbr_t *g, char *xml_data, ut64 len, int pid, RzList *list)