int AddBreakpoint(unsigned long addr, unsigned int type) { t_polymorphicbreakpoint crt_breakpoint; if(numberofpatch>=__MAX_PMBP__) { olly_add_to_list(0, __ERROR__, "[Error at %x08X] Too many breakpoint are already set.", addr); return 0; } crt_breakpoint.index=numberofpatch; crt_breakpoint.addr=addr; crt_breakpoint.type=type; crt_breakpoint.able=1; if(Readmemory(tpatch[numberofpatch].original, addr, (unsigned long)size[crt_breakpoint.type], MM_RESILENT) == 0) { olly_add_to_list(0, __ERROR__, "[Error at %x08X] Can't read the memory.", addr); return 0; } if(Writememory(polymorph[crt_breakpoint.type], addr, (unsigned long)size[crt_breakpoint.type], MM_RESILENT) == 0) { olly_add_to_list(0, __ERROR__, "[Error at %x08X] Can't write the memory / Set the breakpoint.", addr); return 0; } tpatch[numberofpatch].addr = addr; tpatch[numberofpatch].size = size[crt_breakpoint.type]; olly_add_sorted_data(&(breakpoint.data),&crt_breakpoint); olly_add_to_list(0,0,"New breakpoint at 0x%08X", addr); numberofpatch++; return 1; }
int Assembl(char *answer,ulong parm) { int i,j,k,n,good; char s[TEXTLEN]; t_asmmodel model,attempt; t_memory *pmem; t_dump *pasm; // Visualize changes. Setcpu(0,address,0,0,CPU_ASMHIST|CPU_ASMCENTER); if (string[0]=='\0') // No immediate command Sendshortcut(PM_DISASM,address,WM_CHAR,0,0,' '); else { // Assemble immediate command. If there are several possible encodings, // select the shortest one. model.length=0; for (j=0; ; j++) { // Try all possible encodings good=0; for (k=0; k<4; k++) { // Try all possible constant sizes n=Assemble(string,address,&attempt,j,k,model.length==0?answer:s); if (n>0) { good=1; // If another decoding is found, check if it is shorter. if (model.length==0 || n<model.length) model=attempt; // Shortest encoding so far ; }; }; if (good==0) break; // No more encodings }; if (model.length==0) return -1; // Invalid command // Check for imprecise parameters. k=model.mask[0]; for (i=1; i<model.length; i++) k&=model.mask[i]; if (k!=0xFF) { strcpy(answer,"Command contains imprecise operands"); return -1; }; // If there is no backup copy, create it. Dump window always assumes that // backup has the same base and size as the dump, so check it to avoid // strange ireproducible errors. pmem=Findmemory(address); if (pmem==NULL) { //strcpy(answer,"Attempt to assemble to non-existing memory"); wsprintf(answer,"%X",model.code[0]); for(i=1; i<model.length; i++) { wsprintf(answer,"%s%X",answer,model.code[i]); } return -1; }; pasm=(t_dump *)Plugingetvalue(VAL_CPUDASM); if (pasm!=NULL && pmem->copy==NULL && pmem->base==pasm->base && pmem->size==pasm->size) Dumpbackup(pasm,BKUP_CREATE); // Now write assembled code to memory. Writememory(model.code,address,model.length,MM_RESTORE|MM_DELANAL); }; return 0; };
int DisableBreakpoint(t_polymorphicbreakpoint *crt_breakpoint) { if(Writememory(tpatch[crt_breakpoint->index].original, tpatch[crt_breakpoint->index].addr, tpatch[crt_breakpoint->index].size, MM_RESILENT) == 0) { olly_add_to_list(0, __ERROR__, "[Error at %x08X] Can't write the memory / Restore the breakpoint.", crt_breakpoint->addr); return 0; } crt_breakpoint->able = 0; olly_add_to_list(0,0,"Breakpoint at %08X(%d) disabled", crt_breakpoint->addr, crt_breakpoint->index); return 1; }