Python can't handle Windows long paths with parent directory parts - python

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?

Related

pwntools' p32 function is weird

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'

Code doesn't run

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.

Run scons on Windows 10 environment with Python 2.7 and Python 3

How can I run scons on Windows 10 when Python 3.6.1 and Python 2.7.13 is installed? When typing python into my command window I get the following output:
Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 18:41:36) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
Since I personally use Python 3.6.x this is fine for me and I do not want to change this.
When typing py -2 into my command window I get the following output:
Python 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:42:59) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
scons does not work with Python 3.x. It needs to be executed with Python 2.7.x. How can I "tell" scons to use Python 2.7.x?
When I just type scons into the command prompt I get the following output:
PS C:\dev\projectX> scons
Fatal Python error: Py_Initialize: unable to load the file system codec
ModuleNotFoundError: No module named 'encodings'
Current thread 0x00007050 (most recent call first):
Try Changing line 23 in scons.bat from:
python "%scriptname%" %*
to
py -2 "%scriptname%" %*
Note that work on getting SCons to run under both py 2 and py 3.5+ is mostly done and should be released in the next month (or so)
Before running scons in Powershell, amend the PATH environment variable to put your Python 2.7 installation at the front. Something like:
SET PATH=C:\Python27;%path%

Syntax error in command line while executing python programme

I have just started using python3.3. The shell looks like this:
Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:06:53) [MSC v.1600 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> print ("hello world")
It prints hello world correclty, but in the command line it shows error in line 1 (i.e Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:06:53) [MSC v.1600 64 bit (AMD64)] on win32 ) declaring it as a syntax error.
What is the problem??
You are specifying the syntax incorrectly on the command line. The correct syntax is:
$ python3 -c 'print ("hello world")'
That's not an error. That's what appears when you open the interactive interpreter by typing $ python3, telling you what version of python you have and other details (such as the date).

Is there easy way to prevent echo from input?

How to prevent echo from input ??
Have tried "getpass()" but no luck.
On Windows IDLE, it doesn't work
Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:03:43) [MSC v.1600 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import getpass
>>> p = getpass.getpass(prompt="Input: ")
Warning: Password input may be echoed.
Input: abc <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< It still echos..
On the terminal of the Windows, it works
Python 3.3.2 (v3.3.2:d047928ae3f6, May 16 2013, 00:03:43) [MSC v.1600 32 bit (In
tel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import getpass
>>> p = getpass.getpass(prompt="Input: ")
Input:
>>>
Is there a easy way to prevent echo from input ?
I'm assuming your first example there is in IDLE.
From getpass.win_getpass():
if sys.stdin is not sys.__stdin__:
return fallback_getpass(prompt, stream)
IDLE replaces sys.stdin with a different object. getpass detects that somebody has wrapped stdin and fails for security reasons.
See: http://bugs.python.org/issue9290

Categories

Resources