Skip to content

Instantly share code, notes, and snippets.

@hanya
Created September 11, 2021 01:19
Show Gist options
  • Save hanya/167ee3041fd0aa1f5bb4a250aaa232b6 to your computer and use it in GitHub Desktop.
Save hanya/167ee3041fd0aa1f5bb4a250aaa232b6 to your computer and use it in GitHub Desktop.
GDB script to show bits from address
python
def _bits_extend(value, max, min):
vs = []
vs.append("")
for i in range(min, max + 1)[::-1]:
if (value & (1 << i)) > 0:
vs.append(" 1")
else:
vs.append(" 0")
vs.append("")
return "|".join(vs)
def bits(arg0):
addr, tvalue = gdb.execute('x {}'.format(arg0), to_string=True).rstrip().split("\t")
value = int(tvalue, 16)
s = []
s.append("{}\t{}".format(addr, tvalue))
s.append("|31|30|29|28|27|26|25|24|23|22|21|20|19|18|17|16|")
s.append(_bits_extend(value, 31, 16))
#s.append("")
s.append("|15|14|13|12|11|10| 9| 8| 7| 6| 5| 4| 3| 2| 1| 0|")
s.append(_bits_extend(value, 15, 0))
print("\n".join(s))
end
define xbits
python bits($arg0)
end
# Shows bits of value as table from specified address
# xt ADDRESS
# ex: xt 0x10000
alias -a xt = xbits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment