def ungzip_content(self, content): _buf = StringIO(content) with gzip.GzipFile(mode = 'rb', fileobj = _buf) as _gzip_file: _content = _gzip_file.read() _buf.close() return _content
def activate(self, ctx): print("Suggesting variable names...") ea = idaapi.get_screen_ea() vuu = ida_hexrays.get_widget_vdui(ctx.widget) if ea is None: idaapi.warning("Current function not found.") else: f = StringIO() with jsonlines.Writer(f) as writer: try: info, cfunc = func(ea, vuu) # We must set the working directory to the dire dir to open the model correctly os.chdir(dire_dir) p = subprocess.Popen([RUN_ONE, '--model', MODEL], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE, encoding=sys.getdefaultencoding()) #print(info) writer.write(info) comm = p.communicate(input=f.getvalue()) json_results = comm[0] stderr = comm[1] if p.returncode != 0: print(stderr) raise ValueError("Variable prediction failed") results = json.loads(json_results) best_results = results[0][0] #print("best: ", best_results) tuples = map( lambda x: (varnames[x[0]] if x[0] in varnames else x[0], x[1]['new_name']), best_results.items()) FinalRename(dict(tuples), cfunc, vuu).apply_to(cfunc.body, None) # Force the UI to update #vuu.refresh_ctext() except ida_hexrays.DecompilationFailure: idaapi.warning("Decompilation failed") except ValueError as e: idaapi.warning( str(e) + ". See output window for more details.") return 1
def get_xml_status(): cld = cloud() comp = component('status') cld.add_component(comp) serv = service('setup') node_status = get_node_status() serv.add_property(property('state', node_status)) comp.add_service(serv) if node_status == 'READY': for name, running in get_services_status(): serv = service(name) serv.add_property(property('running', ('no','yes')[running])) comp.add_service(serv) io = StringIO() node(cloud=cld).export(io, 0) return io.getvalue()
def __init__(self, result, id, description=None, directive=None, comment=None): self.result = result self.id = id self.description = description try: self.directive = directive.upper() except AttributeError: self.directive = directive self.comment = comment self.yaml = None self._yaml_buffer = StringIO() self.diagnostics = []
def parse(self, source): if isinstance(source, (str, unicode)): self._parse(StringIO(source)) elif hasattr(source, "__iter__"): self._parse(source)
def readpdf(mypdf): rsrcmgr = PDFResourceManager() sio = StringIO() codec = 'utf-8' laparms = LAParams() device = TextConverter(rsrcmgr,sio,codec = codec, laparms)