无忧启动论坛

标题: 如何将VC程序标准库添加到PE中 [打印本页]

作者: cnpirate    时间: 2016-3-24 11:27
标题: 如何将VC程序标准库添加到PE中
自己编写了一个VC程序,需要用到VC的标准库,但是PE环境中没有这些库,请问如何可以把这些库添加到PE中?
作者: slore    时间: 2016-3-24 12:44
不使用.net,不使用MFC,纯WIN32程序的话,/MT编译就可以直接PE用。
作者: cnpirate    时间: 2016-3-24 14:14
slore 发表于 2016-3-24 12:44
不使用.net,不使用MFC,纯WIN32程序的话,/MT编译就可以直接PE用。

自己写的那个程序没有使用.net,也没有使用MFC,而且也改成/MT编译了,但是在PE运行时,还是0xC0150002错误。网上说这个错误,表示库文件缺失。因此我想把VC下的库文件都加入到PE中,看看能不能解决这个问题。
作者: lxl1638    时间: 2016-3-24 16:50
cnpirate 发表于 2016-3-24 14:14
自己写的那个程序没有使用.net,也没有使用MFC,而且也改成/MT编译了,但是在PE运行时,还是0xC0150002错 ...

如果这样,你知道要那些库,头文件已一一列出
作者: lxl1638    时间: 2016-3-24 19:39
frg521 发表于 2016-3-24 17:38
请问老师的RcData压缩资源工具可以分享吗?compress.exe吗?如果那个文件不可单独运行,还请带上附属文件,谢 ...

压缩/解压,代码都是PECMD内置的,就是LZMA命令的代码,这个代码网上有,以前我在时空论坛发过类似的代码。另一个是自己如何读取资源数据,网上也有代码——PE文件头格式。
作者: cnpirate    时间: 2016-3-25 15:07
本帖最后由 cnpirate 于 2016-3-25 16:11 编辑
lxl1638 发表于 2016-3-24 16:50
如果这样,你知道要那些库,头文件已一一列出


我把这个程序在正常Windows 7操作系统上运行时的Resource Monitor工具看到的使用资源截图了,这里面有个
C:\Windows\winsxs\amd64_microsoft.vc90.crt_1fc8b3b9a1e18e3b_9.0.30729.6161_none_08e61857a83bc251
我把这个放到了PE环境中对应的目录下,再执行GantryBoard_while.exe这个程序,依然是0xC0150002这个错误

再补充一下,使用Dependency Walker分析GantryBoard_while.exe,发现程序调用了下面三个dll:LIBSEMA.DLL
KERNEL32.DLLws2_32.DLL

LIBSEMA.DLL    这个我已经将其和exe放到了同一个目录下;
KERNEL32.DLL  这个在PE环境下的\Windows\System32\下面有;
ws2_32.DLL      这个将本机的dll放到了PE环境下的\Windows\System32\中

但是这样做完以后,在PE环境下执行GantryBoard_while.exe依然报0xC0150002错误

ResourceMonitor.png (47.95 KB, 下载次数: 89)

ResourceMonitor.png

作者: 2012tzyx    时间: 2016-3-25 18:49
本帖最后由 2012tzyx 于 2016-3-25 18:58 编辑

vc2008还需要注册表的吧。要么就还得加几个manifest文件。
试试用dependency walker找找依赖。
作者: yfwang0798    时间: 2016-3-25 20:30
本帖最后由 yfwang0798 于 2016-3-25 20:34 编辑

以前在pe3 x86集成vc相关文件和注册表设置,用于适用active password changer  6.01,64位应该类似:
要添加的文件位置
Windows\winsxs 下所有包含 x86 和 vc 字符的文件夹,如
x86_microsoft-windows-vcm-core-codecs_31bf3856ad364e35_6.1.7601.17514_none_6eaa2afd36b1e303
等几个文件夹
Windows\winsxs\manifests 文件夹下包含 x86 和vc名字的文件。例如x86_microsoft.vc80.crt_1fc8b3b9a1e18e3b_8.0.50727.4940_none_d08cc06a442b34fc.manif  等文件。


要添加的注册表位置
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\SideBySide\Winners
下所有包含 x86和vc的注册表。




作者: cnpirate    时间: 2016-3-28 16:21
yfwang0798 发表于 2016-3-25 20:30
以前在pe3 x86集成vc相关文件和注册表设置,用于适用active password changer  6.01,64位应该类似:
要添 ...

按照你说的方法,我把Windows\winsxs下所有包含amd64和vc字符的文件,以及Windows\winsxs\manifests文件下包含amd64和vc字符的文件导入到PE中,并且将注册表也导入,我的程序可以在PE环境下运行了。

非常感谢,谢谢
作者: cnpirate    时间: 2016-3-29 11:26
yfwang0798 发表于 2016-3-25 20:30
以前在pe3 x86集成vc相关文件和注册表设置,用于适用active password changer  6.01,64位应该类似:
要添 ...

添加文件和导入注册表后,在PE环境下,打开文本文件,提示:
The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail.
起初,我以为是注册表导入的不对,但是换一个机器的注册表,还是一样的错误

使用sxstrace.exe获得log文件如下:

=================
Begin Activation Context Generation.
Input Parameter:
        Flags = 0
        ProcessorArchitecture = AMD64
        CultureFallBacks = en-US;en
        ManifestPath = X:\windows\system32\NOTEPAD.EXE
        AssemblyDirectory = X:\windows\system32\
        Application Config File =
-----------------
INFO: Parsing Manifest File X:\windows\system32\NOTEPAD.EXE.
        INFO: Manifest Definition Identity is Notepad2,type="win32",version="5.1.0.0".
        INFO: Reference: Microsoft.Windows.Common-Controls,language="*",processorArchitecture="*",publicKeyToken="6595b64144ccf1df",type="win32",version="6.0.0.0"
INFO: Resolving reference Microsoft.Windows.Common-Controls,language="*",processorArchitecture="*",publicKeyToken="6595b64144ccf1df",type="win32",version="6.0.0.0".
        INFO: Resolving reference for ProcessorArchitecture AMD64.
                INFO: Resolving reference for culture en-US.
                        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_64\Microsoft.Windows.Common-Controls\6.0.0.0_en-US_6595b64144ccf1df\Microsoft.Windows.Common-Controls.DLL.
                                INFO: Attempt to probe manifest at X:\windows\system32\en-US\Microsoft.Windows.Common-Controls.DLL.
                                INFO: Attempt to probe manifest at X:\windows\system32\en-US\Microsoft.Windows.Common-Controls.MANIFEST.
                                INFO: Attempt to probe manifest at X:\windows\system32\en-US\Microsoft.Windows.Common-Controls\Microsoft.Windows.Common-Controls.DLL.
                                INFO: Attempt to probe manifest at X:\windows\system32\en-US\Microsoft.Windows.Common-Controls\Microsoft.Windows.Common-Controls.MANIFEST.
                                INFO: Did not find manifest for culture en-US.
                        INFO: End assembly probing.
                INFO: Resolving reference for culture en.
                        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_64\Microsoft.Windows.Common-Controls\6.0.0.0_en_6595b64144ccf1df\Microsoft.Windows.Common-Controls.DLL.
                                INFO: Did not find manifest for culture en.
                        INFO: End assembly probing.
                INFO: Resolving reference for culture Neutral.
                        INFO: Applying Binding Policy.
                                INFO: Auto Servicing Policy redirected assembly version.
                                INFO: Post policy assembly identity is Microsoft.Windows.Common-Controls,processorArchitecture="AMD64",publicKeyToken="6595b64144ccf1df",type="win32",version="6.0.7601.18837".
                        INFO: Begin assembly probing.
                                INFO: Attempt to probe manifest at X:\windows\WinSxS\manifests\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.7601.18837_none_fa3b1e3d17594757.manifest.
                                INFO: Attempt to probe manifest at X:\windows\assembly\GAC_64\Microsoft.Windows.Common-Controls\6.0.7601.18837__6595b64144ccf1df\Microsoft.Windows.Common-Controls.DLL.
                                INFO: Attempt to probe manifest at X:\windows\system32\Microsoft.Windows.Common-Controls.DLL.
                                INFO: Attempt to probe manifest at X:\windows\system32\Microsoft.Windows.Common-Controls.MANIFEST.
                                INFO: Attempt to probe manifest at X:\windows\system32\Microsoft.Windows.Common-Controls\Microsoft.Windows.Common-Controls.DLL.
                                INFO: Attempt to probe manifest at X:\windows\system32\Microsoft.Windows.Common-Controls\Microsoft.Windows.Common-Controls.MANIFEST.
                                INFO: Did not find manifest for culture Neutral.
                        INFO: End assembly probing.
        INFO: Resolving reference for ProcessorArchitecture MSIL.
                INFO: Resolving reference for culture en-US.
                        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_MSIL\Microsoft.Windows.Common-Controls\6.0.7601.18837_en-US_6595b64144ccf1df\Microsoft.Windows.Common-Controls.DLL.
                                INFO: Did not find manifest for culture en-US.
                        INFO: End assembly probing.
                INFO: Resolving reference for culture en.
                        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_MSIL\Microsoft.Windows.Common-Controls\6.0.7601.18837_en_6595b64144ccf1df\Microsoft.Windows.Common-Controls.DLL.
                                INFO: Did not find manifest for culture en.
                        INFO: End assembly probing.
                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_MSIL\Microsoft.Windows.Common-Controls\6.0.7601.18837__6595b64144ccf1df\Microsoft.Windows.Common-Controls.DLL.
                                INFO: Did not find manifest for culture Neutral.
                        INFO: End assembly probing.
        INFO: Resolving reference for ProcessorArchitecture Data.
                INFO: Resolving reference for culture en-US.
                        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\Microsoft.Windows.Common-Controls\6.0.7601.18837_en-US_6595b64144ccf1df\Microsoft.Windows.Common-Controls.DLL.
                                INFO: Did not find manifest for culture en-US.
                        INFO: End assembly probing.
                INFO: Resolving reference for culture en.
                        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\Microsoft.Windows.Common-Controls\6.0.7601.18837_en_6595b64144ccf1df\Microsoft.Windows.Common-Controls.DLL.
                                INFO: Did not find manifest for culture en.
                        INFO: End assembly probing.
                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\Microsoft.Windows.Common-Controls\6.0.7601.18837__6595b64144ccf1df\Microsoft.Windows.Common-Controls.DLL.
                                INFO: Did not find manifest for culture Neutral.
                        INFO: End assembly probing.
        ERROR: Cannot resolve reference Microsoft.Windows.Common-Controls,language="*",processorArchitecture="*",publicKeyToken="6595b64144ccf1df",type="win32",version="6.0.0.0".
ERROR: Activation Context generation failed.
End Activation Context Generation.

=================
Begin Activation Context Generation.
Input Parameter:
        Flags = 0
        ProcessorArchitecture = AMD64
        CultureFallBacks = en-US;en
        ManifestPath = X:\windows\system32\ndfapi.dll
        AssemblyDirectory = X:\windows\system32\
        Application Config File =
-----------------
INFO: Parsing Manifest File X:\windows\system32\ndfapi.dll.
        INFO: Manifest Definition Identity is ndfapi,processorArchitecture="amd64",type="win32",version="1.0.0.0".
        INFO: Reference: Microsoft.Windows.Common-Controls,language="*",processorArchitecture="amd64",publicKeyToken="6595b64144ccf1df",type="win32",version="6.0.0.0"
INFO: Resolving reference Microsoft.Windows.Common-Controls,language="*",processorArchitecture="amd64",publicKeyToken="6595b64144ccf1df",type="win32",version="6.0.0.0".
        INFO: Resolving reference for ProcessorArchitecture amd64.
                INFO: Resolving reference for culture en-US.
                        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_64\Microsoft.Windows.Common-Controls\6.0.0.0_en-US_6595b64144ccf1df\Microsoft.Windows.Common-Controls.DLL.
                                INFO: Attempt to probe manifest at X:\windows\system32\en-US\Microsoft.Windows.Common-Controls.DLL.
                                INFO: Attempt to probe manifest at X:\windows\system32\en-US\Microsoft.Windows.Common-Controls.MANIFEST.
                                INFO: Attempt to probe manifest at X:\windows\system32\en-US\Microsoft.Windows.Common-Controls\Microsoft.Windows.Common-Controls.DLL.
                                INFO: Attempt to probe manifest at X:\windows\system32\en-US\Microsoft.Windows.Common-Controls\Microsoft.Windows.Common-Controls.MANIFEST.
                                INFO: Did not find manifest for culture en-US.
                        INFO: End assembly probing.
                INFO: Resolving reference for culture en.
                        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_64\Microsoft.Windows.Common-Controls\6.0.0.0_en_6595b64144ccf1df\Microsoft.Windows.Common-Controls.DLL.
                                INFO: Did not find manifest for culture en.
                        INFO: End assembly probing.
                INFO: Resolving reference for culture Neutral.
                        INFO: Applying Binding Policy.
                                INFO: Auto Servicing Policy redirected assembly version.
                                INFO: Post policy assembly identity is Microsoft.Windows.Common-Controls,processorArchitecture="amd64",publicKeyToken="6595b64144ccf1df",type="win32",version="6.0.7601.18837".
                        INFO: Begin assembly probing.
                                INFO: Attempt to probe manifest at X:\windows\WinSxS\manifests\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.7601.18837_none_fa3b1e3d17594757.manifest.
                                INFO: Attempt to probe manifest at X:\windows\assembly\GAC_64\Microsoft.Windows.Common-Controls\6.0.7601.18837__6595b64144ccf1df\Microsoft.Windows.Common-Controls.DLL.
                                INFO: Attempt to probe manifest at X:\windows\system32\Microsoft.Windows.Common-Controls.DLL.
                                INFO: Attempt to probe manifest at X:\windows\system32\Microsoft.Windows.Common-Controls.MANIFEST.
                                INFO: Attempt to probe manifest at X:\windows\system32\Microsoft.Windows.Common-Controls\Microsoft.Windows.Common-Controls.DLL.
                                INFO: Attempt to probe manifest at X:\windows\system32\Microsoft.Windows.Common-Controls\Microsoft.Windows.Common-Controls.MANIFEST.
                                INFO: Did not find manifest for culture Neutral.
                        INFO: End assembly probing.
        ERROR: Cannot resolve reference Microsoft.Windows.Common-Controls,language="*",processorArchitecture="amd64",publicKeyToken="6595b64144ccf1df",type="win32",version="6.0.0.0".
ERROR: Activation Context generation failed.

End Activation Context Generation.




作者: slore    时间: 2016-3-29 11:30
cnpirate 发表于 2016-3-29 11:26
添加文件和导入注册表后,在PE环境下,打开文本文件,提示:
The application has failed to start beca ...

你确定你的/MT设定到release|x64的配置上了么?
/MT的话运行库是直接编译到exe程序里面的。
作者: cnpirate    时间: 2016-3-29 12:06
slore 发表于 2016-3-29 11:30
你确定你的/MT设定到release|x64的配置上了么?
/MT的话运行库是直接编译到exe程序里面的。

嗯嗯,我确认,因为我把程序中某些代码注释掉,程序可以正确执行的。
作者: yfwang0798    时间: 2016-3-29 17:23
国外这个网站有现成的软件,包含notepad等组件。

http://theoven.org/index.php?PHP ... c490083859460d7efa;

它提供的notepad,没有数字签名,不是微软的,但是可以在pe中运行。只要会winbuilder语法,就可以自己定制pe。
作者: cnpirate    时间: 2016-3-30 09:53
yfwang0798 发表于 2016-3-29 17:23
国外这个网站有现成的软件,包含notepad等组件。

http://theoven.org/index.php?PHPSESSID=c2e332fdd9 ...

能提供学习winbuilder语法的资料么,嘿嘿,^_^
作者: yfwang0798    时间: 2016-3-30 13:09
前面介绍的网站下载软件包中有帮助文件,最简单的语法
http://reboot.pro/topic/4424-app ... g-a-new-app-script/

也可以参考别人制作的脚本学习。
作者: cnpirate    时间: 2016-3-30 14:16
yfwang0798 发表于 2016-3-30 13:09
前面介绍的网站下载软件包中有帮助文件,最简单的语法
http://reboot.pro/topic/4424-app-scripts-guide-c ...

非常感谢啊




欢迎光临 无忧启动论坛 (http://wuyou.net./) Powered by Discuz! X3.3