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)
def run(self, ctx): prj = ctx.getMainProject() assert prj, 'Need a project' artifactFile = File(self.path) a = Artifact(artifactFile.getName(), FileInput(artifactFile)) print(a) la = prj.processArtifact(a) print(la)
def run(self, ctx): # Hello world print(u"🔥 JEB scripting") # If the script is run in JEB GUI if isinstance(ctx, IGraphicalClientContext): project = ctx.getMainProject() else: # assume command line & create a tmp project argv = ctx.getArguments() if len(argv) < 1: print('[-] Did you forget to provide the APK file?') return self.inputApk = argv[0] # Init engine engctx = ctx.getEnginesContext() if not engctx: print('[-] Back-end engines not initialized') return # Create a project project = engctx.loadProject('JebFridaHookProject') if not project: print('[-] Failed to open a new project') return # Add artifact to project artifact = Artifact('JebFridaHookArtifact', FileInput(File(self.inputApk))) project.processArtifact(artifact) # loop through all dex files in project & search for dex in project.findUnits(IDexUnit): # Generating hooks for OkHttp3 for idx, result in enumerate( self.do_search(dex, "Certificate pinning failure!", ["Ljava/lang/String;"])): self.frida_hooks.append( self.frida_okhttp3_hook.format( idx=idx, java_class=result.get("class"), java_method=result.get("method"))) print(u"🔥 Fresh Frida Hooks") print("-" * 100) print(self.frida_hook_file.format(hooks="\n".join(self.frida_hooks))) print("-" * 100)
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] artifactFile = File(self.path) a = Artifact(artifactFile.getName(), FileInput(artifactFile)) print(a) la = prj.processArtifact(a) print(la)
def loadArtifacts(self, artifactFilePath): artifactFile = File(artifactFilePath) return Artifact(artifactFile.getName(), FileInput(artifactFile))
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 + '...') if not self.inputFile.endswith('.evm-bytecode'): print( 'Warning: it is recommended your contract file has the evm-bytecode extension in order to guarantee processing by the EVM modules' ) # create a project project = engctx.loadProject('EVMProject') # load and process the artifact artifact = Artifact('EVMArtifact', 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('EVM unit: %s' % unit) # GlobalAnalysis is assumed to be on: the contract is already decompiled # we retrieve a handle on the EVM decompiler ... decomp = DecompilerHelper.getDecompiler(unit) if not decomp: print('No decompiler unit found') return # ... and retrieve a handle on the decompiled contract's INativeSourceUnit src = decomp.decompile("DecompiledContract") print(src) #targets = src.getDecompilationTargets() #print(targets) # let's get the contract's AST astDecompClass = src.getRootElement() # the commented line below will output the entire decompiled source code #print(astDecompClass) # here, we walk the AST tree and print the type of each element in the tree print("*** AST of contract") self.displayASTTree(astDecompClass) # now, let's retrieve the individual methods implemented in the contract methods = unit.getInternalMethods() for method in methods: # retrieve the INativeSourceUnit of the method r = decomp.decompileMethod(method) print("*** AST for method: %s" % method.getName(True)) self.displayASTTree(r.getRootElement()) # list of INativeDecompilationTarget for a decompiled method decompTargets = r.getDecompilationTargets() if decompTargets: # get the first (generally, only) target object decompTarget = decompTargets.get(0) # an INativeDecompilationTarget object aggregates many useful objects resulting from the decompilation of a method # here, we retrieve the most refined CFG of the Intermediate Representation for the method ircfg = decompTarget.getContext().getCfg() # CFG object reference, see package com.pnfsoftware.jeb.core.units.code.asm.cfg print("++++ IR-CFG for method: %s" % method.getName(True)) print(ircfg.formatSimple()) # end of demo, we have enough with one method, uncomment to print out the AST and IR of all methods break
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())