Skip to content

Commit

Permalink
py2: fix long hex in shellcraft etc. (#2230)
Browse files Browse the repository at this point in the history
  • Loading branch information
Arusekk committed Jul 17, 2023
1 parent 94fc5d2 commit d69e294
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pwnlib/filepointer.py
Expand Up @@ -176,7 +176,7 @@ def __setattr__(self,item,value):
def __repr__(self):
structure=[]
for i in self.vars_:
structure.append(" %s: %s" % (i,hex(getattr(self, i))))
structure.append(" %s: %#x" % (i, getattr(self, i)))
return "{"+ "\n".join(structure)+"}"

def __len__(self):
Expand Down
4 changes: 2 additions & 2 deletions pwnlib/shellcraft/__init__.py
Expand Up @@ -153,9 +153,9 @@ def pretty(self, n, comment=True):
if comment: return '%s /* %s */' % (n,self.pretty(int(n)))
else: return '%s (%s)' % (n,self.pretty(int(n)))
elif abs(n) < 10:
return str(n)
return '%d' % n
else:
return hex(n)
return '%#x' % n

def okay(self, s, *a, **kw):
if isinstance(s, six.integer_types):
Expand Down
2 changes: 1 addition & 1 deletion pwnlib/shellcraft/templates/amd64/linux/migrate_stack.asm
Expand Up @@ -5,4 +5,4 @@
${amd64.linux.mmap_rwx(size)}
${amd64.mov('rsp', 'rax')}

add rsp, ${hex((size * 3 // 4) & ~7)}
add rsp, ${'%#x' % ((size * 3 // 4) & ~7)}
4 changes: 2 additions & 2 deletions pwnlib/shellcraft/templates/i386/mov.asm
Expand Up @@ -190,8 +190,8 @@ else:
% else:
<%
a,b = fiddling.xor_pair(srcp, avoid = '\x00\n')
a = hex(packing.unpack(a, dest.size))
b = hex(packing.unpack(b, dest.size))
a = '%#x' % packing.unpack(a, dest.size)
b = '%#x' % packing.unpack(b, dest.size)
%>\
mov ${dest}, ${a}
xor ${dest}, ${a} ^ ${pretty(src)}
Expand Down
4 changes: 2 additions & 2 deletions pwnlib/shellcraft/templates/i386/stackhunter.asm
Expand Up @@ -25,13 +25,13 @@ Example:
<% stackhunter = common.label("stackhunter") %>
%if (cookie & 0xffffff) == 0xfceb58:
${stackhunter}:
cmp eax, ${hex(cookie)}
cmp eax, ${'%#x' % cookie}
jne ${stackhunter}+1
jmp esp
%else:
${stackhunter}:
pop eax
cmp eax, ${hex(cookie)}
cmp eax, ${'%#x' % cookie}
jne ${stackhunter}
jmp esp
%endif
4 changes: 2 additions & 2 deletions pwnlib/shellcraft/templates/mips/mov.asm
Expand Up @@ -130,8 +130,8 @@ if src_reg == 0:
% else:
<%
a,b = fiddling.xor_pair(srcp, avoid = '\x00\n')
a = hex(packing.unpack(a, 32))
b = hex(packing.unpack(b, 32))
a = '%#x' % packing.unpack(a, 32)
b = '%#x' % packing.unpack(b, 32)
%>
li ${tmp_reg}, ${a} ^ ${pretty(src)}
li ${dst}, ${a}
Expand Down

0 comments on commit d69e294

Please sign in to comment.