【问题标题】:Why does renaming reg.exe on Windows Server 2008 x64 causes it to fail to run?为什么在 Windows Server 2008 x64 上重命名 reg.exe 会导致它无法运行?
【发布时间】:2010-02-23 17:21:13
【问题描述】:

我有一个很好的问题。

Windows 附带一个名为 reg.exe 的实用程序已经有一段时间了。从脚本导入 .reg 文件、从脚本修改值等非常方便。因此,在为脚本场景制作副本时(“为什么不在 system32 中使用副本?”-> 软件限制策略,个人偏好)等)我注意到重命名它会使其静默失败:

Windows Server 2008 x64:

Microsoft Windows [Version 6.0.6001]
Copyright (c) 2006 Microsoft Corporation.  All rights reserved.

C:\Windows\system32>reg.exe
ERROR: Invalid syntax.
Type "REG /?" for usage.

C:\Windows\system32>copy reg.exe reg2.exe
        1 file(s) copied.

C:\Windows\system32>reg2.exe

C:\Windows\system32>reg2.exe /?


C:\Windows\system32>reg.exe /?

REG Operation [Parameter List]

  Operation  [ QUERY   | ADD    | DELETE  | COPY    |
               SAVE    | LOAD   | UNLOAD  | RESTORE |
               COMPARE | EXPORT | IMPORT  | FLAGS ]

Return Code: (Except for REG COMPARE)

  0 - Successful
  1 - Failed

For help on a specific operation type:

  REG Operation /?

Examples:

  REG QUERY /?
  REG ADD /?
  REG DELETE /?
  REG COPY /?
  REG SAVE /?
  REG RESTORE /?
  REG LOAD /?
  REG UNLOAD /?
  REG COMPARE /?
  REG EXPORT /?
  REG IMPORT /?
  REG FLAGS /?

C:\Windows\system32>

但是对于 Windows XP x86:

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\chris>cd \WINDOWS\system32

C:\WINDOWS\system32>reg.exe

Console Registry Tool for Windows - version 3.0
Copyright (C) Microsoft Corp. 1981-2001.  All rights reserved


REG Operation [Parameter List]

  Operation  [ QUERY   | ADD    | DELETE  | COPY    |
               SAVE    | LOAD   | UNLOAD  | RESTORE |
               COMPARE | EXPORT | IMPORT ]

Return Code: (Except of REG COMPARE)

  0 - Succussful
  1 - Failed

For help on a specific operation type:

  REG Operation /?

Examples:

  REG QUERY /?
  REG ADD /?
  REG DELETE /?
  REG COPY /?
  REG SAVE /?
  REG RESTORE /?
  REG LOAD /?
  REG UNLOAD /?
  REG COMPARE /?
  REG EXPORT /?
  REG IMPORT /?

C:\WINDOWS\system32>copy reg.exe reg2.exe
        1 file(s) copied.

C:\WINDOWS\system32>reg2.exe

Console Registry Tool for Windows - version 3.0
Copyright (C) Microsoft Corp. 1981-2001.  All rights reserved


REG Operation [Parameter List]

  Operation  [ QUERY   | ADD    | DELETE  | COPY    |
               SAVE    | LOAD   | UNLOAD  | RESTORE |
               COMPARE | EXPORT | IMPORT ]

Return Code: (Except of REG COMPARE)

  0 - Succussful
  1 - Failed

For help on a specific operation type:

  REG Operation /?

Examples:

  REG QUERY /?
  REG ADD /?
  REG DELETE /?
  REG COPY /?
  REG SAVE /?
  REG RESTORE /?
  REG LOAD /?
  REG UNLOAD /?
  REG COMPARE /?
  REG EXPORT /?
  REG IMPORT /?

C:\WINDOWS\system32>

WinDbg 似乎告诉我 CRT 正在杀死它:

Child-SP          RetAddr           Call Site
00000000`0016f798 00000000`779d2f8b ntdll!ZwTerminateProcess+0xa
00000000`0016f7a0 000007fe`fe97d832 ntdll!RtlExitUserProcess+0x8b
00000000`0016f7d0 00000000`ffe7f710 msvcrt!cinit+0x13b
00000000`0016f810 00000000`778a495d reg!DynArrayGetItemType2+0x1fc
00000000`0016f850 00000000`779d8791 kernel32!BaseThreadInitThunk+0xd
00000000`0016f880 00000000`00000000 ntdll!RtlUserThreadStart+0x1d

但是由于我对 WinDbg 不太熟悉(而且这个是 64 位的,所以说,Ollydbg 失败了)我在这里有点不知所措。感谢你们提供的任何信息。

编辑

感谢 Cyber​​Shadow 的帮助和一些谷歌搜索,我找到了解决方案:它在当前安装的语言的子文件夹中查找 .mui(它的翻译)。

Microsoft Windows [Version 6.0.6001]
Copyright (c) 2006 Microsoft Corporation.  All rights reserved.

C:\Windows\system32>cd en-US

C:\Windows\System32\en-US>copy reg.exe.mui reg2.exe.mui
        1 file(s) copied.

C:\Windows\System32\en-US>cd ..

C:\Windows\System32>reg2
ERROR: Invalid syntax.
Type "REG /?" for usage.

C:\Windows\System32>del en-US\reg2.exe.mui

C:\Windows\System32>reg2

C:\Windows\System32>

【问题讨论】:

  • 我在 Win7 x64 上看到了同样的情况。将 reg.exe 复制到另一个目录以同样的方式失败。似乎是一项安全检查,以确保您从系统目录中准确运行“reg.exe”。

标签: windows-server-2008 reverse-engineering rename crt


【解决方案1】:

通过调试器,我发现 LoadString(用于获取使用情况和错误消息)返回 ERROR_MUI_FILE_NOT_LOADED。我认为这在一定程度上解释了它:)

注意事项:

  • 该堆栈跟踪似乎具有误导性(或者至少我们看到了具有相同效果的不同问题)。复制/重命名时,应用程序正常退出,不打印任何内容。
  • 除了无法显示消息外,该实用程序继续正常工作。
  • 这也会影响 32 位版本(您可以在 SysWOW64 中找到)。

【讨论】:

  • 感谢您的信息,我认为这很愚蠢。知道如何将 MUI 文件与重命名的副本重新关联吗?只要可执行文件仍然继续运行并做到这一点,那就太好了。感谢您的帮助!
  • 再次感谢,我找到了它想要的 MUI。我意识到我发布的堆栈跟踪是在进程退出之后 - 有意义的是,在它完成所有操作之后,它称为 ExitProcess。对不起,误导性的痕迹。用解决方案更新了问题。
  • 啊,是的,就这样。找到 reg.exe.mui 并重命名,就可以了。
【解决方案2】:

在这里猜测一下,但有些应用程序使用应用程序的名称来确定它应该做什么——这是一个古老的 UNIX 技巧;例如,/bin/false/bin/true 是相同的二进制文件,但名称决定了返回哪个结果。

当您最终编写 2 个以上 99.9% 相同的程序时,您会这样做,并且您不想为每个程序维护单独的代码库。

【讨论】:

  • 我认为可能是这样,但我认为 MS 不会这样做(而且他们似乎没有这样做,请参阅 Cyber​​Shadow 的回复)
猜你喜欢
  • 2011-02-27
  • 1970-01-01
  • 1970-01-01
  • 2015-12-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多