Skip to content

Commit

Permalink
[MG] add toggle setting in Debug Menu to disable Secure Flags
Browse files Browse the repository at this point in the history
This option MUST be used ONLY for debugging reason, since using that MAY
violate the TOS.

Ok, this is a quite broken-by-design security, since you can do a photo
from another phone or using Telegram Web or using Telegram from an
Android emulator, etc, but still, don't violate TOS, please...

This is only useful for debugging problem when Secure Flags are broken
on your phone...
  • Loading branch information
Timothy Redaelli committed Jan 14, 2024
1 parent cc4a7a5 commit 0bf5843
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 11 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ This includes the following additional features:
- Add toggle setting in Chat Setting to hide "All Chats" tab (feature from NekoX)
- Add toggle setting in Debug Menu to enable Message Details menu
- Add toggle setting in Debug Menu to disable Unified Push support
- Add toggle setting in Debug Menu to disable Secure Flags. This option must **only** be used for debugging.
- Unlock premium app icons for anybody
- Large photos are sent (2560px instead of 1280px)
- Telegram application icons are replaced with [hermes wing (Created by Anthony Ledoux from Noun Project)](https://thenounproject.com/icon/hermes-wing-3559879/)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ private static void updateWindowSecure(Window window) {
}

if (isSecuredNow(window)) {
window.addFlags(WindowManager.LayoutParams.FLAG_SECURE);
if (!SharedConfig.disableSecureFlags) {
window.addFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
} else {
window.clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,14 @@ public static void toggleDisableUnifiedPush() {
.commit();
}

public static void toggleDisableSecureFlags() {
disableSecureFlags = !disableSecureFlags;
ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE)
.edit()
.putBoolean("disableSecureFlags", disableSecureFlags)
.commit();
}

public static void toggleSurfaceInStories() {
useSurfaceInStories = !useSurfaceInStories;
ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE)
Expand Down Expand Up @@ -279,6 +287,7 @@ private static boolean isWhitelisted(MediaCodecInfo codecInfo) {
public static boolean payByInvoice;
public static boolean messageDetailsMenu;
public static boolean disableUnifiedPush;
public static boolean disableSecureFlags;
public static int stealthModeSendMessageConfirm = 2;
private static int lastLocalId = -210000;

Expand Down Expand Up @@ -684,6 +693,7 @@ public static void loadConfig() {
callEncryptionHintDisplayedCount = preferences.getInt("callEncryptionHintDisplayedCount", 0);
messageDetailsMenu = preferences.getBoolean("messageDetailsMenu", false);
disableUnifiedPush = preferences.getBoolean("disableUnifiedPush", false);
disableSecureFlags = preferences.getBoolean("disableSecureFlags", false);

loadDebugConfig(preferences);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
setTheme(R.style.Theme_TMessages);
getWindow().setBackgroundDrawableResource(R.drawable.transparent);
if (SharedConfig.passcodeHash.length() > 0 && !SharedConfig.allowScreenCapture) {
if (SharedConfig.passcodeHash.length() > 0 && !SharedConfig.allowScreenCapture && !SharedConfig.disableSecureFlags) {
try {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,9 @@ public void setNoforwards(boolean noforwards) {
textView.setTextIsSelectable(!noforwards);
}
if (noforwards) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
if (!SharedConfig.disableSecureFlags) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
} else {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
setTheme(R.style.Theme_TMessages);
getWindow().setBackgroundDrawableResource(R.drawable.transparent);
if (SharedConfig.passcodeHash.length() > 0 && !SharedConfig.allowScreenCapture) {
if (SharedConfig.passcodeHash.length() > 0 && !SharedConfig.allowScreenCapture && !SharedConfig.disableSecureFlags) {
try {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -507,7 +507,9 @@ public void onResume() {
if (Build.VERSION.SDK_INT >= 23) {
try {
if ((currentStep == STEP_PAYMENT_INFO || currentStep == STEP_SET_PASSWORD_EMAIL) && !paymentForm.invoice.test) {
getParentActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
if (!SharedConfig.disableSecureFlags) {
getParentActivity().getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
}
} else if (SharedConfig.passcodeHash.length() == 0 || SharedConfig.allowScreenCapture) {
getParentActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
Expand Down
4 changes: 3 additions & 1 deletion TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -14294,7 +14294,9 @@ public boolean openPhoto(final MessageObject messageObject, final TLRPC.FileLoca
avatarsDialogId != 0 && MessagesController.getInstance(currentAccount).isChatNoForwards(-avatarsDialogId) ||
messageObject != null && (MessagesController.getInstance(currentAccount).isChatNoForwards(messageObject.getChatId()) ||
(messageObject.messageOwner != null && messageObject.messageOwner.noforwards)) || messageObject != null && messageObject.hasRevealedExtendedMedia()) {
windowLayoutParams.flags |= WindowManager.LayoutParams.FLAG_SECURE;
if (!SharedConfig.disableSecureFlags) {
windowLayoutParams.flags |= WindowManager.LayoutParams.FLAG_SECURE;
}
} else {
windowLayoutParams.flags &=~ WindowManager.LayoutParams.FLAG_SECURE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3693,6 +3693,7 @@ public boolean onItemClick(View view, int position) {
mgItems = new CharSequence[]{
!SharedConfig.messageDetailsMenu ? "Enable Message Details menu" : "Disable Message Details menu",
SharedConfig.disableUnifiedPush ? "Enable Unified Push" : "Disable Unified Push",
SharedConfig.disableSecureFlags ? "Enable Secure Flags" : "Disable Secure Flags",
};

CharSequence[] joinedItems = new CharSequence[items.length + mgItems.length];
Expand Down Expand Up @@ -3955,6 +3956,8 @@ else if (which == items.length + 0) {
activity.finishAffinity(); // Finishes all activities.
activity.startActivity(intent); // Start the launch activity
System.exit(0);
} else if (which == items.length + 2) {
SharedConfig.toggleDisableSecureFlags();
}
});
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -993,7 +993,9 @@ public int getParentBottomPadding() {
} else {
windowLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
}
windowLayoutParams.flags |= WindowManager.LayoutParams.FLAG_SECURE;
if (!SharedConfig.disableSecureFlags) {
windowLayoutParams.flags |= WindowManager.LayoutParams.FLAG_SECURE;
}
centerImage.setParentView(containerView);
centerImage.setForceCrossfade(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2534,14 +2534,18 @@ public void allowScreenshots(boolean allowScreenshots) {
if (allowScreenshots) {
fragment.getParentActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
} else {
fragment.getParentActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
if (!SharedConfig.disableSecureFlags) {
fragment.getParentActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE);
}
}
}
} else {
if (allowScreenshots) {
windowLayoutParams.flags &= ~WindowManager.LayoutParams.FLAG_SECURE;
} else {
windowLayoutParams.flags |= WindowManager.LayoutParams.FLAG_SECURE;
if (!SharedConfig.disableSecureFlags) {
windowLayoutParams.flags |= WindowManager.LayoutParams.FLAG_SECURE;
}
}
try {
windowManager.updateViewLayout(windowView, windowLayoutParams);
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
#Sat Mar 12 05:53:50 MSK 2016
APP_VERSION_CODE=422802
APP_VERSION_NAME=10.5.0.2
APP_VERSION_CODE=422803
APP_VERSION_NAME=10.5.0.3
APP_PACKAGE=it.belloworld.mercurygram
org.gradle.jvmargs=-Xmx4096M -XX:MaxMetaspaceSize=4096m
org.gradle.daemon=true
Expand Down

0 comments on commit 0bf5843

Please sign in to comment.