Skip to content

Instantly share code, notes, and snippets.

@Fitblip
Created April 13, 2012 21:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fitblip/2380242 to your computer and use it in GitHub Desktop.
Save Fitblip/2380242 to your computer and use it in GitHub Desktop.
Sulley issue #8
orted by netwerkf...@gmail.com, Sep 30, 2008
Index: sulley/primitives.py
===================================================================
--- sulley/primitives.py (revision 154)
+++ sulley/primitives.py (working copy)
@@ -763,6 +763,23 @@
self.rendered = rendered
+ elif self.format == "hex":
+ # if the sign flag is raised and we are dealing with a signed integer (first bit is 1).
+ if self.signed and self.to_binary()[0] == "1":
+ max_num = self.to_decimal("0" + "1" * (self.width - 1))
+ # chop off the sign bit.
+ val = self.value & max_num
+
+ # account for the fact that the negative scale works backwards.
+ val = max_num - val
+
+ # toss in the negative sign.
+ self.rendered = "%x" % ~val
+
+ # unsigned integer or positive signed integer.
+ else:
+ self.rendered = "%x" % self.value
+
#
# ascii formatting.
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment