Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public interface SenseLC extends Library {
- int LC_SUCCESS = 0; // Successful
- int LC_OPEN_DEVICE_FAILED = 1; // Open device failed
- int LC_FIND_DEVICE_FAILED = 2; // No matching device was found
- int LC_INVALID_PARAMETER = 3; // Parameter Error
- int LC_INVALID_BLOCK_NUMBER = 4; // Block Error
- int LC_HARDWARE_COMMUNICATE_ERROR = 5; // Communication error with hardware
- int LC_INVALID_PASSWORD = 6; // Invalid Password
- int LC_ACCESS_DENIED = 7; // No privileges
- int LC_ALREADY_OPENED = 8; // Device is open
- int LC_ALLOCATE_MEMORY_FAILED = 9; // Allocate memory failed
- int LC_INVALID_UPDATE_PACKAGE = 10; // Invalid update package
- int LC_SYN_ERROR = 11; // thread Synchronization error
- int LC_OTHER_ERROR = 12; // Other unknown exceptions
- SenseLC INSTANCE = (SenseLC) Native.load("Sense_LC", SenseLC.class);
- int LC_open(int vendor, int index, long[] handle);
- int LC_close(long handle);
- int LC_passwd(long handle, int type, byte[] passwd);
- int LC_read(long handle, int block, byte[] buffer);
- int LC_write(long handle, int block, byte[] buffer);
- int LC_encrypt(long handle, byte[] plaintext, byte[] ciphertext);
- int LC_decrypt(long handle, byte[] ciphertext, byte[] plaintext);
- int LC_set_passwd(long handle, int type, byte[] passwd, int retries);
- int LC_change_passwd(long handle, int type, byte[] oldpasswd, byte[] newpasswd);
- int LC_get_hardware_info(long handle, LC_hardware_info info);
- int LC_get_software_info(LC_software_info info);
- int LC_Hmac(long handle, byte[] text, int textlen, byte[] digest);
- int LC_Hmac_software(byte[] text, int textlen, byte[] key, byte[] digest);
- int LC_update(long handle, byte[] buffer);
- int LC_set_key(long handle, int type, byte[] key);
- int LC_gen_update_pkg(byte[] serial, int block, byte[] buffer, byte[] key, byte[] uptPkg);
- }
- @FieldOrder({
- "developerNumber",
- "serialNumber",
- "setDate",
- "reservation"
- })
- public class LC_hardware_info extends Structure {
- public int developerNumber;
- public byte[] serialNumber = new byte[8];
- public int setDate;
- public int reservation;
- public String getSerial() {
- return new String(serialNumber, StandardCharsets.UTF_8);
- }
- @Override
- public String toString() {
- return "LC_hardware_info{"
- + "\ndeveloperNumber=" + developerNumber
- + "\nserialNumber=" + getSerial()
- + "\nsetDate=" + setDate
- + "\nreservation=" + reservation
- + "\n}";
- }
- }
- public class Test {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // System.setProperty("jna.debug_load", "true");
- System.setProperty("jna.library.path", System.getProperty("user.dir"));
- SenseLC lib = SenseLC.INSTANCE;
- long[] handle = new long[1];
- int ret = lib.LC_open(0, 0, handle);
- if (ret != SenseLC.LC_SUCCESS) {
- System.out.println("Open: " + SenseLCUtil.getCodeName(ret));
- return;
- }
- LC_hardware_info hi = new LC_hardware_info();
- ret = lib.LC_get_hardware_info(handle[0], hi);
- if (ret != SenseLC.LC_SUCCESS) {
- System.out.println("Read: " + SenseLCUtil.getCodeName(ret));
- return;
- }
- System.out.println(hi);
- ret = lib.LC_close(handle[0]);
- if (ret != SenseLC.LC_SUCCESS) {
- System.out.println("Close: " + SenseLCUtil.getCodeName(ret));
- return;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment