Closed DSBloom closed 6 years ago
Just to be clear, we are in no way or form affiliated with Yubico, so I know as much about this as anyone else.
However, Yubico has a lot of open source software, which is where we got our DLLImports from. I searched for the one you are trying to bind with and found a header file with it here: https://github.com/Yubico/yubico-piv-tool/blob/master/lib/ykpiv.h
Just match the parameters with the right types. Look at it like areas of memory rather than types.
For example, this should always work: IntPtr ykpiv_util_set_cccid(IntPtr state, IntPtr ccc);
You are telling the C# marshaller to simply give you a pointer to each of the memory areas that contain the data. The data type is then just a 'view' or interpretation of the data itself. The only other thing you need to make sure of is that the method you are trying to bind to is present in the DLL file and exported.
You also need to make sure the thing you are trying to bind to is actually exported. Use CFF Explorer and open the DLL file. Go to the "Export Directory" to see the list. I suspect the method you are calling is not exported. If you like the command line, you can also run dumpbin.exe /exports <dllfile>
- dumpbin comes with VS2017 if you have the C++ package installed.
Thank you very much for this. I too found that code and have been trying to implement it. I just don't have much experience with anything other than .Net, so your tips really help. Thanks again.
Turns out the DLL I was trying to use did indeed NOT have that export. I got a newer version from Yubico and it did.
Glad you got it working. I'm closing the issue as resolved.
We are using the EnrollmentStation and YubicoLib code to help write our own Yubikey provisioning software.
We have the need to set the CCC value in order to use the Yubikeys to login to our Mac systems, but the YubikeyPivNative class does not have a method for doing that.
In an attempt to implement it myself I have mimicked the methods in YubikeyPivNative:
[DllImport("Binaries\\libykpiv-1.dll", EntryPoint = "ykpiv_util_set_cccid", CharSet = CharSet.Ansi, SetLastError = true, CallingConvention = CallingConvention.Cdecl)] internal static extern YubicoPivReturnCode YkPivSetCcc(IntPtr state, byte[] ccc);
I found the function name by using DLL Export Viewer, but I get an exception when I attempt to call it using the above code:'Unable to find an entry point named 'ykpiv_util_set_cccid' in DLL 'Binaries\libykpiv-1.dll
I'm sure I have the method signature wrong, since I don't know what arguments
ykpiv_util_set_cccid
is expecting. Is there any light you could shed on this for us?