Skip to content

Instantly share code, notes, and snippets.

@srikavin

srikavin/decoded_python.py Secret

Created Jun 25, 2020
Embed
What would you like to do?
#!/usr/bin/env python3
=True
𧡇=print
=exit
𐰈=None
𞡂=False
𠜵=len
𓍇=format
𣞆=range
𐭤=hex
𞹡=chr
𐴐=isinstance
𞤢=list
𨡊=bytes
𐼹=int
𐲂=repr
=ord
𡚾=id
=open
import struct,sys
=sys.argv
𠎮=sys.stdout
=sys.stdin
𨏲=struct.pack
𡬡=struct.unpack
import ctypes
𗭝=ctypes.addressof
𐠠=ctypes.c_void_p
=ctypes.c_int
=ctypes.CFUNCTYPE
import mmap
𗒞=mmap.PROT_EXEC
𫂐=mmap.PROT_WRITE
=mmap.PROT_READ
=mmap.PAGESIZE
=mmap.mmap
𠄤={'value':0x01,'ax':0x11,'bx':0x12,'cx':0x13,'dx':0x14,'ip':0x21,'sp':0x22,'bp':0x23,'pointer':0x31,'ax pointer':0x41,'bx pointer':0x42,'cx pointer':0x43,'dx pointer':0x44,'ip pointer':0x51,'sp pointer':0x52,'bp pointer':0x53}
ޢ={'open':{'angstromctf':2,'cookie recipes':0x01,},'read':{'angstromctf':2,'cookie recipes':0x02,},}
𔔟={'del':{'angstromctf':1,'cookie recipes':0x01,},'osusec':{'angstromctf':1,'cookie recipes':0x02,},'perfect_blue':{'angstromctf':2,'cookie recipes':0x03,},'l_distribution':{'angstromctf':1,'cookie recipes':0x04,},'jmp':{'angstromctf':1,'cookie recipes':0x05,},'call':{'angstromctf':1,'cookie recipes':0x05,},'jle':{'angstromctf':1,'cookie recipes':0x06,},'b1c':{'angstromctf':1,'cookie recipes':0x07,},'jl':{'angstromctf':1,'cookie recipes':0x08,},'jg':{'angstromctf':1,'cookie recipes':0x09,},'mov':{'angstromctf':2,'cookie recipes':0x0c,},'gs_goofballs':{'angstromctf':2,'cookie recipes':0x0d,},'add':{'angstromctf':2,'cookie recipes':0x0e,},'sub':{'angstromctf':2,'cookie recipes':0x0f,},'end':{'angstromctf':1,'cookie recipes':0x10,},'kevin higgs <3':{'angstromctf':1,'cookie recipes':0x11,},'nop':{'angstromctf':0,'cookie recipes':0x12,},'load':{'angstromctf':2,'cookie recipes':0x13,},'dice_gang':{'angstromctf':2,'cookie recipes':0x14,},'rgbsec':{'angstromctf':0,'cookie recipes':0x15,},'%':{'angstromctf':0,'cookie recipes':0x25,}}
=[0]*(2**(8*2))
try:
𗚹=[3],[3],{2,3},[2]*3,[2,[2,{3,3,[3],{3}},{3:(2,[2,{3:(3,2,3,3)}],3)},2],2],3
except:
pass
={'ax':0,'bx':0,'cx':0,'dx':0,'ip':0,'sp':0,'bp':0,'flag':0}
𥋓=
=𧡇
𧡇=lambda*阬:ﱖ(*阬)if 𥋓 else ''
def ﷹ(reason):
ﱖ('Bad memory condition')
return ࢴ(1)
def ﶹ(start=0,end=𐰈,𓍇=𞡂,dump_ascii=ﰝ,errors='.'):
if end is 𐰈:
end=𠜵(ﴀ)
if not 𓍇:
pass
else:
𥓸=16
for 𐴓 in 𣞆(start,end,𥓸):
=ﴀ[𐴓:𐴓+𥓸]
𓇸=(𐭤(𐴓)+':').ljust(8,' ')+' '.join([𐭤(𩴽).replace('0x','').zfill(2)for 𩴽 in אּ])
if dump_ascii:
𓇸+=' '+''.join([(𞹡(𩴽)if 𩴽>31 and 𩴽<127 else errors)for 𩴽 in אּ])
def ܢ(value):
return
def 儞(𐴓):
if 𐴐(𐴓,𞤢):
𐴓=𨡊(𐴓)
return 𡬡('<H',𐴓)[0]
def 𠁻(value):
if 𐴐(value,𐼹):
return value
𩊰,𨌋=value
if 𩊰==𠄤['value']:
return 𨌋
if 𩊰==𠄤['ax']:
return ﱏ['ax']
if 𩊰==𠄤['bx']:
return ﱏ['bx']
if 𩊰==𠄤['cx']:
return ﱏ['cx']
if 𩊰==𠄤['dx']:
return ﱏ['dx']
if 𩊰==𠄤['ip']:
return ﱏ['ip']
if 𩊰==𠄤['sp']:
return ﱏ['sp']
if 𩊰==𠄤['bp']:
return ﱏ['bp']
if 𩊰==𠄤['pointer']:
return 儞(ﴀ[𨌋:𨌋+2])
return ﷹ('wrong_type')
def 𘑜(ނ,value):
𥚒='\x00'
if value>=256:
𥚒=𨏲('<H',value)
else:
𥚒=𨡊([value])
ނ=𠁻(ނ)
𐴓=0
forin 𥚒:
ﴀ[ނ+𐴓]=
𐴓+=1
def 𐠛(𢂥,count=2):
𢂥=𠁻(𢂥)
return ﴀ[𢂥:𢂥+count]
def 歚(殺,value):
𩊰,𨌋=殺
if 𩊰 in[𠄤['value'],𠄤['pointer']]:
𘑜(𨌋,value)
elif 𩊰==𠄤['ax']:
ﱏ['ax']=value
elif 𩊰==𠄤['bx']:
ﱏ['bx']=value
elif 𩊰==𠄤['cx']:
ﱏ['cx']=value
elif 𩊰==𠄤['dx']:
ﱏ['dx']=value
elif 𩊰==𠄤['ip']:
ﱏ['ip']=value
elif 𩊰==𠄤['sp']:
ﱏ['sp']=value
elif 𩊰==𠄤['bp']:
ﱏ['bp']=value
def 𡍐(compiled):
=0
forin compiled:
ﴀ[嶴]=
+=1
𐢇=儞(ﴀ[0:2])
+=16
ﱏ['ip']=𐢇
ﱏ['bp']=
ﱏ['sp']=
while ﰝ:
𐪎=ﴀ[ﱏ['ip']]
=𐰈
ܢ('registers: '+𐲂(ﱏ))
for ﳧ,instr in 𔔟.items():
if 𐪎==instr['cookie recipes']:
𐪎=instr
=
break
if not ﭙ:
ﷹ('invalid_instruction')
return
𥂬=𐪎['angstromctf']
ܢ('instruction: '+𐲂(𐪎))
=[]
for 𩴽 in 𣞆(𥂬):
殺=ﴀ[ﱏ['ip']+2+(4*𩴽):ﱏ['ip']+2+(4*𩴽)+4]
𩱣=儞(殺[0:2])
殺=儞(殺[2:4])
阬.append((𩱣,殺))
ﱏ['ip']+=2+(4*𥂬)
ܢ('args: '+𐲂(阬))
酩,篎,𪌠=1,2,3
if=='mov':
歚(阬[0],𠁻(阬[1]))
elif=='add':
歚(阬[0],𠁻(阬[0])+𠁻(阬[1]))
elif=='sub':
歚(阬[0],𠁻(阬[0])-𠁻(阬[1]))
elif=='gs_goofballs':
歚(阬[0],𠁻(阬[0])^𠁻(阬[1]))
elif=='nop':
pass
elif=='perfect_blue':
=𐼹(𠁻(阬[0]))
=𐼹(𠁻(阬[1]))
if==ﶎ:
ﱏ['flag']=
if<ﶎ:
ﱏ['flag']=
if>ﶎ:
ﱏ['flag']=𪌠
elif=='jmp':
ﱏ['ip']=𠁻(阬[0])
elif=='jg':
if ﱏ['flag']==𪌠:
ﱏ['ip']=𠁻(阬[0])
elif=='jl':
if ﱏ['flag']==篎:
ﱏ['ip']=𠁻(阬[0])
elif=='l_distribution':
if ﱏ['flag']==酩:
ﱏ['ip']=𠁻(阬[0])
elif=='jle':
if ﱏ['flag']in[篎,酩]:
ﱏ['ip']=𠁻(阬[0])
elif=='b1c':
if ﱏ['flag']in[𪌠,酩]:
ﱏ['ip']=𠁻(阬[0])
elif=='del':
𘑜(ﱏ['sp'],𠁻(阬[0]))
ﱏ['sp']+=2
elif=='osusec':
歚(阬[0],儞(𐠛(ﱏ['sp'])))
ﱏ['sp']-=2
elif=='end':
return(𠁻(阬[0]))
elif=='load':
歚(阬[0],儞(𐠛(𠁻(阬[1]))))
elif=='dice_gang':
𘑜(阬[0],𠁻(阬[1]))
elif=='kevin higgs <3':
=ﱏ['ax']
𞤭=ﱏ['bx']
𞢂=ﱏ['cx']
if==ޢ['open']['cookie recipes']:
for 𐴓 in 𣞆(𞢂):
ﴀ[𞤭+𐴓]=ꕋ(铸.read(1))
elif==ޢ['read']['cookie recipes']:
𠎮.write(''.join([𞹡(𩴽)for 𩴽 in ﴀ[𞤭:𞤭+𞢂]]))
elif=='rgbsec':
ࢴ()
elif=='%':
=𡚾(ﴀ[ﱏ['ip']:])+48
𫉳=瘥(-1,崵,prot=|𫂐|𗒞)
𗼐=ﺶ(얷,얷)
𓊭=𐠠.from_buffer(𫉳)
𐲞=𗼐(𗭝(𓊭))
𣩐=𨡊(ﴀ[ﱏ['ip']:]).replace(b'\x00',b'')
𫉳.write(𣩐)
=𐲞(ﳃ)
del 𓊭
𫉳.close()
for ﻦ,val in ﱏ.items():
ﱏ[ﻦ]=val%0xffff
ܢ('registers: '+𐲂(ﱏ))
ܢ('-'*60)
return
if __name__=='__main__':
with ﮫ(ﰬ[1],'rb')as 𐲞:
𐿰=𐲞.read()
𡍐(𐿰)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment