Skip to content

Instantly share code, notes, and snippets.

@MayerDaniel
Created April 28, 2021 22:46
Show Gist options
  • Save MayerDaniel/f70056f5f65747e527119b13526c6884 to your computer and use it in GitHub Desktop.
Save MayerDaniel/f70056f5f65747e527119b13526c6884 to your computer and use it in GitHub Desktop.
Example LCG String Decryption Patcher
def strdec(offset, key, leng, mult=1664525, const=1013904223):
out = bytearray()
bytes_read = ida_bytes.get_bytes(offset, leng)
for i in range(len(bytes_read)):
key = mult * key + const
b1 = (bytes_read[i] ^ (key >> 12)) & 0xff
out.append(b1)
print(out)
ida_bytes.patch_bytes(offset, bytes(out))
def decrypt_ida(addr):
for xref in CodeRefsTo(addr, 0): #0x4016E6
args = [] #order will be seed, offset, leng
heads = [x for x in Heads(xref - 250, xref)] #reverse since we are looking backwards
heads.reverse()
for h in heads:
if idc.print_insn_mnem(h) == 'push':
args.append(idc.get_operand_value(h,0))
if len(args) == 3:
break
strdec(args[1], args[0], args[2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment