| 606 | # this process can fail in some cases |
| 607 | @staticmethod |
| 608 | def patch_raw(address, patch_data, len): |
| 609 | ea = address |
| 610 | orig_data = '' |
| 611 | |
| 612 | while ea < (address + len): |
| 613 | |
| 614 | if not idc.hasValue(idc.GetFlags(ea)): |
| 615 | print("Keypatch: FAILED to read data at 0x{0:X}".format(ea)) |
| 616 | break |
| 617 | |
| 618 | orig_byte = idc.Byte(ea) |
| 619 | orig_data += chr(orig_byte) |
| 620 | patch_byte = ord(patch_data[ea - address]) |
| 621 | |
| 622 | if patch_byte != orig_byte: |
| 623 | # patch one byte |
| 624 | if idaapi.patch_byte(ea, patch_byte) != 1: |
| 625 | print("Keypatch: FAILED to patch byte at 0x{0:X} [0x{1:X}]".format(ea, patch_byte)) |
| 626 | break |
| 627 | ea += 1 |
| 628 | return (ea - address, orig_data) |
| 629 | |
| 630 | # patch at address, return the number of written bytes & original data |
| 631 | # on patch failure, we revert to the original code, then return (None, None) |