Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import struct
- bbb = open( 'bbb' ).read() ## dump bytes from 0x8048CA2
- www = open( 'www' ).read() ## dump bytes from 0x8048CA0
- sss = open( 'rtfm-e24f03bb1204f8e3d40fae8ac135187a11b0ba5c' ).read()[ 4: ]
- sss = [ ord( x ) for x in sss ]
- class Stripe:
- def __init__( self ):
- self.ttt = 0
- self.pos = 0
- self.out = [ 0 ] * 4800
- self.heap = []
- def back( self ):
- self.heap.append( (self.pos, self.ttt, self.out[ : ]) )
- def rest( self ):
- self.pos, self.ttt, self.out = self.heap.pop()
- def app( self, c ):
- s_c = ord( bbb[ 4 * c ] )
- s_w = struct.unpack( 'h', www[ 4*c: 4*c+2 ] )[ 0 ]
- #print 's_c:', hex( s_c )
- #print 's_w:', hex( s_w )
- cnt = s_c + 2
- #print 'cnt:',cnt
- xxx = s_w << ( 16 - s_c )
- out = self.out
- while True:
- out[ self.pos ] *= 2
- out[ self.pos ] &= 0xff ## cut to byte
- xxx_ = ( xxx & 0xffff ) >> 15
- #print 'xxx:', hex( xxx )
- #print 'xxx_:', hex( xxx_ )
- xxx *= 2
- out[ self.pos ] |= xxx_
- ##out[ self.pos ] &= 0xff ## cut to byte
- self.ttt += 1
- if self.ttt > 7:
- self.ttt, self.pos = 0, self.pos + 1
- cnt -= 1
- if not cnt:
- break
- def brute( self ):
- alph = '\\dbchafsqwrtyuiopgjklzxvnme0123456789 \r\n.,:;{}*!QWERTYUIOPASDFGHJKLZXCVBNM()-#@<>/\'\"='
- #alph = ''.join([ chr( x ) for x in xrange( 128 ) ])
- self.back()
- pload = '\\par \\pard\\plain \\s20\\sb0\\sa0\\hich\\af7\\dbch\\af10\\afs20\\loch\\f5\\fs20{\\rtlch \\ltrch\\loch'
- [ self.app( ord( x ) ) for x in pload ]
- if sum([ x != y for x,y in zip( filter( None, self.out ), sss ) ]) < 2:
- yield pload
- self.rest()
- for i in map( ord, alph ):
- self.back()
- self.app( i )
- if sum([ x != y for x,y in zip( filter( None, self.out ), sss ) ]) < 2:
- yield chr( i )
- self.rest()
- bsol = open( 'sol.bin' ).read()
- s = Stripe()
- [ s.app( ord( x ) ) for x in bsol ]
- def recurs( sol ):
- global bsol, s
- #print sol
- if len( sol ) > len( bsol ):
- print '==> |%s|' % sol
- f = open( 'sol.bin', 'w' )
- f.write( sol )
- f.close()
- bsol = sol
- #s = Stripe()
- #[ s.app( ord( x ) ) for x in sol ]
- for c in list( s.brute() ):
- s.back()
- if len( c ) > 1:
- [ s.app( ord( x ) ) for x in c ]
- else:
- s.app( ord( c ) )
- recurs( sol + c )
- s.rest()
- #print [ hex( x ) for x in s.out[ :10 ] ]
- #print s.pos
- #print s.ttt
- recurs( bsol )
- #for c in xrange( 128 ):
- # recurs( '{\\rtf1' + chr( c ) )
Advertisement
Add Comment
Please, Sign In to add comment