GithubHelp home page GithubHelp logo

Comments (3)

zhkl0228 avatar zhkl0228 commented on August 15, 2024

跟其它的没区别,只是对bitmap的处理你要用java模拟实现

from unidbg.

xiada avatar xiada commented on August 15, 2024
package com.kuaishou;

import cn.banny.unidbg.Module;
import cn.banny.unidbg.arm.ARMEmulator;
import cn.banny.unidbg.file.FileIO;
import cn.banny.unidbg.file.IOResolver;
import cn.banny.unidbg.linux.android.AndroidARMEmulator;
import cn.banny.unidbg.linux.android.AndroidResolver;
import cn.banny.unidbg.linux.android.dvm.*;
import cn.banny.unidbg.memory.Memory;

import java.io.*;

public class KpgDecoder extends AbstractJni implements IOResolver {

    private static final String APP_PACKAGE_NAME = "com.smile.gifmaker";

    private final ARMEmulator emulator;
    private final VM vm;

    private final DvmClass KpgUtil;

    private static final String APK_PATH = "src/test/resources/app/kuaishou.apk";

    private final Module module;
    private KpgDecoder() throws IOException {
        emulator = new AndroidARMEmulator(APP_PACKAGE_NAME);
        emulator.getSyscallHandler().addIOResolver(this);
        System.out.println("== init ===");

        final Memory memory = emulator.getMemory();
        memory.setLibraryResolver(new AndroidResolver(19));
        memory.setCallInitFunction();

        vm = emulator.createDalvikVM(new File(APK_PATH));
        vm.setJni(this);
        DalvikModule dm = vm.loadLibrary("kpg", false);
        dm.callJNI_OnLoad(emulator);
        module = dm.getModule();

        KpgUtil = vm.resolveClass("com/kwai/sdk/libkpg/KpgUtil");
    }

    public static void main(String[] args) {
        try {
            File file = new File("D:\\test.kpg");
            InputStream in = new FileInputStream(file);
            b test = parseKpgHeader(in);
            InputStream in2 = new FileInputStream(file);
            byte[] kWVCPayLoad = getKWVCPayLoad(in2, test);
            KpgDecoder kpgDecoder = new KpgDecoder();
            kpgDecoder.decode(kWVCPayLoad,test);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private void decode(byte[] kWVCPayLoad,b bVar){
        Number ret = KpgUtil.callStaticJniMethod(emulator, "native_decode([BIII)[I",
                vm.addLocalObject(new ByteArray(kWVCPayLoad)), bVar.d, bVar.a, bVar.b);
        long hash = ret.intValue() & 0xffffffffL;
        StringObject obj = vm.getObject(hash);
        vm.deleteLocalRefs();
        System.out.println(obj.getValue());
    }


    public static b parseKpgHeader(InputStream inputStream) {
        byte[] bArr = new byte[4];
        try {
            b bVar = new b();
            inputStream.read(bArr);
            if (compare(bArr, "RIFF")) {
                bVar.c = getInt(inputStream);
                inputStream.read(bArr);
                if (compare(bArr, "KPGB")) {
                    int i = 0;
                    while (i < bVar.c - 4) {
                        inputStream.read(bArr);
                        i += 4;
                        int i2 = getInt(inputStream);
                        i += 4;
                        if (compare(bArr, "KWVC")) {
                            bVar.a = getInt(inputStream);
                            i += 4;
                            bVar.b = getInt(inputStream);
                            i += 4;
                            bVar.d = i2 - 8;
                            bVar.e = i + 12;
                            break;
                        }
                        inputStream.skip((long) i2);
                        i += i2;
                    }
                    if (i < bVar.c) {
                        try {
                            inputStream.close();
                        } catch (IOException e) {
                        }
                        return bVar;
                    } else {
                        try {
                            inputStream.close();
                            return null;
                        } catch (IOException e2) {
                            return null;
                        }
                    }
                } else {
                    try {
                        inputStream.close();
                        return null;
                    } catch (IOException e22) {
                        return null;
                    }
                }
            } else {
                try {
                    inputStream.close();
                    return null;
                } catch (IOException e222) {
                    return null;
                }
            }
        } catch (IOException e2222) {
            try {
                inputStream.close();
                return null;
            } catch (IOException e22222) {
                return null;
            }
        } catch (Throwable th) {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e222222) {
                }
            }
        }
        return null;
    }

    private static boolean compare(byte[] bArr, String str) {
        if (bArr.length != str.length()) {
            return false;
        }
        for (int i = 0; i < bArr.length; i++) {
            if (str.charAt(i) != bArr[i]) {
                return false;
            }
        }
        return true;
    }
    private static int getInt(InputStream inputStream) throws IOException {
        return (((byte) inputStream.read()) & 255) | (((((byte) inputStream.read()) << 8) & 65280) | (((((byte) inputStream.read()) << 16) & 16711680) | ((((byte) inputStream.read()) << 24) & -16777216)));
    }

    public static byte[] getKWVCPayLoad(InputStream inputStream, b bVar) {
        byte[] bArr = new byte[bVar.d];
        try {
            inputStream.skip((long) bVar.e);
            if (inputStream.read(bArr) == bVar.d) {
                return bArr;
            }
            throw new IllegalArgumentException(String.format("getKWVCPayLoad fail, can not read enough bytes of kwvcPayloadLen:%d", new Object[]{Integer.valueOf(bVar.d)}));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }


    @Override
    public FileIO resolve(File workDir, String pathname, int oflags) {
        return null;
    }

    @Override
    public DvmObject callObjectMethodV(BaseVM vm, DvmObject dvmObject, String signature, VaList vaList) {
        switch (signature) {
            case "com/yxcorp/gifshow/App->getPackageName()Ljava/lang/String;":
                return new StringObject(vm, APP_PACKAGE_NAME);
            case "com/yxcorp/gifshow/App->getPackageManager()Landroid/content/pm/PackageManager;":
                return vm.resolveClass("android/content/pm/PackageManager").newObject(null);
        }

        return super.callObjectMethodV(vm, dvmObject, signature, vaList);
    }


    public static class b {
        public int a;
        public int b;
        public int c;
        public int d;
        public int e;
    }

}

test.kpg在这
test.zip

为啥这个会报[swscaler @ 0x804e290] No accelerated colorspace conversion found from yuv420p to bgra.

from unidbg.

zhkl0228 avatar zhkl0228 commented on August 15, 2024

更新最新代码即可支持

from unidbg.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.