There is a library in c ++ and documentation for it. In general, I can work with it, but there is a problem with some functions.
In the documentation:
LONG CLSCRF_MifareStandard_AuthKey( IN LPVOID pReader, IN BYTE bKeyType, IN LPBYTE pbUID, IN DWORD dwSector, IN LPBYTE pbCodedKey ); I connect library:
[DllImport(ClscrflDll)] public static extern uint CLSCRF_MifareStandard_AuthKey(IntPtr pReader, byte bKeyType, IntPtr pbUID, uint dwSector, IntPtr pbCodedKey); For example, a UID is an array of bytes, in IntPrt I translate it like this:
var pbUID = Marshal.AllocHGlobal(UID.Length); Marshal.Copy(UID, 0, pbUID, UID.Length); With the other types, everything seems to be clear. As a result, when I call a function, I get an error:
Attempting to read or write protected memory. This often indicates that the other memory is damaged.
There are suspicions that this is something with pbCodedKey. This is an authorization key. I get it by another function:
[DllImport(ClscrflDll)] public static extern uint CLSCRF_MifareStandard_HostCodeKey(IntPtr pReader, IntPtr pbUncoded, ref IntPtr pbCoded); ///---------- byte[] key = new byte[6] { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; var pbKey = Marshal.AllocHGlobal(key.Length); Marshal.Copy(key, 0, pbKey, key.Length); var _key = Marshal.AllocHGlobal(12); var err = Clscrfl.CLSCRF_MifareStandard_HostCodeKey(pReader, pbKey, ref _key); Her description:
LONG CLSCRF_MifareStandard_HostCodeKey( IN LPVOID pReader, IN LPBYTE pbUncoded, OUT LPBYTE pbCoded ); What could be the problem, at least approximately?
OUT LPBYTE pbCodedinto aref IntPtr pbCoded? There was a pointer to the buffer - there was a pointer to the pointer. - Pavel Mayorov