def _get_ida_bg_color_from_file(self): """ Get the background color of the IDA disassembly views via HTML export. """ logger.debug( "Attempting to get IDA disassembly background color from HTML...") # # TODO/IDA: we need better early detection for if IDA is fully ready, # this isn't effective and this func theme func can crash IDA if # called too early (eg, during db load...). # # this isn't a problem now... but I don't want us to be at risk of # hard crashing people's IDA in the future should we change something. # imagebase = idaapi.get_imagebase() #if imagebase == idaapi.BADADDR: # logger.debug(" - No imagebase...") # return None # create a temp file that we can write to handle, path = tempfile.mkstemp() os.close(handle) # attempt to generate an 'html' dump of the first 0x20 bytes (instructions) ida_fd = idaapi.fopenWT(path) idaapi.gen_file(idaapi.OFILE_LST, ida_fd, imagebase, imagebase + 0x20, idaapi.GENFLG_GENHTML) idaapi.eclose(ida_fd) # read the dumped text with open(path, "r") as fd: html = fd.read() # delete the temp file from disk try: os.remove(path) except OSError: pass # attempt to parse the user's disassembly background color from the html bg_color_text = get_string_between(html, '<body bgcolor="', '">') if bg_color_text: logger.debug(" - Extracted bgcolor '%s' from regex!" % bg_color_text) return QtGui.QColor(bg_color_text) # sometimes the above one isn't present... so try this one bg_color_text = get_string_between(html, '.c1 \{ background-color: ', ';') if bg_color_text: logger.debug(" - Extracted background-color '%s' from regex!" % bg_color_text) return QtGui.QColor(bg_color_text) logger.debug(" - HTML color regex failed...") logger.debug(html) return None
def _save_file(filename, ea, size, offset=0): path = os.path.abspath(filename) of = idaapi.fopenWB(path) if not of: raise Exception, 'Unable to open target file : %s' % path res = idaapi.base2file(of, offset, ea, ea + size) idaapi.eclose(of) return res
def _save_file(filename, ea, size, offset=0): path = os.path.abspath(filename) of = idaapi.fopenWB(path) if not of: raise Exception, 'Unable to open target file : %s'% path res = idaapi.base2file(of, offset, ea, ea+size) idaapi.eclose(of) return res
def _save_file(filename, ea, size, offset=0): path = os.path.abspath(filename) of = idaapi.fopenWB(path) if not of: raise IOError("{:s}.save_file({!r}, {:x}, {:#x}) : Unable to open target file : {:s}".format(__name__, filename, ea, size, path)) res = idaapi.base2file(of, offset, ea, ea+size) idaapi.eclose(of) return res
def __save_file(filename, ea, size, offset=0): path = os.path.abspath(filename) # use IDA to open up a file to write to # XXX: does IDA support unicode file paths? of = idaapi.fopenWB(path) if not of: raise E.DisassemblerError(u"{:s}.save_file({!r}, {:#x}, {:+#x}) : Unable to open target file \"{:s}\".".format(__name__, filename, ea, size, utils.string.escape(path, '"'))) # now we can write the segment into the file we opened res = idaapi.base2file(of, offset, ea, ea+size) idaapi.eclose(of) return res
def __save_file(filename, ea, size, offset=0): path = os.path.abspath(filename) # use IDA to open up a file to write to # XXX: does IDA support unicode file paths? of = idaapi.fopenWB(path) if not of: raise E.DisassemblerError( u"{:s}.save_file({!r}, {:#x}, {:+#x}) : Unable to open target file \"{:s}\"." .format(__name__, filename, ea, size, utils.string.escape(path, '"'))) # now we can write the segment into the file we opened res = idaapi.base2file(of, offset, ea, ea + size) idaapi.eclose(of) return res