The developer of MessengerPro implemented a strategy to handle updates to Facebook Messenger by using dynamic unobfuscation and state management. This approach enables MessengerPro to stay functional even when Messenger updates its internal class names, methods, or fields. Let’s break down the key strategies they used, as evident from the provided files:
1. Dynamic Unobfuscation with OrcaUnobfuscator
The OrcaUnobfuscator class is the core mechanism for adapting to updates. It dynamically discovers and maps obfuscated class names, methods, or fields in Messenger’s codebase. Here's how it works:
Steps Taken:
Dex Analysis with Dexplore Library:
The developer uses the Dexplore library to analyze Messenger’s bytecode dynamically.
The OrcaUnobfuscator searches Dex files to locate obfuscated classes, methods, and fields using patterns and references (e.g., strings, method signatures).
Search Filters for Obfuscated Elements:
The developer uses ClassFilter, MethodFilter, and other filters to locate specific classes, methods, and fields that Messenger obfuscates. For example:
Class Discovery: The loadTypingIndicatorDispatcher method filters for classes referencing specific strings like /t_st or System.arraycopy.
Field Discovery: The loadMessageFieldThreadKey method identifies fields in NewMessageNotification referencing Message and ThreadKey.
Caching Results:
Once unobfuscated, the mappings are cached in SharedPreferences for future use, so the app doesn't need to re-analyze the Dex files unless an update occurs.
Fallback Mechanism:
If Messenger updates its code and obfuscates new elements, the mSearchAgain flag triggers the unobfuscation process again.
Key Example:
The loadMessageFieldThreadKey method dynamically finds the threadKey field in the Message class by analyzing references in the NewMessageNotification class.
2. Hook State Management
The developer uses state tracking to manage hooks' behavior and adapt to Messenger updates. This is implemented through the HookStateTracker and HookManager.
Steps Taken:
Hook States:
Hooks can exist in one of several states (DISABLED, NOT_WORKING, PENDING, APPLIED, WORKING), as defined in the HookState enum.
Example States:
PENDING: The hook is initialized but not yet applied.
NOT_WORKING: The hook failed due to an update or error.
Automatic State Updates:
The BaseHook class wraps XC_MethodHook objects in TrackerMethodHook, which automatically updates the hook state based on the success or failure of the hook.
Resetting and Reloading Hooks:
If Messenger updates, the HookManager can reset all hooks to a PENDING state and attempt to reapply them dynamically.
The reloadPending method reinjects hooks that are still in the PENDING state.
Error Handling:
If a hook fails, it logs the error and disables the hook (setStateNotWorking), preventing the app from crashing.
3. Modular Hook Design
The hooks themselves are modular and centralized in the MProHookManager. Each hook is associated with a specific feature and can be updated independently. For example:
MessageReceivedHook: Captures incoming messages.
AdBlockHook: Blocks advertisements.
Hooks are registered with the HookManager, and features using these hooks are managed by the FeatureManager.
4. User Configuration and Debugging
To allow users to debug and reconfigure hooks as needed:
Settings Activity:
The SettingsActivity provides advanced options for users to modify unobfuscation settings, API codes, and hook states.
Users can trigger reloads or reset hooks directly from the UI.
Logging:
The Logger class logs unobfuscation and hook-related issues to help debug problems caused by updates.
5. Example of Adapting to Updates
Let’s say Messenger updates and obfuscates the threadKey field in the Message class. Here’s how the app adapts:
When the field cannot be located, the HookState for hooks relying on threadKey is marked as NOT_WORKING.
If mSearchAgain is enabled, the OrcaUnobfuscator searches for the field again using updated patterns (e.g., analyzing new references in the Dex files).
Once the field is rediscovered, the hook is re-enabled, and its state is updated to WORKING.
Conclusion
The developer of MessengerPro implemented a robust system to adapt to updates in Messenger by combining:
Dynamic unobfuscation via Dex analysis.
State management to track and recover from hook failures.
Modular hooks for easy updates.
User-configurable settings and logging for debugging.
This approach ensures MessengerPro remains functional even as Messenger evolves.
The Block Typing Indicator feature in MessengerPro prevents your contacts from seeing when you're typing, thereby enhancing your privacy. This feature works by intercepting and blocking the event or API calls responsible for notifying the other party that you're typing. Here’s how it works in the MessengerPro codebase:
Key Components Related to Typing Indicator Blocking
TypingIndicatorSentHook:
This hook is likely responsible for intercepting outgoing typing indicator events.
It hooks into the Messenger app's internal functionality that dispatches the typing indicator (e.g., a method or API call).
By intercepting this event, it stops the typing indicator from being sent.
Unobfuscation with OrcaUnobfuscator:
The OrcaUnobfuscator class identifies obfuscated classes and methods inside Messenger responsible for typing indicator behavior.
Specifically, it identifies the TypingIndicatorDispatcher class using the loadTypingIndicatorDispatcher() method.
The TypingIndicatorDispatcher is the internal Messenger component that manages typing indicator events. By hooking into this class, the app can block the typing indicator from being sent.
Hook Logic:
The hook modifies the behavior of the typing dispatch method to return early or suppress the event, preventing it from reaching the recipient.
How the Feature Works
1. Hooking into TypingIndicatorDispatcher
The TypingIndicatorDispatcher class is dynamically located using the OrcaUnobfuscator:
The OrcaUnobfuscator.loadTypingIndicatorDispatcher method identifies this class by analyzing Messenger's Dex files.
It looks for specific patterns, such as references to strings like "/t_st" (possibly indicating "typing status") or method signatures like System.arraycopy.
2. Intercepting the Typing Indicator Method
Once the TypingIndicatorDispatcher class is identified, the hook intercepts its key method responsible for sending typing indicators:
The TypingIndicatorSentHook hooks into this method using the XposedBridge.hookMethod() function.
The hook logic modifies the method's behavior to prevent the typing indicator from being sent. For example:
It may call param.setResult(null) to stop propagation.
It could also replace the method's implementation with a no-op (a method that does nothing).
3. Dynamic State Management
The hook’s behavior is managed dynamically:
If the typing indicator functionality changes (e.g., Messenger updates its internal logic), the HookStateTracker detects failures and disables the hook until it can be updated.
The MProHookManager ensures the hook is re-applied once the unobfuscation process identifies the new typing indicator implementation.
4. User Control
Users can enable or disable the feature via the MessengerPro settings.
The feature interacts with the FeatureManager, which associates the TypingIndicatorSentHook with the "Block Typing Indicator" feature.
Relevant Code Flow
Unobfuscation of Typing Indicator Dispatcher
From the OrcaUnobfuscator class:
[Redacted
public Class<?> loadTypingIndicatorDispatcher() {
return loadClass(CLASS_TYPING_INDICATOR_DISPATCHER, new ClassFilter.Builder()
.setReferenceTypes(ReferenceTypes.builder().addString().addMethodWithDetails().build())
.setReferenceFilter(pool ->
pool.stringsContain("/t_st") &&
pool.methodSignaturesContain("java.lang.System.arraycopy(java.lang.Object,int,java.lang.Object,int,int):void"))
.build());
}
This method identifies the TypingIndicatorDispatcher class by searching for specific references in Messenger’s Dex files.
Hooking the Typing Indicator Method
The TypingIndicatorSentHook hooks a method in the dispatcher class. For example:
[Redacted
XposedBridge.hookMethod(typingIndicatorMethod, new XC_MethodHook() {
@[Redacted Person]
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
// Block the typing indicator from being sent
param.setResult(null); // Prevents the method from executing
}
});
Feature Registration
The TypingIndicatorSentHook is registered in the MProHookManager:
[Redacted
addHook(new TypingIndicatorSentHook());
This ensures the feature is loaded and managed by the app.
How It Prevents Typing Indicators
Blocking the Event:
The hook modifies or cancels the method responsible for sending typing indicators.
By returning early or nullifying the method’s result, the indicator never reaches the Messenger servers.
Dynamic Updates:
If the method or class responsible for typing indicators changes in a Messenger update, the unobfuscation process re-identifies the new implementation.
The hook is then re-applied automatically.
Benefits of the Approach
Privacy:
Prevents others from knowing when you’re typing.
Ideal for users who value discretion.
Adaptability:
The dynamic unobfuscation mechanism ensures the feature remains functional even if Messenger obfuscates or changes its internal implementation.
User Control:
Users can easily enable or disable the feature via the app’s settings.
Summary
The Block Typing Indicator feature works by:
Dynamically identifying the TypingIndicatorDispatcher class and its relevant method.
Hooking into the method to block or suppress typing indicator events.
Using unobfuscation and state management to adapt to changes in Messenger’s internal functionality.
This implementation ensures the feature remains effective and reliable, providing users with enhanced privacy.