2010-03-12 57 views
3

我有一个可执行文件,它是批处理过程的一部分。这一个可执行文件打开了一个控制台窗口,这是令人讨厌的,因为它对最终用户没用,并且偷走了他们的活动任务。如何戳一个控制控制台窗口显示的win32 PE中的标志

我们无法从源代码(轻松地)编译此EXE的新版本。有没有简单的方法在PE中旋转这个设置?

回答

7

找到它。

editbin.exe /subsystem:windows foo.exe 

editbin.exe是MSVC

4

的一部分,我已经与蟒蛇在15分钟内根据PE规范 http://msdn.microsoft.com/en-us/library/windows/hardware/gg463119.aspx

我不知道写了它的Windows EXE二进制文件与控制台|窗户子系统具有相同的 入口点格式(具有相同的参数),但似乎是这样。

Python代码:

import sys 
import struct 

if len(sys.argv) < 4: 
    print "Change Exe Run Mode Application by [email protected]\nNot sufficient parametrs. 'exe_src_name.exe' 'exe_dest_name.exe' 'to_console' or 'to_windows'" 
    sys.exit(-1) 

source = open(sys.argv[1], "rb") 
dest = open(sys.argv[2], "w+b") 
dest.write(source.read()) 

dest.seek(0x3c) 
(PeHeaderOffset,)=struct.unpack("H", dest.read(2)) 

dest.seek(PeHeaderOffset) 
(PeSignature,)=struct.unpack("I", dest.read(4)) 
if PeSignature != 0x4550: 
    print "Error in Find PE header" 

dest.seek(PeHeaderOffset + 0x5C) 

if sys.argv[3].strip() == "to_console": 
    # console mode 
    dest.write(struct.pack("H", 0x03)) 
elif sys.argv[3].strip() == "to_windows": 
    # window mode 
    dest.write(struct.pack("H", 0x02)) 
else: 
    print "Wrong Format: '" + sys.argv[3] + "'" 

source.close() 
dest.close() 

print "Completed succesfully.."