MapPhysToLin C# example

My x64 port of InpOut32
Post Reply
Usipusi
New User
Posts: 4
Joined: Mon Dec 21, 2020 11:32 am

MapPhysToLin C# example

Post by Usipusi »

Hi Mate!

I can't find an example of how to properly export functions in C#...

Code: Select all

        [DllImport("inpoutx64.dll",  EntryPoint = "MapPhysToLin", CallingConvention = CallingConvention.StdCall)]
        [return: MarshalAs(UnmanagedType.LPArray)]
        private static unsafe extern byte* MapPhysToLin(UIntPtr pbPhysAddr, uint dwPhysSize, out IntPtr pPhysicalMemoryHandle);

        [DllImport("inpoutx64.dll", EntryPoint = "UnmapPhysicalMemory", CallingConvention = CallingConvention.StdCall)]
        [return: MarshalAs(UnmanagedType.Bool)]
        private static extern bool UnmapPhysicalMemory(IntPtr PhysicalMemoryHandle, byte[] pbLinAddr);
User avatar
phil
Site Admin
Posts: 7611
Joined: Sun Apr 06, 2003 11:12 pm

Re: MapPhysToLin C# example

Post by phil »

Last time I looked, the .NET 2.0 samples worked (both VB and C#) and they are still available for download on my website. Whats the problem?
https://www.highrez.co.uk/downloads/inp ... efault.htm

NOTE: This is completely unsupported and a dead project now as far as I am concerned. I am unable to to rebuild it as I don't have the ability to sign drivers (etc.etc.). It should still work but its not something I can commit any time to other than the odd question here and there!
--[ Phil ]--
--[ Administrator & XMBC Author ]--
Logitech G9/G604/M720/MX518, Microsoft Intellimouse, Trust 16341 BT Mouse
Windows 10 x64, AMD Ryzen 5900x, MSI x570 Tomahawk, 32GB DDR4,
nVidia RTX 2070s, Evo 970 1Tb NVME, 2x2TB WD Black (RAID1)
Usipusi
New User
Posts: 4
Joined: Mon Dec 21, 2020 11:32 am

Re: MapPhysToLin C# example

Post by Usipusi »

The example does not contain the function I am asking about, so I wrote to the forum.
User avatar
phil
Site Admin
Posts: 7611
Joined: Sun Apr 06, 2003 11:12 pm

Re: MapPhysToLin C# example

Post by phil »

Sorry, I missed that!

Not sure those functions even work as its not something Ive ever used (or tested), so I don't have a great answer for you I'm afraid.
If I recall, I copied them from WinRing0 but never actually used them. The C++ signatures should be in the header files in the source archive - so it should be relatively easy to work out (comparing to the ones that are imported in the .NET example, but as I said, I have no idea if they actually work!)

Regards,
Phil
--[ Phil ]--
--[ Administrator & XMBC Author ]--
Logitech G9/G604/M720/MX518, Microsoft Intellimouse, Trust 16341 BT Mouse
Windows 10 x64, AMD Ryzen 5900x, MSI x570 Tomahawk, 32GB DDR4,
nVidia RTX 2070s, Evo 970 1Tb NVME, 2x2TB WD Black (RAID1)
Usipusi
New User
Posts: 4
Joined: Mon Dec 21, 2020 11:32 am

Re: MapPhysToLin C# example

Post by Usipusi »

All functions work and even this one (Latest Win10). This is good news. By the way, Winring is not able to read physical memory even if you use #define _PHYSICAL_MEMORY_SUPPORT and recompile DLL. Your project is unique.

Code: Select all

        [DllImport("inpoutx64.dll",  EntryPoint = "MapPhysToLin", CallingConvention = CallingConvention.StdCall)]       
        private static unsafe extern byte * MapPhysToLin(UIntPtr pbPhysAddr, uint dwPhysSize, out IntPtr pPhysicalMemoryHandle);

        [DllImport("inpoutx64.dll", EntryPoint = "UnmapPhysicalMemory", CallingConvention = CallingConvention.StdCall)]
        [return: MarshalAs(UnmanagedType.Bool)]
        private static extern bool UnmapPhysicalMemory(IntPtr PhysicalMemoryHandle, byte[] pbLinAddr);
I may be of use to someone, I will leave the solution to the problem here :D

_____

P.s. I have heard that MS has influenced all similar projects. Is this true?
I'm sorry, I don't know where to read about the reasons.
User avatar
phil
Site Admin
Posts: 7611
Joined: Sun Apr 06, 2003 11:12 pm

Re: MapPhysToLin C# example

Post by phil »

Glad to hear it works (didn't really expect that) and thanks for updating this thread - I hope it will help others!
I must have got the code from somewhere, I assume WinRing0 as it was open source like InpOut. I didn't write InpOut, only ported it to x64 and my driver experience is pretty much that!

By "Influence" I think you are referring to the almost impossible requirements to build drivers. They have to be signed with a driver code signing certificate - these are not available to hobbyists, only legally registered companies and cost quite a bit ($300+ a year). So it kind rules out these little projects. WinRin0 was killed when MS revoked their certificate meaning the driver will not install. That hasn't happened to InpOut yet but it could if someone were to abuse it like WinRing0 was used and abused (by malware developers). If/When that happens, InpOut will be dead unless someone manages to sign it with a new certificate - and take the risk that it will also be revoked (its a lot of pain, money and effort to get a certificate, to have it revoked because some random out there abuses the driver is not feasible).

So you could say Microsoft influenced it - but I can see why (if WinRni0 was used to bypass HDCP or other naughty things, they had every right to I guess).
--[ Phil ]--
--[ Administrator & XMBC Author ]--
Logitech G9/G604/M720/MX518, Microsoft Intellimouse, Trust 16341 BT Mouse
Windows 10 x64, AMD Ryzen 5900x, MSI x570 Tomahawk, 32GB DDR4,
nVidia RTX 2070s, Evo 970 1Tb NVME, 2x2TB WD Black (RAID1)
Usipusi
New User
Posts: 4
Joined: Mon Dec 21, 2020 11:32 am

Re: MapPhysToLin C# example

Post by Usipusi »

Thank you very much for the information.
I really hope that MS policy never affects your project.
Happy upcoming holidays :)
Post Reply