Repository: Gallopsled/pwntools

Issue:
AssertionError importing pwn on 32 bit ubuntu
```
ubuntu@ubuntu-xenial:~/tools$ uname -a
Linux ubuntu-xenial 4.4.0-47-generic #68-Ubuntu SMP Wed Oct 26 19:39:59 UTC 2016 i686 i686 i686 GNU/Linux
```

```python
ubuntu@ubuntu-xenial:~/tools$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from pwn import *
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ubuntu/tools/pwntools/pwn/__init__.py", line 2, in <module>
    from .toplevel import *
  File "/home/ubuntu/tools/pwntools/pwn/toplevel.py", line 20, in <module>
    import pwnlib
  File "/home/ubuntu/tools/pwntools/pwnlib/__init__.py", line 40, in <module>
    importlib.import_module('.%s' % module, 'pwnlib')
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/ubuntu/tools/pwntools/pwnlib/dynelf.py", line 54, in <module>
    from . import elf
  File "/home/ubuntu/tools/pwntools/pwnlib/elf/__init__.py", line 1, in <module>
    from .corefile import Core
  File "/home/ubuntu/tools/pwntools/pwnlib/elf/corefile.py", line 13, in <module>
    from .datatypes import *
  File "/home/ubuntu/tools/pwntools/pwnlib/elf/datatypes.py", line 544, in <module>
    assert ctypes.sizeof(elf_prstatus_amd64) == 0x150
AssertionError
>>>
```

I have all the dependencies and the latest `pwntools` from `pip`.

On a 64 bit VM instead it's working fine
Guard clause to handle 32 bits unsupported in setup.py
Added a guard clause to `setup.py` in order to prevent incorrectly trying to install pwntools with a 32-bit Python installation. Resolves Gallopsled/pwntools-tutorial#15.



Discussion:
Yes, I also have this problem when I use `pip install` 

My PC:
win10 64bit
virtualbox 5.2
both Ubuntu14.04/Ubuntu16.04 32bit have this problem.
This is a duplicate of #518 
I thought it was worth adding since the issue was still open in pwntools-tutorial and python 32 bit installations are still available for Windows. However, this issue in particular had been stale for quite some time (~3 years).
I consider the issue with 32 bits only applicable to Python 2.x.  (Except for the tests, which could be made more portable maybe.)  Also, I would prefer a warning (maybe with an interactive question asked) than a big error impossible to bypass.
What kind of logic flow did you have in mind? Based off the issue I thought it was worth stopping early since it is kind of an irrecoverable issue.
I mean that pwntools is useful on 32-bit arches as well, but some features of it may not work under python 2.  Here is all I know:
- The only officially supported host platform for now is latest Ubuntu LTS on amd64 (read: this is a reference platform).
- Some of the doctests currently only work on Ubuntu LTS on amd64, because they must assume *something*.
- I personally tested pwntools on both arm64 (py2, py3) and i386 (py3) to work in every case I could possibly imagine.
- Historically, pwntools is known to have had broken stuff on 32-bit builds of Python 2 (one thing still broken is MIPS shellcraft).  This is caused by Python 2 integers being limited to platform-dependent value ranges, and us using `hex(n)` or `repr(n)` instead of `"%#x" % n` or `"{:#x}".format(n)` in some places.  Python 3 does not have such a problem, because it simply treats everything similar to `long`s from py2 (bignums) and never adds any `L` suffix.

I think I will fix all of 32-bit problems shortly, and then we can get rid of the warning, which is worded too strongly in the first place.

And I really do not like some commercial software going to great lengths trying to make 'unsupported' mean 'impossible', so I do not want pwntools to be like that.  This is just being mean to all well-aware users.  Yes, yes, I know advanced users can just patch the check away, but still.
We could limit the check to python 2 only. But I don't 100% understand what's broken exactly.

The other message doesn't prevent you from using pwntools on 32bit and only warns you, that there might be problems.

We could only log a warning during pip install, but I don't know if it's a good idea to stall on an `input()` call or similar, since it could break scripted installs.

This isn't your fault @fercevik729. You just brought up the issue again. Documenting possible incompatibility with 32bit Python 2 in the install instructions could fix the original issue in the pwntools-tutorial repo as well, without touching the setup.py?
I see. In that case should I modify the installation instructions in the README and revert my changes?

Resolving patch:
diff --git a/pwnlib/filepointer.py b/pwnlib/filepointer.py
--- a/pwnlib/filepointer.py
+++ b/pwnlib/filepointer.py
@@ -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):
diff --git a/pwnlib/shellcraft/__init__.py b/pwnlib/shellcraft/__init__.py
--- a/pwnlib/shellcraft/__init__.py
+++ b/pwnlib/shellcraft/__init__.py
@@ -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):


Test patch: