Module opaque
[hide private]
[frames] | no frames]

Source Code for Module opaque

  1  # This file is part of Androguard. 
  2  # 
  3  # Copyright (C) 2010, Anthony Desnos <desnos at t0t0.org> 
  4  # All rights reserved. 
  5  # 
  6  # Androguard is free software: you can redistribute it and/or modify 
  7  # it under the terms of the GNU Lesser General Public License as published by 
  8  # the Free Software Foundation, either version 3 of the License, or 
  9  # (at your option) any later version. 
 10  # 
 11  # Androguard is distributed in the hope that it will be useful, 
 12  # but WITHOUT ANY WARRANTY; without even the implied warranty of   
 13  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 14  # GNU Lesser General Public License for more details. 
 15  # 
 16  # You should have received a copy of the GNU Lesser General Public License 
 17  # along with Androguard.  If not, see <http://www.gnu.org/licenses/>. 
 18   
 19  import random 
 20   
21 -class PRNG :
22 - def __init__(self, value, prefix="x") :
23 self.__value = value
24
25 - def run(self) :
26 elements = self._find_cong( self.__value ) 27 print "ELEMENTS ", elements 28 29 print self._cong( elements[0], elements[1], elements[2], elements[3], elements[4], self.__value, elements[4] ) 30 31 values= { "GERME" : elements[0], 32 "A" : elements[1], 33 "C" : elements[2], 34 "M" : elements[3], 35 "ITER" : elements[4] 36 } 37 38 print values 39 return values
40
41 - def _find_cong(self, value) :
42 elements = self.__find_cong( value ) 43 while elements == None : 44 elements = self.__find_cong( value ) 45 return elements
46
47 - def __find_cong(self, value) :
48 germe = random.randint(0, value * 2) 49 a = 1 % 4 50 m = random.randint(value, value * 2) 51 c = random.randint(0, 255) 52 n = random.randint(value, value * 2) 53 iter = random.randint(5, 30) 54 55 res = self._cong(germe, a, c, m, n, value, iter) 56 return res
57
58 - def _cong(self, germe, a, c, m, n, value, iter) :
59 map = {} 60 y = 0 61 for i in range(0, n) : 62 y = (a * germe + c) % m 63 germe = y 64 map[i] = germe 65 if y == value : 66 print "%d FIND !!!" % y 67 if i >= iter : 68 return [map[i - iter], a, c, m, iter] 69 print y, 70 print "" 71 return None
72 73
74 -class INT :
75 - def __init__(self, value, size=2, prefix="x") :
76 self.__value = value 77 self.__prefix = prefix 78 self.__size = size 79 80 self.__ops = [ ("+", lambda x,y : x + y) , 81 ("-", lambda x,y : x - y), 82 # ("*", lambda x,y : x * y), 83 # ("<<", lambda x,y : x << y ), 84 # (">>", lambda x,y : x >> y), 85 # ("&", lambda x,y : x & y), 86 # ("|", lambda x,y : x | y) 87 ] 88 89 self.__rops = { "+" : "-", 90 "-" : "+", 91 "<<" : ">>", 92 ">>" : "<<", 93 }
94
95 - def run(self) :
96 h = {} 97 l = [] 98 99 cvalue = self.__value 100 101 order = [] 102 for i in range(0, self.__size) : 103 operation = self.__ops[ random.randint( 0, len(self.__ops) - 1 ) ] 104 rvalue = random.randint(0, abs( self.__value ) * 100) 105 nvalue = operation[1]( cvalue, rvalue ) 106 order.append( [ cvalue, rvalue, nvalue, operation ] ) 107 cvalue = nvalue 108 109 order.reverse() 110 # print order 111 112 113 idx = 0 114 l = [] 115 current_var = self.__prefix + str(idx) 116 current = [ current_var, "=", order[0][2] ] 117 l.append( current ) 118 for i in order : 119 op = self.__rops[ i[3][0] ] 120 lvalue = i[1] 121 122 idx += 1 123 o_current_var = current_var 124 current_var = self.__prefix + str(idx) 125 126 current = [ current_var, "=", o_current_var, op, lvalue ] 127 128 l.append( current ) 129 130 return l
131