Skip to content
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

RtlGetVersion not found in NtDll #421

Closed
emako opened this issue Sep 5, 2023 · 6 comments
Closed

RtlGetVersion not found in NtDll #421

emako opened this issue Sep 5, 2023 · 6 comments
Assignees

Comments

@emako
Copy link

emako commented Sep 5, 2023

<PackageReference Include="Vanara.PInvoke.NtDll" Version="3.4.16" />

RtlGetVersion not found in NtDll.

@dahall
Copy link
Owner

dahall commented Sep 7, 2023

See

public static extern bool GetVersionEx(ref OSVERSIONINFOEX lpVersionInfo);

@dahall dahall closed this as completed Sep 7, 2023
@emako
Copy link
Author

emako commented Sep 10, 2023

It looks different from the API results of NtDll.
R2X3O7$0QXUF1X57AT~QSHS

@emako
Copy link
Author

emako commented Sep 10, 2023

image
NtDll.RtlGetVersion is OK.

public static class NtDll
{
    [SecurityCritical]
    [DllImport(Lib.NTdll, SetLastError = true, CharSet = CharSet.Unicode)]
    [DefaultDllImportSearchPaths(DllImportSearchPath.System32)]
    public static extern int RtlGetVersion(out OSVERSIONINFOEX versionInfo);
}
[StructLayout(LayoutKind.Sequential)]
public struct OSVERSIONINFOEX
{
    public int OSVersionInfoSize;
    public int MajorVersion;
    public int MinorVersion;
    public int BuildNumber;
    public int Revision;
    public int PlatformId;
    [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
    public string CSDVersion;
    public ushort ServicePackMajor;
    public ushort ServicePackMinor;
    public short SuiteMask;
    public byte ProductType;
    public byte Reserved;
}

Could you reopen the issuse?

@dahall
Copy link
Owner

dahall commented Sep 11, 2023

Both those methods (GetVersionEx and RtlGetVersion) are marked as obsolete in lieu of the functions in VersionHelpers.h. You can find the Varana equivalents at PInvoke/Kernel32/VersionHelpers.cs

@dahall dahall reopened this Sep 11, 2023
@dahall
Copy link
Owner

dahall commented Sep 11, 2023

To use GetVersionEx you have to set the size or use the Default field:

var ver = OSVERSIONINFOEX.Default;
if (!GetVersionEx(ref ver)) ...

@dahall dahall self-assigned this Sep 13, 2023
@emako
Copy link
Author

emako commented Sep 15, 2023

Kernel32.OSVERSIONINFOEX.Default make Kernel32.GetVersionEx return true, but it seems that the value is not eq to NtDll.RtlGetVersion.

Kernel32.GetVersionEx
image

NtDll.RtlGetVersion
image

Addtional infos:

My TargetFramework like following and I don't use any app.manifest file.

<TargetFramework>net7.0-windows10.0.22621.0</TargetFramework> // in my exe csproj
<TargetFramework>net7.0-windows</TargetFramework> // in my lib csproj

dahall added a commit that referenced this issue Sep 25, 2023
dahall added a commit that referenced this issue Sep 25, 2023
@dahall dahall closed this as completed Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants