Skip to content
This repository was archived by the owner on May 4, 2023. It is now read-only.

Commit ef00997

Browse files
committed
Improve Androidacy api for config with certificate pinning + minor code changes.
1 parent e565a70 commit ef00997

File tree

5 files changed

+68
-26
lines changed

5 files changed

+68
-26
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
android:theme="@style/Theme.MagiskModuleManager"
2929
android:fullBackupContent="@xml/full_backup_content"
3030
android:dataExtractionRules="@xml/data_extraction_rules"
31+
android:networkSecurityConfig="@xml/network_security_config"
3132
android:usesCleartextTraffic="false"
3233
tools:targetApi="s">
3334
<receiver android:name="com.fox2code.mmm.manager.ModuleBootReceive"

app/src/main/java/com/fox2code/mmm/ActionButtonType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public void doAction(ImageButton button, ModuleHolder moduleHolder) {
110110
String config = moduleHolder.getMainModuleConfig();
111111
if (config == null) return;
112112
if (config.startsWith("https://www.androidacy.com/")) {
113-
IntentHelper.openUrlAndroidacy(button.getContext(), config, false);
113+
IntentHelper.openUrlAndroidacy(button.getContext(), config, true);
114114
} else {
115115
IntentHelper.openConfig(button.getContext(), config);
116116
}

app/src/main/java/com/fox2code/mmm/androidacy/AndroidacyWebAPI.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,13 @@
1010
import com.fox2code.mmm.manager.LocalModuleInfo;
1111
import com.fox2code.mmm.manager.ModuleInfo;
1212
import com.fox2code.mmm.manager.ModuleManager;
13+
import com.fox2code.mmm.utils.Files;
1314
import com.fox2code.mmm.utils.IntentHelper;
1415

16+
import java.io.File;
17+
import java.io.IOException;
18+
import java.nio.charset.StandardCharsets;
19+
1520
public class AndroidacyWebAPI {
1621
private static final String TAG = "AndroidacyWebAPI";
1722
private final AndroidacyActivity activity;
@@ -131,4 +136,33 @@ public long getModuleVersionCode(String moduleId) {
131136
public void hideActionBar() {
132137
this.activity.hideActionBar();
133138
}
139+
140+
/**
141+
* Return true if the module is an Andoridacy module.
142+
*/
143+
@JavascriptInterface
144+
public boolean isAndroidacyModule(String moduleId) {
145+
LocalModuleInfo localModuleInfo = ModuleManager.getINSTANCE().getModules().get(moduleId);
146+
return localModuleInfo != null && ("Androidacy".equals(localModuleInfo.author) ||
147+
(localModuleInfo.config != null &&
148+
localModuleInfo.config.startsWith("https://www.androidacy.com/")));
149+
}
150+
151+
/**
152+
* get a module file, return an empty string if not
153+
* an Andoridacy module or if file doesn't exists.
154+
*/
155+
@JavascriptInterface
156+
public String getAndroidacyModuleFile(String moduleId, String moduleFile) {
157+
if (!this.isAndroidacyModule(moduleId)) return "";
158+
File moduleFolder = new File("/data/adb/modules/" + moduleId);
159+
File absModuleFile = new File(moduleFolder, moduleFile).getAbsoluteFile();
160+
if (!absModuleFile.getPath().startsWith(moduleFolder.getPath())) return "";
161+
try {
162+
return new String(Files.readSU(absModuleFile
163+
.getAbsoluteFile()), StandardCharsets.UTF_8);
164+
} catch (IOException e) {
165+
return "";
166+
}
167+
}
134168
}

app/src/main/java/com/fox2code/mmm/installer/InstallerActivity.java

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -209,14 +209,30 @@ private void doInstall(File file,boolean noExtensions,boolean rootless) {
209209
"sh \"" + installScript.getAbsolutePath() + "\"" +
210210
" /dev/null 1 \"" + file.getAbsolutePath() + "\"")
211211
.to(installerController, installerMonitor);
212-
} else if (MainApplication.isUsingMagiskCommand() || noExtensions) {
213-
installerMonitor = new InstallerMonitor(new File(InstallerInitializer
214-
.peekMagiskPath().equals("/sbin") ? "/sbin/magisk" : "/system/bin/magisk"));
212+
} else {
213+
String installCommand;
214+
File installExecutable;
215+
if (InstallerInitializer.peekMagiskVersion() >=
216+
Constants.MAGISK_VER_CODE_INSTALL_COMMAND &&
217+
(noExtensions || MainApplication.isUsingMagiskCommand())) {
218+
installCommand = "magisk --install-module \"" + file.getAbsolutePath() + "\"";
219+
installExecutable = new File(InstallerInitializer.peekMagiskPath()
220+
.equals("/sbin") ? "/sbin/magisk" : "/system/bin/magisk");
221+
} else {
222+
installExecutable = this.extractInstallScript("module_installer_compat.sh");
223+
if (installExecutable == null) {
224+
this.setInstallStateFinished(false,
225+
"! Failed to extract module install script", "");
226+
return;
227+
}
228+
installCommand = "sh \"" + installExecutable.getAbsolutePath() + "\"" +
229+
" /dev/null 1 \"" + file.getAbsolutePath() + "\"";
230+
}
231+
installerMonitor = new InstallerMonitor(installExecutable);
215232
if (noExtensions) {
216233
installJob = Shell.su( // No Extensions
217234
"cd \"" + this.moduleCache.getAbsolutePath() + "\"",
218-
"magisk --install-module \"" + file.getAbsolutePath() + "\"")
219-
.to(installerController, installerMonitor);
235+
installCommand).to(installerController, installerMonitor);
220236
} else {
221237
installJob = Shell.su("export MMM_EXT_SUPPORT=1",
222238
"export MMM_USER_LANGUAGE=" + (MainApplication.isForceEnglish() ?
@@ -225,27 +241,8 @@ private void doInstall(File file,boolean noExtensions,boolean rootless) {
225241
"export MMM_APP_VERSION=" + BuildConfig.VERSION_NAME,
226242
"export MMM_TEXT_WRAP=" + (this.textWrap ? "1" : "0"),
227243
"cd \"" + this.moduleCache.getAbsolutePath() + "\"",
228-
"magisk --install-module \"" + file.getAbsolutePath() + "\"")
229-
.to(installerController, installerMonitor);
230-
}
231-
} else {
232-
File installScript = this.extractInstallScript("module_installer_compat.sh");
233-
if (installScript == null) {
234-
this.setInstallStateFinished(false,
235-
"! Failed to extract module install script", "");
236-
return;
244+
installCommand).to(installerController, installerMonitor);
237245
}
238-
installerMonitor = new InstallerMonitor(installScript);
239-
installJob = Shell.su("export MMM_EXT_SUPPORT=1",
240-
"export MMM_USER_LANGUAGE=" + (MainApplication.isForceEnglish() ?
241-
"en-US" : Resources.getSystem()
242-
.getConfiguration().locale.toLanguageTag()),
243-
"export MMM_APP_VERSION=" + BuildConfig.VERSION_NAME,
244-
"export MMM_TEXT_WRAP=" + (this.textWrap ? "1" : "0"),
245-
"cd \"" + this.moduleCache.getAbsolutePath() + "\"",
246-
"sh \"" + installScript.getAbsolutePath() + "\"" +
247-
" /dev/null 1 \"" + file.getAbsolutePath() + "\"")
248-
.to(installerController, installerMonitor);
249246
}
250247
boolean success = installJob.exec().isSuccess();
251248
// Wait one UI cycle before disabling controller or processing results
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<network-security-config>
3+
<domain-config>
4+
<domain includeSubdomains="true">androidacy.com</domain>
5+
<pin-set expiration="2023-01-02">
6+
<pin digest="SHA-256">V6pbbd2/CCaa1dr+vGnpUrA1xoZ/GgncNuYzD26dikw=</pin>
7+
<pin digest="SHA-256">FEzVOUp4dF3gI0ZVPRJhFbSJVXR+uQmMH65xhs1glH4=</pin>
8+
</pin-set>
9+
</domain-config>
10+
</network-security-config>

0 commit comments

Comments
 (0)