1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| start=0x140001000 end=0x014001C694 addr_list=[0]*11 now_addr=start
addr_target=['push rax','push rax','pushfq','call $+5','pop rax','add rax,','mov ','popfq','pop rax','retn']
while(now_addr<=end): addr_list[0]=now_addr addr_list[1]=next_head(now_addr) if print_insn_mnem(addr_list[0])=='push' and print_insn_mnem(addr_list[1])=='pop' and print_operand(addr_list[0],0)==print_operand(addr_list[1],0): patch_byte(addr_list[0],0x90) patch_byte(addr_list[1],0x90) now_addr+=2 continue now_addr+=1
def check(): cnt=0 for i in range(10): if i==5 or i==6: cnt+=generate_disasm_line(addr_list[i],flags=0).find(addr_target[i])!=-1 else: cnt+=addr_target[i]==generate_disasm_line(addr_list[i],flags=0) return cnt now_addr=start while(now_addr<=end):
if generate_disasm_line=="nop": now_addr+=1 continue addr_list[0]=now_addr for i in range(1,10): addr_list[i]=next_head(addr_list[i-1]) if check()==10: patch_byte(addr_list[0],0xE9) data=get_operand_value(addr_list[5],1)+addr_list[4] data-=(addr_list[0]+5) patch_dword(addr_list[0]+1,data&0xFFFFFFFF) for i in range(addr_list[0]+5,addr_list[9]+1): patch_byte(i,0x90) now_addr=addr_list[9]
elif check()==9: patch_byte(addr_list[0],0x68) data=get_operand_value(addr_list[5],1)+addr_list[4] patch_dword(addr_list[0]+1,data&0xFFFFFFFF) for i in range(addr_list[0]+5,addr_list[8]+1): patch_byte(i,0x90) now_addr=addr_list[9] else: now_addr+=1
|