コード例 #1
0
ファイル: ppc-gen.c プロジェクト: Jacopo/xrop
// unsigned int, char *, size_t, int, int, size_t
// Generate all the PowerPC gadgets
gadget_list * generate_powerpc(unsigned long long vma, char * rawbuf, size_t size, int bits, int endian, size_t depth, char * re){
    insn_t * it;
    unsigned int i = 0, j = 0;
    uint32_t * ppcbuf = (uint32_t *) rawbuf;
    size_t nsize_ppc = size / 4;

    for(i = 0; i < nsize_ppc; i++){
        if(is_ppc_end(&ppcbuf[i], bits, endian)){
            insn_list * gadget = NULL;
            it = disassemble_one(vma + i * 4, (char *)&ppcbuf[i], PPC_INSTR_SIZE, ARCH_powerpc, bits, endian);
            if(!is_valid_instr(it, ARCH_powerpc)) continue;
            prepend_instr(it, &gadget);
            for(j = 1; j < depth; j++){
                char * iptr = (char *)&ppcbuf[i] - (j * 4);
                unsigned int nvma = (vma + i * 4) - (j * 4);
                if(nvma < vma) break;
                it = disassemble_one(nvma, iptr, PPC_INSTR_SIZE, ARCH_powerpc, bits, endian);
                if(!is_valid_instr(it, ARCH_powerpc) 
                        || is_ppc_end((uint32_t *)iptr, bits, endian) 
                        || is_branch(it, ARCH_powerpc)) break;
                prepend_instr(it, &gadget);
            }
            print_gadgets_list(&gadget, re);
            free_all_instrs(&gadget);
        }
    }

    return NULL;
}
コード例 #2
0
//  \/
//there is an address error somewhere in this routine.				
static void ScrollFromTop(WINDOW *w, HEX_DAT *d)
{
	WIN_RECT wr={ 0, 0, 0, 0 };
	BACKGROUND_DAT *bg=&gBGDAT;
	USHORT result_top;
	USHORT result_bottom;
	USHORT *ptr;
	char buff[150];
	DASM_DAT dasm;

	wr.x1=WinWidth(w);
	wr.y1=ScrollFromBottom_helper+C(6-1,8-1);
	
	if((ULONG)bg->baseaddr && (ULONG)d->top>(ULONG)bg->baseaddr && bg->hOffsetTable)
	{
		ptr=HeapDeref(bg->hOffsetTable);
		result_top=bsearch(ptr, (ULONG)d->top - (ULONG)bg->baseaddr, bg->entries-1);
		result_bottom=bsearch(ptr, (ULONG)bottom_addr - (ULONG)bg->baseaddr, bg->entries-1);
		
		if(result_top==USHRT_MAX || result_bottom==USHRT_MAX)
		{
			d->top-=2;
			WinPaint(w, d);
			
			#ifdef DEBUG
				ST_helpMsg("Address Not In Buffer.");
			#endif
			
			return;
		}			
		
		if(result_top)
		{
			result_top--;	//the previous instruction
			result_bottom--;
		}
		
		d->top=(char*)&bg->baseaddr[ptr[result_top]>>1];
		bottom_addr=(char*)&bg->baseaddr[ptr[result_bottom]>>1];

		WinScrollV(w, &wr, C(-6,-8));
		
		disassemble_one((unsigned short*)d->top, &dasm);
		sprintf(buff, "%lx%s", d->top, dasm.text);
		WinStrXY(w, 1, 1, buff);
	}