Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
Signed-off-by: tiann <[email protected]>
  • Loading branch information
tiann committed May 25, 2022
1 parent 6978d7b commit 1e94179
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.os.Build;
import android.os.DropBoxManager;

import com.lody.virtual.client.VClientImpl;
import com.lody.virtual.client.core.InvocationStubManager;
import com.lody.virtual.client.core.VirtualCore;
import com.lody.virtual.client.hook.base.BinderInvocationStub;
Expand Down Expand Up @@ -70,6 +71,26 @@ public static void fixContext(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
ContentResolverJBMR2.mPackageName.set(context.getContentResolver(), hostPkg);
}

if (ContextImpl.getAttributionSource != null) {
fixAttributionSource(ContextImpl.getAttributionSource.call(context), hostPkg, VClientImpl.get().getVUid());
}
}

public static void fixAttributionSource(Object attr, String pkg, int uid) {
if (attr == null) {
return;
}
try {
Object mAttributionSourceState = Reflect.on(attr).get("mAttributionSourceState");
Reflect.on(mAttributionSourceState).set("uid", uid);
Reflect.on(mAttributionSourceState).set("packageName", pkg);

Object next = Reflect.on(attr).call("getNext").get();
fixAttributionSource(next, pkg, uid);
} catch (Throwable e) {
e.printStackTrace();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import android.os.ParcelFileDescriptor;

import com.lody.virtual.client.core.VirtualCore;
import com.lody.virtual.client.fixer.ContextFixer;
import com.lody.virtual.client.hook.base.MethodBox;
import com.lody.virtual.helper.compat.BuildCompat;
import com.lody.virtual.helper.utils.Reflect;
import com.lody.virtual.helper.utils.VLog;

import java.lang.reflect.InvocationHandler;
Expand Down Expand Up @@ -162,6 +162,9 @@ public Object invoke(Object proxy, Method method, Object... args) throws Throwab
// Android 11: https://cs.android.com/android/platform/superproject/+/master:frameworks/base/core/java/android/content/IContentProvider.java?q=IContentProvider&ss=android%2Fplatform%2Fsuperproject
start = 2;
}
if (BuildCompat.isS() ) {
tryFixAttributionSource(args);
}
try {
String name = method.getName();
if ("call".equals(name)) {
Expand Down Expand Up @@ -214,9 +217,7 @@ public Object invoke(Object proxy, Method method, Object... args) throws Throwab
String[] selectionArgs = null;
String sortOrder = null;
Bundle queryArgs = null;
if (BuildCompat.isS()) {
fixAttributionSource(args[0]);
}

if (Build.VERSION.SDK_INT >= 26) {
queryArgs = (Bundle) args[start + 2];
if (queryArgs != null) {
Expand Down Expand Up @@ -249,13 +250,18 @@ public interface HookFetcher {
ProviderHook fetch(boolean external, IInterface provider);
}

private void fixAttributionSource(Object attribution) {
try {
Object mAttributionSourceState = Reflect.on(attribution).get("mAttributionSourceState");
Reflect.on(mAttributionSourceState).set("uid", VirtualCore.get().myUid());
Reflect.on(mAttributionSourceState).set("packageName", VirtualCore.get().getHostPkg());
} catch (Throwable e) {
e.printStackTrace();
private void tryFixAttributionSource(Object[] args) {
if (args == null || args.length == 0) {
return;
}
Object attribution = args[0];
if (attribution == null) {
return;
}
if (!attribution.getClass().getName().equals("android.content.AttributionSource")) {
return;
}

ContextFixer.fixAttributionSource(attribution, VirtualCore.get().getHostPkg(), VirtualCore.get().myUid());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -450,13 +450,27 @@ public static PackageInfo generatePackageInfo(VPackage p, int flags, long firstI
return pi;
}

private static boolean copyNeeded(int flags, VPackage p,
PackageUserState state, Bundle metaData, int userId) {
if (!state.installed || state.hidden) {
return true;
}
return (flags & PackageManager.GET_META_DATA) != 0
&& (metaData != null || p.mAppMetaData != null);
}

public static ApplicationInfo generateApplicationInfo(VPackage p, int flags,
PackageUserState state, int userId) {
if (p == null) return null;
if (!checkUseInstalledOrHidden(state, flags)) {
return null;
}

if (!copyNeeded(flags, p, state, null, userId)) {
initApplicationAsUser(p.applicationInfo, userId);
return p.applicationInfo;
}

// Make shallow copy so we can store the metadata/libraries safely
ApplicationInfo ai = new ApplicationInfo(p.applicationInfo);
if ((flags & PackageManager.GET_META_DATA) != 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ public class ContextImpl {
public static RefObject<PackageManager> mPackageManager;

public static RefMethod<Context> getReceiverRestrictedContext;

public static RefMethod<Object> getAttributionSource;
}

0 comments on commit 1e94179

Please sign in to comment.