8 #include <sys/socket.h>
9 #include <netinet/in.h>
10 #include <sys/sysctl.h>
11 #include <sys/types.h>
14 #include <arpa/inet.h>
17 #include <sys/ptrace.h>
18 #include <sys/types.h>
23 #if __KFBSD__ || __DragonFly__
26 #elif __OpenBSD__ || __NetBSD__
31 static void addr_to_string(
struct sockaddr_storage *ss,
char *
buffer,
int buflen) {
32 char buffer2[INET6_ADDRSTRLEN];
38 switch (ss->ss_family) {
51 sizeof(buffer2)) !=
NULL) {
66 #if __KFBSD__ || __NetBSD__
68 struct ptrace_lwpinfo linfo = { 0 };
70 int ret =
ptrace(PT_LWPINFO,
dbg->
pid, (
char *)&linfo,
sizeof(linfo));
81 if (linfo.pl_event == PL_EVENT_NONE) {
87 siginfo = linfo.pl_siginfo;
89 struct ptrace_siginfo sinfo = { 0 };
90 if (
ptrace(PT_GET_SIGINFO,
dbg->
pid, (
char *)&sinfo,
sizeof(sinfo)) == -1) {
99 siginfo = sinfo.psi_siginfo;
127 #if __KFBSD__ || __NetBSD__
136 return (
r == 0 ?
true :
false);
140 #if defined(__NetBSD__)
142 #elif defined(__FreeBSD__) && __FreeBSD_version >= 1400030
143 struct ptrace_coredump
pc = { .pc_fd =
dest->fd, .pc_flags = PC_ALL, .pc_limit = 0 };
151 struct kinfo_proc *kp;
157 if (!(kp = kinfo_getproc(
dbg->
pid))) {
164 rdi->uid = kp->ki_uid;
165 rdi->gid = kp->ki_pgid;
168 switch (kp->ki_stat) {
192 struct kinfo_proc *kp;
193 char err[_POSIX2_LINE_MAX];
206 kp = kvm_getprocs(kd, KERN_PROC_PID,
dbg->
pid,
sizeof(*kp), &rc);
210 rdi->uid = kp->p_uid;
211 rdi->gid = kp->p__pgid;
216 if (kp->p_psflags & PS_ZOMBIE) {
218 }
else if (kp->p_psflags & PS_STOPPED) {
220 }
else if (kp->p_psflags & PS_PPWAIT) {
222 }
else if ((kp->p_psflags & PS_EXEC) || (kp->p_psflags & PS_INEXEC)) {
231 struct kinfo_proc2 *kp;
232 char err[_POSIX2_LINE_MAX];
245 kp = kvm_getproc2(kd, KERN_PROC_PID,
dbg->
pid,
sizeof(*kp), &np);
249 rdi->uid = kp->p_uid;
250 rdi->gid = kp->p__pgid;
255 switch (kp->p_stat) {
284 #define KVM_OPEN_FLAG KVM_NO_FILES
285 #define KVM_GETPROCS(kd, opt, arg, cntptr) \
286 kvm_getproc2(kd, opt, arg, sizeof(struct kinfo_proc2), cntptr)
287 #define KP_COMM(x) (x)->p_comm
288 #define KP_PID(x) (x)->p_pid
289 #define KP_PPID(x) (x)->p_ppid
290 #define KP_UID(x) (x)->p_uid
291 #define KINFO_PROC kinfo_proc2
292 #elif defined(__OpenBSD__)
293 #define KVM_OPEN_FLAG KVM_NO_FILES
294 #define KVM_GETPROCS(kd, opt, arg, cntptr) \
295 kvm_getprocs(kd, opt, arg, sizeof(struct kinfo_proc), cntptr)
296 #define KP_COMM(x) (x)->p_comm
297 #define KP_PID(x) (x)->p_pid
298 #define KP_PPID(x) (x)->p_ppid
299 #define KP_UID(x) (x)->p_uid
300 #define KINFO_PROC kinfo_proc
302 #define KVM_OPEN_FLAG O_RDONLY
303 #define KVM_GETPROCS(kd, opt, arg, cntptr) \
304 kvm_getprocs(kd, opt, arg, cntptr)
305 #define KP_COMM(x) (x)->kp_comm
306 #define KP_PID(x) (x)->kp_pid
307 #define KP_PPID(x) (x)->kp_ppid
308 #define KP_UID(x) (x)->kp_uid
309 #define KINFO_PROC kinfo_proc
311 #define KVM_OPEN_FLAG O_RDONLY
312 #define KVM_GETPROCS(kd, opt, arg, cntptr) \
313 kvm_getprocs(kd, opt, arg, cntptr)
314 #define KP_COMM(x) (x)->ki_comm
315 #define KP_PID(x) (x)->ki_pid
316 #define KP_PPID(x) (x)->ki_ppid
317 #define KP_UID(x) (x)->ki_uid
318 #define KINFO_PROC kinfo_proc
320 char errbuf[_POSIX2_LINE_MAX];
321 struct KINFO_PROC *kp, *
entry;
326 kvm_t *kd = kvm_openfiles(
NULL,
"/dev/null",
NULL, KVM_OPEN_FLAG, errbuf);
328 kvm_t *kd = kvm_openfiles(
NULL,
NULL,
NULL, KVM_OPEN_FLAG, errbuf);
331 eprintf(
"kvm_openfiles failed: %s\n", errbuf);
335 kp = KVM_GETPROCS(kd, KERN_PROC_PROC, 0, &cnt);
336 for (
i = 0;
i < cnt;
i++) {
358 struct kinfo_vmentry *kve;
365 mib[2] = KERN_PROC_VMMAP;
375 if (sysctl(mib, 4,
buf, &
len,
NULL, 0) != 0) {
387 kve = (
struct kinfo_vmentry *)(
uintptr_t)bp;
389 kve->kve_end, kve->kve_protection, 0);
393 bp += kve->kve_structsize;
400 struct kinfo_vmentry
entry;
407 mib[1] = KERN_PROC_VMMAP;
412 eprintf(
"Could not get memory map: %s\n", strerror(errno));
421 if (old_end ==
entry.kve_end) {
429 entry.kve_protection, 0);
435 old_end =
entry.kve_end;
447 int perm,
type, mib[4];
451 struct kinfo_file *kve;
456 mib[2] = KERN_PROC_FILEDESC;
466 if (sysctl(mib, 4,
buf, &
len,
NULL, 0) != 0) {
479 kve = (
struct kinfo_file *)(
uintptr_t)bp;
480 bp += kve->kf_structsize;
484 switch (kve->kf_type) {
485 case KF_TYPE_VNODE:
type =
'v';
break;
488 #if __FreeBSD_version < 1200031
489 if (kve->kf_sock_domain ==
AF_LOCAL) {
493 addr_to_string(&kve->kf_sa_local,
path,
sizeof(
path));
495 addr_to_string(&kve->kf_sa_peer,
path,
sizeof(
path));
497 addr_to_string(&kve->kf_sa_local,
path,
sizeof(
path));
499 addr_to_string(&kve->kf_sa_peer,
path + strlen(
path),
503 if (kve->kf_sock_domain ==
AF_LOCAL) {
505 (
struct sockaddr_un *)&kve->kf_un.kf_sock.kf_sa_local;
508 addr_to_string(&kve->kf_un.kf_sock.kf_sa_local,
path,
sizeof(
path));
510 addr_to_string(&kve->kf_un.kf_sock.kf_sa_peer,
path,
sizeof(
path));
512 addr_to_string(&kve->kf_un.kf_sock.kf_sa_local,
path,
sizeof(
path));
514 addr_to_string(&kve->kf_un.kf_sock.kf_sa_peer,
path + strlen(
path),
520 case KF_TYPE_PIPE:
type =
'p';
break;
521 case KF_TYPE_FIFO:
type =
'f';
break;
522 case KF_TYPE_KQUEUE:
type =
'k';
break;
523 #if __FreeBSD_version < 1300130
525 case KF_TYPE_CRYPTO:
type =
'c';
break;
527 case KF_TYPE_MQUEUE:
type =
'm';
break;
528 case KF_TYPE_SHM:
type =
'h';
break;
529 case KF_TYPE_PTS:
type =
't';
break;
530 case KF_TYPE_SEM:
type =
'e';
break;
532 case KF_TYPE_UNKNOWN:
533 default:
type =
'-';
break;
535 perm = (kve->kf_flags & KF_FLAG_READ) ?
RZ_PERM_R : 0;
536 perm |= (kve->kf_flags & KF_FLAG_WRITE) ?
RZ_PERM_W : 0;
557 if (!(
dd = opendir(
path))) {
567 if (de->
d_name[0] ==
'.') {
571 len2 = strlen(de->
d_name);
572 if (
len + len2 + 1 >=
sizeof(
file)) {
586 type = st.st_mode & S_IFIFO ?
'P' : st.st_mode & S_IFSOCK ?
'S'
587 : st.st_mode & S_IFCHR ?
'C'
590 if (lstat(
path, &st) != -1) {
591 if (st.st_mode & S_IRUSR) {
594 if (st.st_mode & S_IWUSR) {
618 static int get_rz_status(
int stat) {
639 int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PID | KERN_PROC_INC_THREAD,
pid };
640 struct kinfo_proc *kp;
650 len +=
sizeof(*kp) +
len / 10;
652 if (sysctl(mib, 4, kp, &
len,
NULL, 0) == -1) {
659 for (
i = 0;
i <
max;
i++) {
663 pid_stat = get_rz_status(kp[
i].ki_stat);
665 kp[
i].ki_uid, pid_stat, (
ut64)kp[
i].ki_wchan);
672 eprintf(
"bsd_thread_list unsupported on this platform\n");
RzList * bsd_desc_list(int pid)
int bsd_handle_signals(RzDebug *dbg)
RzList * bsd_pid_list(RzDebug *dbg, int pid, RzList *list)
RzList * bsd_native_sysctl_map(RzDebug *dbg)
int bsd_reg_write(RzDebug *dbg, int type, const ut8 *buf, int size)
RzList * bsd_thread_list(RzDebug *dbg, int pid, RzList *list)
bool bsd_generate_corefile(RzDebug *dbg, char *path, RzBuffer *dest)
RzDebugInfo * bsd_info(RzDebug *dbg, const char *arg)
static static fork const void static count static fd const char const char static newpath const char static path const char path
static static sync static getppid static getegid const char static filename char static len readlink
RZ_API RzDebugDesc * rz_debug_desc_new(int fd, char *path, int perm, int type, int off)
RZ_API void rz_debug_desc_free(RzDebugDesc *p)
RZ_API RzList * rz_debug_map_list_new(void)
RZ_API RzDebugMap * rz_debug_map_new(char *name, ut64 addr, ut64 addr_end, int perm, int user)
size_t map(int syms, int left, int len)
RZ_API void Ht_() free(HtName_(Ht) *ht)
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_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
RZ_API RZ_OWN RzList * rz_list_new(void)
Returns a new initialized RzList pointer (free method is not initialized)
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 * malloc(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 static fork const void static count static fd const char static mode const char static pathname const char static path const char static dev const char static group static getpid static getuid void void static data static pause const char static mode static sync const char const char static newpath const char static pathname unsigned long static filedes void static end_data_segment static handler static getegid char static len static pgid const char static path static newfd static getpgrp static euid const sigset_t static mask const char static len const gid_t static list const char const char static newpath const char static library readdir
static static fork const void static count static fd const char static mode const char static pathname const char static path const char static dev const char static group static getpid static getuid ptrace
RZ_API RzDebugPid * rz_debug_pid_new(const char *path, int pid, int uid, char status, ut64 pc)
@ RZ_DEBUG_REASON_BREAKPOINT
@ RZ_DEBUG_REASON_SEGFAULT
void(* RzListFree)(void *ptr)
#define RZ_LOG_ERROR(fmtstr,...)
#define rz_strf(buf,...)
Convenience macro for local temporary strings.
_W64 unsigned int uintptr_t
struct in6_addr sin6_addr
if(dbg->bits==RZ_SYS_BITS_64)
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static const z80_opcode dd[]