java解包 安卓和ios

33 篇文章 0 订阅

1.安卓

		<dependency>
            <groupId>net.dongliu</groupId>
            <artifactId>apk-parser</artifactId>
        </dependency>

import net.dongliu.apk.parser.ApkFile;
import net.dongliu.apk.parser.bean.ApkMeta;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;

public class APKUtil {
    private static final Logger LOGGER = LoggerFactory.getLogger(APKUtil.class);


    public static Map<String, String> getApkInfo(File file) {
        try {
            Map<String, String> apkInfo = new HashMap<>();
            ApkFile apkFile = new ApkFile(file);
            ApkMeta apkMeta = apkFile.getApkMeta();
            apkInfo.put("appName", apkMeta.getName());
            apkInfo.put("packName", apkMeta.getPackageName());
            apkInfo.put("versionCode", String.valueOf(apkMeta.getVersionCode()));
            apkInfo.put("versionName", apkMeta.getVersionName());
            return apkInfo;
        } catch (Exception e) {
            LOGGER.error("获取apk信息错误:", e);
            return null;
        }
    }

    public static void inputStreamToFile(InputStream ins, File file) {
        try {
            OutputStream os = new FileOutputStream(file);
            int bytesRead = 0;
            byte[] buffer = new byte[8192];
            while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) {
                os.write(buffer, 0, bytesRead);
            }
            os.close();
            ins.close();
        } catch (Exception e) {
            LOGGER.error("转换文件错误:", e);
        }
    }
}

2.ios

		<dependency>
            <groupId>com.googlecode.plist</groupId>
            <artifactId>dd-plist</artifactId>
        </dependency>

import com.dd.plist.NSDictionary;
import com.dd.plist.NSString;
import com.dd.plist.PropertyListParser;

import java.io.*;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;


public class IPAUtils {
    /**
     * 解压IPA文件,只获取IPA文件的Info.plist文件存储指定位置
     *
     * @param file           zip文件
     * @param unzipDirectory 解压到的目录
     * @throws Exception
     */
    private static File getZipInfo(File file, String unzipDirectory) throws Exception {
        // 定义输入输出流对象
        InputStream input = null;
        OutputStream output = null;
        File result = null;
        File unzipFile = null;
        ZipFile zipFile = null;
        try {
            // 创建zip文件对象
            zipFile = new ZipFile(file);
            // 创建本zip文件解压目录
            String name = file.getName().substring(0, file.getName().lastIndexOf("."));
            unzipFile = new File(unzipDirectory + "/" + name);
            if (unzipFile.exists()) {
                unzipFile.delete();
            }
            unzipFile.mkdir();
            // 得到zip文件条目枚举对象
            Enumeration<? extends ZipEntry> zipEnum = zipFile.entries();
            // 定义对象
            ZipEntry entry = null;
            String entryName = null;
            String names[] = null;
            int length;
            // 循环读取条目
            while (zipEnum.hasMoreElements()) {
                // 得到当前条目
                entry = zipEnum.nextElement();
                entryName = new String(entry.getName());
                // 用/分隔条目名称
                names = entryName.split("\\/");
                length = names.length;
                for (int v = 0; v < length; v++) {
                    if (entryName.endsWith(".app/Info.plist")) { // 为Info.plist文件,则输出到文件
                        input = zipFile.getInputStream(entry);
                        result = new File(unzipFile.getAbsolutePath() + "/Info.plist");
                        output = new FileOutputStream(result);
                        byte[] buffer = new byte[1024 * 8];
                        int readLen = 0;
                        while ((readLen = input.read(buffer, 0, 1024 * 8)) != -1) {
                            output.write(buffer, 0, readLen);
                        }
                        break;
                    }
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            if (input != null) {
                input.close();
            }
            if (output != null) {
                output.flush();
                output.close();
            }
            // 必须关流,否则文件无法删除
            if (zipFile != null) {
                zipFile.close();
            }
        }

        // 如果有必要删除多余的文件
        if (file.exists()) {
            file.delete();
        }
        return result;
    }

    /**
     * IPA文件的拷贝,把一个IPA文件复制为Zip文件,同时返回Info.plist文件 参数 oldfile 为 IPA文件
     */
    private static File getIpaInfo(File oldfile) throws IOException {
        try {
            int byteread = 0;
            String filename = oldfile.getAbsolutePath().replaceAll(".ipa", ".zip");
            File newfile = new File(filename);
            if (oldfile.exists()) {
                // 创建一个Zip文件
                InputStream inStream = new FileInputStream(oldfile);
                FileOutputStream fs = new FileOutputStream(newfile);
                byte[] buffer = new byte[1444];
                while ((byteread = inStream.read(buffer)) != -1) {
                    fs.write(buffer, 0, byteread);
                }
                if (inStream != null) {
                    inStream.close();
                }
                if (fs != null) {
                    fs.close();
                }
                // 解析Zip文件
                return getZipInfo(newfile, newfile.getParent());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 通过IPA文件获取Info信息
     */
    public static Map<String, String> getVersionInfo(File ipa) throws Exception {

        File file = getIpaInfo(ipa);
        Map<String, String> info = new HashMap<>();
        // 需要第三方jar包dd-plist
        NSDictionary rootDict = (NSDictionary) PropertyListParser.parse(file);
        // 应用包名
        NSString parameters = (NSString) rootDict.objectForKey("CFBundleIdentifier");
        info.put("CFBundleIdentifier", parameters.toString());
        // 应用名称
        parameters = (NSString) rootDict.objectForKey("CFBundleName");
        info.put("CFBundleName", parameters.toString());
        // 应用版本
        parameters = (NSString) rootDict.objectForKey("CFBundleVersion");
        info.put("CFBundleVersion", parameters.toString());
        // 应用展示的名称
        parameters = (NSString) rootDict.objectForKey("CFBundleDisplayName");
        info.put("CFBundleDisplayName", parameters.toString());
        // 应用所需IOS最低版本
        parameters = (NSString) rootDict.objectForKey("MinimumOSVersion");
        info.put("MinimumOSVersion", parameters.toString());
        parameters = (NSString) rootDict.objectForKey("CFBundleShortVersionString");
        info.put("CFBundleShortVersionString", parameters.toString());
        // 如果有必要,应该删除解压的结果文件
        file.delete();
        file.getParentFile().delete();

        return info;
    }
}

操作系统:ubuntu10.10可虚拟机可其他linux可其他版本 & Windows 7 Ubuntu下操作: 下载unyaffs和yaffs2.tar.gz,并编译yaffs2再复制到/bin下(自己找资料) 1.Ubuntu下,在任意文件夹下面建立一个system文件夹,我的是在home/jamly/下面建的 2.将下载的自己喜欢的直刷ROM中的system.img复制到system文件夹中 3.在终端中输入如下命令操作(/home/jamly/替换成自己电脑中的路径,你的不是我的) cd /home/jamly/system sudo unyaffs /home/jamly/system/system.img(用unyaffs命令解压system.img) 保留操作【sudo chmod -R 777 *(打开读写操作最高权限)】 4.删除system.img 5.自己搞system文件夹下的文件,胡搞瞎搞乱搞阴搞暗搞黑搞,怎么搞自己搞我不搞…… 6用mkyaffs2image命令打包system.img 经过自己摸索,发现有时候会出现开机不能启动的现象,可能是因为修改时没有用root权限登录进行操作,操作完成后应该用cd ./ sudo ls -h 命令查看被修该国的文件的文件属性,如果显示的不是-drrwx-rx-x- root root ……,注意下划线部分,如果不是root root的话,要修改 sudo chown-R root:root /home/jamly/system/具体文件夹的文件 一般我是直接在/system文件夹下操作所有的文件,宁可错杀不可漏网 还有修改权限的的命令 一般是修改成-drwxx-rx-x-,意思是root权限有读写执行权限,用户组有读执行权限,其他用户有执行权限,操作方法是 sudo -chmod -R 4755 /home/jamly/system/具体文件夹的文件 上述步骤在打包前面进行,弄完之后再ROOT系统权限。 sudo mkyaffs2image /home/jamly/system/ /home/jamly/system.img sudo chmod -R 777 /home/jamly/system.img(打开刚生成的system.img读写操作最高权限) 7.复制system.img到原直刷文件夹下Win7刷机…… ps1:如果想弄system.ext2里面的东西可以挂载ystem.ext2到某个文件夹下复制里面的内容到system文件夹下再操作 sudo mount -o loop /home/jamly/system.ext2 /mnt 进入/mnt文件夹中复制 ps2:个别老大的systwm.img文件为systwm.bin,重命名即可。如果解压后里面有squashed.sqsh文件,也可以挂载然后弄出来瞎搞 sudo mount -t squashfs -o loop /home/jamly/system/squashed.sqsh /mnt 具体点的找google帮忙人肉squashfs命令。 ps3: 在system文件夹下理论(记住是理论上的)ROOT方法 cd /home/jamly cat /home/jamly/system/bin/sh >/home/jamly/system/bin/su cat /home/jamly/system/bin/sh >/home/jamly/system/xbin/su chmod 4755 /home/jamly/system/bin/su chmod 4755 /home/jamly/system/xbin/su 信息来源:起点手机论坛 原文链接:http://www.qdppc.com/forum.php?mod=viewthread&tid=43806&fromuid=1
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值