本文整理汇总了Python中com.pnfsoftware.jeb.core.RuntimeProjectUtil.findUnitsByType方法的典型用法代码示例。如果您正苦于以下问题:Python RuntimeProjectUtil.findUnitsByType方法的具体用法?Python RuntimeProjectUtil.findUnitsByType怎么用?Python RuntimeProjectUtil.findUnitsByType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.pnfsoftware.jeb.core.RuntimeProjectUtil
的用法示例。
在下文中一共展示了RuntimeProjectUtil.findUnitsByType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from com.pnfsoftware.jeb.core import RuntimeProjectUtil [as 别名]
# 或者: from com.pnfsoftware.jeb.core.RuntimeProjectUtil import findUnitsByType [as 别名]
def run(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
project = projects[0] # Get current project(IRuntimeProject)
print('Decompiling code units of %s...' % project)
self.codeUnit = RuntimeProjectUtil.findUnitsByType(project, ICodeUnit, False)[0] # Get the current codeUnit(ICodeUnit)
# enumerate the decompiled classes, find and process the target class
units = RuntimeProjectUtil.findUnitsByType(project, IJavaSourceUnit, False)
targetClass = "" # Taget class
targetClassMain = "" # Main taget class
for unit in units:
javaClass = unit.getClassElement() # Get a reference to the Java class defined in this unit
if javaClass.getName() == self.TARGET_CLASS_NAME: # If the current class is the target class, store the target class
targetClass = javaClass
if javaClass.getName() == self.TARGET_CLASS_NAME_MAIN: # If the current class is the main target class, store the main target class
targetClassMain = javaClass
self.cstbuilder = unit.getFactories().getConstantFactory()
self.processTargetClass(targetClass)
if self.dic:
self.processMainTargetClass(targetClassMain) # If dic is not empty, which means some variables are called by other class(main target class), we should run substitStr() method
示例2: run
# 需要导入模块: from com.pnfsoftware.jeb.core import RuntimeProjectUtil [as 别名]
# 或者: from com.pnfsoftware.jeb.core.RuntimeProjectUtil import findUnitsByType [as 别名]
def run(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]
print('Decompiling code units of %s...' % prj)
self.codeUnit = RuntimeProjectUtil.findUnitsByType(prj, ICodeUnit, False)[0]
print(self.codeUnit)
# the encryption keys could be determined by analyzing the decryption method
self.targetClass = 'MainActivity'
self.keys = [409, 62, -8]
# enumerate the decompiled classes, find and process the target class
units = RuntimeProjectUtil.findUnitsByType(prj, IJavaSourceUnit, False)
for unit in units:
javaClass = unit.getClassElement()
if javaClass.getName().find(self.targetClass) >= 0:
self.cstbuilder = unit.getFactories().getConstantFactory()
self.processClass(javaClass)
break
示例3: run
# 需要导入模块: from com.pnfsoftware.jeb.core import RuntimeProjectUtil [as 别名]
# 或者: from com.pnfsoftware.jeb.core.RuntimeProjectUtil import findUnitsByType [as 别名]
def run(self, ctx):
self.ctx = ctx
argv = ctx.getArguments()
if len(argv) < 2:
print('Provide an input file and the output folder')
return
self.inputFile = argv[0]
self.outputDir = argv[1]
print('Decompiling ' + self.inputFile + '...')
engctx = ctx.getEnginesContext()
if not engctx:
print('Back-end engines not initialized')
return
# Create a project
project = engctx.loadProject('PlaceholderProjectName')
if not project:
print('Failed to open a new project')
return
# Add the input file as a project artifact
artifact = Artifact('PlaceholderArtifactName',FileInput(File(self.inputFile)))
project.processArtifact(artifact)
# Decompile code units
codeUnits = RuntimeProjectUtil.findUnitsByType(project, ICodeUnit, False)
for codeUnit in codeUnits:
self.decompileForCodeUnit(codeUnit)
示例4: run
# 需要导入模块: from com.pnfsoftware.jeb.core import RuntimeProjectUtil [as 别名]
# 或者: from com.pnfsoftware.jeb.core.RuntimeProjectUtil import findUnitsByType [as 别名]
def run(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
# get the first native code unit available
units = RuntimeProjectUtil.findUnitsByType(projects[0], INativeCodeUnit, False)
if not units:
print('No unit available')
return
unit = units[0]
print('Unit: %s' % unit)
''' create the following type:
// Size: 10, Padding: 1, Alignment: 1
struct MyStruct1 {
int a;
unsigned char[3][2] b;
};
'''
typeman = unit.getTypeManager()
tInt = typeman.getType('int')
tS1 = typeman.createStructure('MyStruct1')
typeman.addStructureField(tS1, 'a', tInt)
typeman.addStructureField(tS1, 'b', TypeUtil.buildArrayType(typeman, 'unsigned char', 2, 3))
示例5: run
# 需要导入模块: from com.pnfsoftware.jeb.core import RuntimeProjectUtil [as 别名]
# 或者: from com.pnfsoftware.jeb.core.RuntimeProjectUtil import findUnitsByType [as 别名]
def run(self, ctx):
self.ctx = 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]
print('Decompiling code units of %s...' % prj)
units = RuntimeProjectUtil.findUnitsByType(prj, IJavaSourceUnit, False)
for unit in units:
self.processSourceTree(unit.getClassElement())
doc = self.getTextDocument(unit)
javaCode, formattedMarks = self.formatTextDocument(doc)
print(javaCode)
if(formattedMarks):
print('=> Marks:')
print(formattedMarks)
print('Done.')
示例6: run
# 需要导入模块: from com.pnfsoftware.jeb.core import RuntimeProjectUtil [as 别名]
# 或者: from com.pnfsoftware.jeb.core.RuntimeProjectUtil import findUnitsByType [as 别名]
def run(self, ctx):
self.keys = {}
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
project = projects[0] # Get current project(IRuntimeProject)
print('Decompiling code units of %s...' % project)
self.dexunit = RuntimeProjectUtil.findUnitsByType(project, IDexUnit, False)[0] # Get dex context, needs >=V2.2.1
self.currentunit = ctx.getFocusedView().getActiveFragment().getUnit() # Get current Source Tab in Focus
javaclass = self.currentunit.getClassElement() # needs >V2.1.4
curaddr=ctx.getFocusedView().getActiveFragment().getActiveAddress() # needs 2.1.4
print('Current class: %s' % javaclass.getName())
print('Current address: %s' % curaddr)
self.cstbuilder = self.currentunit.getFactories().getConstantFactory() # we need a context to cstbuilder to replace strings
self.processTargetClass(javaclass) #Call our main function
self.currentunit.notifyListeners(JebEvent(J.UnitChange))
示例7: run
# 需要导入模块: from com.pnfsoftware.jeb.core import RuntimeProjectUtil [as 别名]
# 或者: from com.pnfsoftware.jeb.core.RuntimeProjectUtil import findUnitsByType [as 别名]
def run(self, ctx):
self.ctx = ctx
engctx = ctx.getEnginesContext()
if not engctx:
print('Back-end engines not initialized')
return
prj = engctx.getProject(0)
if not prj:
print('There is no opened project')
return
codeUnits = RuntimeProjectUtil.findUnitsByType(prj, ICodeUnit, False)
if not codeUnits:
return
dex = codeUnits[0]
# ---- SAMPLE --- Replace this by your own method name
targetMethod = 'Lcom/pnfsoftware/raasta/AppHelp;->onCreate(Landroid/os/Bundle;)V'
javaMethod = self.getDecompiledMethod(dex, targetMethod)
if not javaMethod:
print('The method was not found or was not decompiled')
return
print('Java Method: %s (%s)' % (javaMethod, javaMethod.getName()))
示例8: run
# 需要导入模块: from com.pnfsoftware.jeb.core import RuntimeProjectUtil [as 别名]
# 或者: from com.pnfsoftware.jeb.core.RuntimeProjectUtil import findUnitsByType [as 别名]
def run(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
# get the first unit available
units = RuntimeProjectUtil.findUnitsByType(projects[0], None, False)
if not units:
print('No unit available')
return
unit = units[0]
print('Unit: %s' % unit)
# retrieve the formatter, which is a producer of unit representations
formatter = unit.getFormatter()
# create an extra document (text document), wrap it in a representtion
lines = ArrayList()
lines.add(Line('There are two hard problems in computer science: cache invalidation, naming things, and off-by-one errors.'))
lines.add(Line(' - Phil Karlton (and others)'))
extraDoc = StaticTextDocument(lines)
extraPres = UnitRepresentationAdapter(100, 'Quotes', False, extraDoc)
# add the newly created representation to our unit, and notify clients
# the second argument indicates that the presentation should be persisted when saving the project
formatter.addPresentation(extraPres, True)
unit.notifyListeners(JebEvent(J.UnitChange));
示例9: run
# 需要导入模块: from com.pnfsoftware.jeb.core import RuntimeProjectUtil [as 别名]
# 或者: from com.pnfsoftware.jeb.core.RuntimeProjectUtil import findUnitsByType [as 别名]
def run(self, ctx):
# retrieve JEB's engines from the provided IClientContext
engctx = ctx.getEnginesContext()
if not engctx:
print('Back-end engines not initialized')
return
# retrieve the current project (must exist)
projects = engctx.getProjects()
if projects:
project = projects[0]
else:
argv = ctx.getArguments()
if len(argv) < 1:
print('No project found, please provide an input contract file')
return
self.inputFile = argv[0]
print('Processing ' + self.inputFile + '...')
# create a project
project = engctx.loadProject('Project')
# load and process the artifact
artifact = Artifact('Artifact', FileInput(File(self.inputFile)))
project.processArtifact(artifact)
project = engctx.getProjects()[0]
# retrieve the primary code unit (must be the result of an EVM contract analysis)
units = RuntimeProjectUtil.findUnitsByType(project, INativeCodeUnit, False)
if not units:
print('No native code unit found')
return
unit = units[0]
print('Native code unit: %s' % unit)
# GlobalAnalysis is assumed to be on (default)
decomp = DecompilerHelper.getDecompiler(unit)
if not decomp:
print('No decompiler unit found')
return
# retrieve a handle on the method we wish to examine
method = unit.getInternalMethods().get(0)#('sub_1001929')
src = decomp.decompile(method.getName(True))
if not src:
print('Routine was not decompiled')
return
print(src)
decompTargets = src.getDecompilationTargets()
print(decompTargets)
decompTarget = decompTargets.get(0)
ircfg = decompTarget.getContext().getCfg()
# CFG object reference, see package com.pnfsoftware.jeb.core.units.code.asm.cfg
print("+++ IR-CFG for %s +++" % method)
print(ircfg.formatSimple())
示例10: getTargetDoc
# 需要导入模块: from com.pnfsoftware.jeb.core import RuntimeProjectUtil [as 别名]
# 或者: from com.pnfsoftware.jeb.core.RuntimeProjectUtil import findUnitsByType [as 别名]
def getTargetDoc(self, prj, targetXML):
units = RuntimeProjectUtil.findUnitsByType(prj, IXmlUnit, False)
for unit in units:
if not unit.isProcessed():
unit.process()
if unit.getName() == targetXML:
doc = unit.getDocument()
return doc
return None
示例11: run
# 需要导入模块: from com.pnfsoftware.jeb.core import RuntimeProjectUtil [as 别名]
# 或者: from com.pnfsoftware.jeb.core.RuntimeProjectUtil import findUnitsByType [as 别名]
def run(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]
prjname = prj.getName()
prgdir = ctx.getProgramDirectory()
datafile = os.path.join(prgdir, 'codedata.txt')
data = {}
if os.path.exists(datafile):
with open(datafile, 'r') as f:
try:
data = json.load(f)
except:
pass
print('Current data:', data)
d = data.get(prjname, None)
if not d:
print('Nothing to reload')
return
units = RuntimeProjectUtil.findUnitsByType(prj, ICodeUnit, False)
if not units:
print('No code unit available')
return
for unit in units:
if not unit.isProcessed():
continue
a = d.get(unit.getName(), None)
if a:
renamed_classes = a['renamed_classes']
renamed_fields = a['renamed_fields']
renamed_methods = a['renamed_methods']
comments = a['comments']
for sig, name in renamed_classes.items():
unit.getClass(sig).setName(name)
for sig, name in renamed_fields.items():
unit.getField(sig).setName(name)
for sig, name in renamed_methods.items():
unit.getMethod(sig).setName(name)
# note: comments are applied last since `addr` can be a refactored one here
for addr, comment in comments.items():
unit.setComment(addr, comment)
print('Basic refactoring data was applied')
示例12: run
# 需要导入模块: from com.pnfsoftware.jeb.core import RuntimeProjectUtil [as 别名]
# 或者: from com.pnfsoftware.jeb.core.RuntimeProjectUtil import findUnitsByType [as 别名]
def run(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]
prjname = prj.getName()
prgdir = ctx.getProgramDirectory()
bpfile = os.path.join(prgdir, 'breakpoints.txt')
with open(bpfile, 'r+') as f:
try:
bpdict = json.load(f)
except:
bpdict = {}
#print('Current breakpoints file:', bpdict)
d = bpdict.get(prjname, None)
if not d:
print('Nothing to reload')
return
# get the first code unit available (code units re interactive units)
units = RuntimeProjectUtil.findUnitsByType(prj, IDebuggerUnit, False)
if not units:
print('No unit available')
return
cnt = 0
for dbg in units:
a = d.get(dbg.getName(), None)
if a:
print(a)
for entry in a:
address = entry['address']
enabled = entry['enabled']
#print('- Debugger: %s (for %s): %s (%s)' % (dbg.getName(), dbg.getPotentialDebuggees(), address, 'enabled' if enabled else 'disabled'))
bp = dbg.getBreakpoint(address, None)
if not bp: # do not overwrite an already-set breakpoint
bp = dbg.setBreakpoint(address, None)
if bp:
if not enabled:
bp.setEnabled(False)
cnt += 1
else:
print('Cannot restore breakpoint at address: %s' % address)
print('Breakpoints reloaded: %d.' % cnt)
示例13: run
# 需要导入模块: from com.pnfsoftware.jeb.core import RuntimeProjectUtil [as 别名]
# 或者: from com.pnfsoftware.jeb.core.RuntimeProjectUtil import findUnitsByType [as 别名]
def run(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
# get the first code unit available (code units re interactive units)
units = RuntimeProjectUtil.findUnitsByType(projects[0], ICodeUnit, False)
if not units:
print('No unit available')
return
unit = units[0]
print('Unit: %s' % unit)
# the metadata manager is optional (a unit may choose to not provide one)
mm = unit.getMetadataManager()
if not mm:
print('The unit does not have a metadata manager')
return
# assume the code unit has classes (pick the second one)
c = unit.getClasses()[1]
targetAddress = c.getAddress()
g = mm.getGroupByName('custom')
if not g:
print('Creating new metadata group (type: RGB) ...')
g = MetadataGroup('custom', MetadataGroupType.RGB)
mm.addGroup(g)
print('Done')
print('Adding a piece of metadata at address "%s" ...' % targetAddress)
g.setData(targetAddress, 0x00FF30)
print('Done')
print('If the unit has a text document representation with a an Overview bar, do a Refresh to visualize the metadata')
print('Listing all metadata for this unit (if possible) ...')
for g1 in mm.getGroups():
print('- Group %s (type: %s)' % (g1.getName(), g1.getType()))
alldata = g1.getAllData()
if alldata == None:
print('(This group manager does not allow metadata enumeration)')
else:
for k in alldata:
print(' - at "%s" -> %s' % (k, alldata[k]))
示例14: run
# 需要导入模块: from com.pnfsoftware.jeb.core import RuntimeProjectUtil [as 别名]
# 或者: from com.pnfsoftware.jeb.core.RuntimeProjectUtil import findUnitsByType [as 别名]
def run(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]
prjname = prj.getName()
prgdir = ctx.getProgramDirectory()
bpfile = os.path.join(prgdir, 'breakpoints.txt')
with open(bpfile, 'r+') as f:
try:
bpdict = json.load(f)
except:
bpdict = {}
#print('Current breakpoints file:', bpdict)
units = RuntimeProjectUtil.findUnitsByType(prj, IDebuggerUnit, False)
if not units:
print('No unit available')
return
d = {}
cnt = 0
for dbg in units:
# may be null for a detached debugger
bplist = dbg.getBreakpoints()
if bplist:
a = []
for bp in bplist:
address = bp.getAddress()
enabled = bp.isEnabled()
#print('- Debugger: %s (for %s): %s (%s)' % (dbg.getName(), dbg.getPotentialDebuggees(), address, 'enabled' if enabled else 'disabled'))
a.append({'address': address, 'enabled': enabled})
cnt += 1
d[dbg.getName()] = a
bpdict[prjname] = d
with open(bpfile, 'w') as f:
try:
json.dump(bpdict, f, indent=True)
except Exception as e:
print('ERROR: Cannot save to breakpoints file: %s' % e)
print('Breakpoints saved: %d.' % cnt)
示例15: run
# 需要导入模块: from com.pnfsoftware.jeb.core import RuntimeProjectUtil [as 别名]
# 或者: from com.pnfsoftware.jeb.core.RuntimeProjectUtil import findUnitsByType [as 别名]
def run(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
project = projects[0] # Get current project(IRuntimeProject)
print('Decompiling code units of %s...' % project)
self.codeUnit = RuntimeProjectUtil.findUnitsByType(project, ICodeUnit, False)[0] # Get the current codeUnit(ICodeUnit)
# RuntimeProjectUtil: A collection of utility methods to navigate and act on JEB2 projects.
# findUnitsByType: Find all units of a project that are of the specified type
# ICodeUnit: Code units are inherently interactive, in order to provide facility for code refactoring, modification...
# enumerate the decompiled classes, find and process the target class
units = RuntimeProjectUtil.findUnitsByType(project, IJavaSourceUnit, False)
# IJavaSourceUnit: Definition of a source unit representing a Java class in the form of an Abstract Syntax Tree
for unit in units:
javaClass = unit.getClassElement() # Get a reference to the Java class defined in this unit
# IJavaClass: Java AST interface to represent a Java class. Class elements contain other classes (inner classes), fields, and methods
if javaClass.getName() == self.TARGET_CLASS_NAME: # If the current class is the target class
self.cstbuilder = unit.getFactories().getConstantFactory()
# getFactories: A collection of Java AST element factories
# IJavaFactories: A collection of Java AST element factories(methods)
# IJavaConstantFactory(self.cstbuilder): Builder for Java AST constants
self.processClass(javaClass) # Process the target class
break