-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
215 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/main/kotlin/com/yoavst/jeb/plugins/constarg/GetXPlugin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package com.yoavst.jeb.plugins.constarg | ||
|
||
import com.pnfsoftware.jeb.core.IPluginInformation | ||
import com.pnfsoftware.jeb.core.PluginInformation | ||
import com.pnfsoftware.jeb.core.units.code.android.IDexUnit | ||
import com.pnfsoftware.jeb.core.units.code.android.dex.IDexMethod | ||
import com.yoavst.jeb.plugins.JEB_VERSION | ||
import com.yoavst.jeb.plugins.PLUGIN_VERSION | ||
import com.yoavst.jeb.utils.* | ||
import com.yoavst.jeb.utils.renaming.RenameEngine | ||
|
||
class GetXPlugin : BasicEnginesPlugin(supportsClassFilter = true, defaultForScopeOnThisClass = false) { | ||
override fun getPluginInformation(): IPluginInformation = PluginInformation( | ||
"GetX plugin", | ||
"Fire the plugin to scan the apk for getX methods and use that for naming", | ||
"Yoav Sternberg", | ||
PLUGIN_VERSION, | ||
JEB_VERSION, | ||
null | ||
) | ||
|
||
override fun processUnit(unit: IDexUnit, renameEngine: RenameEngine) { | ||
val visitor = simpleNameMethodVisitor(renameEngine) | ||
val renamers = unit.methods.asSequence().mapToPairNotNull(visitor).associate { (method, result) -> | ||
method.currentSignature to result | ||
} | ||
ConstArgMassRenaming(renamers, isOperatingOnlyOnThisClass, classFilter, recursive = false).processUnit(unit, renameEngine) | ||
} | ||
|
||
|
||
private fun simpleNameMethodVisitor(renameEngine: RenameEngine): (IDexMethod) -> ExtendedRenamer? = { method -> | ||
val currentName = method.currentName | ||
val name = renameEngine.getModifiedInfo(currentName)?.let { (realName, _) -> realName } ?: currentName | ||
if (name.startsWith("get") && name.length >= 4) { | ||
val fieldName = name.substring(3).decapitalize() | ||
when { | ||
method.parameterTypes.size == 0 -> { | ||
ExtendedRenamer(-1, { RenameResult(assigneeName = fieldName) }, -1) | ||
} | ||
method.isStatic && method.parameterTypes.size == 1 -> { | ||
ExtendedRenamer(-1, { RenameResult(argumentName = fieldName) }, 0) | ||
} | ||
else -> null | ||
} | ||
} else if (name.startsWith("set") && name.length >= 4) { | ||
val fieldName = name.substring(3).decapitalize() | ||
when { | ||
method.parameterTypes.size == 1 -> { | ||
ExtendedRenamer(-1, { RenameResult(argumentName = fieldName) }, 0) | ||
} | ||
method.isStatic && method.parameterTypes.size == 2 -> { | ||
ExtendedRenamer(-1, { RenameResult(argumentName = fieldName) }, 1) | ||
} | ||
else -> null | ||
} | ||
} else null | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.yoavst.jeb.plugins | ||
|
||
import com.pnfsoftware.jeb.core.Version | ||
|
||
val PLUGIN_VERSION: Version = Version.create(0, 2, 0) | ||
val JEB_VERSION: Version = Version.create(3, 0, 16) |
Oops, something went wrong.