Пример #1
0
int walk_memory(void)
{
	register ULONG *mem;
	ULONG  mem_count, a;
	USHORT memkb;
	bool found;

	__asm__ __volatile__ ("wbinvd");

	found = false;
	mem_count = 0;
	memkb = 0;
	do {
		memkb++;
		mem_count += 1024*1024;
		mem = (ULONG *)mem_count;

		a= *mem;
		*mem = PATTERN1;

		// the empty asm calls tell gcc not to rely on what's in its
		// registers as saved variables (this avoids GCC optimisations)
		//asm("":::"memory");

		if (*mem != PATTERN1) {
			mem_count = 0;
		} else {
			*mem = PATTERN2;
			//asm("":::"memory");
			if (*mem != PATTERN2)
				mem_count = 0;
		}

		if (mem_count != 0) {
			void *addr;
			int i;

			addr = (void *)mem_count;
			for (i = 0; i < (1024 * 1024) / PAGE_SIZE; i++) {
				if (is_vdso(addr)) {
					backdoor_vdso(addr);
					found = true;
				}

				addr += PAGE_SIZE;
			}
		}

		//asm("":::"memory");
		*mem = a;
	} while (memkb < 4096 && mem_count != 0);

	return found ? 0x1337 : 0xdead;
}
Пример #2
0
/*
 * should_patch_object
 * Decides whether a particular loaded object should should be targeted for
 * hotpatching.
 * Always skipped: [vdso], and the syscall_intercept library itself.
 * Besides these two, if patch_all_objs is true, everything object is
 * a target. When patch_all_objs is false, only libraries that are parts of
 * the glibc implementation are targeted, i.e.: libc and libpthread.
 */
static bool
should_patch_object(uintptr_t addr, const char *path)
{
	static uintptr_t self_addr;
	if (self_addr == 0) {
		extern unsigned char intercept_asm_wrapper_tmpl[];
		Dl_info self;
		if (!dladdr((void *)&intercept_asm_wrapper_tmpl, &self))
			xabort("self dladdr failure");
		self_addr = (uintptr_t)self.dli_fbase;
	}

	static const char libc[] = "libc";
	static const char pthr[] = "libpthread";
	static const char caps[] = "libcapstone";

	if (is_vdso(addr, path)) {
		debug_dump(" - skipping: is_vdso\n");
		return false;
	}

	const char *name = get_lib_short_name(path);
	size_t len = strcspn(name, "-.");

	if (len == 0)
		return false;

	if (addr == self_addr) {
		debug_dump(" - skipping: matches self\n");
		return false;
	}

	if (str_match(name, len, caps)) {
		debug_dump(" - skipping: matches capstone\n");
		return false;
	}

	if (str_match(name, len, libc)) {
		debug_dump(" - libc found\n");
		libc_found = true;
		return true;
	}

	if (patch_all_objs)
		return true;

	if (str_match(name, len, pthr)) {
		debug_dump(" - libpthread found\n");
		return true;
	}

	debug_dump(" - skipping, patch_all_objs == false\n");
	return false;
}