Skip to content

Commit

Permalink
Merge pull request #5 from rodit/mappings-cache
Browse files Browse the repository at this point in the history
Add support for cached mapping loading
  • Loading branch information
rodit authored Apr 6, 2022
2 parents 50cfc46 + 786cdd1 commit 0033db2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 10 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
applicationId "xyz.rodit.snapmod"
minSdk 24
targetSdk 32
versionCode 1
versionName "1.0"
versionCode 2
versionName "1.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand All @@ -34,7 +34,7 @@ dependencies {

implementation files('libs/snapmod.jar')
implementation 'androidx.preference:preference:1.2.0'
implementation 'xyz.rodit:xposed:1.2.1'
implementation 'xyz.rodit:xposed:1.3.0'

testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/xyz/rodit/snapmod/Shared.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ public class Shared {

public static final String SNAPMOD_FORCE_RESUME_ACTIVITY = SNAPMOD_PACKAGE_NAME + ".ForceResumeActivity";

public static final String CONTEXT_HOOK_CLASS = "com.snap.mushroom.MainActivity";
public static final String CONTEXT_HOOK_METHOD = "onCreate";
public static final String CONTEXT_HOOK_CLASS = "android.app.Application";
public static final String CONTEXT_HOOK_METHOD = "attach";

public static final String SNAPMOD_MEDIA_PREFIX = "SnapMod_";

Expand Down
43 changes: 38 additions & 5 deletions app/src/main/java/xyz/rodit/snapmod/SnapHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Date;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -50,6 +51,7 @@
import xyz.rodit.snapmod.mappings.LocalMessageContent;
import xyz.rodit.snapmod.mappings.LocationMessage;
import xyz.rodit.snapmod.mappings.LocationMessageBuilder;
import xyz.rodit.snapmod.mappings.MainActivity;
import xyz.rodit.snapmod.mappings.MediaBaseBase;
import xyz.rodit.snapmod.mappings.MediaContainer;
import xyz.rodit.snapmod.mappings.MediaType;
Expand All @@ -75,6 +77,7 @@
import xyz.rodit.xposed.HooksBase;
import xyz.rodit.xposed.client.http.StreamProvider;
import xyz.rodit.xposed.client.http.streams.FileProxyStreamProvider;
import xyz.rodit.xposed.mappings.LoadScheme;

public class SnapHooks extends HooksBase {

Expand All @@ -88,6 +91,7 @@ public class SnapHooks extends HooksBase {

public SnapHooks() {
super(Collections.singletonList(Shared.SNAPCHAT_PACKAGE),
EnumSet.of(LoadScheme.CACHED_ON_CONTEXT, LoadScheme.SERVICE),
Shared.SNAPMOD_PACKAGE_NAME,
Shared.SNAPMOD_CONFIG_ACTION,
Shared.CONTEXT_HOOK_CLASS,
Expand All @@ -108,8 +112,6 @@ protected void beforeHookedMethod(MethodHookParam param) {

@Override
protected void onContextHook(Context context) {
mainActivity = context;

Thread.setDefaultUncaughtExceptionHandler((thread, throwable) -> {
XposedBridge.log("Uncaught exception on thread " + thread + ".");
XposedBridge.log(throwable);
Expand All @@ -118,16 +120,34 @@ protected void onContextHook(Context context) {

@Override
protected void onConfigLoaded(boolean first) {
Intent intent = new Intent();
intent.setClassName(Shared.SNAPMOD_PACKAGE_NAME, Shared.SNAPMOD_FORCE_RESUME_ACTIVITY);
mainActivity.startActivity(intent);
try {
if (mappingsLoaded) {
performStoryHooks();
}
} catch (Throwable t) {
XposedBridge.log("Error performing story (un)hooks.");
XposedBridge.log(t);
}

if (mainActivity != null) {
Intent intent = new Intent();
intent.setClassName(Shared.SNAPMOD_PACKAGE_NAME, Shared.SNAPMOD_FORCE_RESUME_ACTIVITY);
mainActivity.startActivity(intent);
}
}

@Override
protected void performHooks() throws Throwable {
requireFileService(Shared.SNAPMOD_FILES_ACTION);
requireStreamServer(0);

MainActivity.attachBaseContext.hook(new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) {
mainActivity = (Context) param.thisObject;
}
});

// Prevent screenshot/save to gallery notifications
ConversationManager.sendMessageWithContent.hook(new XC_MethodHook() {
@Override
Expand Down Expand Up @@ -423,6 +443,7 @@ protected void beforeHookedMethod(MethodHookParam param) {
}
});

// Allow public story downloads
InAppReportManagerImpl.handle.hook(new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) {
Expand All @@ -442,6 +463,10 @@ protected void beforeHookedMethod(MethodHookParam param) {
}
});

performStoryHooks();
}

private void performStoryHooks() throws Throwable {
if (config.getBoolean("allow_download_stories")) {
Class<?> clsOperaContextActions = OperaContextActions.getMappedClass();
Field reportAction = null;
Expand Down Expand Up @@ -521,6 +546,14 @@ protected void beforeHookedMethod(MethodHookParam param) {
ChatMediaInAppReportClient.report.hook(downloadHook);
TopicSnapInAppReportClient.report.hook(downloadHook);
DirectSnapInAppReportClient.report.hook(downloadHook);
} else {
PublicUserStoryInAppReportClient.report.unhook();
FriendStoryInAppReportClient.report.unhook();
PublisherStoryInAppReportClient.report.unhook();
AdInAppReportClient.report.unhook();
ChatMediaInAppReportClient.report.unhook();
TopicSnapInAppReportClient.report.unhook();
DirectSnapInAppReportClient.report.unhook();
}
}

Expand Down

0 comments on commit 0033db2

Please sign in to comment.