Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/358.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用Python 2.7编写文件而不被Windows阻止?_Python_Windows 7_Permissions - Fatal编程技术网

用Python 2.7编写文件而不被Windows阻止?

用Python 2.7编写文件而不被Windows阻止?,python,windows-7,permissions,Python,Windows 7,Permissions,我正在编写一个简单的模糊程序,用于Windows应用程序,该程序基于Charlie Miller代码,该代码来自《照顾一群猴子的谈话》。然而,我一直收到错误 Traceback (most recent call last): File "D:/Python27/fuzzer.py", line 29, in <module> process=subprocess.Popen([app_choice,fuzz_output]) File "D:\Python27\

我正在编写一个简单的模糊程序,用于Windows应用程序,该程序基于Charlie Miller代码,该代码来自《照顾一群猴子的谈话》。然而,我一直收到错误

  Traceback (most recent call last):
  File "D:/Python27/fuzzer.py", line 29, in <module>
    process=subprocess.Popen([app_choice,fuzz_output])
  File "D:\Python27\lib\subprocess.py", line 679, in __init__
    errread, errwrite)
  File "D:\Python27\lib\subprocess.py", line 896, in _execute_child
   startupinfo)
WindowsError: [Error 5] Access is denied

我相信
C:\ProgramFiles(x86)\Adobe\Reader 9.0\Reader
是文件夹的路径,而不是可执行文件。因此,尝试使用
Popen
运行它毫无意义


此外,在编写Windows路径时,应该使用原始字符串
r“C:\ProgramFiles(x86)\Adobe\Reader 9.0\Reader\AcroRd32.exe”
,或者使用斜杠代替
“C:/ProgramFiles(x86)/Adobe/Reader 9.0/Reader/AcroRd32.exe”
。您很幸运,路径中没有任何有效的转义序列。

我感觉您需要以管理员身份运行它才能访问程序文件。运行此命令时,您当前的目录是什么?请记住,写入Program Files下的目录与尝试写入UNIX计算机上的/usr/bin或类似系统目录有点类似。文件名无效,您需要可执行文件的完整路径,而不仅仅是目录才能启动进程。
#List of file names (all located in the python folder)
fuzz_files=[ "slides_algo-guiding.pdf", "slides_algo-intro-annotated-   final.pdf","slides_algo-merge1.pdf"]
apps=["C:\Program Files (x86)\Adobe\Reader 9.0\Reader"
  ]
#Creates an output file in the Python folder
fuzz_output="fuzz.pdf"
FuzzFactor=50
num_tests=1000
import math
import string
import random
import subprocess
import time

for i in range(num_tests):
    file_choice=random.choice(fuzz_files)
    app_choice=random.choice(apps)
    buf=bytearray(open(file_choice,'rb').read())
    #Charlie Miller code

    numwrites=random.randrange(math.ceil((float(len(buf))/FuzzFactor)))+1
    for j in range(numwrites):
        rbyte=random.randrange(256)
        rn=random.randrange(len(buf))
        buf[rn]="%c"%(rbyte)
     #End Charlie miller code

     #Write code
     open(fuzz_output,'wb').write(buf)
     process=subprocess.Popen([app_choice,fuzz_output])

     time.sleep(1)
     crashed=process.poll()
    if not crashed:
       process.terminate()