Skip to content

Instantly share code, notes, and snippets.

@hasherezade
Created May 8, 2015 18:27
Show Gist options
  • Save hasherezade/10e7788e5a621e39908e to your computer and use it in GitHub Desktop.
Save hasherezade/10e7788e5a621e39908e to your computer and use it in GitHub Desktop.
# Flags util (for .gdbinit)
# set of commands for easy manipulation on FLAGS
# CC-BY: hasherezade
define translate_flag
if $argc == 0
help translate_flag
else
set $retval = (-1)
if $arg0 == 'O'
set $retval = 0xB
end
if $arg0 == 'D'
set $retval = 0xA
end
if $arg0 == 'I'
set $retval = 0x9
end
if $arg0 == 'T'
set $retval = 0x8
end
if $arg0 == 'S'
set $retval = 0x7
end
if $arg0 == 'Z'
set $retval = 0x6
end
if $arg0 == 'A'
set $retval = 0x4
end
if $arg0 == 'P'
set $retval = 0x2
end
if $arg0 == 'C'
set $retval = 0x0
end
end
end
document translate_flag
Use: translate_flag <arg>
Translates a flag name(represented by char) into the mask that can be applied to on eflags, i.e:
'O' -> 0xB, 'D' -> 0xA, ... , 'C' -> 0x0
example:
translate_flag 'Z' (returns 6)
end
define check_flag_num
if $argc == 0
set $retval = (-1)
help check_flag_num
else
if ($eflags >> $arg0) & 1
set $retval = 1
printf "[X]"
else
set $retval = 0
printf "[ ]"
end
end
end
document check_flag_num
Use: check_flag_num <arg>
Checks if the flag (defined by mask) is set
end
define check_flag
if $argc == 0
set $retval = (-1)
help check_flag
else
translate_flag $arg0
check_flag_num $retval
end
end
document check_flag
Use: check_flag <arg>
Checks if the flag (defined by name) is set
end
define flags
printf " O D I T S Z * A * P * C \n"
set $flag = 0xB
while $flag >= 0
check_flag_num $flag
#if $retval == 1
# printf "[X]"
#else
# printf "[ ]"
#else
set $flag = $flag - 1
end
printf "\n"
end
document flags
Prints flags
end
define neg_flag_num
if $argc == 0
help neg_flag_num
end
if $arg0 < 0 || $arg0 > 0x0B || $arg0 == 1 || $arg0 == 3 || $arg0 == 5
printf "Invalid flag mask!\n"
else
set $val = 1 << $arg0
set $eflags = $eflags ^ $val
flags
end
end
document neg_flag_num
Use : neg_flag_num <arg>
Negates value of the flag, defined by its mask
example:
neg_flag_num 6 (negates ZF)
end
define neg_flag
set $flag_offset = (-1)
if $argc > 0
translate_flag $arg0
set $flag_offset = $retval
end
if $flag_offset == (-1)
printf "Invalid flag supplied!\n"
help neg_flag
else
neg_flag_num $flag_offset
end
end
document neg_flag
Use: neg_flag <arg>
Negates value of the flag, defined by its name: (O D I T S Z A P C)
example:
neg_flag 'Z' (negates ZF)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment