When I start a python interactive session from the command line I am greeted by :
Python 3.9.6 (default, Jun 30 2021, 10:22:16)
[GCC 11.1.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
Is there a way of disabling that message so that I go immediately to the >>> prompt?
Yes, there is a way to do so.
Type in the cmd:
python -q
instead of
python
and this should do the trick.
I'm testing on Intel x86_64, Ubuntu 64bit, Python3, Pwntools v4.3.1
$ python
Python 3.7.4 (default, Aug 13 2019, 20:35:49)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from pwn import *
>>> addr = 0xbffffb78
>>> print(p32(addr))
b'x\xfb\xff\xbf'
In my opinion, the correct packing result for 0xbffffb78 should be\x78\xfb\xff\xbf.
But why did b'x\xfb\xff\xbf' happen?
where is \x78 ?
And what is the correct way of packing, not using p32()?
This is just how Python renders bytes objects. If a byte can be rendered as an ASCII character, it is displayed as one.
>>> b"\x78"
b'x'
To see the bytes rendered as hex you can use the hex method of the bytes object:
>>> b'x\xfb\xff\xbf'.hex()
'78fbffbf'
I'm trying to use .. in a Windows long filename within Python and it is producing unexpected results.
Here is the output from the Python REPL:
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.path.exists(u'\\\\?\\C:\\BitBucket\\crab6\\product\\installer\\windows\\..\\usage.txt')
False
>>> os.path.exists(u'\\\\?\\C:\\BitBucket\\crab6\\product\\installer\\usage.txt')
True
(I realize the path above isn't over 260 characters and therefore the long path syntax is unnecessary, but for the purposes of this post I've made it more manageable. The outcome is the same with very long paths.)
Has anyone else encountered this, and is it a purposeful limitation of long filenames?
When i try to run my code all i get is this:
Python 3.6.2 (v3.6.2:5fd33b5, Jul 8 2017, 04:14:34) [MSC v.1900 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>>
RESTART: C:/Users/Owner/Documents/School Work/Computer Science/Python/Coding Practise/Fruit Machine.py
>>>
it doesnt run, it just tells me where my file is saved... please help.
It's likely that your code is running properly, but nothing in your code is outputting anything (i.e. you haven't put any prints or inputs). So your code is running as programmed, but if you're expecting something to be printed, you need to use the print and input statements.
I am seeing inconsistent behavior when creating temporary directories in Python:
# System Python, Windows Console
C:\Python33>python
Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:06:53) [MSC v.1600 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tempfile
>>> tempfile.mkdtemp()
'c:\\windows\\temp\\tmpte7fcc'
# Virtualenv Python, Windows Console
Scripts>python
Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:06:53) [MSC v.1600 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tempfile
>>> tempfile.mkdtemp()
'c:\\windows\\temp\\tmprziefb'
# System Python, Cygwin Console
$ /cygdrive/c/Python33/python.exe
Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:06:53) [MSC v.1600 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tempfile
>>> tempfile.mkdtemp()
'c:\\windows\\temp\\tmprk4fcu'
# Virtualenv Python, Cygwin Console
$ Scripts/python
Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:06:53) [MSC v.1600 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import tempfile
>>> tempfile.mkdtemp()
'c:\\cygwin\\tmp\\tmppeozcl
The first three cases create temporary directories in C:\Windows\Temp (as expected). Why does the fourth case create temporary directories somewhere else?
EDIT: Additional data requested in the comments:
# System Python, Windows Console
C:\Python33>python
Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:06:53) [MSC v.1600 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> import tempfile
>>> tempfile._candidate_tempdir_list()
['C:\\WINDOWS\\TEMP', 'C:\\WINDOWS\\TEMP', 'c:\\temp', 'c:\\tmp', '\\temp', '\\tmp', 'C:\\Python33']
>>> [os.environ.get(envname) for envname in ('TMPDIR', 'TEMP', 'TMP')]
[None, 'C:\\WINDOWS\\TEMP', 'C:\\WINDOWS\\TEMP']
# Virtualenv Python, Windows Console
Scripts>python
Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:06:53) [MSC v.1600 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> import tempfile
>>> tempfile._candidate_tempdir_list()
['C:\\WINDOWS\\TEMP', 'C:\\WINDOWS\\TEMP', 'c:\\temp', 'c:\\tmp', '\\temp', '\\tmp', 'C:\\_PROJECTS\\python-veracity']
>>> [os.environ.get(envname) for envname in ('TMPDIR', 'TEMP', 'TMP')]
[None, 'C:\\WINDOWS\\TEMP', 'C:\\WINDOWS\\TEMP']
# System Python, Cygwin Console
$ /cygdrive/c/Python33/python.exe
Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:06:53) [MSC v.1600 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> import tempfile
>>> tempfile._candidate_tempdir_list()
['C:\\Cygwin\\tmp', 'C:\\WINDOWS\\TEMP', 'c:\\temp', 'c:\\tmp', '\\temp', '\\tmp', 'C:\\_PROJECTS\\python-veracity']
>>> [os.environ.get(envname) for envname in ('TMPDIR', 'TEMP', 'TMP')]
[None, 'C:\\Cygwin\\tmp', 'C:\\WINDOWS\\TEMP']
# Virtualenv Python, Cygwin Console
$ Scripts/python
Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:06:53) [MSC v.1600 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> import tempfile
>>> tempfile._candidate_tempdir_list()
['C:\\Cygwin\\tmp', 'C:\\Cygwin\\tmp', 'c:\\temp', 'c:\\tmp', '\\temp', '\\tmp', 'C:\\_PROJECTS\\python-veracity']
>>> [os.environ.get(envname) for envname in ('TMPDIR', 'TEMP', 'TMP')]
[None, 'C:\\Cygwin\\tmp', 'C:\\Cygwin\\tmp']
The tempfile module looks for the environment variables TMPDIR, TEMP and TMP. If one of these variables is set then its value is used as base directory for temporary files and directories. I guess Cygwin sets one of these to C:\cygwin\tmp.