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

Source Code for Module misc

 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 types, random, string 
20   
21  ANDROGUARD_VERSION = "b0" 
22   
23  ANDROAXML_VERSION = "0.1" 
24  ANDRODD_VERSION = "0.1" 
25  ANDRODIFF_VERSION = "0.1" 
26  ANDROSIM_VERSION = "0.1" 
27  ANDRODUMP_VERSION = "0.1" 
28  ANDROLYZE_VERSION = "0.2" 
29  ANDROMARKS_VERSION = "0.1" 
30  ANDROXGMML_VERSION = "0.1" 
31   
32   
33   
34   
35 -class Color:
36 normal = "\033[0m" 37 black = "\033[30m" 38 red = "\033[31m" 39 green = "\033[32m" 40 yellow = "\033[33m" 41 blue = "\033[34m" 42 purple = "\033[35m" 43 cyan = "\033[36m" 44 grey = "\033[37m" 45 bold = "\033[1m" 46 uline = "\033[4m" 47 blink = "\033[5m" 48 invert = "\033[7m"
49
50 -def long2int( l ) :
51 if l > 0x7fffffff : 52 l = (0x7fffffff & l) - 0x80000000 53 return l
54
55 -def long2str(l):
56 """Convert an integer to a string.""" 57 if type(l) not in (types.IntType, types.LongType): 58 raise ValueError, 'the input must be an integer' 59 60 if l < 0: 61 raise ValueError, 'the input must be greater than 0' 62 s = '' 63 while l: 64 s = s + chr(l & 255L) 65 l >>= 8 66 67 return s
68
69 -def str2long(s):
70 """Convert a string to a long integer.""" 71 if type(s) not in (types.StringType, types.UnicodeType): 72 raise ValueError, 'the input must be a string' 73 74 l = 0L 75 for i in s: 76 l <<= 8 77 l |= ord(i) 78 79 return l
80
81 -def random_string() :
82 return random.choice( string.letters ) + ''.join([ random.choice(string.letters + string.digits) for i in range(10 - 1) ] )
83
84 -def is_android(real_filename) :
85 fd = open( real_filename, "r") 86 val = None 87 88 f_bytes = fd.read(3) 89 90 if f_bytes[0:2] == "PK" : 91 val = "APK" 92 elif f_bytes[0:3] == "dex" : 93 val = "DEX" 94 95 fd.close() 96 return val
97