Friday, 1 March 2013

Run python-2.7 program inside the WinPE environment

This is notes I took few hours after the performance. They are incomplete.

Since version 2.6, python binaries are compiled with a compiler that depend of an annoying DLL. Because they don't have the right to redistribute this DLL, you have to download this free DLL and install it yourself.
99% of the time this DLL is installed by another package and you don't event know that you need it.

This DLL is missing in WinPE and is particular because it is handled by SxS.

Here is what I did.

First I have installed the python 2.7 32bits from Activestate on my XP.
Then I have booted the target host using a WinPE CD.
I have mounted the C: drive of my XP on the WinPE on G:

net use G: \\name_or_ip\C$  /user:Administrator password

Then cd to G:\Python27, an tried to start python interpreter :

The application has failed to start because its side-by-side configuration is in
correct. Please see the application event log or use the command-line 
sxstrace.exe tool for more detail.

I have used sxstrace as follow :

X:\>SxsTrace Trace -logfile:SxsTrace.etl

Tracing started. Trace will be saved to file SxsTrace.etl.
Press Enter to stop tracing...

Then I ran python.exe once again to get the trace, stopped SxsTrace and parsed the .etl file

X:\>SxsTrace Parse -logfile:SxsTrace.etl -outfile:SxsTrace.txt
Parsing log file SxsTrace.etl...
Parsing finished! Output saved to file SxsTrace.txt.

In the file, I found something like this (this one is about python-2.6) but is identical :

Begin Activation Context Generation.
Input Parameter:
Flags = 0
ProcessorArchitecture = x86
CultureFallBacks = en-US;en
ManifestPath = G:\Python26\python.exe
AssemblyDirectory = G:\Python26\
Application Config File = 
INFO: Parsing Manifest File G:\Python26\python.exe.
INFO: Manifest Definition Identity is (null).
INFO: Reference: Microsoft.VC90.CRT,processorArchitecture="x86",publicKeyToken="1fc8b3b9a1e18e3b",type="win32",version="9.0.21022.8"
INFO: Resolving reference Microsoft.VC90.CRT,processorArchitecture="x86",publicKeyToken="1fc8b3b9a1e18e3b",type="win32",version="9.0.21022.8".
INFO: Resolving reference for ProcessorArchitecture x86.
INFO: Resolving reference for culture Neutral.
INFO: Applying Binding Policy.
INFO: No publisher policy found.
INFO: No binding policy redirect found.
INFO: Begin assembly probing.
INFO: Did not find the assembly in WinSxS.
INFO: Attempt to probe manifest at X:\windows\assembly\GAC_32\Microsoft.VC90.CRT\9.0.21022.8__1fc8b3b9a1e18e3b\Microsoft.VC90.CRT.DLL.
INFO: Attempt to probe manifest at G:\Python26\Microsoft.VC90.CRT.DLL.
INFO: Attempt to probe manifest at G:\Python26\Microsoft.VC90.CRT.MANIFEST.
INFO: Attempt to probe manifest at G:\Python26\Microsoft.VC90.CRT\Microsoft.VC90.CRT.DLL.
INFO: Attempt to probe manifest at G:\Python26\Microsoft.VC90.CRT\Microsoft.VC90.CRT.MANIFEST.
INFO: Did not find manifest for culture Neutral.
INFO: End assembly probing.
ERROR: Cannot resolve reference Microsoft.VC90.CRT,processorArchitecture="x86",publicKeyToken="1fc8b3b9a1e18e3b",type="win32",version="9.0.21022.8".
ERROR: Activation Context generation failed.
End Activation Context Generation.

The two most important lines are :

INFO: Attempt to probe manifest at G:\Python26\Microsoft.VC90.CRT.MANIFEST.

On my XP I just copied few files :

copy C:\WINDOWS\WinSxS\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_x-ww_d08d0375\*.dll C:\Python27
copy c:\WINDOWS\WinSxS\Manifests\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.21022.8_x-ww_d08d0375.manifest G:\Python26\Microsoft.VC90.CRT.MANIFEST
copy C:\Windows\system32\python27.dll c:\Python27

I started again python.exe and it was working.

I'have not yet tried, but I expect that copying the whole C:\Python27 to the WinPE CD should be enough.

I have copied the same .dll to my Python26 and to a official Python27 install and both worked too.

Hope this help.

No comments:

Post a Comment