[原创] 签名对抗学习笔记 | 宜武汇-ag真人国际厅网站

package com.lxz;

 

import android.content.componentname;

import android.content.intent;

import android.content.intentfilter;

import android.content.pm.activityinfo;

import android.content.pm.applicationinfo;

import android.content.pm.changedpackages;

import android.content.pm.featureinfo;

import android.content.pm.instrumentationinfo;

import android.content.pm.packageinfo;

import android.content.pm.packageinstaller;

import android.content.pm.packagemanager;

import android.content.pm.permissiongroupinfo;

import android.content.pm.permissioninfo;

import android.content.pm.providerinfo;

import android.content.pm.resolveinfo;

import android.content.pm.serviceinfo;

import android.content.pm.sharedlibraryinfo;

import android.content.pm.signature;

import android.content.pm.versionedpackage;

import android.content.res.resources;

import android.content.res.xmlresourceparser;

import android.graphics.rect;

import android.graphics.drawable.drawable;

import android.os.build;

import android.os.userhandle;

import android.util.log;

 

import androidx.annotation.nonnull;

import androidx.annotation.nullable;

 

import java.util.list;

 

public class hook extends packagemanager {

    private packagemanager mbase;

    private string mpackagename;

 

    // 此处的签名使用 getsignature 获取原包的签名信息

    string signature_str = "3082037130820259a003020102020419f0a927300d06092a864886f70d01010b05003068310b300906035504061302434e310f300d0603550408130646754a69616e310f300d0603550407130646755a686f753111300f060355040a13084c69616e596f6e673111300f060355040b13084c69616e596f6e673111300f060355040313084c6f756973204c753020170d3138303632393037323931365a180f32303733303430313037323931365a3068310b300906035504061302434e310f300d0603550408130646754a69616e310f300d0603550407130646755a686f753111300f060355040a13084c69616e596f6e673111300f060355040b13084c69616e596f6e673111300f060355040313084c6f756973204c7530820122300d06092a864886f70d01010105000382010f003082010a0282010100a55431f01fb453e65d7e070bc82e606c11e9bf77831367701e4d7c79a44c014afa2be320caade2e75f8d9160ecaa6e5a39ca63d8ee5ddaffe54f6da0d1f7ea24efa9591681fa39561780c2bef75ec72096e121524da2f9c84d9455593639e63ca41cdbf7a349e0e26cf5f27564825fa524eb3efdbac5ec62f851053cc833537182e6d24dffaaf50274e6062650d527d76856e188d144116731689881a05db10d8bb159bbef9cfd314b205c785e51d4a34e0db54fa89b7ddb837559338f1f58e38df78f7e5acceeaf94546c78d1b8eea3a25e095fc1c959e77860962b3e980e31b63c3089e3541e27cea1631c3b2c59bcfd4c7384123c778c599473a3a319b2270203010001a321301f301d0603551d0e04160414fc7d539fc8aea2e08ade9cd07c47f43621f3b209300d06092a864886f70d01010b05000382010100088fe8de887969eb896e5d9c31aead82bc348faff1917fb224018a38f6d0126e0a9af191bf84ca84cf530cbe2ba0a4993059ae89ce2a05266a8192b044b4a8e18e510a8c6b7e022bebe5482b09a7b80f47661adf9f53fd65b69cf3acb2efc69b89bac3e90eabf1e7ed719b0efd38159cb5f3fea51ee62307ca5f09cbb85660323a41597438aba3999d3626fcbfa628d5510a435c78a82482d1447c3cff3ea19a7ae87d347b7e5e7b0237029cd2e5e57baa907bde58cb5483ef54dcee05fabaadb1a46c88113d85333c6979d846490d3e8def5aa4c3d94d2fc6497bea36901e6a18e1000db8da1f4bb31421138fbf2cb3a22d0458ef28e7167458278a79bf67ef";

 

    public hook(packagemanager base, string packagename) {

        this.mbase = base;

    }

 

    @override // android.content.pm.packagemanager

    public packageinfo getpackageinfo(string packagename, int flags) throws packagemanager.namenotfoundexception {

 

        if (!mpackagename.equals(packagename)) {

            // 不是自己在检查 packageinfo 信息,返回真实信息

            return this.mbase.getpackageinfo(packagename, flags);

        }

        if (flags != packagemanager.get_signatures) {

            // 检查的不是 signature, 返回真实信息

            return this.mbase.getpackageinfo(packagename, flags);

        }

 

        packageinfo pkginfo = new packageinfo();

        byte bytes[] = hextobytes(signature_str);

        pkginfo.signatures = new signature[]{new signature(bytes)};

        log.e("lxz","强制返回正确签名");

        return pkginfo;

    }

 

    // 将 byte[] 转换为 16 进制字符串

    public static string bytestohex(byte[] bytes) {

        stringbuilder hexstring = new stringbuilder();

        for (byte b : bytes) {

            string hex = integer.tohexstring(0xff & b);

            if (hex.length() == 1) {

                hexstring.append('0');

            }

            hexstring.append(hex);

        }

        return hexstring.tostring();

    }

 

    // 将 16 进制字符串转换为 byte[]

    public static byte[] hextobytes(string hexstring) {

        if (length % 2 != 0) {

            throw new illegalargumentexception("invalid hex string length");

        }

        byte[] bytes = new byte[length / 2];

        for (int i = 0; i < length; i = 2) {

            string hex = hexstring.substring(i, i 2);

            bytes[i / 2] = (byte) integer.parseint(hex, 16);

        }

        return bytes;

    }

 

    @override

    public packageinfo getpackageinfo(@nonnull versionedpackage versionedpackage, int flags) throws namenotfoundexception {

        // 这里好像也可以返回 packageinfo,但我没做处理

        return this.mbase.getpackageinfo(versionedpackage, flags);

    }

    @override

    public list getinstalledpackages(int flags) {

        return this.mbase.getinstalledpackages(flags);

    }

    @override

    public string[] currenttocanonicalpackagenames(string[] names) {

        return this.mbase.currenttocanonicalpackagenames(names);

    }

    @override

    public string[] canonicaltocurrentpackagenames(string[] names) {

        return this.mbase.canonicaltocurrentpackagenames(names);

    }

    @override

    public intent getlaunchintentforpackage(string packagename) {

        return this.mbase.getlaunchintentforpackage(packagename);

    }

    @override

    public intent getleanbacklaunchintentforpackage(string packagename) {

        return this.mbase.getleanbacklaunchintentforpackage(packagename);

    }

    @override

    public int[] getpackagegids(string packagename) throws packagemanager.namenotfoundexception {

        return this.mbase.getpackagegids(packagename);

    }

    @override

    public int[] getpackagegids(@nonnull string packagename, int flags) throws namenotfoundexception {

        return new int[0];

    }

    @override

    public int getpackageuid(@nonnull string packagename, int flags) throws namenotfoundexception {

        return 0;

    }

    @override

    public permissioninfo getpermissioninfo(string name, int flags) throws packagemanager.namenotfoundexception {

        return this.mbase.getpermissioninfo(name, flags);

    }

    @override

    public list querypermissionsbygroup(string group, int flags) throws packagemanager.namenotfoundexception {

        return this.mbase.querypermissionsbygroup(group, flags);

    }

    @override

    public permissiongroupinfo getpermissiongroupinfo(string name, int flags) throws packagemanager.namenotfoundexception {

        return this.mbase.getpermissiongroupinfo(name, flags);

    }

    @override

    public list getallpermissiongroups(int flags) {

        return this.mbase.getallpermissiongroups(flags);

    }

    @override

    public applicationinfo getapplicationinfo(string packagename, int flags) throws packagemanager.namenotfoundexception {

        return this.mbase.getapplicationinfo(packagename, flags);

    }

    @override

    public activityinfo getactivityinfo(componentname component, int flags) throws packagemanager.namenotfoundexception {

        return this.mbase.getactivityinfo(component, flags);

    }

    @override

    public activityinfo getreceiverinfo(componentname component, int flags) throws packagemanager.namenotfoundexception {

        return this.mbase.getreceiverinfo(component, flags);

    }

    @override

    public serviceinfo getserviceinfo(componentname component, int flags) throws packagemanager.namenotfoundexception {

        return this.mbase.getserviceinfo(component, flags);

    }

    @override

    public providerinfo getproviderinfo(componentname component, int flags) throws packagemanager.namenotfoundexception {

        return this.mbase.getproviderinfo(component, flags);

    }

    @override

    public list getpackagesholdingpermissions(string[] permissions, int flags) {

        return this.mbase.getpackagesholdingpermissions(permissions, flags);

    }

    @override

    public int checkpermission(string permname, string pkgname) {

        return this.mbase.checkpermission(permname, pkgname);

    }

    @override

    public boolean ispermissionrevokedbypolicy(string permname, string pkgname) {

        return this.mbase.ispermissionrevokedbypolicy(permname, pkgname);

    }

    @override

    public boolean addpermission(permissioninfo info) {

        return this.mbase.addpermission(info);

    }

    @override

        return this.mbase.addpermissionasync(info);

    }

    @override

    public void removepermission(string name) {

        this.mbase.removepermission(name);

    }

    @override

    public int checksignatures(string pkg1, string pkg2) {

        return this.mbase.checksignatures(pkg1, pkg2);

    }

    @override

    public int checksignatures(int uid1, int uid2) {

        return this.mbase.checksignatures(uid1, uid2);

    }

    @override

    public string[] getpackagesforuid(int uid) {

        return this.mbase.getpackagesforuid(uid);

    }

    @override

    public string getnameforuid(int uid) {

        return this.mbase.getnameforuid(uid);

    }

    @override

    public list getinstalledapplications(int flags) {

        return this.mbase.getinstalledapplications(flags);

    }

    @override

    public boolean isinstantapp() {

        return false;

    }

    @override

    public boolean isinstantapp(@nonnull string packagename) {

        return false;

    }

    @override

    public int getinstantappcookiemaxbytes() {

        return 0;

    }

    @nonnull

    @override

    public byte[] getinstantappcookie() {

        return new byte[0];

    }

    @override

    public void clearinstantappcookie() {

 

    }

    @override

    public void updateinstantappcookie(@nullable byte[] cookie) {

 

    }

    @override

    public string[] getsystemsharedlibrarynames() {

        return this.mbase.getsystemsharedlibrarynames();

    }

    @nonnull

    @override

    public list getsharedlibraries(int flags) {

        return null;

    }

 

    @nullable

    @override

    public changedpackages getchangedpackages(int sequencenumber) {

        return null;

    }

    @override

    public featureinfo[] getsystemavailablefeatures() {

        return this.mbase.getsystemavailablefeatures();

    }

    @override

    public boolean hassystemfeature(string name) {

        return this.mbase.hassystemfeature(name);

    }

 

    @override

    public boolean hassystemfeature(@nonnull string featurename, int version) {

        return false;

    }

    @override

    public resolveinfo resolveactivity(intent intent, int flags) {

        return this.mbase.resolveactivity(intent, flags);

    }

    @override

    public list queryintentactivities(intent intent, int flags) {

        return this.mbase.queryintentactivities(intent, flags);

    }

    @override

    public list queryintentactivityoptions(componentname caller, intent[] specifics, intent intent, int flags) {

        return this.mbase.queryintentactivityoptions(caller, specifics, intent, flags);

    }

    @override

    public list querybroadcastreceivers(intent intent, int flags) {

        return this.mbase.querybroadcastreceivers(intent, flags);

    }

    @override

    public resolveinfo resolveservice(intent intent, int flags) {

        return this.mbase.resolveservice(intent, flags);

    }

    @override

    public list queryintentservices(intent intent, int flags) {

        return this.mbase.queryintentservices(intent, flags);

    }

    @override

    public list queryintentcontentproviders(intent intent, int flags) {

        return this.mbase.queryintentcontentproviders(intent, flags);

    }

    @override

    public providerinfo resolvecontentprovider(string name, int flags) {

        return this.mbase.resolvecontentprovider(name, flags);

    }

    @override

    public list querycontentproviders(string processname, int uid, int flags) {

        return this.mbase.querycontentproviders(processname, uid, flags);

    }

    @override

    public instrumentationinfo getinstrumentationinfo(componentname classname, int flags) throws packagemanager.namenotfoundexception {

        return this.mbase.getinstrumentationinfo(classname, flags);

    }

    @override

    public list queryinstrumentation(string targetpackage, int flags) {

        return this.mbase.queryinstrumentation(targetpackage, flags);

    }

    @override

    public drawable getdrawable(string packagename, int resid, applicationinfo appinfo) {

        return this.mbase.getdrawable(packagename, resid, appinfo);

    }

    @override

    public drawable getactivityicon(componentname activityname) throws packagemanager.namenotfoundexception {

        return this.mbase.getactivityicon(activityname);

    }

    @override

    public drawable getactivityicon(intent intent) throws packagemanager.namenotfoundexception {

        return this.mbase.getactivityicon(intent);

    }

    @override

    public drawable getactivitybanner(componentname activityname) throws packagemanager.namenotfoundexception {

        return this.mbase.getactivitybanner(activityname);

    }

    @override

    public drawable getactivitybanner(intent intent) throws packagemanager.namenotfoundexception {

        return this.mbase.getactivitybanner(intent);

    }

    @override

    public drawable getdefaultactivityicon() {

        return this.mbase.getdefaultactivityicon();

    }

    @override

    public drawable getapplicationicon(applicationinfo info) {

        return this.mbase.getapplicationicon(info);

    }

    @override

    public drawable getapplicationicon(string packagename) throws packagemanager.namenotfoundexception {

        return this.mbase.getapplicationicon(packagename);

    }

    @override

    public drawable getapplicationbanner(applicationinfo info) {

        return this.mbase.getapplicationbanner(info);

    }

    @override

    public drawable getapplicationbanner(string packagename) throws packagemanager.namenotfoundexception {

        return this.mbase.getapplicationbanner(packagename);

    }

    @override

    public drawable getactivitylogo(componentname activityname) throws packagemanager.namenotfoundexception {

        return this.mbase.getactivitylogo(activityname);

    }

    @override

    public drawable getactivitylogo(intent intent) throws packagemanager.namenotfoundexception {

        return this.mbase.getactivitylogo(intent);

    }

    @override

    public drawable getapplicationlogo(applicationinfo info) {

        return this.mbase.getapplicationlogo(info);

    }

    @override

    public drawable getapplicationlogo(string packagename) throws packagemanager.namenotfoundexception {

        return this.mbase.getapplicationlogo(packagename);

    }

    @override

    public drawable getuserbadgedicon(drawable icon, userhandle user) {

        return this.mbase.getuserbadgedicon(icon, user);

    }

    @override

    public drawable getuserbadgeddrawablefordensity(drawable drawable, userhandle user, rect badgelocation, int badgedensity) {

        return this.mbase.getuserbadgeddrawablefordensity(drawable, user, badgelocation, badgedensity);

    }

    @override

    public charsequence getuserbadgedlabel(charsequence label, userhandle user) {

        return this.mbase.getuserbadgedlabel(label, user);

    }

    @override

    public charsequence gettext(string packagename, int resid, applicationinfo appinfo) {

        return this.mbase.gettext(packagename, resid, appinfo);

    }

    @override

    public xmlresourceparser getxml(string packagename, int resid, applicationinfo appinfo) {

        return this.mbase.getxml(packagename, resid, appinfo);

    }

    @override

    public charsequence getapplicationlabel(applicationinfo info) {

        return this.mbase.getapplicationlabel(info);

    }

    @override

    public resources getresourcesforactivity(componentname activityname) throws packagemanager.namenotfoundexception {

        return this.mbase.getresourcesforactivity(activityname);

    }

    @override

    public resources getresourcesforapplication(applicationinfo app) throws packagemanager.namenotfoundexception {

        return this.mbase.getresourcesforapplication(app);

    }

    @override

    public resources getresourcesforapplication(string apppackagename) throws packagemanager.namenotfoundexception {

        return this.mbase.getresourcesforapplication(apppackagename);

    }

    @override

    public void verifypendinginstall(int id, int verificationcode) {

        this.mbase.verifypendinginstall(id, verificationcode);

    }

    @override

    public void extendverificationtimeout(int id, int verificationcodeattimeout, long millisecondstodelay) {

        this.mbase.extendverificationtimeout(id, verificationcodeattimeout, millisecondstodelay);

    }

    @override

    public void setinstallerpackagename(string targetpackage, string installerpackagename) {

        this.mbase.setinstallerpackagename(targetpackage, installerpackagename);

    }

    @override

    public string getinstallerpackagename(string packagename) {

        return this.mbase.getinstallerpackagename(packagename);

    }

    @override

    public void addpackagetopreferred(string packagename) {

        this.mbase.addpackagetopreferred(packagename);

    }

    @override

    public void removepackagefrompreferred(string packagename) {

        this.mbase.removepackagefrompreferred(packagename);

    }

    @override

    public list getpreferredpackages(int flags) {

        return this.mbase.getpreferredpackages(flags);

    }

    @override

    public void addpreferredactivity(intentfilter filter, int match, componentname[] set, componentname activity) {

        this.mbase.addpreferredactivity(filter, match, set, activity);

    }

    @override

    public void clearpackagepreferredactivities(string packagename) {

        this.mbase.clearpackagepreferredactivities(packagename);

    }

    @override

    public int getpreferredactivities(list outfilters, list outactivities, string packagename) {

        return this.mbase.getpreferredactivities(outfilters, outactivities, packagename);

    }

    @override

    public void setcomponentenabledsetting(componentname componentname, int newstate, int flags) {

        this.mbase.setcomponentenabledsetting(componentname, newstate, flags);

    }

    @override

    public int getcomponentenabledsetting(componentname componentname) {

        return this.mbase.getcomponentenabledsetting(componentname);

    }

    @override

    public void setapplicationenabledsetting(string packagename, int newstate, int flags) {

        this.mbase.setapplicationenabledsetting(packagename, newstate, flags);

    }

    @override

    public int getapplicationenabledsetting(string packagename) {

        return this.mbase.getapplicationenabledsetting(packagename);

    }

    @override

    public boolean issafemode() {

        return this.mbase.issafemode();

    }

    @override

    public void setapplicationcategoryhint(@nonnull string packagename, int categoryhint) {

 

    }

    @override

    public packageinstaller getpackageinstaller() {

        return this.mbase.getpackageinstaller();

    }

    @override

    public boolean canrequestpackageinstalls() {

        return false;

    }

原文链接:https://bbs.kanxue.com/thread-278195.htm

网络摘文,本文作者:15h,如若转载,请注明出处:https://www.15cov.cn/2023/08/27/原创-签名对抗学习笔记/

发表评论

邮箱地址不会被公开。 必填项已用*标注

网站地图