mirror of
https://github.com/gryf/mc_adbfs.git
synced 2025-12-18 20:10:21 +01:00
Fix quoting for 'adb shell'
This commit is contained in:
29
adbfs
29
adbfs
@@ -16,6 +16,7 @@ import os
|
|||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
|
import shlex
|
||||||
|
|
||||||
__version__ = 0.11
|
__version__ = 0.11
|
||||||
|
|
||||||
@@ -337,9 +338,16 @@ class Adb(object):
|
|||||||
|
|
||||||
self.__su_check()
|
self.__su_check()
|
||||||
|
|
||||||
|
def _shell_cmd(self, *args, with_root=False):
|
||||||
|
if with_root and self._got_root:
|
||||||
|
args = ('su', '-c', shlex.quote(' '.join(shlex.quote(x) for x in args)))
|
||||||
|
|
||||||
|
cmd = [self.conf.adb_command, 'shell'] + [shlex.quote(x) for x in args]
|
||||||
|
return cmd
|
||||||
|
|
||||||
def __su_check(self):
|
def __su_check(self):
|
||||||
"""Check if we are able to get elevated privileges"""
|
"""Check if we are able to get elevated privileges"""
|
||||||
cmd = [self.conf.adb_command] + 'shell su -c whoami'.split()
|
cmd = self._shell_cmd('su', '-c', 'whoami')
|
||||||
try:
|
try:
|
||||||
with open(os.devnull, 'w') as fnull:
|
with open(os.devnull, 'w') as fnull:
|
||||||
result = check_output(cmd, stderr=fnull)
|
result = check_output(cmd, stderr=fnull)
|
||||||
@@ -389,10 +397,8 @@ class Adb(object):
|
|||||||
|
|
||||||
def _retrieve_single_dir_list(self, dir_):
|
def _retrieve_single_dir_list(self, dir_):
|
||||||
"""Retrieve file list using adb"""
|
"""Retrieve file list using adb"""
|
||||||
lscmd = self.conf.box['rls'].format(dir_)
|
lscmd = self.conf.box['rls'].format(shlex.quote(dir_))
|
||||||
if self._got_root:
|
command = self._shell_cmd(*shlex.split(lscmd), with_root=True)
|
||||||
lscmd = 'su -c "{}"'.format(lscmd)
|
|
||||||
command = [self.conf.adb_command, 'shell', lscmd]
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if self.conf.debug:
|
if self.conf.debug:
|
||||||
@@ -449,12 +455,9 @@ class Adb(object):
|
|||||||
if not root:
|
if not root:
|
||||||
lscmd = self.conf.box['ls']
|
lscmd = self.conf.box['ls']
|
||||||
else:
|
else:
|
||||||
lscmd = self.conf.box['rls'].format(root.filepath)
|
lscmd = self.conf.box['rls'].format(shlex.quite(root.filepath))
|
||||||
|
|
||||||
if self._got_root:
|
command = self._shell_cmd(*shlex.split(lscmd), with_root=True)
|
||||||
lscmd = 'su -c "{}"'.format(lscmd)
|
|
||||||
|
|
||||||
command = [self.conf.adb_command, 'shell', lscmd]
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if self.conf.debug:
|
if self.conf.debug:
|
||||||
@@ -566,7 +569,7 @@ class Adb(object):
|
|||||||
sys.stderr.write(self.error)
|
sys.stderr.write(self.error)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
cmd = [self.conf.adb_command, 'shell', 'rm', dst]
|
cmd = self._shell_cmd('rm', dst)
|
||||||
try:
|
try:
|
||||||
err = check_output(cmd)
|
err = check_output(cmd)
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
@@ -584,7 +587,7 @@ class Adb(object):
|
|||||||
sys.stderr.write(self.error)
|
sys.stderr.write(self.error)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
cmd = [self.conf.adb_command, 'shell', 'rm', '-r', dst]
|
cmd = self._shell_cmd('rm', '-r', dst)
|
||||||
try:
|
try:
|
||||||
err = check_output(cmd)
|
err = check_output(cmd)
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
@@ -605,7 +608,7 @@ class Adb(object):
|
|||||||
if not dst.startswith('/'):
|
if not dst.startswith('/'):
|
||||||
dst = '/' + dst
|
dst = '/' + dst
|
||||||
|
|
||||||
cmd = [self.conf.adb_command, 'shell', 'mkdir', dst]
|
cmd = self._shell_cmd('mkdir', dst)
|
||||||
try:
|
try:
|
||||||
err = check_output(cmd)
|
err = check_output(cmd)
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
|
|||||||
Reference in New Issue
Block a user