Beispiel #1
0
 def extract_files(self):
     files = FS.walk_files(self.idir, ewhites=('.png', '.jpg'), cut=len(self.idir) + 1)
     print(len(files))
     s = ''
     for f in files:
         s += '"' + f + '",\n'
     FS.write_text(self.flist, s)
Beispiel #2
0
    def __init__(self):
        DeApkBase.__init__(self, 'tmcs')
        self.odir = os.path.join(self.root, self.name + '_res')
        self.idir = os.path.join(self.dist, 'assets')

        # for fn in FS.walk_files(self.idir, ext_whites=['.csprite'], cut_pos=len(self.idir)+1):
        #     with open(os.path.join(self.idir, fn), 'rb') as fp:
        #         tmp = fp.read()
        #         buffer = None
        #         for i in range(len(tmp)-3):
        #             if tmp[i] == ord('P') and tmp[i+1] == ord('K') and tmp[i+2] == ord('M'):
        #                 buffer = tmp[i:]
        #                 break
        #     if buffer is not None:
        #         dst = os.path.join(self.odir, fn[0:-8] + '.pkm')
        #         FS.make_parent(dst)
        #         with open(dst, 'wb') as fp:
        #             fp.write(buffer)

        # pkmdir = '/Users/joli/Desktop/test/rob/apk/tmcs_pkm'
        # for fn in FS.walk_files(pkmdir, ext_whites=['.pkm'], cut_pos=len(pkmdir) + 1):
        #     dst = os.path.join(self.odir, os.path.dirname(fn))
        #     FS.make_parent(dst)
        #     os.system('/Users/joli/source/mac/app/hack/MTCT/bin/etcpack %s %s' % (
        #         os.path.join(pkmdir, fn), dst
        #     ))

        from PIL import Image
        ppmdir = '/Users/joli/Desktop/test/rob/apk/tmcs_ppm'
        for fn in FS.walk_files(ppmdir, ewhites=['.ppm'], cut=len(ppmdir) + 1):
            dst = os.path.join(self.odir, fn[0:-8] + '.png')
            FS.make_parent(dst)
            image = Image.open(os.path.join(ppmdir, fn))
            image.save(dst, format='png')
Beispiel #3
0
 def create_lua_table():
     filelist = set()
     with open(
             '/Users/joli/Desktop/apps/三国杀名将传/assets/package1_filelist.txt',
             'r') as fp:
         for item in fp.read().split('\n'):
             if item:
                 name = item[item.find(':') + 1:]
                 fext = FS.extensions(name)
                 if fext == '.png' or fext == '.jpg':
                     filelist.add('"%s"' % name)
     with open('/Users/joli/Desktop/apps/三国杀名将传/assets/patch_filelist.txt',
               'r') as fp:
         for item in fp.read().split('\n'):
             if item:
                 name = item[item.find(':') + 1:]
                 fext = FS.extensions(name)
                 if fext == '.png' or fext == '.jpg':
                     filelist.add('"%s"' % name)
     filelist = sorted(filelist)
     print(len(filelist))
     fileroot = '/Users/joli/Documents/AndroidStudio/DeviceExplorer/emulator-5554/data/user/0/com.tencent.tmgp.sanguosha.mjz/files'
     resroot = '/Users/joli/Desktop/apps/apk/res'
     n = 0
     for i in range(len(filelist)):
         filename = filelist[i][1:-1]
         hackname = 'hackimage_%d.%s' % (i + 1, filename[-3:])
         hackpath = os.path.join(fileroot, hackname)
         if os.path.isfile(hackpath):
             dst = os.path.join(resroot, filename)
             FS.make_parent(dst)
             shutil.copy2(hackpath, dst)
         else:
             n += 1
             print("miss", n, i, filename, hackname)
Beispiel #4
0
 def split_res(self):
     # with open(os.path.join(self.idir, 'package.was'), 'rb') as fp:
     with open(os.path.join(self.idir, 'patch.was'), 'rb') as fp:
         buffer = fp.read()
         buffer = buffer[32:]
     e = len(buffer)
     p = 0
     while p < e:
         p += 4
         b = buffer[p:p+4]
         fs = Bit.u32_from(b)
         p += 24
         b = buffer[p:p+4]
         ns = Bit.u32_from(b)
         p += 4
         fn = Text.unicodes2str(buffer[p:p+ns])
         p += ns + 1
         if fn.endswith('.luac'):
             fn = 'src/' + fn
         else:
             fn = 'res/' + fn
         print(p, fs, fn)
         fb = buffer[p:p+fs]
         p += fs
         fp = os.path.join(self.odir, fn)
         FS.make_parent(fp)
         with open(fp, 'wb') as fp:
             fp.write(fb)
     print(p, e)
Beispiel #5
0
    def decrypt_res(self):
        import biplist

        def readplist(pf):
            try:
                pli = biplist.readPlist(pf)
                return pli
            except biplist.InvalidPlistException as e:
                print('error', e)

        path = os.path.join(self.root, self.name + '_pull1')
        for fn in FS.walk_files(path, cut=len(path) + 1):
            if fn.endswith('.DS_Store'):
                continue
            print(fn)
            ft = os.path.join(path, fn)
            # fs = FS.read_text(ft)
            # if fs.startswith('<?xml') and fs.find('.dtd"/>') != -1:
            #     fs = fs.replace('.dtd"/>', '.dtd">', 1)
            #     FS.write_text(ft, fs)
            plist = readplist(ft)
            if plist:
                s = plist.get('base64')
            else:
                s = FS.read_text(ft)[:-31]
            try:
                s = base64.b64decode(s)
                FS.write_text(os.path.join(self.root, self.name + '_pull', fn), s.decode('utf-8'))
            except:
                pass
Beispiel #6
0
 def fullpath(parent, info):
     for key in info:
         obj = info[key]
         if isinstance(obj, dict):
             fullpath('%s/%s' % (parent, key), obj)
         else:
             ext = FS.extensions(key)
             isetc = False
             if ext == '.etc':
                 isetc = True
                 ext = '.png'
             filename = '%s_%s%s' % (FS.filename(key), obj, ext)
             if not _httpload(parent, filename):
                 if isetc:
                     filename = '%s_%s%s' % (FS.filename(key), obj,
                                             '.jpg')
                     if not _httpload(parent, filename):
                         filename = '%s_%s%s' % (FS.filename(key), obj,
                                                 '.etc')
                         if not _httpload(parent, filename):
                             failurl = parent + '/' + filename
                             log.e('fail', failurl)
                             errors.append(failurl)
                 else:
                     failurl = parent + '/' + filename
                     log.e('fail', failurl)
                     errors.append(failurl)
Beispiel #7
0
    def find_paths(self):
        # paths = set()
        # with open(os.path.join(self.idir, 'package.was'), 'rb') as fp:
        #     ret = RobCom.find_binary_paths(fp.read(), self.exts)
        #     if ret:
        #         for k in ret:
        #             paths.add(k[1])
        # with open(os.path.join(self.idir, 'patch.was'), 'rb') as fp:
        #     ret = RobCom.find_binary_paths(fp.read(), self.exts)
        #     if ret:
        #         for k in ret:
        #             paths.add(k[1])
        # with open(os.path.join(self.root, 'files.txt'), 'w') as fp:
        #     for k in sorted(paths):
        #         fp.writelines('"%s",\n' % k)

        # with open(os.path.join(self.root, 'files.txt'), 'w') as fp:
        #     resdir = os.path.join(self.odir, 'res')
        #     for fn in FS.walk_files(resdir, ext_whites=('.png', '.jpg'), cut_pos=len(resdir)+1):
        #         fp.writelines('"%s",\n' % fn)
        with open(os.path.join(self.root, 'files.txt'), 'w') as fp:
            resdir = os.path.join(self.odir, 'res')
            for fn in FS.walk_files(resdir, ewhites=('.json', '.plist', '.atlas'), cut=len(resdir) + 1):
                fp.writelines('"%s",\n' % fn)
            srcdir = os.path.join(self.odir, 'src')
            for fn in FS.walk_files(srcdir, ewhites=['.luac'], cut=len(srcdir) + 1):
                fp.writelines('"%s",\n' % fn)
Beispiel #8
0
 def save_files(self):
     files = FS.walk_files(self.idir, ewhites=('.png', '.jpg'), cut=len(self.idir) + 1)
     print(len(files))
     s = ''
     for f in files:
         s += '"' + f + '",\n'
     FS.write_text(os.path.join(self.idir, 'files.txt'), s)
Beispiel #9
0
def main():
    working_dir = '/Users/joli/Desktop/test/asset'
    # 乱斗
    project_dir = '/Users/joli/proj/sdk_uzone/trunk/projects/luandou'
    target_dir = os.path.join(project_dir,
                              'luandou_xc/app_shenshi/package/FuYaows')
    source_dir = os.path.join(project_dir, 'resource/xiuxian')
    # # 战国
    # project_dir = '/Users/joli/proj/sdk_uzone/trunk/projects/zhanguo'
    # target_dir = os.path.join(project_dir, 'zhanguo_xc/app_tendo/package/sgdyx')
    # source_dir = os.path.join(project_dir, 'resource/dudai_vn')

    # 打包资源
    magic = b'wushen'
    build_pkg = os.path.join(working_dir, 'wushen.bytes')
    build_dir = os.path.join(working_dir, 'resource')
    blur_kb = random.randint(1024, 2048) * 1024
    fill_mb = 3
    make_resource(build_dir, source_dir, target_dir)
    ab = AssetBuilder(magic=magic, blend=True)
    ab.pack(build_pkg, build_dir, blurkb=blur_kb, fillmb=fill_mb)
    with AssetPackage(build_pkg, magic=magic) as ap:
        ap.unpack(os.path.join(working_dir, 'unpack'), build_dir, output=True)
    log.i('AssetBuilder blur=%dkb, fill=%fmb' % (blur_kb / 1024, fill_mb))
    FS.explorer(working_dir)
Beispiel #10
0
 def load_by_disktree():
     svdir = '/Users/joli/Desktop/apps/h5/map'
     iddir = os.path.join(dstdir, 'map')
     flist = sorted(os.listdir(iddir))
     guess = 1000
     ss = requests.session()
     ss.keep_alive = False
     num = 0
     # for n in range(len(flist)-1, -1, -1):
     for n in range(95, -1, -1):
         fid = flist[n]
         col = guess
         end = False
         for i in range(guess):
             for j in range(col):
                 filename = 'pic%d_%d.swf' % (i, j)
                 file_url = '%s/map/%s/swf/%s' % (cdnurl, fid, filename)
                 log.d(n, "load", file_url)
                 response = ss.get(file_url)
                 if response.status_code == 404:
                     if i == 0:
                         col = j
                     else:
                         end = True
                     break
                 elif response.status_code == 200:
                     filepath = os.path.join(svdir, fid, filename)
                     FS.make_parent(filepath)
                     with open(filepath, "wb") as fp:
                         fp.write(response.content)
                 else:
                     log.e(num, file_url)
                     errors.append(file_url)
             if end:
                 break
Beispiel #11
0
def test_split_images():
    from com.arts import SplitImages
    # SplitImages.tp('/Users/joli/Desktop/snsgz/effect/effect_beifa_2/effect_beifa_2.plist')
    pro = '/Users/joli/Desktop/test/rob/1'
    src = os.path.join(pro, 'snxyj')
    for f in FS.walk_files(src, ewhites=['.plist'], cut=len(src) + 1):
        d = os.path.join(pro, 'snxyj_ef', os.path.dirname(f), FS.filename(f))
        SplitImages.tp(os.path.join(src, f), outputdir=d)
Beispiel #12
0
 def load(self):
     if not os.path.isfile(self._path):
         return
     if self._hide:
         FS.set_file_archive(self._path)
     self._old_map = json.loads(FS.read_text(self._path))
     if self._hide:
         FS.set_file_hidden(self._path)
Beispiel #13
0
 def pull_hack_files(self, outdir, files, ftype=None):
     miss = []
     phone_dir = '/data/data/%s/files' % self.appid
     for i in range(len(files)):
         f = '%s/%s' % (outdir, files[i])
         FS.make_parent(f)
         if ADB.pull('%s/hack%d.%s' % (phone_dir, i + 1, ftype if ftype else f[-3:]), f) != 0:
             miss.append(f)
     print('miss', len(miss), miss)
Beispiel #14
0
def laya_sk(skpath, imagepath=None, outputdir=None):
    from jonlin.utils import Bit
    with open(skpath, 'rb') as fp:
        ba = Bit.ByteArray().init_buffer(fp.read())
        ani_version = ba.read_utf8()
        ani_classname = ba.read_utf8()
        ani_names = ba.read_utf8()
        ani_count = ba.read_u8()
        pub_data_pos = ba.read_u32()
        ext_data_pos = ba.read_u32()
        # print(pub_data_pos, ext_data_pos)
        ba.set_position(ext_data_pos)
        ext_buffer = ba.read_bytes(ba.get_available())
        ba = Bit.ByteArray().init_buffer(ext_buffer)
        tex_count = ba.read_int()
        tex_array = ba.read_utf8().split('\n')
        tex_books = {}
        tex_frames = []
        for i in range(tex_count):
            tex_name = tex_array[i * 2 + 1]
            tex_books[tex_name] = tex_array[i * 2]
            x = ba.read_float()
            y = ba.read_float()
            w = ba.read_float()
            h = ba.read_float()
            fx = ba.read_float()
            fy = ba.read_float()
            fw = ba.read_float()
            fh = ba.read_float()
            # print(tex_name, x, y, w, h, fx, fy, fw, fh)
            tex_frames.append((tex_name, x, y, w, h, fx, fy, fw, fh))
        # crop images
        atlas_root = os.path.dirname(skpath)
        if outputdir is None:
            imagesdir = os.path.join(atlas_root,
                                     FS.filename(skpath) + '_images')
        else:
            imagesdir = outputdir
        # if not os.path.isdir(imagesdir):
        #     os.makedirs(imagesdir)
        image_map = {}
        for src in set(tex_books.values()):
            image_map[src] = Image.open(os.path.join(atlas_root, src))
        for frame in tex_frames:
            tex_name = frame[0]
            x = frame[1]
            y = frame[2]
            w = frame[3]
            h = frame[4]
            rect = (x, y, x + w, y + h)
            image = image_map[tex_books[tex_name]]
            item_img = image.crop(rect)
            item_src = os.path.join(imagesdir, tex_name + '.png')
            FS.make_parent(item_src)
            item_img.save(item_src)
Beispiel #15
0
 def __init__(self):
     # self._generate()
     self._resdir = os.path.abspath(
         os.path.join(__file__, '../../../../resource'))
     self._nounlist = FS.read_text(
         os.path.join(self._resdir, 'endict/starnoun1.txt')).split('\n')
     self._verblist = FS.read_text(
         os.path.join(self._resdir, 'endict/starnoun1.txt')).split('\n')
     self._nounimax = len(self._nounlist) - 1
     self._verbimax = len(self._verblist) - 1
     log.d(f'noun:{self._nounimax+1}, verb:{self._verbimax+1}')
Beispiel #16
0
 def edit(self, excel_name, sheet_name, sheet_obj, sheet_area, errors):
     index_info = _Lua2.gen_index_info(sheet_obj, sheet_area, errors)
     if not index_info:
         return
     lua_str = self._mk_items(sheet_obj, sheet_area, sheet_name, index_info,
                              errors)
     if lua_str and not errors:
         parent = os.path.join(self._out_root, excel_name)
         FS.make_parent(parent)
         with open(os.path.join(parent, sheet_name + '.lua'), 'wb') as fp:
             fp.write(lua_str.encode('utf-8'))
Beispiel #17
0
 def _httpload(host, filename):
     # filename = '%s_%s%s' % (FS.get_file_name(key), obj, ext)
     file_url = '%s/%s' % (host, filename)
     response = httpss.get(file_url)
     if response.status_code == 200:
         filename = file_url[len(cdnurl) + 1:]
         print(filename)
         filepath = os.path.join(dstdir, filename)
         FS.make_parent(filepath)
         with open(filepath, "wb") as fp:
             fp.write(response.content)
         return True
Beispiel #18
0
 def copy_files(self):
     src = os.path.join(self.idir, 'Data')
     dst = os.path.join(self.odir, 'Data')
     files = FS.walk_files(src, cut=len(src) + 1)
     for f in files:
         if f[0] == '.':
             continue
         if FS.extensions(f) == '.bin':
             continue
         d = os.path.join(dst, f)
         if os.path.isfile(d):
             continue
         FS.moveto(os.path.join(src, f), d)
Beispiel #19
0
 def _build_lua(self, src, dst):
     log.i(src)
     self._cstree.input_init()
     with open(src, 'r', encoding='utf-8') as fp:
         for s in fp.readlines():
             self._cstree.input_line(s)
     text = self._cstree.build(self._flag_dangling, self._flag_hidden,
                               self._flag_repeat)
     if text is None:
         log.e('build text error:', src)
     else:
         FS.make_parent(dst)
         with open(dst, 'w', encoding='utf-8') as fp:
             fp.write(text)
Beispiel #20
0
 def pull_files(self):
     fs = '/Users/joli/Documents/AndroidStudio/DeviceExplorer/meizu-m3s-Y15QKBPR242LL/data/data/com.youzu.snsgz2.aligames/files'
     files = self.read_files()
     misss = []
     for i in range(len(files)):
         fn = files[i]
         i += 1
         src = os.path.join(fs, 'hack%d%s' % (i, FS.extensions(fn)))
         if os.path.isfile(src):
             dst = os.path.join(self.odir, fn)
             FS.moveto(src, dst)
         else:
             misss.append(i)
     print(misss)
Beispiel #21
0
 def compile(self, src_dir, dst_dir, is_debug=False):
     tamplate = '%s -o %s %s' if is_debug else '%s -s -o %s %s'
     tail_pos = len(src_dir) + 1
     for (root, _, files) in os.walk(src_dir):
         for file_name in files:
             if not file_name.endswith('.lua'):
                 continue
             src_file = os.path.join(root, file_name)
             lua_file = src_file[tail_pos:]
             dst_file = os.path.join(dst_dir, lua_file)
             print('compile', lua_file)
             FS.make_parent(dst_file)
             os.system(tamplate % (self._compiler, dst_file, src_file))
     print('compile lua done')
Beispiel #22
0
 def _output1():
     src = '/Users/joli/Downloads/configIOS_json190731'
     dst = '/Users/joli/Downloads/configIOS_excel'
     for filename in FS.walk_files(src, ewhites=['.json'],
                                   cut=len(src) + 1):
         print('------------------------------------', filename)
         name = FS.filename(filename)
         conf = demjson.decode_file(os.path.join(src, filename))
         if not conf:
             print('empty config')
             continue
         wb = openpyxl.Workbook()
         # print(wb.get_sheet_names())
         _build_book2(wb, conf, name)
         wb.save(os.path.join(dst, name + '.xlsx'))
Beispiel #23
0
 def split_files(pkg, buffer):
     with open(pkg + '_filelist.txt', 'r') as fp:
         filelist = []
         for item in fp.read().split('\n'):
             if item:
                 colon = item.find(':')
                 filelist.append((int(item[0:colon]), item[colon + 1:]))
         print("filelist:", len(filelist))
     pos = len(buffer)
     for i in range(len(filelist) - 1, -1, -1):
         item = filelist[i]
         path = os.path.join(pkg, item[1])
         FS.make_parent(path)
         beg = item[0] + len(item[1]) + 1
         with open(path, 'wb') as fp:
             fp.write(buffer[beg:pos])
         pos = item[0]
Beispiel #24
0
def test_lupa():
    import lupa
    print(lupa.version)
    file = '/Users/joli/proj/sdk_uzone/trunk/projects/luandou/runtime/src/csb/Activity/acLimintTimeHero.lua'
    text = FS.read_text(file)
    lua = lupa.LuaRuntime()
    ast = lua.compile(text)
    print(ast)
Beispiel #25
0
 def read_files(self):
     files = []
     s = FS.read_text(os.path.join(self.idir, 'files.txt'))
     for f in s.split('\n'):
         if f:
             files.append(f[1:-2])
     print(len(files))
     return files
Beispiel #26
0
 def analyse_json(self, json_root):
     print(json_root)
     types_list = set()
     for p in FS.walk_files(json_root, ewhites=['.json']):
         obj = json.loads(FS.read_text(p))
         if not obj:
             continue
         if isinstance(obj, dict):
             t = obj['__type__']
             if t.startswith('cc.'):
                 if t == 'cc.JsonAsset':
                     if not obj['json']['frames']:
                         print(p)
                 types_list.add(t)
             continue
         # print(type(obj))
     print(types_list)
Beispiel #27
0
 def decrypt_res(self):
     raw_root = os.path.join(self.root, 'khsg_wf_dist/assets/res/raw-assets')
     for f in FS.walk_files(raw_root, ewhites=['.png']):
         with open(f, 'rb') as fp:
             buffer = self.decrypt_png(fp.read())
         with open(f, 'wb') as fp:
             fp.write(buffer)
     print('finish')
Beispiel #28
0
 def read_files(self):
     files = []
     s = FS.read_text(self.flist)
     for f in s.split('\n'):
         if f:
             files.append(f[1:-2])
     print(len(files))
     return files
Beispiel #29
0
    def build(work_dir):
        import biplist
        config = biplist.readPlist(os.path.join(work_dir, 'config.plist'))
        curdir = config['work_dir'] if 'work_dir' in config else work_dir

        build_dir = os.path.join(curdir, 'build')
        shutil.rmtree(build_dir)
        shutil.copytree(config['resource_dir'], build_dir)

        assets_dir = os.path.join(config['project_dir'], 'assets')
        for fn in os.listdir(assets_dir):
            if fn in config['keeps']:
                continue
            fp = os.path.join(assets_dir, fn)
            if os.path.isfile(fp):
                os.remove(fp)
            elif os.path.isdir(fp):
                shutil.rmtree(fp)

        skin_dir = os.path.join(config['project_dir'], 'skin')
        FS.merge_tree(skin_dir, build_dir)

        template_dir = os.path.join(curdir, 'template',
                                    config['template_name'])
        white_list = FS.walk_files(template_dir, cut=len(template_dir) + 1)
        FS.moveto_dir(build_dir, assets_dir, white_list)
        FS.rm_empty_dirs(build_dir)

        zip_path = shutil.make_archive(build_dir, 'zip', build_dir)
        obb_path = os.path.join(
            build_dir, 'main.%s.%s.obb' % (config['version'], config['appid']))
        shutil.move(zip_path, obb_path)

        print('make obb done =>', obb_path)
Beispiel #30
0
 def _output2():
     json_ver = '/Users/joli/Downloads/fy/assets/game/resource/1_00.58_version.json'
     conf_src = '/Users/joli/Downloads/fy/assets/game/resource/config'
     conf_dst = '/Users/joli/Downloads/fy/assets/game/resource/config'
     ver_dict = {}
     for k, v in json.loads(FS.read_text(json_ver)).items():
         ver_dict[v] = k
     for f in FS.walk_files(conf_src, ewhites=['.json']):
         # f = '/Users/joli/Downloads/fy/assets/game/resource/config/4643a093.json'
         config = demjson.decode_file(f)
         if not config:
             print('empty config:' + f)
             continue
         vf = ver_dict[FS.filename(f)]
         df = os.path.join(conf_dst, vf[0:vf.rfind('.')] + '.xlsx')
         print(f)
         print(vf)
         print(df)
         wb = openpyxl.Workbook()
         if vf.startswith('global/') or 'error_code_data' in vf:
             print(config)
             _build_sheet1(wb.active, config, FS.filename(df), flat=True)
         else:
             _build_book1(wb, config, FS.filename(df))
         FS.make_parent(df)
         wb.save(df)