I have an .exe file where file compiled by py2exe in my .exe folder I have some .dll files, one .exe file and library.zip file and inside this zip I have to many .pyccompiled files.
I have decompiled this files from library.zip using Easy Python Decompiler and that program created me new file where I can see and change my code.
I have opened this file where I needed and I changed my code using python editor and finaly I saved as new script code with the some name and extension .pyc
with purpose to replace first .pyc.
zip again library folder and I tried to run .exe prgram but after the changes the program doesn't execute.
What have I done wrong in my task? Do I need to re-compile again in some way?
pyc and py file are NOT the same. While they represent the same code, they are totally different :
the py file represents the code you are typing, can be interpreted by the python interpreter, is not native, and is portable
the pyc file is a compiled version of the py file, that is not portable, not intended to be modified by an human, but faster
You cannot swap them and expect it to work. You will need to compile it to pyc before. You will find more information here : How can I manually generate a .pyc file from a .py file
Related
You know that a python file converted to an exe file can be deciphered and its codes can be displayed.
What is the way to prevent this decryption event? I don't want to people see the codes.
You can use Nuitka to convert .py file into a C-based standalone executable. Then, pass a resulting .exe file through VMProtect to obfuscate the binaries.
For example, I have a Python file like this:
print("Hello World")
Now I am converting it to an .exe file using pyinstaller.
But I found a method to convert it back:
Use pyinstxtractor.py:
python pyinstxtractor.py yourFileName.exe
This will extract .exe and create a folder named yourFileName.exe_extracted.
Inside the yourFileName.exe_extracted folder, find the file without
any extension.
Edit it with HxD editor and from any pycache file created with the
same version of Python, copy the first row and insert it into your
file.
Save and Rename the file with .pyc extension.
Decompile the compiled bytecode (.pyc) to .py using any online tool,
like https://www.toolnb.com/tools-lang-en/pyc.html
Is there any way to prevent converting the .exe file converting back to his .py file?
Thanks.
You can use an obfuscation tool such as PyArmor and add at-least some level of code-protection to your original python script.
The official documentation of PyArmor has more info on this here https://pyarmor.readthedocs.io/en/latest/advanced.html#bundle-obfuscated-scripts-to-one-executable-file
I know I should have used version control but I have accidentally overwritten a script (.py file) by saving another script with exactly the same name while using Spyder.
Is there any way at all this can be recovered?
Once the file has been compiled to a pyc it is lost. If you still have the old pyc file you may be able to decompile it:
Is it possible to decompile a compiled .pyc file into a .py file?
Is it possible to repack/rebuild a PyInstaller exe file after extracting the files from it using PyInstaller Extractor? I also decomplied most of the files with Easy Python Decomplier. I modified one .py file and I want the new exe file to contain this modified file. How can I repack the application?
You may leave all not modified files as *.pyc.
Once you have full modules structure ready, just find the original entrypoint and pack the bundle again, it should work.
I have a project that uses COM and 'Python' scripting. Earlier we were using 'ComTypes' now we use Win32Com. To keep backward compatibility I need to change name of some of the interfaces. So here is what I do
1) Use the 'makepy' utility to create a python file from my .tlb file, this creates a .py file at ..\Lib\site-packages\win32com\gen_py folder
2) I change the name of the interface that I am interested in changing in the created python file.
3) When I load my application a corresponding .pyc file gets created and everything works fine.
Now I don't want to repeat this exercise on every machine where my software is deployed. So through the installer I copy the .py and .pyc files to ..\Lib\site-packages\win32com\gen_py
But when my application is launched it does not recognize the changed interface. Behaves as if there is no .py or .pyc file. All other interfaces work, but the changed name one does not work. It dynamically seem to create compiled python behind the scene, ignoring the .pyc file.
If I delete the .dat file and .pyc file at those locations, it does create the .pyc file again when the application is launched. However its not utilized, because my changed interface does not work.
If I use the steps 1,2 and 3 everything works again !! I am puzzled.
Please help.
OK. I found out what is the problem. When you create a python file using makepy tool it updates the dicts.dat file in gen_py directory. So you need to copy over that file as well to other machines.