Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dex Modification Modes #19

Merged
merged 13 commits into from
Nov 20, 2024
Merged

Dex Modification Modes #19

merged 13 commits into from
Nov 20, 2024

Conversation

xihan123
Copy link

This pull request introduces a new feature to handle different dex modification modes in the patching process, along with some minor updates and refactoring. The most important changes include adding support for dex modification modes in the Patcher and LSPatch classes, updating the UI to allow users to select the dex modification mode, and adding corresponding string resources.

New Feature: Dex Modification Modes

  • Added a new parameter dexMod to the Patcher.Options class and updated the Patcher methods to handle this parameter (manager/src/main/java/org/lsposed/lspatch/Patcher.kt). [1] [2]
  • Introduced a new method dexModLvStr to map dex modification levels to user-friendly strings (manager/src/main/java/org/lsposed/lspatch/ui/page/NewPatchScreen.kt).
  • Updated the PatchOptionsBody composable to include a dropdown for selecting the dex modification mode (manager/src/main/java/org/lsposed/lspatch/ui/page/NewPatchScreen.kt).
  • Added a new property dexMod to the NewPatchViewModel class and updated the patch submission logic to include this property (manager/src/main/java/org/lsposed/lspatch/ui/viewmodel/NewPatchViewModel.kt). [1] [2]

Updates to LSPatch Class

  • Added a new parameter dexMode to the LSPatch class and updated the patching logic to handle different dex modes (patch/src/main/java/org/lsposed/patch/LSPatch.java). [1] [2] [3] [4]

String Resources

  • Added new string resources for dex modification modes in English, Simplified Chinese, and Traditional Chinese (manager/src/main/res/values/strings.xml, manager/src/main/res/values-zh-rCN/strings.xml, manager/src/main/res/values-zh-rTW/strings.xml). [1] [2] [3]

- 在 LSPatch 中增加 dexMode 参数,用于选择 Dex 处理模式
- 在 AppManageViewModel 和 NewPatchViewModel 中添加 Dex 模式的相关逻辑
- 更新 NewPatchScreen UI,增加 Dex 模式选择功能
- 在 Patcher 中处理 Dex 模式参数
- 更新相关资源文件,添加 Dex 模式的字符串定义
@JingMatrix
Copy link
Owner

JingMatrix commented Nov 10, 2024

Thanks for you work!
I think it is better to use a check box, and call it Inject loader dex, with default option off.
For description in the manage, I would like to use

For applications with isolated services, such as the render engines of browsers, please turn on option to ensure that they work properly.

Its Chinese translation could be

对那些需要孤立服务进程的应用程序,譬如说浏览器的渲染引擎,请勾选此选项以确保他们正常运行。

For command line description, use

Inject directly the loder dex file into the original application package

- 移除 Dex 模式选项,改为直接注入 loader Dex 文件
- 更新相关 UI 和字符串资源
- 修改 NewPatchViewModel 中的 dexMod 属性类型
@xihan123
Copy link
Author

QQ20241111-001305

release.zip

@JingMatrix
Copy link
Owner

JingMatrix commented Nov 15, 2024

Sorry, I am very busy with my thesis recently.
I would like to use a boolean valued variable to indicate the dex injection option in the Java codes, intead of 0 or 1, since there will be no other alternative patching approches under consideration.
If you are not available for this modification, I will push changes to your branch in few days (when I find more free time).

Thanks again for you help, I appreciate it!

Copy link
Owner

@JingMatrix JingMatrix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may need to change few variable names to keep consistent and easy to understand for others.


object Patcher {

class Options(
private val dexMod: Boolean,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change dexMod to injectDex

@@ -90,4 +90,6 @@
<string name="settings_keystore_wrong_alias">Wrong alias name</string>
<string name="settings_keystore_wrong_alias_password">Wrong alias password</string>
<string name="settings_detail_patch_logs">Detail patch logs</string>
<string name="patch_dex_mod">Inject loader dex</string>
<string name="patch_dex_desc">For applications with isolated services, such as the render engines of browsers, please turn on option to ensure that they work properly.</string>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please turn on option -> please turn on this option

@@ -79,6 +78,9 @@ public PatchError(String message, Throwable cause) {
@Parameter(names = {"-l", "--sigbypasslv"}, description = "Signature bypass level. 0 (disable), 1 (pm), 2 (pm+openat). default 0")
private int sigbypassLevel = 0;

@Parameter(names = {"-dex", "--dexmod"}, description = "Inject directly the loder dex file into the original application package")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For argument option name, it is better to use only {"--injectdex"}

@@ -239,7 +241,8 @@ public void patch(File srcApkFile, File outputFile) throws PatchError, IOExcepti
for (StoredEntry entry : srcZFile.entries()) {
String name = entry.getCentralDirectoryHeader().getName();
if (dstZFile.get(name) != null) continue;
if (name.startsWith("META-INF") && (name.endsWith(".SF") || name.endsWith(".MF") || name.endsWith(".RSA"))) continue;
if (name.startsWith("META-INF") && (name.endsWith(".SF") || name.endsWith(".MF") || name.endsWith(".RSA")))
continue;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why a newline here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IDEA code optimization

return name.startsWith("classes") && name.endsWith(".dex");
}).collect(Collectors.toList()).size() + 1;
dstZFile.add("classes" + dexCount + ".dex", is);
if (!dexMode) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change the variable dexMode

…iated code - rename the --dexmod argument to --injectdex

- Update related variables in the LSPatch, NewPatchScreen, NewPatchViewModel, and Patcher classes
- Modify the description in the string resource file
@JingMatrix JingMatrix merged commit b831523 into JingMatrix:master Nov 20, 2024
1 check passed
@JingMatrix
Copy link
Owner

Congratulations to your contributions, it is merge! Thanks for your patience, I appreciate it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants