0

Hello! I have the following script:

import os
import stat

curDir = os.getcwd()

autorun_signature = [ "[Autorun]",
                      "Open=regsvr.exe",
                      "Shellexecute=regsvr.exe",
                      "Shell\Open\command=regsvr.exe",
                      "Shell=Open" ]

content = []

def read_signature(file_path):
    try:
        with open(file_path) as data:
            for i in range(0,5):
                content.append(data.readline())
    except IOError as err:
        print("File Error: "+   str(err))

read_signature(os.getcwd()+'/'+'autorun.inf')

if(content==autorun_signature):
    print("Equal content")
else:
    print("Not equal")

It prints not equal, then I tried this method:

import os
import stat

curDir = os.getcwd()

autorun_signature =  "[Autorun]\nOpen=regsvr.exe\nShellexecute=regsvr.exe\nShell\Open\command=regsvr.exe\nShell=Open"

content = ""

def read_signature(file_path):
    try:
        with open(file_path) as data:
            content = data.read()
    except IOError as err:
        print("File Error: "+   str(err))

read_signature(os.getcwd()+'/'+'autorun.inf')

if(content==autorun_signature):
    print("Equal content")
else:
    print("Not equal")

It also print not equal! I want to store the content of autorun.inf file in script and every time i find such file I want to check its content if it is or not, I could not do, can anyone help me? the content of autorun.inf:

[Autorun]
Open=regsvr.exe
Shellexecute=regsvr.exe
Shell\Open\command=regsvr.exe
Shell=Open
2
  • If you print content after reading it, what does it display? Commented Sep 12, 2011 at 17:25
  • You should parse your text into dictionaries and then compare... Commented Sep 12, 2011 at 18:19

2 Answers 2

1

Linebreaks under Windows \r\n are different from Linux's \n.

So try replacing \n with \r\n.

Sign up to request clarification or add additional context in comments.

Comments

1

It is probably due to the fact that Windows new lines are \r\n instead of \n. Also, you should escape the "\", so instead use"\\".

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.