根据网上的教程显示 jeb1可以编写java脚本插件 但是我目前使用的jeb2 发现用不了java脚本 于是尝试使用python编写
根据网上找了个demo 运行脚本的时候报了如下错:
提示我查看这个txt寻找解决办法.png
这个SCRIPTS.TXT文件在软件目录的scripts目录下:
JEB2 Decompiler
PNF Software, Inc.
https://www.pnfsoftware.com
> SCRIPTS
This directory contains scripts for JEB2 clients.
The official UI desktop client allows Python script execution via the Jython
package. (Note: scripts should not be confused with plugins, although they use
similar APIs.)
In order to run scripts, a Jython package is required.
Setting up Jython:
- Download a stand-alone Jython package from http://www.jython.org/downloads.html
We recommend either version 2.5 (fastest) or version 2.7 (latest)
- Drop the downloaded 'jython-standalone-???.jar' file in the scripts/
sub-directory located in your JEB installation directory
- Make sure that the client property '.ScriptsFolder' refers to that directory
(it is the case by default; use 'Edit/Options, Advanced...' to verify this)
How to use:
- Scripts can be executed via the 'File/Scripts/Execute...' menu command
- Note that JEB2 scripts significantly differ from JEB1 scripts. Refer to the
JEB2 developer portal for tutorials and APIs documentation:
https://www.pnfsoftware.com/jeb2/devportal
- Scripts should not be used for heavy-lifting operations. They are meant to
execute small tasks within a the context of a JEB2 client.
它的意思是去http://www.jython.org/downloads.html这个网站下载独立的jar文件
image.png
然后放到程序目录的scripts目录下。
运行的话 文件->脚本->运行脚本 然后点击的py脚本即可运行。
helloworld
JEB2SampleScript.py
from com.pnfsoftware.jeb.client.api import IScript
class JEB2SampleScript(IScript):
def run(self, ctx):
print('Hello, JEB2')
反编译类名(拿抖音做试验 可以用 贼慢)
JEB2DeobscureClass.py
# -*- coding: utf-8 -*-
"""
Deobscure class name(use debug directives as source name) for PNF Software's JEB2.
"""
__author__ = 'Ericli'
from com.pnfsoftware.jeb.client.api import IScript
from com.pnfsoftware.jeb.core import RuntimeProjectUtil
from com.pnfsoftware.jeb.core.units.code import ICodeUnit, ICodeItem
from com.pnfsoftware.jeb.core.units.code.android import IDexUnit
from com.pnfsoftware.jeb.core.actions import Actions, ActionContext, ActionCommentData, ActionRenameData
from java.lang import Runnable
class JEB2DeobscureClass(IScript):
def run(self, ctx):
ctx.executeAsync("Running deobscure class ...", JEB2AutoRename(ctx))
print('Done')
class JEB2AutoRename(Runnable):
def __init__(self, ctx):
self.ctx = ctx
def run(self):
ctx = self.ctx
engctx = ctx.getEnginesContext()
if not engctx:
print('Back-end engines not initialized')
return
projects = engctx.getProjects()
if not projects:
print('There is no opened project')
return
prj = projects[0]
units = RuntimeProjectUtil.findUnitsByType(prj, IDexUnit, False)
for unit in units:
classes = unit.getClasses()
if classes:
for clazz in classes:
# print(clazz.getName(True), clazz)
sourceIndex = clazz.getSourceStringIndex()
clazzAddress = clazz.getAddress()
if sourceIndex == -1 or '$' in clazzAddress:# Do not rename inner class
# print('without have source field', clazz.getName(True))
continue
sourceStr = str(unit.getString(sourceIndex))
if '.java' in sourceStr:
sourceStr = sourceStr[:-5]
# print(clazz.getName(True), sourceIndex, sourceStr, clazz)
if clazz.getName(True) != sourceStr:
self.comment_class(unit, clazz, clazz.getName(True)) # Backup origin clazz name to comment
self.rename_class(unit, clazz, sourceStr, True) # Rename to source name
def rename_class(self, unit, originClazz, sourceName, isBackup):
actCtx = ActionContext(unit, Actions.RENAME, originClazz.getItemId(), originClazz.getAddress())
actData = ActionRenameData()
actData.setNewName(sourceName)
if unit.prepareExecution(actCtx, actData):
try:
result = unit.executeAction(actCtx, actData)
if result:
print('rename to %s success!' % sourceName)
else:
print('rename to %s failed!' % sourceName)
except Exception, e:
print (Exception, e)
def comment_class(self, unit, originClazz, commentStr):
actCtx = ActionContext(unit, Actions.COMMENT, originClazz.getItemId(), originClazz.getAddress())
actData = ActionCommentData()
actData.setNewComment(commentStr)
if unit.prepareExecution(actCtx, actData):
try:
result = unit.executeAction(actCtx, actData)
if result:
print('comment to %s success!' % commentStr)
else:
print('comment to %s failed!' % commentStr)
except Exception, e:
print (Exception, e)
- JEB2.2.x是默认不显示这些调试信息的可以根据以下步骤在设置中打开:Edit -> Options -> Engines -> 修改ShowDebugDirectives的值为true(点一下就好).
相关链接:https://www.pnfsoftware.com/blog/writing-jeb2-scripts-in-python/
https://bbs.pediy.com/thread-227046.htm