Example #1
0
/*
 * dump the binary into the allocated buffer
 * we dump each segment and advance the buffer
 */
static void dump_binary(mach_vm_address_t address, pid_t pid, void *buffer)
{
#if DEBUG
    printf("[DEBUG] Executing %s\n", __FUNCTION__);
#endif
    vm_region_basic_info_data_64_t region_info;
    // allocate a buffer to read the header info
    struct mach_header header;
    readmem((mach_vm_offset_t*)&header, address, sizeof(struct mach_header), pid, &region_info);
    
    if (header.magic != MH_MAGIC && header.magic != MH_MAGIC_64)
    {
		printf("[ERROR] Target is not a mach-o binary!\n");
        exit(1);
    }
    
    mach_vm_address_t imagefilesize = 0;
    
    // read the header info to find the LINKEDIT
    uint8_t *loadcmds = malloc(header.sizeofcmds*sizeof(uint8_t));
    readmem((mach_vm_offset_t*)loadcmds, address+sizeof(struct mach_header), header.sizeofcmds, pid, &region_info);
    // process and retrieve address and size of linkedit
    uint8_t *loadCmdAddress = 0;
    // first load cmd address
    loadCmdAddress = (uint8_t*)loadcmds;
    struct load_command *loadCommand    = NULL;
    struct segment_command *segCmd      = NULL;
    struct segment_command_64 *segCmd64 = NULL;
    // process commands to find the info we need

    for (uint32_t i = 0; i < header.ncmds; i++)
    {
        loadCommand = (struct load_command*)loadCmdAddress;
        // 32bits and 64 bits segment commands
        // LC_LOAD_DYLIB to find the ordinal
        if (loadCommand->cmd == LC_SEGMENT)
        {
            segCmd = (struct segment_command*)loadCmdAddress;
            if (strcmp((char*)(segCmd->segname), "__PAGEZERO") != 0)
            {
                readmem(buffer, segCmd->vmaddr, segCmd->filesize, pid, &region_info);
            }
            buffer += segCmd->filesize;
        }
        else if (loadCommand->cmd == LC_SEGMENT_64)
        {
            segCmd64 = (struct segment_command_64*)loadCmdAddress;
            if (strcmp((char*)(segCmd64->segname), "__PAGEZERO") != 0)
            {
                imagefilesize += segCmd64->filesize;
            }
            buffer += segCmd->filesize;
        }
        // advance to next command
        loadCmdAddress += loadCommand->cmdsize;
    }
    free(loadcmds);
}
Example #2
0
/*
 * for Xen extraction
 */
unsigned long long
kvtop_xen_x86_64(unsigned long kvaddr)
{
	unsigned long long dirp, entry;

	if (!is_xen_vaddr(kvaddr))
		return NOT_PADDR;

	if (is_xen_text(kvaddr))
		return (unsigned long)kvaddr - XEN_VIRT_START + info->xen_phys_start;

	if (is_direct(kvaddr))
		return (unsigned long)kvaddr - DIRECTMAP_VIRT_START;

	if ((dirp = kvtop_xen_x86_64(SYMBOL(pgd_l4))) == NOT_PADDR)
		return NOT_PADDR;
	dirp += pml4_index(kvaddr) * sizeof(unsigned long long);
	if (!readmem(MADDR_XEN, dirp, &entry, sizeof(entry)))
		return NOT_PADDR;

	if (!(entry & _PAGE_PRESENT))
		return NOT_PADDR;

	dirp = entry & ENTRY_MASK;
	dirp += pgd_index(kvaddr) * sizeof(unsigned long long);
	if (!readmem(MADDR_XEN, dirp, &entry, sizeof(entry)))
		return NOT_PADDR;

	if (!(entry & _PAGE_PRESENT))
		return NOT_PADDR;

	dirp = entry & ENTRY_MASK;
	dirp += pmd_index(kvaddr) * sizeof(unsigned long long);
	if (!readmem(MADDR_XEN, dirp, &entry, sizeof(entry)))
		return NOT_PADDR;

	if (!(entry & _PAGE_PRESENT))
		return NOT_PADDR;

	if (entry & _PAGE_PSE) {
		entry = (entry & ENTRY_MASK) + (kvaddr & ((1UL << PMD_SHIFT) - 1));
		return entry;
	}
	dirp = entry & ENTRY_MASK;
	dirp += pte_index(kvaddr) * sizeof(unsigned long long);
	if (!readmem(MADDR_XEN, dirp, &entry, sizeof(entry)))
		return NOT_PADDR;

	if (!(entry & _PAGE_PRESENT)) {
		return NOT_PADDR;
	}

	entry = (entry & ENTRY_MASK) + (kvaddr & ((1UL << PTE_SHIFT) - 1));

	return entry;
}
Example #3
0
File: x86.c Project: karibou/progit
int
get_machdep_info_x86(void)
{
	unsigned long vmlist, vmalloc_start;

	/* PAE */
	if ((vt.mem_flags & MEMORY_X86_PAE)
	    || ((SYMBOL(pkmap_count) != NOT_FOUND_SYMBOL)
	      && (SYMBOL(pkmap_count_next) != NOT_FOUND_SYMBOL)
	      && ((SYMBOL(pkmap_count_next)-SYMBOL(pkmap_count))/sizeof(int))
	      == 512)) {
		DEBUG_MSG("\n");
		DEBUG_MSG("PAE          : ON\n");
		vt.mem_flags |= MEMORY_X86_PAE;
		info->max_physmem_bits  = _MAX_PHYSMEM_BITS_PAE;
	} else {
		DEBUG_MSG("\n");
		DEBUG_MSG("PAE          : OFF\n");
		info->max_physmem_bits  = _MAX_PHYSMEM_BITS;
	}
	info->page_offset = __PAGE_OFFSET;

	if (SYMBOL(_stext) == NOT_FOUND_SYMBOL) {
		ERRMSG("Can't get the symbol of _stext.\n");
		return FALSE;
	}
	info->kernel_start = SYMBOL(_stext) & ~KVBASE_MASK;
	DEBUG_MSG("kernel_start : %lx\n", info->kernel_start);

	if (!remap_init())
		return FALSE;

	/*
	 * For the compatibility, makedumpfile should run without the symbol
	 * vmlist and the offset of vm_struct.addr if they are not necessary.
	 */
	if ((SYMBOL(vmlist) == NOT_FOUND_SYMBOL)
	    || (OFFSET(vm_struct.addr) == NOT_FOUND_STRUCTURE)) {
		return TRUE;
	}
	if (!readmem(VADDR, SYMBOL(vmlist), &vmlist, sizeof(vmlist))) {
		ERRMSG("Can't get vmlist.\n");
		return FALSE;
	}
	if (!readmem(VADDR, vmlist + OFFSET(vm_struct.addr), &vmalloc_start,
	    sizeof(vmalloc_start))) {
		ERRMSG("Can't get vmalloc_start.\n");
		return FALSE;
	}
	info->vmalloc_start = vmalloc_start;
	DEBUG_MSG("vmalloc_start: %lx\n", vmalloc_start);

	return TRUE;
}
Example #4
0
File: x86.c Project: karibou/progit
unsigned long long
vtop_x86_PAE(unsigned long vaddr)
{
	unsigned long long page_dir, pgd_pte, pmd_paddr, pmd_pte;
	unsigned long long pte_paddr, pte;

	if (SYMBOL(swapper_pg_dir) == NOT_FOUND_SYMBOL) {
		ERRMSG("Can't get the symbol of swapper_pg_dir.\n");
		return NOT_PADDR;
	}

	page_dir  = SYMBOL(swapper_pg_dir);
	page_dir += pgd_index_PAE(vaddr) * sizeof(unsigned long long);
	if (!readmem(VADDR, page_dir, &pgd_pte, sizeof(pgd_pte))) {
		ERRMSG("Can't get pgd_pte (page_dir:%llx).\n", page_dir);
		return NOT_PADDR;
	}
	if (!(pgd_pte & _PAGE_PRESENT))
		return NOT_PADDR;

	if (info->vaddr_for_vtop == vaddr)
		MSG("  PGD : %16llx => %16llx\n", page_dir, pgd_pte);

	pmd_paddr  = pgd_pte & ENTRY_MASK;
	pmd_paddr += pmd_index(vaddr) * sizeof(unsigned long long);
	if (!readmem(PADDR, pmd_paddr, &pmd_pte, sizeof(pmd_pte))) {
		ERRMSG("Can't get pmd_pte (pmd_paddr:%llx).\n", pmd_paddr);
		return NOT_PADDR;
	}
	if (!(pmd_pte & _PAGE_PRESENT))
		return NOT_PADDR;

	if (info->vaddr_for_vtop == vaddr)
		MSG("  PMD : %16llx => %16llx\n", pmd_paddr, pmd_pte);

	if (pmd_pte & _PAGE_PSE)
		return (pmd_pte & ENTRY_MASK) + (vaddr & ((1UL << PMD_SHIFT) - 1));

	pte_paddr  = pmd_pte & ENTRY_MASK;
	pte_paddr += pte_index(vaddr) * sizeof(unsigned long long);
	if (!readmem(PADDR, pte_paddr, &pte, sizeof(pte)))
		return NOT_PADDR;

	if (!(pte & _PAGE_PRESENT))
		return NOT_PADDR;

	if (info->vaddr_for_vtop == vaddr)
		MSG("  PTE : %16llx => %16llx\n", pte_paddr, pte);

	return (pte & ENTRY_MASK) + (vaddr & ((1UL << PTE_SHIFT) - 1));
}
Example #5
0
File: x86.c Project: karibou/progit
int get_xen_info_x86(void)
{
	unsigned long frame_table_vaddr;
	unsigned long xen_end;
	int i;

	if (SYMBOL(pgd_l2) == NOT_FOUND_SYMBOL &&
	    SYMBOL(pgd_l3) == NOT_FOUND_SYMBOL) {
		ERRMSG("Can't get pgd.\n");
		return FALSE;
	}

	if (SYMBOL(pgd_l3) == NOT_FOUND_SYMBOL) {
		ERRMSG("non-PAE not support right now.\n");
		return FALSE;
	}

	if (SYMBOL(frame_table) == NOT_FOUND_SYMBOL) {
		ERRMSG("Can't get the symbol of frame_table.\n");
		return FALSE;
	}
	if (!readmem(VADDR_XEN, SYMBOL(frame_table), &frame_table_vaddr,
	    sizeof(frame_table_vaddr))) {
		ERRMSG("Can't get the value of frame_table.\n");
		return FALSE;
	}
	info->frame_table_vaddr = frame_table_vaddr;

	if (SYMBOL(xenheap_phys_end) == NOT_FOUND_SYMBOL) {
		ERRMSG("Can't get the symbol of xenheap_phys_end.\n");
		return FALSE;
	}
	if (!readmem(VADDR_XEN, SYMBOL(xenheap_phys_end), &xen_end,
	    sizeof(xen_end))) {
		ERRMSG("Can't get the value of xenheap_phys_end.\n");
		return FALSE;
	}
	info->xen_heap_start = 0;
	info->xen_heap_end   = paddr_to_pfn(xen_end);

	/*
	 * pickled_id == domain addr for x86
	 */
	for (i = 0; i < info->num_domain; i++) {
		info->domain_list[i].pickled_id =
			info->domain_list[i].domain_addr;
	}

	return TRUE;
}
Example #6
0
static void get_rchan_buf(int cpu, ulong rchan)
{
	ulong rchan_buf;
	struct per_cpu_data *pcd;

	pcd = &per_cpu[cpu];
	readmem(rchan + rchan_offsets.buf + sizeof(void*) * cpu,
		KVADDR, &rchan_buf, sizeof(void*),
		"rchan.buf", FAULT_ON_ERROR);
	readmem(rchan_buf + rchan_offsets.buf_start,
		KVADDR, &pcd->buf.start, sizeof(void*),
		"rchan.buf.start", FAULT_ON_ERROR);
	if (old_format == 1) {
		readmem(rchan_buf + rchan_offsets.buf_offset,
			KVADDR, &pcd->buf.offset, sizeof(unsigned),
			"rchan.buf.offset", FAULT_ON_ERROR);
		readmem(rchan_buf + rchan_offsets.buf_subbufs_produced,
			KVADDR, &pcd->buf.subbufs_produced, sizeof(int32_t),
			"rchan.buf.subbufs_produced", FAULT_ON_ERROR);
		readmem(rchan_buf + rchan_offsets.buf_padding,
			KVADDR, &pcd->buf.padding, sizeof(unsigned*),
			"rchan.buf.padding", FAULT_ON_ERROR);
	} else {
		readmem(rchan_buf + rchan_offsets.buf_offset,
			KVADDR, &pcd->buf.offset, sizeof(size_t),
			"rchan.buf.offset", FAULT_ON_ERROR);
		readmem(rchan_buf + rchan_offsets.buf_subbufs_produced,
			KVADDR, &pcd->buf.subbufs_produced, sizeof(size_t),
			"rchan.buf.subbufs_produced", FAULT_ON_ERROR);
		readmem(rchan_buf + rchan_offsets.buf_padding,
			KVADDR, &pcd->buf.padding, sizeof(size_t*),
			"rchan.buf.padding", FAULT_ON_ERROR);
	}
	return;
}
Example #7
0
void VZ89::readRaw(uint8_t rawData[6]) {
	static uint8_t buff[6];
	memset(buff, 0, sizeof(buff));

	//read raw temperature
	readmem(VZ89_CMD_GETSTATUS, rawData, 6);
}
Example #8
0
static int
cmd_readmem_run( chain_t *chain, char *params[] )
{
	uint32_t adr;
	uint32_t len;
	FILE *f;

	if (cmd_params( params ) != 4)
		return -1;

	if (!bus) {
		printf( _("Error: Bus driver missing.\n") );
		return 1;
	}

	if (cmd_get_number( params[1], &adr) || cmd_get_number( params[2], &len))
		return -1;

	f = fopen( params[3], "w" );
	if (!f) {
		printf( _("Unable to create file `%s'!\n"), params[3] );
		return 1;
	}
	readmem( bus, f, adr, len );
	fclose( f );

	return 1;
}
Example #9
0
void ADXL345::readAccRaw(int *_AccX, int *_AccY, int *_AccZ)
{
  readmem(DATAX0, 6, &_buff[0]);
  *_AccX = _buff[1] << 8 | _buff[0];
  *_AccY = _buff[3] << 8 | _buff[2];
  *_AccZ = _buff[5] << 8 | _buff[4];
}
Example #10
0
int get_xen_basic_info_x86(void)
{
	if (SYMBOL(pgd_l2) == NOT_FOUND_SYMBOL &&
	    SYMBOL(pgd_l3) == NOT_FOUND_SYMBOL) {
		ERRMSG("Can't get pgd.\n");
		return FALSE;
	}

	if (SYMBOL(pgd_l3) == NOT_FOUND_SYMBOL) {
		ERRMSG("non-PAE not support right now.\n");
		return FALSE;
	}

	if (SYMBOL(frame_table) != NOT_FOUND_SYMBOL) {
		unsigned long frame_table_vaddr;

		if (!readmem(VADDR_XEN, SYMBOL(frame_table),
		    &frame_table_vaddr, sizeof(frame_table_vaddr))) {
			ERRMSG("Can't get the value of frame_table.\n");
			return FALSE;
		}
		info->frame_table_vaddr = frame_table_vaddr;
	} else
		info->frame_table_vaddr = FRAMETABLE_VIRT_START;

	if (!info->xen_crash_info.com ||
	    info->xen_crash_info.com->xen_major_version < 4) {
		unsigned long xen_end;

		if (SYMBOL(xenheap_phys_end) == NOT_FOUND_SYMBOL) {
			ERRMSG("Can't get the symbol of xenheap_phys_end.\n");
			return FALSE;
		}
		if (!readmem(VADDR_XEN, SYMBOL(xenheap_phys_end), &xen_end,
		    sizeof(xen_end))) {
			ERRMSG("Can't get the value of xenheap_phys_end.\n");
			return FALSE;
		}
		info->xen_heap_start = 0;
		info->xen_heap_end   = paddr_to_pfn(xen_end);
	}

	return TRUE;
}
Example #11
0
static int
remap_init(void)
{
	int n;

	if (SYMBOL(node_remap_start_vaddr) == NOT_FOUND_SYMBOL)
		return TRUE;
	if (SYMBOL(node_remap_end_vaddr) == NOT_FOUND_SYMBOL)
		return TRUE;
	if (SYMBOL(node_remap_start_pfn) == NOT_FOUND_SYMBOL)
		return TRUE;
	if (ARRAY_LENGTH(node_remap_start_pfn) == NOT_FOUND_STRUCTURE)
		return TRUE;

	n = ARRAY_LENGTH(node_remap_start_pfn);
	remap_start_vaddr = calloc(3 * n, sizeof(unsigned long));
	if (!remap_start_vaddr) {
		ERRMSG("Can't allocate remap allocator info.\n");
		return FALSE;
	}
	remap_end_vaddr = remap_start_vaddr + n;
	remap_start_pfn = remap_end_vaddr + n;

	if (!readmem(VADDR, SYMBOL(node_remap_start_vaddr), remap_start_vaddr,
		     n * sizeof(unsigned long))) {
		ERRMSG("Can't get node_remap_start_vaddr.\n");
		return FALSE;
	}
	if (!readmem(VADDR, SYMBOL(node_remap_end_vaddr), remap_end_vaddr,
		     n * sizeof(unsigned long))) {
		ERRMSG("Can't get node_remap_end_vaddr.\n");
		return FALSE;
	}
	if (!readmem(VADDR, SYMBOL(node_remap_start_pfn), remap_start_pfn,
		     n * sizeof(unsigned long))) {
		ERRMSG("Can't get node_remap_start_pfn.\n");
		return FALSE;
	}

	max_numnodes = n;
	return TRUE;
}
Example #12
0
/* Read a num/string to user mode, accounting for offset.  Not a huge fan of the
 * 'size' parameter (the old plan9 users just picked NUMSIZE (12), though they
 * seem to want to limit it).  */
int readnum(unsigned long off, char *buf, unsigned long n, unsigned long val,
            size_t size)
{
    char tmp[64];
    size = MIN(sizeof(tmp), size);
    /* we really need the %* format. */
    size = snprintf(tmp, size, "%lu", val);
    /* size is now strlen, so the rest of this is just like readstr. */
    /* always include the \0 */
    return readmem(off, buf, n, tmp, size + 1);
}
Example #13
0
static long ver_emit_nlstr(char *dest, const char *src, long size,
						   long offset)
{
	long n, slen = strlen(src);
	char *buf = kmalloc(slen + 1, MEM_WAIT);

	snprintf(buf, slen + 1, "%s", src);
	n = readmem(offset, dest, size, buf, slen + 1);
	kfree(buf);

	return n;
}
Example #14
0
int
get_machdep_info_ppc(void)
{
	unsigned long vmlist, vmalloc_start;

	info->section_size_bits = _SECTION_SIZE_BITS;
	info->max_physmem_bits  = _MAX_PHYSMEM_BITS;
	info->page_offset = __PAGE_OFFSET;

	if (SYMBOL(_stext) != NOT_FOUND_SYMBOL)
		info->kernel_start = SYMBOL(_stext);
	else {
		ERRMSG("Can't get the symbol of _stext.\n");
		return FALSE;
	}
		
	DEBUG_MSG("kernel_start : %lx\n", info->kernel_start);

	/*
	 * For the compatibility, makedumpfile should run without the symbol
	 * vmlist and the offset of vm_struct.addr if they are not necessary.
	 */
	if ((SYMBOL(vmlist) == NOT_FOUND_SYMBOL)
	    || (OFFSET(vm_struct.addr) == NOT_FOUND_STRUCTURE)) {
		return TRUE;
	}
	if (!readmem(VADDR, SYMBOL(vmlist), &vmlist, sizeof(vmlist))) {
		ERRMSG("Can't get vmlist.\n");
		return FALSE;
	}
	if (!readmem(VADDR, vmlist + OFFSET(vm_struct.addr), &vmalloc_start,
	    sizeof(vmalloc_start))) {
		ERRMSG("Can't get vmalloc_start.\n");
		return FALSE;
	}
	info->vmalloc_start = vmalloc_start;
	DEBUG_MSG("vmalloc_start: %lx\n", vmalloc_start);

	return TRUE;
}
Example #15
0
static int check_global_buffer(ulong rchan)
{
	int cpu;
	ulong rchan_buf[2];

	for (cpu = 0; cpu < 2; cpu++) {
		readmem(rchan + rchan_offsets.buf + sizeof(void*) * cpu,
			KVADDR, &rchan_buf[cpu], sizeof(void*),
			"rchan.buf", FAULT_ON_ERROR);
	}
	if (rchan_buf[0] == rchan_buf[1])
		return 1;
	return 0;
}
Example #16
0
static ulong get_rchan(ulong rchan_addr)
{
	ulong rchan;

	readmem(rchan_addr, KVADDR, &rchan, sizeof(void*),
		"rchan", FAULT_ON_ERROR);
	if (old_format == 1) {
		readmem(rchan + rchan_offsets.subbuf_size,
			KVADDR, &chan.subbuf_size, sizeof(unsigned),
			"rchan.subbuf_size", FAULT_ON_ERROR);
		readmem(rchan + rchan_offsets.n_subbufs,
			KVADDR, &chan.n_subbufs, sizeof(unsigned),
			"rchan.n_subbufs", FAULT_ON_ERROR);
	} else {
		readmem(rchan + rchan_offsets.subbuf_size,
			KVADDR, &chan.subbuf_size, sizeof(size_t),
			"rchan.subbuf_size", FAULT_ON_ERROR);
		readmem(rchan + rchan_offsets.n_subbufs,
			KVADDR, &chan.n_subbufs, sizeof(size_t),
			"rchan.n_subbufs", FAULT_ON_ERROR);
	}

	return rchan;
}
Example #17
0
static ssize_t read_buildid(void *va, long n, off64_t off)
{
	/* Each build_id byte needs 2 chars, and 1 for the \0 */
	char build_id[BUILD_ID_SZ * 2 + 1] = {0};
	uint8_t hi, lo;
	uint8_t *b = (uint8_t*)get_build_id_start();

	for (int i = 0; i < BUILD_ID_SZ; i++) {
		hi = *b >> 4;
		lo = *b & 0xf;
		build_id[i * 2 + 0] = num_to_nibble(hi);
		build_id[i * 2 + 1] = num_to_nibble(lo);
		b++;
	}
	return readmem(off, va, n, build_id, sizeof(build_id));
}
Example #18
0
void L3G4200D::readGyroRaw(int *_GyroX, int *_GyroY, int *_GyroZ){
  readmem(0x28, 1, &_buff[0]);
  readmem(0x29, 1, &_buff[1]);
  readmem(0x2A, 1, &_buff[2]);
  readmem(0x2B, 1, &_buff[3]);
  readmem(0x2C, 1, &_buff[4]);
  readmem(0x2D, 1, &_buff[5]);
  *_GyroX = (int16_t)((_buff[1] << 8) | _buff[0]);
  *_GyroY = (int16_t)((_buff[3] << 8) | _buff[2]);
  *_GyroZ = (int16_t)((_buff[5] << 8) | _buff[4]);
}
/*
 *  Versions of disk_dump that support it contain the "dump_level" symbol.
 *  Version 1 and later compressed kdump dumpfiles contain the dump level
 *  in an additional field of the sub_header_kdump structure.
 */
static int 
get_dump_level(void)
{
	int dump_level;

	if (DISKDUMP_VALID()) {
		if (symbol_exists("dump_level") &&
		    readmem(symbol_value("dump_level"), KVADDR, &dump_level,
		    sizeof(dump_level), "dump_level", QUIET|RETURN_ON_ERROR))
                 	return dump_level;
	} else if (KDUMP_CMPRS_VALID()) {
		if (dd->header->header_version >= 1)
			return dd->sub_header_kdump->dump_level;
	}

	return -1;
}
Example #20
0
/* read memory */
int SECTION(SEC_KDEBUG) rmf(bfd_vma memaddr,
	bfd_byte *myaddr, word_t length,
	struct disassemble_info *info)
{
    int readmem (addr_t vaddr, addr_t contents, word_t size);

    char* d = (char*) myaddr;
    char* s = (char*) memaddr;
    int len = length;
    while (len--)
    {
#if 1
	if (! readmem ((addr_t) s, (addr_t) d, sizeof (char)))
	    return 1;
#else
	*d = *s;
#endif
	d++; s++;
    };
    return 0;
};
void
dwarf_debug(struct bt_info *bt)
{
	struct unwind_frame_info *frame;
	ulong bp;
	int is_ehframe = (!st->dwarf_debug_frame_size && st->dwarf_eh_frame_size);

	if (!bt->hp->eip) {
		dump_local_unwind_tables();
		return;
	}

	if (!(kt->flags & DWARF_UNWIND_CAPABLE)) {
		error(INFO, "not DWARF capable\n");
		return;
	}

        frame = (struct unwind_frame_info *)GETBUF(sizeof(struct unwind_frame_info));

	/*
	 *  XXX: This only works for the first PC/SP pair seen in a normal
	 *  backtrace, so it's not particularly helpful.  Ideally it should
         *  be capable to take any PC/SP pair in a stack, but it appears to
	 *  related to the rbp value. 
	 */

	UNW_PC(frame) = bt->hp->eip;
	UNW_SP(frame) = bt->hp->esp;

        readmem(UNW_SP(frame), KVADDR, &bp,
 		sizeof(unsigned long), "reading bp", FAULT_ON_ERROR);
        frame->regs.rbp = bp;  /* fixme for x86 */

	unwind(frame, is_ehframe);

	fprintf(fp, "frame size: %lx (%lx)\n", 
		(ulong)UNW_SP(frame), (ulong)UNW_SP(frame) - bt->hp->esp);

	FREEBUF(frame);
}
Example #22
0
static void output_cpu_logs(char *dirname)
{
	int i;
	struct per_cpu_data *pcd;
	size_t n, idx, start, end, len;
	size_t padding;
	char *source, fname[MAX_FNAME + 1];

	/* allocate subbuf memory */
	subbuf = GETBUF(chan.subbuf_size);
	if (!subbuf) {
		error(FATAL, "cannot allocate memory\n");
	}

	for (i = 0; i < kt->cpus; i++) {
		pcd = &per_cpu[i];

		if (pcd->buf.subbufs_produced == 0 && pcd->buf.offset == 0) {
			if (is_global == 1) {
				error(WARNING, "There is no data in the relay buffer.\n");
				break;
			} else {
				error(WARNING, "[cpu:%d]There is no data in the relay buffer.\n", i);
				continue;
			}
		}

		end = pcd->buf.subbufs_produced + 1;
		if (pcd->buf.subbufs_produced >= chan.n_subbufs) {
			start = end - chan.n_subbufs;
		} else {
			start = 0;
		}

		create_output_filename(fname, MAX_FNAME, i);
		fprintf(fp, "--- generating '%s/%s' ---\n", dirname, fname);
		fprintf(fp, "  subbufs ready on relayfs:%ld\n", (long)end);
		fprintf(fp, "  n_subbufs:%ld, read subbuf from:%ld(%ld) "
			"to:%ld(%ld) (offset:0-%ld)\n\n",
			(long)chan.n_subbufs,
			(long)start,
			(long)(start % chan.n_subbufs),
			(long)end-1,
			(long)((end-1) % chan.n_subbufs),
			(long) pcd->buf.offset);
		outfp = open_output_file(dirname, fname);

		for (n = start; n < end; n++) {
			/* read relayfs subbufs and write to log file */
			idx = n % chan.n_subbufs;
			source = pcd->buf.start + idx * chan.subbuf_size;
			if (old_format == 1) {
				readmem((ulong)pcd->buf.padding + sizeof(unsigned) * idx,
					KVADDR, &padding, sizeof(unsigned),
					"padding", FAULT_ON_ERROR);
			} else {
				readmem((ulong)pcd->buf.padding + sizeof(padding) * idx,
					KVADDR, &padding, sizeof(padding),
					"padding", FAULT_ON_ERROR);
			}
			if (n == end - 1) {
				len = pcd->buf.offset;
			} else {
				len = chan.subbuf_size;
			}

			if (old_format == 1) {
				source += sizeof(unsigned int);
				len -= sizeof(unsigned int) + padding;
			} else {
				len -= padding;
			}
			if (len > 0) {
				readmem((ulong)source, KVADDR, subbuf, len,
					"subbuf", FAULT_ON_ERROR);
				if (fwrite(subbuf, len, 1, outfp) != 1) {
					error(FATAL, "cannot write log data\n");
				}
			}
		}
		fclose(outfp);
		outfp = NULL;

		/*
		 * -a option retrieve the old data of subbuffer where the
		 * probe record is written at that time.
		 */
		if (retrieve_all == 1 && start != 0) {
			strncat(fname, ".may_broken", MAX_FNAME);
			fprintf(fp, "--- generating '%s/%s' ---\n", dirname, fname);
			fprintf(fp, "  read subbuf %ld(%ld) (offset:%ld-%ld)\n",
				(long)start-1,
				(long)((start-1) % chan.n_subbufs),
				(long)pcd->buf.offset,
				(long)chan.subbuf_size);
			outfp = open_output_file(dirname, fname);

			idx = (start - 1) % chan.n_subbufs;
			source = pcd->buf.start + idx * chan.subbuf_size +
				 pcd->buf.offset;
			len = chan.subbuf_size - pcd->buf.offset;
			if (len) {
				readmem((ulong)source, KVADDR, subbuf, len,
					"may_broken_subbuf", FAULT_ON_ERROR);
				if (fwrite(subbuf, len, 1, outfp) != 1) {
					error(FATAL,
					      "cannot write log data(may_broken)\n");
				}
			}
			fclose(outfp);
			outfp = NULL;
		}
		if (is_global == 1)
			break;
	}
	if (subbuf) {
		FREEBUF(subbuf);
		subbuf = NULL;
	}
	return;
}
Example #23
0
void ITG3200::setZgyroStandby(bool _Status) {
  readmem(PWR_MGM, 1, &_buff[0]);
  writemem(PWR_MGM, ((_buff[0] & PWRMGM_STBY_ZG) | _Status << 3));
}
Example #24
0
byte ITG3200::getClockSource() {  
  readmem(PWR_MGM, 1, &_buff[0]);
  return (_buff[0] & PWRMGM_CLK_SEL);
}
int main(int argc, char *argv[])
{


  if(argc != 2) { printf("Not correct argumento\n"); return 1; }
  
  // sig is easy to find: 
  // first search for youtube.com in friendsui
  // next, go to the array it's referenced in
  // lastly click the xref of the array!
  // the start of the function is what this sig is!
  const char *sig = "\x55"
  "\x57"
  "\x56"
  "\x53"
  "\x83\xEC?"
  "\xE8????"
  "\x81?????"
  "\x8B???"
  "\x8D?????"
  "\x8D?????"
  "\xEB?"
  "\x83\xC6\x04";

  pid_t pid;

  sscanf(argv[1], "%d", &pid);
  
  
  char temp[256];
  snprintf(temp, 256, "/proc/%i/mem", pid);
  FILE *f = fopen(temp, "rb+");

  char mem[1];

  const char *now = sig;

  memory mems;
  int skip = 0;

  while(GetMemory(&mems, argv[1], "friendsui.so",skip))
  {

    printf("%08lX - %08lX\n", mems.start, mems.end);

    for(long i = mems.start; i < mems.end; i++)
    {

      if(!readmem(f, i, (void *)mem, 1))
      {
        printf("END!! :(: %08lX\n", i);
        break;
      }

      if(*now == '?' || *now == mem[0])
      {
        now++;
        if(!*now) // end of sig
        {
          long write = i - strlen(sig) + 1;

          // mov eax, 1 
          // retn
          if(!writemem(f, write, (void *)"\xB8\x01\x00\x00\x00\xC3", 6))
          {
            printf("NO WRITE!!\n");
          }
          printf("Found!!! %08lX\n", i);
          break;
        }
      }
      else
        now = sig;
    }
    skip++;
  }
  fclose(f);
  printf("Done!\n");


  return 0;
}
Example #26
0
byte ITG3200::getFilterBW() {  
  readmem(DLPF_FS, 1, &_buff[0]);
  return (_buff[0] & DLPFFS_DLPF_CFG); 
}
Example #27
0
void ITG3200::setFSRange(byte _Range) {
  readmem(DLPF_FS, 1, &_buff[0]);   
  writemem(DLPF_FS, ((_buff[0] & ~DLPFFS_FS_SEL) | (_Range << 3)) ); 
}
Example #28
0
byte ITG3200::getFSRange() {
  readmem(DLPF_FS, 1, &_buff[0]);
  return ((_buff[0] & DLPFFS_FS_SEL) >> 3);
}
Example #29
0
byte ITG3200::getSampleRateDiv() {
  readmem(SMPLRT_DIV, 1, &_buff[0]);
  return _buff[0];
}
Example #30
0
void ITG3200::setClockSource(byte _CLKsource) {   
  readmem(PWR_MGM, 1, &_buff[0]);
  writemem(PWR_MGM, ((_buff[0] & ~PWRMGM_CLK_SEL) | _CLKsource)); 
}