def recovermarks(): '''Utilizing any tag information found in the database, recreate all the database marks.''' # collect result = [] for fn,l in database.select('marks'): m = set( (l['marks']) if hasattr(l['marks'],'__iter__') else [int(x,16) for x in l['marks'].split(',')] if type(l['marks']) is str else [l['marks']]) res = [(ea,d['mark']) for ea,d in function.select(fn,'mark')] if m != set(a for a,_ in res): logging.warning("%x: ignoring cached version of marks due to being out-of-sync with real values : %r : %r", fn, map(hex,m), map(hex,set(a for a,_ in res))) result.extend(res) result.sort(cmp=lambda x,y: cmp(x[1],y[1])) # discovered marks versus database marks result = dict(result) current = {ea:descr for ea,descr in database.marks()} # create tags for x,y in result.items(): if (x not in current) or (current[x] != result[x]): if current[x] != result[x]: logging.info('%x: database tag is newer than mark description : %r', x, result[x]) database.mark(x, y) continue logging.warning('%x: skipping already existing mark : %r', x, current[x]) # marks that aren't reachable in the database for ea in set(current.viewkeys()).difference(result.viewkeys()): logging.warning('%x: unreachable mark (global) : %r', ea, current[ea]) # color them colormarks()
def recovermarks(): """Walk through the tags made by ``colormarks`` and re-create the marks that were found. This is useful if any marks were accidentally deleted and can be used for recovering them as long as they were initally tagged properly. """ # collect result = [] for fn, l in database.select('marks'): m = {item for item in l['marks']} if hasattr(l['marks'], '__iter__') else { int(item, 16) for item in l['marks'].split(',') } if isinstance(l['marks'], six.string_types) else {l['marks']} res = [(ea, d['mark']) for ea, d in func.select(fn, 'mark')] if m != {ea for ea, _ in res}: logging.warning( "{:s} : Ignoring the function tag \"{:s}\" for function {:#x} due to its value being out-of-sync with the contents values ({!s} <> {!s})." .format('.'.join([__name__, 'recovermarks']), fn, builtins.map("{:#x}".format, m), builtins.map("{:#x}".format, {ea for ea, _ in res}))) result.extend(res) result.sort(key=lambda item: item[1]) # discovered marks versus database marks result = {ea: item for ea, item in result.items()} current = {ea: descr for ea, descr in database.marks()} # create tags for x, y in result.items(): if x in current: logging.warning( "{:#x}: skipping already existing mark : {!r}".format( x, current[x])) continue # x not in current if x not in current: logging.info("{:#x}: adding missing mark due to tag : {!r}".format( x, result[x])) elif current[x] != result[x]: logging.info( "{:#x}: database tag is different than mark description : {!r}" .format(x, result[x])) else: assert current[x] == result[x] database.mark(x, y) # marks that aren't reachable in the database for ea in {item for item in current.keys() }.difference({item for item in result.keys()}): logging.warning("{:#x}: unreachable mark (global) : {!r}".format( ea, current[ea])) # color them colormarks()
def recovermarks(): '''Utilizing any tag information found in the database, recreate all the database marks.''' # collect result = [] for fn, l in database.select('marks'): m = set((l['marks']) if hasattr(l['marks'], '__iter__') else [int(x, 16) for x in l['marks']. split(',')] if type(l['marks']) is str else [l['marks']]) res = [(ea, d['mark']) for ea, d in function.select(fn, 'mark')] if m != set(a for a, _ in res): logging.warning( "{:x}: ignoring cached version of marks due to being out-of-sync with real values : {!r} : {!r}" .format(fn, map(hex, m), map(hex, set(a for a, _ in res)))) result.extend(res) result.sort(cmp=lambda x, y: cmp(x[1], y[1])) # discovered marks versus database marks result = dict(result) current = {ea: descr for ea, descr in database.marks()} # create tags for x, y in result.items(): if x in current: logging.warning( "{:x}: skipping already existing mark : {!r}".format( x, current[x])) continue # x not in current if x not in current: logging.info("{:x}: adding missing mark due to tag : {!r}".format( x, result[x])) elif current[x] != result[x]: logging.info( "{:x}: database tag is different than mark description : {!r}". format(x, result[x])) else: assert current[x] == result[x] database.mark(x, y) # marks that aren't reachable in the database for ea in set(current.viewkeys()).difference(result.viewkeys()): logging.warning("{:x}: unreachable mark (global) : {!r}".format( ea, current[ea])) # color them colormarks()
def recovermarks(): """Walk through the tags made by `colormarks` and re-create the marks that were found. This is useful if any marks were accidentally deleted and can be used for recovering them as long as they were initally tagged properly. """ # collect result = [] for fn, l in database.select('marks'): m = set( (l['marks']) if hasattr(l['marks'], '__iter__') else [int(x, 16) for x in l['marks'].split(',')] if type(l['marks']) is str else [l['marks']]) res = [(ea, d['mark']) for ea, d in func.select(fn, 'mark')] if m != set(a for a, _ in res): logging.warning("{:#x}: ignoring cached version of marks due to being out-of-sync with real values : {!r} : {!r}".format(fn, builtins.map(hex, m), builtins.map(hex, set(a for a, _ in res)))) result.extend(res) result.sort(cmp=lambda x, y: cmp(x[1], y[1])) # discovered marks versus database marks result = dict(result) current = {ea : descr for ea, descr in database.marks()} # create tags for x, y in result.items(): if x in current: logging.warning("{:#x}: skipping already existing mark : {!r}".format(x, current[x])) continue # x not in current if x not in current: logging.info("{:#x}: adding missing mark due to tag : {!r}".format(x, result[x])) elif current[x] != result[x]: logging.info("{:#x}: database tag is different than mark description : {!r}".format(x, result[x])) else: assert current[x] == result[x] database.mark(x, y) # marks that aren't reachable in the database for ea in set(current.viewkeys()).difference(result.viewkeys()): logging.warning("{:#x}: unreachable mark (global) : {!r}".format(ea, current[ea])) # color them colormarks()
def recovermarks(): """Walk through the tags made by ``colormarks`` and re-create the marks that were found. This is useful if any marks were accidentally deleted and can be used for recovering them as long as they were initally tagged properly. """ # collect result = [] for fn, l in database.select('marks'): m = set( (l['marks']) if hasattr(l['marks'], '__iter__') else [int(x, 16) for x in l['marks'].split(',')] if type(l['marks']) is str else [l['marks']]) res = [(ea, d['mark']) for ea, d in func.select(fn, 'mark')] if m != { a for a, _ in res }: logging.warning("{:s} : Ignoring the function tag \"{:s}\" for function {:#x} due to its value being out-of-sync with the contents values ({!s} <> {!s}).".format('.'.join((__name__, 'recovermarks')), fn, builtins.map(hex, m), builtins.map(hex, set(a for a, _ in res)))) result.extend(res) result.sort(cmp=lambda x, y: cmp(x[1], y[1])) # discovered marks versus database marks result = dict(result) current = {ea : descr for ea, descr in database.marks()} # create tags for x, y in result.items(): if x in current: logging.warning("{:#x}: skipping already existing mark : {!r}".format(x, current[x])) continue # x not in current if x not in current: logging.info("{:#x}: adding missing mark due to tag : {!r}".format(x, result[x])) elif current[x] != result[x]: logging.info("{:#x}: database tag is different than mark description : {!r}".format(x, result[x])) else: assert current[x] == result[x] database.mark(x, y) # marks that aren't reachable in the database for ea in set(current.viewkeys()).difference(result.viewkeys()): logging.warning("{:#x}: unreachable mark (global) : {!r}".format(ea, current[ea])) # color them colormarks()