def __init__(self, driver, smalidir): self.make_changes = False self.driver = driver self.smalidir = smalidir # self.smali_files = smali_files self.emu = Emulator() self.emu2 = Emulator()
def __init__(self, driver, smalidir, mfilters=None): self.make_changes = False self.driver = driver self.smalidir = smalidir # method filters self.mfilters = mfilters # self.smali_files = smali_files self.emu = Emulator() self.emu2 = Emulator()
def run_data_file(data_file): emu = Emulator() ret = emu.run(data_file) outx = emu.vm.variables.copy() outx.update({'ret': ret}) return str(OrderedDict(sorted(outx.items()))).replace( 'OrderedDict([(', '{').replace(')])', '}').replace("',", "':").replace("), (", ', ')
def get_arguments_from_clinit(self, field): reg = '([\w\W]+?)sput-object (v\d+), %s' % re.escape(field) sput_obj_ptn = re.compile(reg) from smaliemu.emulator import Emulator emu = Emulator() array_data_ptn = re.compile(r':array_[\w\d]+\s*.array-data[\w\W\s]+.end array-data') class_name = field.split('->')[0] for sf in self.smali_files: if sf.class_name == class_name: for mtd in sf.methods: arr = [] if mtd.name == '<clinit>': matchs = sput_obj_ptn.search(mtd.body).groups() snippet = matchs[0] code_content = matchs[0] array_data_context = re.split(r'\n+', array_data_ptn.search(mtd.body).group()) # print(array_data_context) return_register_name = matchs[1] arr = re.split(r'\n+', snippet)[:-1] arr.append('return-object %s' % return_register_name) arr.extend(array_data_context) # print(arr) # raise Exception try: # TODO 默认异常停止,这种情况可以考虑,全部跑一遍。 # 因为有可能参数声明的时候,位置错位,还有可能是寄存器复用。 arr_data = emu.call(arr, thrown=True) if len(emu.vm.exceptions) > 0: break arguments = [] byte_arr = [] for item in arr_data: if item == '': item = 0 byte_arr.append(item) arguments.append('[B:' + str(byte_arr)) return arguments except Exception as e: print(e) pass break
def __init__(self, driver, smalidir): Plugin.__init__(self, driver, smalidir) self.emu2 = Emulator() # 匹配参数为内置类型的静态调用函数 INVOKE_STATIC_RE = ( r'invoke-static.*?{([(v|p)\.\d,\s]*)}, (.*?);->(.*?)' r'\(((?:B|S|C|I|J|F|D|Ljava/lang/String;|' r'\[B|\[S|\[C|\[I|\[J|\[F|\[D|\[Ljava/lang/String;' r')*?)\)Ljava/lang/String;') # 匹配proto PROTO_RE = (r'(B|S|C|I|J|F|D|Ljava/lang/String;|' r'\[B|\[S|\[C|\[I|\[J|\[F|\[D|\[Ljava/lang/String;)') self.invoke_static_ptn = re.compile(INVOKE_STATIC_RE) self.proto_ptn = re.compile(PROTO_RE) self.arr_data_ptn = re.compile(self.ARRAY_DATA_PATTERN) self.move_result_obj_ptn = re.compile(self.MOVE_RESULT_OBJECT)
def __init__(self, driver, smalidir): Plugin.__init__(self, driver, smalidir) self.emu2 = Emulator() self.templets = [] if not self.templets: self._init_templets()
# Software distributed under the License is distributed # on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either # express or implied. See the GPL for the specific language # governing rights and limitations. # # You should have received a copy of the GPL along with this # program. If not, go to http://www.gnu.org/licenses/gpl.html # or write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. import sys import os sys.path.append(os.path.join(os.path.dirname(__file__), '..')) from smaliemu.emulator import Emulator emu = Emulator() filename = os.path.join(os.path.dirname(__file__), 'decryptor.smali') # Arguments for the method. # args = { # 'p0': (-62, -99, -106, -125, -123, -105, -98, -37, -105, -97, -103, -41, -118, -97, -113, -103, -109, -104, -115, 111, 98, 103, 35, 52), # 'p1': 19 # } # ret = emu.run(filename, args) # print(emu.stats) # print("RESULT: %s" % ret) # print('-' * 100) emu2 = Emulator()
def __init__(self, driver, smalidir): Plugin.__init__(self, driver, smalidir) self.emu2 = Emulator()
def __init__(self, driver, methods, smali_files): self.emu = Emulator() Plugin.__init__(self, driver, methods, smali_files)