Comments (3)
I think it is a bad idea to directly edit the files in the python standard library. It might break other python scripts/programmes using that function. Also, you will need to edit it every time when python is updated.
In fact, python allows you to replace functions on the fly (also called monkey-patching). So you can change the behaviour of the relevant function in the subprocess module within adb-sync
itself without modifying the file in standard library.
Just add the code after all the from ... import ...
lines after line 28 of the adb-sync
file like the following (code copied from standard library file with adjustments made):
... # code before
from typing import Callable, cast, Dict, List, IO, Iterable, Optional, Tuple, Type
def list2cmdline_patch(seq):
"""
Translate a sequence of arguments into a command line
string, using the same rules as the MS C runtime:
1) Arguments are delimited by white space, which is either a
space or a tab.
2) A string surrounded by double quotation marks is
interpreted as a single argument, regardless of white space
contained within. A quoted string can be embedded in an
argument.
3) A double quotation mark preceded by a backslash is
interpreted as a literal double quotation mark.
4) Backslashes are interpreted literally, unless they
immediately precede a double quotation mark.
5) If backslashes immediately precede a double quotation mark,
every pair of backslashes is interpreted as a literal
backslash. If the number of backslashes is odd, the last
backslash escapes the next double quotation mark as
described in rule 3.
"""
# See
# http://msdn.microsoft.com/en-us/library/17w5ykft.aspx
# or search http://msdn.microsoft.com for
# "Parsing C++ Command-Line Arguments"
result = []
needquote = False
for arg in seq:
bs_buf = []
# Add a space to separate this argument from the others
if result:
result.append(' ')
arg = arg.decode() if type(arg)==bytes else arg
needquote = (" " in arg) or ("\t" in arg) or not arg
if needquote:
result.append('"')
for c in arg:
if c == '\\':
# Don't know if we need to double yet.
bs_buf.append(c)
elif c == '"':
# Double backslashes.
result.append('\\' * len(bs_buf)*2)
bs_buf = []
result.append('\\"')
else:
# Normal char
if bs_buf:
result.extend(bs_buf)
bs_buf = []
result.append(c)
# Add remaining backslashes, if any.
if bs_buf:
result.extend(bs_buf)
if needquote:
result.extend(bs_buf)
result.append('"')
return ''.join(result)
subprocess.list2cmdline = list2cmdline_patch
class OSLike(object):
... # code after
And change the isWorking()
function as below:
def IsWorking(self) -> bool:
"""Tests the adb connection."""
# This string should contain all possible evil, but no percent signs.
# Note this code uses 'date' and not 'echo', as date just calls strftime
# while echo does its own backslash escape handling additionally to the
# shell's. Too bad printf "%s\n" is not available.
s = '(; #`ls`$PATH\'"(\\\\\\\\){};!\xc0\xaf\xff\xc2\xbf'
test_strings = [
b'(', s.encode('utf-8')
]
for test_string in test_strings:
good = False
...
from adb-sync.
Hi.
One line above this file C:\Users\Marco\AppData\Local\Programs\Python\Python37\lib\subprocess.py, line 529, add this line "arg = arg.decode() if type(arg)==bytes else arg" without quotes and in file adb-sync line 214 change and add this lines:
s = '(; #ls
$PATH'"(\\\\){};!\xc0\xaf\xff\xc2\xbf'
test_strings = [
b'(', s.encode('utf-8')
]
After that, it works like a charm.
Test it.
from adb-sync.
I followed the instructions above, and eventually got it working. However, the instructions are a little unclear, so I thought I'd help clarify.
For the first step, the line above which you insert the new line is indeed line 529 at the time of this writing (v3.7.4). To prevent a misalignment from an update however, this is the actual content of line 529 above which to insert: needquote = (" " in arg) or ("\t" in arg) or not arg
(technically this is line 530, but line 529 is an empty line, so just put the new line above one of them)
For the second step, the new code was not formatted properly as a code block, meaning when I copy and paste it in it's invalid. Instead of trying to figure out how Github mangled the string, I just added a "return true" line at the start of that "IsWorking()" function.
from adb-sync.
Related Issues (20)
- error running it. stacktrace. HOT 1
- Colon not supported in folder name HOT 8
- Hard-coded location of python3 HOT 2
- TypeError with latest rev HOT 1
- adb-sync seems to close standard input? HOT 3
- anyway to --reverse and --delete?
- Problems with encoding: UnicodeDecodeError: 'utf-8' codec can't decode byte: invalid start byte HOT 6
- Is this project still active? HOT 2
- windows 10 HOT 8
- adb-sync doesn't work correctly with symlinks
- Crashes when trying to copy files with question marks in the name.
- Copying from external storage HOT 4
- adb-sync doesn't copy files properly if names are same on local and remote HOT 5
- When the file length is the same, it will be considered as no difference HOT 1
- two way sync breaks when filename contains spaces
- Scanning and diffing takes a long time for large directories HOT 2
- "bad date" from "touch" when using -t option HOT 1
- Ignore unreadable files
- Use my fork HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from adb-sync.