Exemplo n.º 1
0
def masseur(apk,
            dex=None,
            resources=None,
            out=None,
            adb_options=None,
            keystore=None,
            install=False,
            quiet=False):
    if not out:
        out = os.path.basename(apk)
    if not keystore:
        keystore = findKeystore()
    with utils.TempDir() as temp:
        processed_apk = None
        if dex:
            processed_apk = repack(apk, dex, resources, temp, quiet)
        else:
            utils.Print('Signing original APK without modifying dex files',
                        quiet=quiet)
            processed_apk = os.path.join(temp, 'processed.apk')
            shutil.copyfile(apk, processed_apk)
        signed_apk = sign(processed_apk, keystore, temp, quiet=quiet)
        aligned_apk = align(signed_apk, temp, quiet=quiet)
        utils.Print('Writing result to {}'.format(out), quiet=quiet)
        shutil.copyfile(aligned_apk, out)
        if install:
            adb_cmd = ['adb']
            if adb_options:
                adb_cmd.extend(
                    [option for option in adb_options.split(' ') if option])
            adb_cmd.extend(['install', '-t', '-r', '-d', out])
            utils.RunCmd(adb_cmd, quiet=quiet)
Exemplo n.º 2
0
def repack(apk, processed_out, resources, temp, quiet):
    processed_apk = os.path.join(temp, 'processed.apk')
    shutil.copyfile(apk, processed_apk)
    if not processed_out:
        utils.Print('Using original APK as is', quiet=quiet)
        return processed_apk
    utils.Print('Repacking APK with dex files from {}'.format(processed_apk),
                quiet=quiet)

    # Delete original dex files in APK.
    with utils.ChangedWorkingDirectory(temp, quiet=quiet):
        cmd = ['zip', '-d', 'processed.apk', '*.dex']
        utils.RunCmd(cmd, quiet=quiet)

    # Unzip the jar or zip file into `temp`.
    if processed_out.endswith('.zip') or processed_out.endswith('.jar'):
        cmd = ['unzip', processed_out, '-d', temp]
        if quiet:
            cmd.insert(1, '-q')
        utils.RunCmd(cmd, quiet=quiet)
        processed_out = temp

    # Insert the new dex and resource files from `processed_out` into the APK.
    with utils.ChangedWorkingDirectory(processed_out, quiet=quiet):
        dex_files = glob.glob('*.dex')
        resource_files = glob.glob(resources) if resources else []
        cmd = ['zip', '-u', '-9', processed_apk] + dex_files + resource_files
        utils.RunCmd(cmd, quiet=quiet)
    return processed_apk
Exemplo n.º 3
0
def GetAttendance(users, date_list, ulist):
    # 单人,单天分析
    for id in users:
        utils.Print("用户: " + utils.IntToStr(id))
        if id not in ulist:
            # 1、始终未打卡
            continue
        user_info = ulist[id]
        for date in date_list:
            times = user_info.Times()
            if date not in times:
                # 2.1、当天没有打卡记录
                continue
            # 当天打卡记录
            time_list = list(times[date])
            # 2.2、空列表代表当天没有打卡记录
            list_len = len(time_list)
            if list_len == 0:
                continue
            # 排序计算出最早最晚
            time_list.sort()
            # 最早
            earliest = time_list[0]
            # 最晚
            last = time_list[list_len - 1]
            str = "早: " + utils.TimeToStr(
                earliest) + "    晚: " + utils.TimeToStr(last)
            utils.Print(str)
            goal_item = GoalItem(earliest, last)
            user_info.AddGoal(date, goal_item)
Exemplo n.º 4
0
def align(signed_apk, temp, quiet):
    utils.Print('Aligning', quiet=quiet)
    aligned_apk = os.path.join(temp, 'aligned.apk')
    zipalign_path = ('zipalign' if 'build_tools' in os.environ.get('PATH') else
                     os.path.join(utils.getAndroidBuildTools(), 'zipalign'))
    cmd = [zipalign_path, '-f', '4', signed_apk, aligned_apk]
    utils.RunCmd(cmd, quiet=quiet)
    return signed_apk
Exemplo n.º 5
0
def sign(unsigned_apk, signed_apk, keystore, quiet=False):
    utils.Print('Signing (ignore the warnings)', quiet=quiet)
    cmd = ['zip', '-d', unsigned_apk, 'META-INF/*']
    utils.RunCmd(cmd, quiet=quiet)
    cmd = [
        'jarsigner', '-sigalg', 'SHA1withRSA', '-digestalg', 'SHA1',
        '-keystore', keystore, '-storepass', 'android', '-signedjar',
        signed_apk, unsigned_apk, 'androiddebugkey'
    ]
    utils.RunCmd(cmd, quiet=quiet)
Exemplo n.º 6
0
def repack(processed_out, original_apk, temp, quiet):
    processed_apk = os.path.join(temp, 'processed.apk')
    shutil.copyfile(original_apk, processed_apk)
    if not processed_out:
        utils.Print('Using original APK as is', quiet=quiet)
        return processed_apk
    utils.Print('Repacking APK with dex files from {}'.format(processed_apk),
                quiet=quiet)
    with utils.ChangedWorkingDirectory(temp, quiet=quiet):
        cmd = ['zip', '-d', 'processed.apk', '*.dex']
        utils.RunCmd(cmd, quiet=quiet)
    if processed_out.endswith('.zip') or processed_out.endswith('.jar'):
        cmd = ['unzip', processed_out, '-d', temp]
        if quiet:
            cmd.insert(1, '-q')
        utils.RunCmd(cmd, quiet=quiet)
        processed_out = temp
    with utils.ChangedWorkingDirectory(processed_out, quiet=quiet):
        dex = glob.glob('*.dex')
        cmd = ['zip', '-u', '-9', processed_apk] + dex
        utils.RunCmd(cmd, quiet=quiet)
    return processed_apk
Exemplo n.º 7
0
def OnParse():
    # get date list
    ev_ids = cal.get_calevents(tag="reminder")
    if len(ev_ids) == 0:
        messagebox.showinfo("提示", "需要选中考勤的日期哦")
        return None
    date_list = []
    for ev_id in ev_ids:
        date = cal.calevent_cget(ev_id, 'date')
        date_list.append(date)
        utils.Print(date)
    # get file path
    path = entry.get()
    if len(path) == 0:
        messagebox.showinfo("提示", "好像没有指定考勤文件的路径哦")
        return None
    # parse file
    ParseFile(path, date_list)

    # check whether the file name is valid
    date_list = utils.GetDateListFromPath(path)
    if len(date_list) != 2:
        messagebox.showinfo("提示", "文件名称的日期格式不正确哦(9.1-9.9.xlsx)")
        return None
    for dt in date_list:
        if not utils.StrIsValidDate(dt):
            messagebox.showinfo("提示", "文件名称的日期格式不正确哦(9.1-9.9.xlsx)")
            return None
    date1 = utils.StrToDate(date_list[0])
    date2 = utils.StrToDate(date_list[1])
    if date1.month != date2.month:
        messagebox.showinfo("提示", "起止日期必须在同一个月份哦")
        return None
    if date1.day > date2.day:
        messagebox.showinfo("提示", "结束日期必须大于起始日期哦")
        return None

    # save file
    dir_name = os.path.dirname(path)
    os.startfile(dir_name)
    return None
Exemplo n.º 8
0
 def Print(s):
     utils.Print(s, start_time)