Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to remove a section from the import table? #345

Open
galeone opened this issue Apr 19, 2022 · 0 comments
Open

Is it possible to remove a section from the import table? #345

galeone opened this issue Apr 19, 2022 · 0 comments

Comments

@galeone
Copy link

galeone commented Apr 19, 2022

Hi! Thank you for this great library. I'm trying to use it for removing from the import table of a .dll all the references to another library. Here's what I wrote so far

import sys

import pefile

pe = pefile.PE(
    "./build/mxe/usr/x86_64-w64-mingw32.shared.posix.web/bin/libgio-2.0-0.dll"
)

kill = -1
newlist = pe.DIRECTORY_ENTRY_IMPORT
for idx, imp in enumerate(pe.DIRECTORY_ENTRY_IMPORT):
    if "libz1.dll" in str(imp.dll):
        kill = idx
        break
if kill < 0:
    print("libz1.dll not found among imported descriptors")
    sys.exit()
print(kill)
del pe.DIRECTORY_ENTRY_IMPORT[kill]

pe.write("libgio-2.0-0.dll")

I thought this was enough for removing any reference to libz1.dll in the library libgio-2.0-0.dll, but it looks like pe.write is not able to make persistent this change, in fact, if I load ./libgio-2.0-0.dll I can still find this imported symbols.

What am I doing wrong? Is it something pefile can help me do?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant