Esempio n. 1
0
static pid_list *scan_pid_maps(const char *fname, pid_t pid,
				inode_list *ilist, pid_list *plist)
{
	FILE *file;
	char line[MAX_LINE + 1];
	int major, minor;
	ino_t inode;
	long long uint64_inode;
	dev_t dev;

	file = fopen_for_read(fname);
	if (!file)
		return plist;
	while (fgets(line, MAX_LINE, file)) {
		if (sscanf(line, "%*s %*s %*s %x:%x %llu", &major, &minor, &uint64_inode) != 3)
			continue;
		inode = uint64_inode;
		if (major == 0 && minor == 0 && inode == 0)
			continue;
		dev = makedev(major, minor);
		if (search_dev_inode(ilist, dev, inode))
			plist = add_pid(plist, pid);
	}
	fclose(file);
	return plist;
}
Esempio n. 2
0
static void scan_link(const char *lname, pid_t pid)
{
	struct stat st;

	if (stat(lname, &st) >= 0) {
		if (search_dev_inode(&st))
			add_pid(pid);
	}
}
Esempio n. 3
0
static pid_list *scan_link(const char *lname, pid_t pid,
				inode_list *ilist, pid_list *plist)
{
	ino_t inode;
	dev_t dev;

	if (!file_to_dev_inode(lname, &dev, &inode))
		return plist;
	if (search_dev_inode(ilist, dev, inode))
		plist = add_pid(plist, pid);
	return plist;
}
Esempio n. 4
0
static void scan_pid_maps(const char *fname, pid_t pid)
{
	FILE *file;
	char line[MAX_LINE + 1];
	int major, minor;
	long long uint64_inode;
	struct stat st;

	file = fopen_for_read(fname);
	if (!file)
		return;

	while (fgets(line, MAX_LINE, file)) {
		if (sscanf(line, "%*s %*s %*s %x:%x %llu", &major, &minor, &uint64_inode) != 3)
			continue;
		st.st_ino = uint64_inode;
		if (major == 0 && minor == 0 && st.st_ino == 0)
			continue;
		st.st_dev = makedev(major, minor);
		if (search_dev_inode(&st))
			add_pid(pid);
	}
	fclose(file);
}
Esempio n. 5
0
static smallint scan_proc_net_or_maps(const char *path, unsigned port)
{
	FILE *f;
	char line[MAX_LINE + 1], addr[68];
	int major, minor, r;
	long long uint64_inode;
	unsigned tmp_port;
	smallint retval;
	struct stat statbuf;
	const char *fmt;
	void *f*g, *sag;

	f = fopen_for_read(path);
	if (!f)
		return 0;

	if (G.recursion_depth == PROC_NET) {
		int fd;

		/* find socket dev */
		statbuf.st_dev = 0;
		fd = socket(AF_INET, SOCK_DGRAM, 0);
		if (fd >= 0) {
			fstat(fd, &statbuf);
			close(fd);
		}

		fmt = "%*d: %64[0-9A-Fa-f]:%x %*x:%*x %*x "
			"%*x:%*x %*x:%*x %*x %*d %*d %llu";
		f*g = addr;
		sag = &tmp_port;
	} else {
		fmt = "%*s %*s %*s %x:%x %llu";
		f*g = &major;
		sag = &minor;
	}

	retval = 0;
	while (fgets(line, MAX_LINE, f)) {
		r = sscanf(line, fmt, f*g, sag, &uint64_inode);
		if (r != 3)
			continue;

		statbuf.st_ino = uint64_inode;
		if (G.recursion_depth == PROC_NET) {
			r = strlen(addr);
			if (r == 8 && (option_mask32 & OPT_IP6))
				continue;
			if (r > 8 && (option_mask32 & OPT_IP4))
				continue;
			if (tmp_port == port)
				add_inode(&statbuf);
		} else {
			if (major != 0 && minor != 0 && statbuf.st_ino != 0) {
				statbuf.st_dev = makedev(major, minor);
				retval = search_dev_inode(&statbuf);
				if (retval)
					break;
			}
		}
	}
	fclose(f);

	return retval;
}
Esempio n. 6
0
static smallint scan_recursive(const char *path)
{
	DIR *d;
	struct dirent *d_ent;
	smallint stop_scan;
	smallint retval;

	d = opendir(path);
	if (d == NULL)
		return 0;

	G.recursion_depth++;
	retval = 0;
	stop_scan = 0;
	while (!stop_scan && (d_ent = readdir(d)) != NULL) {
		struct stat statbuf;
		pid_t pid;
		char *subpath;

		subpath = concat_subpath_file(path, d_ent->d_name);
		if (subpath == NULL)
			continue; /* . or .. */

		switch (G.recursion_depth) {
		case PROC_DIR:
			pid = (pid_t)bb_strtou(d_ent->d_name, NULL, 10);
			if (errno != 0
			 || pid == G.mypid
			/* "this PID doesn't use specified FILEs or PORT/PROTO": */
			 || scan_recursive(subpath) == 0
			) {
				break;
			}
			if (option_mask32 & OPT_KILL) {
				if (kill(pid, G.killsig) != 0) {
					bb_perror_msg("kill pid %s", d_ent->d_name);
					G.kill_failed = 1;
				}
			}
			if (!(option_mask32 & OPT_SILENT))
				printf("%s ", d_ent->d_name);
			retval = 1;
			break;

		case PROC_DIR_LINKS:
			switch (
				index_in_substrings(
					"cwd"  "\0" "exe"  "\0"
					"root" "\0" "fd"   "\0"
					"lib"  "\0" "mmap" "\0"
					"maps" "\0",
					d_ent->d_name
				)
			) {
			enum {
				CWD_LINK,
				EXE_LINK,
				ROOT_LINK,
				FD_DIR_LINKS,
				LIB_DIR_LINKS,
				MMAP_DIR_LINKS,
				MAPS,
			};
			case CWD_LINK:
			case EXE_LINK:
			case ROOT_LINK:
				goto scan_link;
			case FD_DIR_LINKS:
			case LIB_DIR_LINKS:
			case MMAP_DIR_LINKS:
				// change for ofgwrite
				retval = scan_recursive(subpath);
				break;
			case MAPS:
				// change for ofgwrite
				retval = scan_proc_net_or_maps(subpath, 0);
			default:
				break;
			}
			break;
		case PROC_SUBDIR_LINKS:
  scan_link:
			if (stat(subpath, &statbuf) < 0)
				break;
			// change for ofgwrite
			retval = search_dev_inode(&statbuf);
			if (retval)
			{
				if (strcmp(d_ent->d_name, "exe") == 0)
				{
					char* ln = xmalloc_readlink(subpath);
					if (ln != NULL)
					{
						// change for ofgwrite: Don't kill VU+ and GB specific processes
						if (strcmp(ln, "/oldroot/usr/bin/dvb_server") == 0
							|| strcmp(ln, "/oldroot/usr/bin/init_client") == 0
							|| strcmp(ln, "/oldroot/usr/bin/ntfs-3g") == 0
							|| strcmp(ln, "/oldroot/usr/share/platform/dvb_init") == 0
							|| strcmp(ln, "/oldroot/usr/bin/nxserver") == 0
							|| strcmp(ln, "/oldroot/usr/bin/init_driver") == 0
							|| strcmp(ln, "/oldroot/usr/share/platform/dvb_init.bin") == 0
							|| strcmp(ln, "/oldroot/usr/share/platform/nxserver") == 0
							|| strcmp(ln, "/oldroot/usr/bin/showiframe") == 0
							|| strcmp(ln, "/oldroot/usr/bin/libreader") == 0
							|| ( strncmp(ln, "/oldroot/lib/modules/", 21) == 0
								&& strstr(ln, "/extra/hi_play.ko") != NULL )
						   )
						{
							my_printf("found vu or gb or octagon or ntfs process %s -> don't kill\n", ln);
							retval = 0;
							stop_scan=1;
						}
						free(ln);
					}
				}
			}
		default:
			break;
		}
		free(subpath);
	}
	closedir(d);
	G.recursion_depth--;
	return retval;
}