ont

GintS 2013 re100

ont
Feb 18th, 2013
448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.85 KB | None | 0 0
  1. import struct
  2.  
  3. bbb = open( 'bbb' ).read()   ## dump bytes from 0x8048CA2
  4. www = open( 'www' ).read()   ## dump bytes from 0x8048CA0
  5. sss = open( 'rtfm-e24f03bb1204f8e3d40fae8ac135187a11b0ba5c' ).read()[ 4: ]
  6. sss = [ ord( x ) for x in sss ]
  7.  
  8. class Stripe:
  9.     def __init__( self ):
  10.         self.ttt = 0
  11.         self.pos = 0
  12.         self.out = [ 0 ] * 4800
  13.  
  14.         self.heap = []
  15.  
  16.     def back( self ):
  17.         self.heap.append( (self.pos, self.ttt, self.out[ : ]) )
  18.  
  19.     def rest( self ):
  20.         self.pos, self.ttt, self.out = self.heap.pop()
  21.  
  22.     def app( self, c ):
  23.         s_c = ord( bbb[ 4 * c ] )
  24.         s_w = struct.unpack( 'h', www[ 4*c: 4*c+2 ] )[ 0 ]
  25.         #print 's_c:', hex( s_c )
  26.         #print 's_w:', hex( s_w )
  27.  
  28.         cnt = s_c + 2
  29.         #print 'cnt:',cnt
  30.         xxx = s_w << ( 16 - s_c )
  31.  
  32.         out = self.out
  33.         while True:
  34.  
  35.             out[ self.pos ] *= 2
  36.             out[ self.pos ] &= 0xff  ## cut to byte
  37.  
  38.             xxx_ = ( xxx & 0xffff ) >> 15
  39.             #print 'xxx:', hex( xxx )
  40.             #print 'xxx_:', hex( xxx_ )
  41.             xxx *= 2
  42.  
  43.             out[ self.pos ] |= xxx_
  44.             ##out[ self.pos ] &= 0xff  ## cut to byte
  45.  
  46.             self.ttt += 1
  47.             if self.ttt > 7:
  48.                 self.ttt, self.pos = 0, self.pos + 1
  49.  
  50.             cnt -= 1
  51.             if not cnt:
  52.                 break
  53.        
  54.     def brute( self ):
  55.         alph =  '\\dbchafsqwrtyuiopgjklzxvnme0123456789 \r\n.,:;{}*!QWERTYUIOPASDFGHJKLZXCVBNM()-#@<>/\'\"='
  56.         #alph = ''.join([ chr( x ) for x in xrange( 128 ) ])
  57.  
  58.         self.back()
  59.         pload = '\\par \\pard\\plain \\s20\\sb0\\sa0\\hich\\af7\\dbch\\af10\\afs20\\loch\\f5\\fs20{\\rtlch \\ltrch\\loch'
  60.         [ self.app( ord( x ) ) for x in pload ]
  61.         if sum([ x != y for x,y in zip( filter( None, self.out ), sss ) ]) < 2:
  62.             yield pload
  63.  
  64.         self.rest()
  65.  
  66.         for i in map( ord, alph ):
  67.             self.back()
  68.             self.app( i )
  69.  
  70.             if sum([ x != y for x,y in zip( filter( None, self.out ), sss ) ]) < 2:
  71.                 yield chr( i )
  72.  
  73.             self.rest()
  74.  
  75.  
  76. bsol = open( 'sol.bin' ).read()
  77.  
  78. s = Stripe()
  79. [ s.app( ord( x ) ) for x in bsol ]
  80.  
  81. def recurs( sol ):
  82.     global bsol, s
  83.     #print sol
  84.  
  85.     if len( sol ) > len( bsol ):
  86.         print '==> |%s|' % sol
  87.         f = open( 'sol.bin', 'w' )
  88.         f.write( sol )
  89.         f.close()
  90.         bsol = sol
  91.  
  92.     #s = Stripe()
  93.     #[ s.app( ord( x ) ) for x in sol ]
  94.  
  95.     for c in list( s.brute() ):
  96.         s.back()
  97.         if len( c ) > 1:
  98.             [ s.app( ord( x ) ) for x in c ]
  99.         else:
  100.             s.app( ord( c ) )
  101.         recurs( sol + c )
  102.         s.rest()
  103.  
  104.  
  105. #print [ hex( x ) for x in s.out[ :10 ] ]
  106. #print s.pos
  107. #print s.ttt
  108.  
  109. recurs( bsol )
  110.  
  111. #for c in xrange( 128 ):
  112. #    recurs( '{\\rtf1' + chr( c ) )
Advertisement
Add Comment
Please, Sign In to add comment