コード例 #1
0
ファイル: RobAPK.py プロジェクト: atom-chen/joli-hipy
    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')
コード例 #2
0
ファイル: TestRob.py プロジェクト: atom-chen/joli-hipy
 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)
コード例 #3
0
ファイル: TestRob.py プロジェクト: atom-chen/joli-hipy
 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
コード例 #4
0
ファイル: TestRob.py プロジェクト: atom-chen/joli-hipy
 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)
コード例 #5
0
ファイル: RobAPK.py プロジェクト: atom-chen/joli-hipy
 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)
コード例 #6
0
ファイル: RobAPK.py プロジェクト: atom-chen/joli-hipy
 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)
コード例 #7
0
ファイル: SplitImages.py プロジェクト: atom-chen/joli-hipy
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)
コード例 #8
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'))
コード例 #9
0
ファイル: TestRob.py プロジェクト: atom-chen/joli-hipy
 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
コード例 #10
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)
コード例 #11
0
ファイル: MakeScript.py プロジェクト: atom-chen/joli-hipy
 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')
コード例 #12
0
ファイル: TestRob.py プロジェクト: atom-chen/joli-hipy
 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]
コード例 #13
0
ファイル: TestRob.py プロジェクト: atom-chen/joli-hipy
def test_hack_xor():
    sig = b'laoma'
    src_dir = '/Users/joli/Downloads/nds_19041501/assets'
    dst_dir = '/Users/joli/Downloads/nds_19041501/de_assets'
    for filename in FS.walk_files(src_dir, cut=len(src_dir) + 1):
        # src = '/Users/joli/Downloads/nds_19041501/assets/src/accountLogin/Img_account_bg.png'
        # dst = '/Users/joli/Downloads/nds_19041501/assets/src/accountLogin/Img_account_bg1.png'
        src = os.path.join(src_dir, filename)
        dst = os.path.join(dst_dir, filename)
        with open(src, 'rb') as fp:
            temp = fp.read()
            if temp[:5] == sig:
                temp = temp[5:]
                size = len(temp)
                data = bytearray(size)
                for i in range(size):
                    data[i] = temp[i] ^ 0x6
            else:
                continue
        FS.make_parent(dst)
        with open(dst, 'wb') as fp:
            fp.write(data)
コード例 #14
0
ファイル: MakeAsset.py プロジェクト: atom-chen/joli-hipy
 def unpack(self, dest, refer, output=False):
     start_t = time.time()
     filenum, filemap = 0, {}
     for tag in FS.walk_files(refer, cut=len(refer) + 1):
         filemap[Math.hash_bkdr(tag, self._hseed)] = tag
     for hashcode in self._hashmap:
         if hashcode not in filemap:
             continue
         filename = filemap[hashcode]
         fileinfo = self._hashmap[hashcode]
         log.i('unpack file:', filename)
         buffer = self._read(fileinfo)
         if output:
             pos = os.path.join(dest, filename)
             FS.make_parent(pos)
             with open(pos, 'wb') as fp:
                 fp.write(buffer)
         else:
             assert len(buffer) == fileinfo[1], 'file error:' + filename
         filenum += 1
     log.i('unpack bale done, 数量:%d, 耗时:%.2fs' %
           (filenum, time.time() - start_t))
コード例 #15
0
ファイル: TestRob.py プロジェクト: atom-chen/joli-hipy
 def dexxtea_file(src, dst, bsign, bkey):
     with open(src, 'rb') as fp:
         data = dexxtea(fp.read(), bsign, bkey)
     FS.make_parent(dst)
     with open(dst, 'wb') as fp:
         fp.write(data)
コード例 #16
0
ファイル: SplitImages.py プロジェクト: atom-chen/joli-hipy
def spine(atlaspath, imagepath=None, outputdir=None, fixwhite=True):
    with open(atlaspath, 'r') as fp:
        atlases, atlas, header, frames, frame = [], None, None, None, None
        for line in fp.readlines():
            if line.isspace():
                header, frames = {}, []
                atlas = {'header': header, 'frames': frames}
                atlases.append(atlas)
                continue
            line = ''.join(line.split())  # 去除空格
            if not line:
                continue
            pos = line.find(':')
            if header is not None:
                if -1 == pos:
                    header['image'] = line
                else:
                    pos += 1
                    if line.startswith('size'):
                        header['size'] = tuple(
                            [int(x) for x in line[pos:].split(',')])
                    elif line.startswith('format'):
                        header['format'] = line[pos:]
                    elif line.startswith('filter'):
                        header['filter'] = tuple(
                            [x for x in line[pos:].split(',')])
                    elif line.startswith('repeat'):
                        header['repeat'] = line[pos:]
                        header = None
            else:
                if -1 == pos:
                    frame = {'name': line}
                    frames.append(frame)
                else:
                    pos += 1
                    if line.startswith('rotate'):
                        frame['rotate'] = False if line[
                            pos:] == 'false' else True
                    elif line.startswith('xy'):
                        frame['xy'] = tuple(
                            [int(x) for x in line[pos:].split(',')])
                    elif line.startswith('size'):
                        frame['size'] = tuple(
                            [int(x) for x in line[pos:].split(',')])
                    elif line.startswith('orig'):
                        frame['orig'] = tuple(
                            [int(x) for x in line[pos:].split(',')])
                    elif line.startswith('offset'):
                        frame['offset'] = tuple(
                            [int(x) for x in line[pos:].split(',')])
                    elif line.startswith('index'):
                        frame['index'] = int(line[pos:])
    for atlas in atlases:
        if not atlas['frames']:
            continue
        image_name = atlas['header']['image']
        atlas_dir = os.path.dirname(atlaspath)
        if imagepath is None:
            imagepath = os.path.join(atlas_dir, image_name)
        if not os.path.isfile(imagepath):
            continue
        if outputdir is None:
            outputdir = os.path.join(atlas_dir,
                                     FS.filename(image_name) + '_images')
        image = Image.open(imagepath)
        for frame in atlas['frames']:
            if 'xy' not in frame:
                continue
            x, y = frame['xy']
            w, h = frame['size']
            if frame['rotate']:
                w, h = h, w
            rect = (x, y, x + w, y + h)
            item_img = image.crop(rect)
            if frame['rotate']:
                # item_img = item_img.rotate(270)
                item_img = item_img.transpose(Image.ROTATE_270)
            if fixwhite:
                x, y = frame['offset']
                y = frame['orig'][1] - y - item_img.size[1]
                rect = (x, y, x + item_img.size[0], y + item_img.size[1])
                item_box = Image.new('RGBA', size=frame['orig'])
                item_box.paste(item_img, rect)
                item_img = item_box
            item_path = os.path.join(outputdir, frame['name'] + '.png')
            FS.make_parent(item_path)
            item_img.save(item_path)
コード例 #17
0
ファイル: RobCom.py プロジェクト: atom-chen/joli-hipy
 def defile(src, dst, bsig, bkey):
     with open(src, 'rb') as fp:
         buffer = XXTEA.decrypt(fp.read(), bsig, bkey)
     FS.make_parent(dst)
     with open(dst, 'wb') as fp:
         fp.write(buffer)