-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: Address bug where createwith does not handle all kinds of dotnet executables #141
base: main
Are you sure you want to change the base?
Fix: Address bug where createwith does not handle all kinds of dotnet executables #141
Conversation
There's a lot of stuff going on! My understanding is that there are two proposed improvements:
|
@frerich
|
…eflector.exe, it can be install by https://download.red-gate.com/ReflectorInstaller.exe
8e5ef0e
to
ec9696d
Compare
@bgianfo, I have rebased to only include this commit. |
@sonyps5201314 Thanks for elaborating!
|
For what it's worth, in case the Detours project should continue to support Windows NT, Windows XP (at least prior to SP2), and Windows Server 2003, it would probably be worthwhile to consider setting up some CI for this since I suspect that many external contributors might not take those platforms into account. |
DETOUR_DEBUG will be set, only when Detours can not work fine, it helps users find the wrong place as quickly as possible,It is a logging system, just like in ntdll, it can be turned on when needed and when something goes wrong. from Windows 2000 wiki page, |
Supporting these old platforms will not increase the amount of code. I don't think it is necessary to spend too much time on this issue. The core foundation of Detours is VirtualAlloc and VirtualProtect, process independent virtual address space and can modify PAGE_EXECUTE permission. As long as these conditions can be guaranteed. |
@sonyps5201314 It would be great if you could address the question in #104 (comment) -- what does your definition of |
If it's worthless, official people would not let you rebase your code by |
The theoretical result should be you can test by yourself by compile below code by any vc version from 6.0 as a console app. #include <stdio.h>
#include <windows.h>
#ifndef PROCESSOR_ARCHITECTURE_AMD64
#define PROCESSOR_ARCHITECTURE_AMD64 9
#endif
#ifndef PROCESSOR_ARCHITECTURE_ARM64
#define PROCESSOR_ARCHITECTURE_ARM64 12
#endif
BOOL Is64BitOS()
{
BOOL bRet = FALSE;
HMODULE hModule = GetModuleHandle(TEXT("kernel32.dll"));
if (!hModule)
{
return bRet;
}
VOID(WINAPI * _GetNativeSystemInfo)(OUT LPSYSTEM_INFO lpSystemInfo) = (void(__stdcall*)(LPSYSTEM_INFO))GetProcAddress(hModule, "GetNativeSystemInfo");
if (!_GetNativeSystemInfo)
{
return bRet;
}
SYSTEM_INFO si;
_GetNativeSystemInfo(&si);
if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 || si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_ARM64 ||
si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_IA64 || si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_ALPHA64)
{
bRet = TRUE;
}
return bRet;
}
int main()
{
BOOL bIs64BitOS = Is64BitOS();
printf("bIs64BitOS=%d", bIs64BitOS);
printf("\n");
getchar();
return 0;
}
In my 64 bit Windows 8.1, it is The reason you are puzzled is because you don’t understand the function of GetNativeSystemInfo. |
@sonyps5201314 Thanks for the explanation. Just to clarify my understanding:
Is this accurate? If so, can you clean this PR such that only those two aspects are addressed? As it is, there seem to be a lot of unrelated changes which make it a bit hard to see what's going on, e.g. in modules.cpp:872. Also, the |
In the official original code (including the official final commercial version 3.0 build 343), the logical judgment of bIs32BitProcess is indeed problematic, but it has now been corrected and it is perfect. It is because of defects that the corresponding formatting parameters are not given and it is just a guess of you. If this sentence DETOUR_TRACE is meaningless, it is estimated that the official has deleted it a long time ago. Only the original developer of this code knows the reason. So I think that keeping this code is a respect for the original author, and we cannot determine the original author's intentions and expressions, so we cannot decide to remove it. Detours is great. It uses such a small code to implement x86, x64, ia64, arm, arm64 hooks. There is no similar software on the market that can support such a comprehensive and stable instruction set, but Microsoft has published it in 2002. In the future, it may also support linux/unix to complete all operating systems, expand Microsoft’s influence and contribution to the world, and win more praise. It has served various commercial projects for many years. Selling it at a high price is enough to show its technical content. This is Microsoft's official high affirmation of the value of this project. Including NVIDIA is also a customer of this software. You can find it in NVIDIA's graphics driver. Therefore, when we modify these codes, we should think twice and stay in awe, so as not to make it unstable. This is related to Microsoft's reputation.
from https://en.wikipedia.org/wiki/Windows_XP_editions#Windows_XP_64-Bit_Edition 3.my #141's purpose is 'Fix can not createwith all kinds of dot net exe', and not only 'Determine whether the process is 32-bit', That's all, thanks for your attention. |
I still think that it makes sense to
|
The purpose of this PR is to fix the createwith startup problem of all types of .net programs. With only one PR, other users can understand how to fix it, and what errors are fixed. And dividing into two PRs as you said is more like a fix you submitted before, which does not meet the purpose of this PR. I also explained before that in order to achieve this goal, it is not just a modification of the code in this place. Users can also open this PR to understand the details of our discussion. |
@bgianfo Thanks for bringing this PR to my attention! I finished reviewing this code and added some questions and concerns as comments to this PR. |
Thanks @frerich for taking a look. |
@sonyps5201314 / @frerich can we please seperate the revert of the #104 commit and fix so the history is clean? The current proposed PR muddles them togeather. |
@bgianfo Thanks for bringing this up again! It appears that I understood this PR to improve two aspects of the source code, one of which being the portability of the code. PR #104 introduced the usage of the If so, I find it hard to come up with a tested PR since I lack access to Windows XP installations which do not have SP2 installed. I could do a blind patch at best (i.e. a patch which I never tried myself), but I'd rather not do that. :-) @sonyps5201314 quoted the Detours wiki, which pointed out that "Detours is compatible only with the Windows NT family of operating systems: Windows NT, Windows XP, and Windows Server 2003". Is this still accurate? If so, I suspect that all contributors to the project would benefit greatly from a CI setup which makes sure that all PRs are exercised (at least built) on all supported platforms. I'm afraid that otherwise, such portability issues might creep in rather sooner than later. |
YES,however, the first submission of this PR of mine has deleted the relevant code of @frerich because it conflicts with mine. Therefore, there should be no confusion. |
The merge conflict has been fixed. |
fix can not use createwith api to start all kinds of .net exe, like https://github.com/Microsoft/Detours/files/2918112/DotNetAppTest.zip in #54
this commit revert "Improved Detours logic for detection of 32bit processes (#104)" , because there are some bugs in that commit,
for example:
1. from detours wiki text:
Is Detours compatible with Windows 95, Windows 98, or Windows ME? No. Detours is compatible only with the Windows NT family of operating systems: Windows NT, Windows XP, and Windows Server 2003, etc. Detours does not work on the Windows 9x family of operating systems because they have a primitive virtual memory system.
we known Detours compatible with Windows 2000 and later system. but IsWow64Process is only available from Windows XP SP2,
these code:
are from "Improved Detours logic for detection of 32bit processes (#104)" commit, and
IsWow64ProcessHelper
will return FALSE when it can not findIsWow64Process
function,if
IsWow64ProcessHelper
return FALSE, you will return FALSE too, andDetourUpdateProcessWithDll
will be failed.so these code will make Detours no longer compatible with all windows NT family.
2. "Improved Detours logic for detection of 32bit processes (#104)" commit delete these follow codes in
DetourUpdateProcessWithDll
:if uncommnet
// #define DETOUR_DEBUG 1
, it will make the follow code can not be compile success:
Finally, my
Detour::Is64BitProcess
code Provides a more perfect solution, it have test on all different kinds of windows version from Windows 2000 to Winodws 10, include x86 and x64 architecture.