sarsta

Untitled

Nov 20th, 2020
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.64 KB | None | 0 0
  1. public interface SenseLC extends Library {
  2.  
  3. int LC_SUCCESS = 0; // Successful
  4. int LC_OPEN_DEVICE_FAILED = 1; // Open device failed
  5. int LC_FIND_DEVICE_FAILED = 2; // No matching device was found
  6.  
  7. int LC_INVALID_PARAMETER = 3; // Parameter Error
  8. int LC_INVALID_BLOCK_NUMBER = 4; // Block Error
  9. int LC_HARDWARE_COMMUNICATE_ERROR = 5; // Communication error with hardware
  10. int LC_INVALID_PASSWORD = 6; // Invalid Password
  11. int LC_ACCESS_DENIED = 7; // No privileges
  12. int LC_ALREADY_OPENED = 8; // Device is open
  13. int LC_ALLOCATE_MEMORY_FAILED = 9; // Allocate memory failed
  14. int LC_INVALID_UPDATE_PACKAGE = 10; // Invalid update package
  15. int LC_SYN_ERROR = 11; // thread Synchronization error
  16. int LC_OTHER_ERROR = 12; // Other unknown exceptions
  17.  
  18. SenseLC INSTANCE = (SenseLC) Native.load("Sense_LC", SenseLC.class);
  19.  
  20. int LC_open(int vendor, int index, long[] handle);
  21.  
  22. int LC_close(long handle);
  23.  
  24. int LC_passwd(long handle, int type, byte[] passwd);
  25.  
  26. int LC_read(long handle, int block, byte[] buffer);
  27.  
  28. int LC_write(long handle, int block, byte[] buffer);
  29.  
  30. int LC_encrypt(long handle, byte[] plaintext, byte[] ciphertext);
  31.  
  32. int LC_decrypt(long handle, byte[] ciphertext, byte[] plaintext);
  33.  
  34. int LC_set_passwd(long handle, int type, byte[] passwd, int retries);
  35.  
  36. int LC_change_passwd(long handle, int type, byte[] oldpasswd, byte[] newpasswd);
  37.  
  38. int LC_get_hardware_info(long handle, LC_hardware_info info);
  39.  
  40. int LC_get_software_info(LC_software_info info);
  41.  
  42. int LC_Hmac(long handle, byte[] text, int textlen, byte[] digest);
  43.  
  44. int LC_Hmac_software(byte[] text, int textlen, byte[] key, byte[] digest);
  45.  
  46. int LC_update(long handle, byte[] buffer);
  47.  
  48. int LC_set_key(long handle, int type, byte[] key);
  49.  
  50. int LC_gen_update_pkg(byte[] serial, int block, byte[] buffer, byte[] key, byte[] uptPkg);
  51.  
  52. }
  53.  
  54. @FieldOrder({
  55. "developerNumber",
  56. "serialNumber",
  57. "setDate",
  58. "reservation"
  59. })
  60. public class LC_hardware_info extends Structure {
  61.  
  62. public int developerNumber;
  63. public byte[] serialNumber = new byte[8];
  64. public int setDate;
  65. public int reservation;
  66.  
  67. public String getSerial() {
  68. return new String(serialNumber, StandardCharsets.UTF_8);
  69. }
  70.  
  71. @Override
  72. public String toString() {
  73. return "LC_hardware_info{"
  74. + "\ndeveloperNumber=" + developerNumber
  75. + "\nserialNumber=" + getSerial()
  76. + "\nsetDate=" + setDate
  77. + "\nreservation=" + reservation
  78. + "\n}";
  79. }
  80.  
  81. }
  82.  
  83. public class Test {
  84.  
  85. /**
  86. * @param args the command line arguments
  87. */
  88. public static void main(String[] args) {
  89. // System.setProperty("jna.debug_load", "true");
  90. System.setProperty("jna.library.path", System.getProperty("user.dir"));
  91.  
  92. SenseLC lib = SenseLC.INSTANCE;
  93.  
  94. long[] handle = new long[1];
  95. int ret = lib.LC_open(0, 0, handle);
  96. if (ret != SenseLC.LC_SUCCESS) {
  97. System.out.println("Open: " + SenseLCUtil.getCodeName(ret));
  98. return;
  99. }
  100.  
  101. LC_hardware_info hi = new LC_hardware_info();
  102. ret = lib.LC_get_hardware_info(handle[0], hi);
  103. if (ret != SenseLC.LC_SUCCESS) {
  104. System.out.println("Read: " + SenseLCUtil.getCodeName(ret));
  105. return;
  106. }
  107.  
  108. System.out.println(hi);
  109.  
  110. ret = lib.LC_close(handle[0]);
  111. if (ret != SenseLC.LC_SUCCESS) {
  112. System.out.println("Close: " + SenseLCUtil.getCodeName(ret));
  113. return;
  114. }
  115.  
  116. }
  117.  
  118. }
  119.  
Advertisement
Add Comment
Please, Sign In to add comment