Python application decompiler - python

I have a website that offers files to people; this site is related to a SAT decoder based on Linux. Some people developed "plugins" written in Python that access my site and get those files directly from the decoder without visiting the site. I know I could block them by using JavaScript methods on the website but I would like to know what this plugin does first. The files of those plugins are a series of pyo files which, from what I understood, are compiled Python scripts.
Is there a way I can get the source of those files or at least see what they "call"?
I only found non-working or not free services. I mean there must be a way; people crack almost every software made by major software houses and I can't "get" what a Python script does?

Exploring and decompiling python bytecode

Related

COMException accessing WMP from Plex Plugin (using Python for .NET)

My Goal
I'm trying to create a plugin for Plex Media Server (PMS) that will interface with WMP (Windows Media Player) to get metadata about Windows media library items.
The Setup
PMS uses Python 2.7 as its primary script host. Plex Plugins are
written in Python, though they operate in a sandboxed capacity. Unfortunately there's sad little documentation on what exactly the boundaries are on this sandboxed functionality.
I decided to use Python for .NET to access the Windows SDK to interface with WMPLib.
Python for .NET (http://pythonnet.github.io/) is a Python
library used to access functionality from .NET assemblies from within
the Python runtime.
I created a .NET assembly to access WMPLib, which
is a part of the Windows SDK designed to programmatically access the
functionality of WMP. WMPLib is basically a COM Interop wrapper for
.NET targeting wmp.dll.
What's Working?
The whole chain from Python on through the COM-based WMP access is working. If I fire up the embedded Plex Script Host that comes with Plex Media Server (a version of Python 2.7), I can readily access data from WMP. That means that the following links in the chain are all working:
Python is loading Python for .NET
Python for .NET is loading my .NET assembly
My .NET assembly is loading WMPLib (Interop.WMPLib.dll, a .NET assembly for COM Interop)
WMPLib is successfully opening and utilizing wmp.dll (accessed from C:\Windows\System32)
What's Not Working?
Activating the COM Interop part of this chain is not working from within the sandboxed Plex plugin. Again, this plugin is written in standard Python, but something is subtly different about the Python execution environment once the sandboxing code has run. I get the following exception when running the WMP access code from within the plugin:
COMException: Exception from HRESULT: 0xC00D1327
at WMPLib.IWMPPlayer4.get_mediaCollection()
In this scenario I know that Python for .NET is working, because I've already loaded and accessed other things from my .NET assembly at this point.
C:\Windows\System32 is at the front of PATH variable. I'm assuming that COM dlls should be located via the PATH environment variable (This seems to say so), but I'm not entirely certain of that. How a COM assembly should be located in this unique scenario (Python accessing .NET accessing COM) is one of the biggest unknowns for me.
The Questions
How might the Plex plugin sandbox be changing the Python execution environment such that accessing the COM assembly is no longer working?
How should the COM assembly be located and accessed by the environment in this case?
Does it require specific permissions that the Plex sandbox may have locked down?
Maybe I should at least win some kind of prize for arriving at a question that intersects so many different technologies in a uniquely confusing way...
Edit 1
I've ruled out any .NET related issues entirely, thanks to #Paulo's suggestion below. I'm now doing all interop with WMPLib through the comtypes Python library. Now I'm getting the following error:
COMError: (-1072884953, None, (None, None, None, 0, None))
Though -1072884953 is a different error code, a little digging around makes it appear that this error is associated with (maybe equivalent to?) the same error that I was getting through .NET interop (this post makes it appear so).
So now the facts that I'm stuck with are these:
wmp.dll is loading in all cases (which #Paulo helped me to figure
out below).
When the code accessing WMP is run outside the Plex sandbox environment, library items can be accessed from WMP just fine.
When the code accessing WMP is run inside the Plex sandbox environment, library items cannot be accessed from WMP.
The error code that I get (whether from .NET or Python based COM interop is NS_E_CURL_INVALIDPATH: The URL contains a path that is not valid. This error appears to be involved with attempted playback in most cases.
This is odd because I've never gotten as far as playback in my scenario... I'm only attempting to call wmp.mediaCollection
So the Plex sandbox truly seems to be key in this scenario. Any further ideas?
Edit 2
Minimally, this is the code that it takes to fail:
from comtypes.client import CreateObject
wmp = CreateObject("{6BF52A52-394A-11d3-B153-00C04F79FAA6}")
collection = wmp.mediaCollection
That collection = wmp.mediaCollection is where the error happens.
So there really aren't any parameters being passed in that could be causing the failure. To reiterate, this code runs fine in the general Python 2.7 context. It only fails within the Plex plugin sandbox. I don't know how to get details on how the Plex sandbox may be changing the execution environment. I'd imagine my answer lies in that direction.
Let me get this straight, and correct me if I'm wrong:
You have a running instance of Python 2.7, Plex Media Server
You're using a library, Python for .NET, to load a .NET into your process
You're loading WMPLib, an imported COM interop assembly, in .NET to use the Windows Media Player library through Python for .NET
Let's clear this out:
0xC00D1327 is NS_E_CURL_INVALIDPATH:
The URL contains a path that is not valid.
It seems like a legitimate object error, not a COM error.
The DLL search order has little to do with it, since wmp.dll is registered with a full path under InProcServer32 registry keys for each provided class, and that's what ultimately matters.
In fact and as you stated, if you've reached this point, it's clearly not a problem about loading .NET assemblies or COM not finding a DLL.
Now, to the questions:
Since the error seems legit, you might not have access to the media collection (Internet zone?), or WMP is not correctly registered/installed, or some codec is missing or not correctly registered/installed, etc.
What are you loading into WMP? Try with basic things, such as local .WAV, .MP3, .AVI and .MPG files, then try more advanced formats e.g. MPEG4-encoded videos, or maybe remote locations.
You should attempt a more direct approach, although I can't really vouch which is better: win32com (part of pywin32) or comtypes.
It was a long while ago since I've looked at them, so take this with a grain of salt: with comtypes, you're able to use your COM objects much like regular Python objects with properties and methods, while win32com seems more inclined to do things by runtime name dispatching.
At least you'll be punching something you really have to put up with (Python) instead of loading .NET for something that doesn't even require it (WMP).
I don't know what that sandboxing is about, but my guess is that it's a Python-only sandbox, not something that restricts usage of the operating system.
EDIT: Are you providing a filename (e.g. C:\path\to\file.mp4) where a URL is expected (file:///C:/path/to/file.mp4), or vice-versa? I guess you must show the failing code and what values are being provided.

Python automatic build tool

at my work i write numerous small python scripts for DB management, most scripts use one or two common libraries which i sometimes update,
before distribution i freeze the scripts with cxfreeze and copy over some resources and upload to a server.
i would like to set up some up some system which would allow me to automatically rebuild/freeze all of the scripts
, copy over some files, archive and upload to server.
I'm not sure where even to look for such a system, because most of what if found is complicated server based systems like AHP for compiled languages, while i need something small for a single computer
obviously i can write something fast and dirty in python but it seems illogical that there isn't something ready made for these simple requirements.
please forgive my ignorance, I'm still learning.
Have you considered using make? If you're familiar with it from another language, it might be the easiest. There's also a list on the python wiki here.
Have a look at buildout. From their site:
Buildout is a Python-based build system for creating, assembling and deploying applications from multiple parts, some of which may be non-Python-based. It lets you create a buildout configuration and reproduce the same software later.
We are using it to do exactly what you describe. It is flexible and easy to extend through recipes.

XAMPP - Execute Python script on web page

How can I execute a Python script on a webpage?
I've used XAMPP to create the Apache server. Are there any tutorials/examples or guides on how to execute a .py script? I'm using Windows 7 and have installed Python on my local machine. If I access the .py script via the web link, it looks as if its HTML code and nothing is executed.
Typically, you don't execute Python in the browser. Instead, the browser accesses a resource (or "webpage", like http://example.com/mypage) by requesting the resource from the server. The server (for example, Apache), when administered correctly, passes off handling of the request to some Python script. Then, your Python script creates some output (for example, HTML) which the server then returns to the browser for the browser to display.
However, some web sites have found it useful to have logic (scripts) run in the browser, rather than on the server. The standard way of doing this is using JavaScript (although in the past there WERE other languages built into browsers, such as VBScript in Internet Explorer).
Right now, pretty much all browsers have settled on JavaScript as THE scripting language in the browser. In order for you to use any other language in the browser (including Python), the browser must support that scripting language (or needs to have an add-on to support that scripting language). Simply having Python installed on your client alongside the browser is not enough. For more information, please see the Python documentation Web Browser Programming.
Another option is to use something like Pyjs. This is a library that has you write your code in Python, and converts the necessary parts to JavaScript. This isn't exactly "Python in the browser", but it might be something you are looking for.
I guess this links will help....
https://community.apachefriends.org/f/viewtopic.php?t=42975
Usually a good resource for Python is the official documentation.
They do a great job of explaining many aspects of Python. Using Python on the web is a big part and they have a great overview.

How do you distribute Python scripts?

I have a server which executes Python scripts from a certain directory path. Incidently this path is a check-out from the SVN trunk version of the scripts. However, I get the feeling that this isn't the right way to provide and update scripts for a server.
Do you suggest other approaches? (compile, copy, package, ant etc.)
In the end a web server will execute some Python script with parameters. How do I do the update process?
Also, I have trouble deciding what is best to handle updated versions which only work for new projects on the server. Therefore, if I update the Python scripts, but only newly created web jobs will know how to handle that. I "delivery" to one of many directories which keep track of versions and the server picks the right one?!
EDIT: I webserver is basically an interface that runs some data analysis. That analysis is the actual scripts that take some parameters and mingle data. I don't really change the web interface. I only need to update the data scripts stored on webserver. Indeed, in some advanced version the web server should also pick the right version of my data scripts. However, at the moment I have no idea which would be the easiest way.
The canonical way of distributing Python code/functionality is by using a PyPi compliant package manager.
A list of available PyPi implementations on python.org:
http://wiki.python.org/moin/PyPiImplementations
Instructions on setting up and using EggBasket:
http://chrisarndt.de/projects/eggbasket/#installation
Instructions on installing ChiShop:
http://justcramer.com/2011/04/04/setting-up-your-own-pypi-server/
Note that for this to work you need to distribute your code as "Eggs"; you can find out how to do this here: http://peak.telecommunity.com/DevCenter/setuptools
A great blog post on the usage of eggs and the different parts in packaging: http://mxm-mad-science.blogspot.com/2008/02/python-eggs-simple-introduction.html

Start creating websites by using Python

I am basically a PHP guy. now moving towards python. I am starting to learn python.
How do I install it and start working it, and develop websites .
I got totally confused with the alternative implementations in the download section of the Python site. Can you tell me what "alternative implementations" means?.
I mean to say: I can create a .php file in my server and then access it from browser like http://example.com/index.php, so I was wondering whether I can do the same with python, like creating a .py file and accessing from browser http://example.com/index.py.
Just as a disclaimer, I interpret you saying "run Python in a browser" as "making a website with Python."
If you want to start writing web applications in Python, you can either use CGI or use one of its many web app frameworks. Python is not like PHP in the sense that you can't just embed it in HTML. Many of those frameworks come with development servers that you can use to test your web app (by looking at it in a browser).
A particularly good Python web framework is Django.
I really do recommend that you do the Python tutorial before you dive into any of those frameworks, though. Python is not only for writing web applications, so you'll have to get some fundamentals down first before any of that makes sense to you.
As for installing Python, I recommend you take the version you got with your OS if you use Mac or Linux, or installing the Python 2.7.1 32-bit binary from python.org if you use Windows. The alternative implementations include a Python that runs on the Java virtual machine and one that runs on the .NET Common Language Runtime, but for your purposes the reference implementation, CPython, should work fine.
Python by default is a general purpose scripting language and is not meant specifically for web application development (like PHP is primarily). So, you'll first need to download and install Python (choose the version that's appropriate for your OS) from www.python.org I'd recommend v2.7.1 but you can try out v3.2 if you'd like.
The other versions (IronPython, Jython, etc) are Python implementations on other platforms (.NET and JVM respectively), and in all likelihood you don't need to bother with them unless you really want to.
To start working with Python and create web applications you will also need to download and install a Python-based web framework. There are many of them, too many in fact to list here. However, there is a page on the Python Wiki that has a list of useful frameworks for web development.
You don't "run it from a browser". You don't run PHP from a browser, either.
The way to use Python for web development is to use a framework like Django or Pyramid.
Sage or CodeNode let you run Python in a browser.
You can get a limited Python experience by pointing your browser to http://shell.appspot.com/ . You will be running Python 2.5.2 on Google's site.

Categories