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;
String signature_str =
"3082037130820259a003020102020419f0a927300d06092a864886f70d01010b05003068310b300906035504061302434e310f300d0603550408130646754a69616e310f300d0603550407130646755a686f753111300f060355040a13084c69616e596f6e673111300f060355040b13084c69616e596f6e673111300f060355040313084c6f756973204c753020170d3138303632393037323931365a180f32303733303430313037323931365a3068310b300906035504061302434e310f300d0603550408130646754a69616e310f300d0603550407130646755a686f753111300f060355040a13084c69616e596f6e673111300f060355040b13084c69616e596f6e673111300f060355040313084c6f756973204c7530820122300d06092a864886f70d01010105000382010f003082010a0282010100a55431f01fb453e65d7e070bc82e606c11e9bf77831367701e4d7c79a44c014afa2be320caade2e75f8d9160ecaa6e5a39ca63d8ee5ddaffe54f6da0d1f7ea24efa9591681fa39561780c2bef75ec72096e121524da2f9c84d9455593639e63ca41cdbf7a349e0e26cf5f27564825fa524eb3efdbac5ec62f851053cc833537182e6d24dffaaf50274e6062650d527d76856e188d144116731689881a05db10d8bb159bbef9cfd314b205c785e51d4a34e0db54fa89b7ddb837559338f1f58e38df78f7e5acceeaf94546c78d1b8eea3a25e095fc1c959e77860962b3e980e31b63c3089e3541e27cea1631c3b2c59bcfd4c7384123c778c599473a3a319b2270203010001a321301f301d0603551d0e04160414fc7d539fc8aea2e08ade9cd07c47f43621f3b209300d06092a864886f70d01010b05000382010100088fe8de887969eb896e5d9c31aead82bc348faff1917fb224018a38f6d0126e0a9af191bf84ca84cf530cbe2ba0a4993059ae89ce2a05266a8192b044b4a8e18e510a8c6b7e022bebe5482b09a7b80f47661adf9f53fd65b69cf3acb2efc69b89bac3e90eabf1e7ed719b0efd38159cb5f3fea51ee62307ca5f09cbb85660323a41597438aba3999d3626fcbfa628d5510a435c78a82482d1447c3cff3ea19a7ae87d347b7e5e7b0237029cd2e5e57baa907bde58cb5483ef54dcee05fabaadb1a46c88113d85333c6979d846490d3e8def5aa4c3d94d2fc6497bea36901e6a18e1000db8da1f4bb31421138fbf2cb3a22d0458ef28e7167458278a79bf67ef"
;
public
hook(PackageManager base, String packageName) {
this
.mPackageName = packageName;
this
.mBase = base;
}
@Override
public
PackageInfo getPackageInfo(String packageName,
int
flags)
throws
PackageManager.NameNotFoundException {
if
(!mPackageName.equals(packageName)) {
return
this
.mBase.getPackageInfo(packageName, flags);
}
if
(flags != PackageManager.GET_SIGNATURES) {
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;
}
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();
}
public
static
byte
[] hexToBytes(String hexString) {
int
length = hexString.length();
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 {
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
public
boolean
addPermissionAsync(PermissionInfo info) {
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
;
}
}