Ishan112 / pefile

Automatically exported from code.google.com/p/pefile
Other
0 stars 0 forks source link

Files locked when verifying a list of files with pefile.PE #47

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. Build a list of 100+ files
2. Put them all to process by verifying if they are a PE file or not (using 
pefile.PE class)
3. Try to change the extensions of all those files right after verify if is is 
a PE file. In my case, the file will be locked.

What is the expected output? What do you see instead?

Expected output: File extension changed sucessfully.
Instead, I get a locked file and I'm not able to make any modification in the 
file.

What version of the product are you using? On what operating system?

Version: pefile-1.2.10-139.zip
OS: Windows
Python 2.6

Please provide any additional information below.

After a few moment, the file is able to be modified again.
Im running with exactly 246 files and in a certain step I verify if all of them 
are a PE file.
Something like this:

def IsExecutableFile( SrcPath ):   
    try:
        pefile.PE( SrcPath, fast_load = True )
        return True
    except:
        return False

After verifying all those files, I try to change the file extension and I get 
that error

ERROR_SHARING_VIOLATION
32 (0x20)
The process cannot access the file because it is being used by another process.

Thanks
Filipe

Original issue reported on code.google.com by SpindolaFilipe@gmail.com on 15 May 2014 at 1:22

GoogleCodeExporter commented 9 years ago
It may be due to the pefile.PE instance not being destroyed immediately and 
still keeping the file open. I'd suggest trying to force Python to free the 
object:

pe = pefile.PE(SrcPath, fast_load = True)
del pe

With a bit of luck that releases the file. You could also try to directly close 
the mmap'd file:

pe = pefile.PE(SrcPath, fast_load = True)
# Then just close the internal mmap view of the file.
pe.__data__.close()

Original comment by ero.carr...@gmail.com on 19 May 2014 at 9:27

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Hi,

I have the same issue.
Only "workaround" that is working for me is to use an own open,read,close 
function:

with open(file, "rb") as file_content:
     pe= pefile.PE(data=file_content.read(), fast_load=True)

Suggested solutions like:
del pe
or
pe.__data__.close()
did not work

Using Python 3.4.2

Original comment by CatWisel...@gmail.com on 13 Nov 2014 at 1:49