Browse Source

Merge pull request #153 in CORE/base-third from ~HARRISON/base-third:feature/10.0 to feature/10.0

* commit '7d2e9d348525ac35856c49040a449f5b1da5a0b3':
  REPORT-11969 注册增强
research/11.0
Harrison 6 years ago
parent
commit
33b1510083
  1. 3
      build.third_step2.gradle
  2. BIN
      fine-sense4/lib/jna-3.2.2.jar
  3. 63
      fine-sense4/src/Sense4/Elite4.java
  4. 20
      fine-sense4/src/Sense4/EliteLockIO.java
  5. 276
      fine-sense4/src/Sense4/EliteLockIO32.java
  6. 274
      fine-sense4/src/Sense4/EliteLockIO64.java
  7. 65
      fine-sense4/src/Sense4/LockUtils.java
  8. 218
      fine-sense4/src/Sense4/Sense32.java
  9. 219
      fine-sense4/src/Sense4/Sense64.java
  10. 690
      fine-sense4/src/Sense4/sense4.h

3
build.third_step2.gradle

@ -22,6 +22,7 @@ sourceSets{
srcDirs = [ srcDirs = [
"${srcDir}/fine-aspectj/src", "${srcDir}/fine-aspectj/src",
"${srcDir}/fine-spring/src", "${srcDir}/fine-spring/src",
"${srcDir}/fine-sense4/src",
"${srcDir}/fine-spring/resources" "${srcDir}/fine-spring/resources"
] ]
} }
@ -44,6 +45,7 @@ def branchName=buildDir.substring(buildDir.lastIndexOf (java.io.File.separator)+
dependencies{ dependencies{
compile fileTree(dir:"${srcDir}/fine-aspectj/lib",include:'**/*.jar') compile fileTree(dir:"${srcDir}/fine-aspectj/lib",include:'**/*.jar')
compile fileTree(dir:"${srcDir}/fine-spring/lib",include:'**/*.jar') compile fileTree(dir:"${srcDir}/fine-spring/lib",include:'**/*.jar')
compile fileTree(dir:"${srcDir}/fine-sense4/lib",include:'**/*.jar')
compile fileTree(dir:"${srcDir}/build/libs/",include:'**/*.jar') compile fileTree(dir:"${srcDir}/build/libs/",include:'**/*.jar')
compile "com.fr.third:fine-third:10.0-FEATURE-SNAPSHOT" compile "com.fr.third:fine-third:10.0-FEATURE-SNAPSHOT"
compile fileTree(dir:"../../finereport-lib-other/${branchName}",include:'**/*.jar') compile fileTree(dir:"../../finereport-lib-other/${branchName}",include:'**/*.jar')
@ -67,6 +69,7 @@ task copyFiles(type:Copy,dependsOn:'compileJava'){
println "------------------------------------------------copyfiles" println "------------------------------------------------copyfiles"
with dataContent.call("${srcDir}/fine-spring/src") with dataContent.call("${srcDir}/fine-spring/src")
with dataContent.call("${srcDir}/fine-spring/resources") with dataContent.call("${srcDir}/fine-spring/resources")
with dataContent.call("${srcDir}/fine-sense4/src")
into "${classesDir}" into "${classesDir}"
} }
} }

BIN
fine-sense4/lib/jna-3.2.2.jar

Binary file not shown.

63
fine-sense4/src/Sense4/Elite4.java

@ -0,0 +1,63 @@
package Sense4;
/**
* @author Lanlan
* @date 2018/11/25
*/
public class Elite4 {
public static byte[] readElite4Serial() {
EliteLockIO eliteLockIO = LockUtils.getEliteLockIOInstance();
eliteLockIO.initS4(false);
byte[] serial = eliteLockIO.readEliteSerial();
eliteLockIO.closeS4();
return serial;
}
/*
* Write byte[] to elite4
*/
public static boolean writeBytes2ToElite4(byte[] bytes) {
EliteLockIO eliteLockIO = LockUtils.getEliteLockIOInstance();
eliteLockIO.initS4(true);
byte[] write_len_bytes = LockUtils.intToByteArray1(bytes.length + 4);
if (!eliteLockIO.write_internal_file(0, 4, write_len_bytes)) {
eliteLockIO.closeS4();
return false;
}
if (!eliteLockIO.write_internal_file(4, bytes.length, bytes)) {
eliteLockIO.closeS4();
return false;
}
eliteLockIO.closeS4();
return true;
}
/*
* Read byte[] from elite4
*/
public static byte[] readBytesFromElitee4() {
EliteLockIO eliteLockIO = LockUtils.getEliteLockIOInstance();
eliteLockIO.initS4(true);
byte[] len_out = eliteLockIO.read_internal_file(0, 4);
int read_len = LockUtils.byteArray2Int(len_out) - 4;
if (read_len < 0) {
eliteLockIO.closeS4();
return new byte[0];
}
byte read_bytes[] = eliteLockIO.read_internal_file(4, read_len);
eliteLockIO.closeS4();
return read_bytes;
}
public static String toHexString(byte[] b) {
return LockUtils.toHexString(b);
}
}

20
fine-sense4/src/Sense4/EliteLockIO.java

@ -0,0 +1,20 @@
package Sense4;
/**
* @author Lanlan
* @date 2018/11/25
*/
public interface EliteLockIO {
void initS4(boolean changeDir);
void closeS4();
boolean write_internal_file(int offset, int write_len, byte[] write_bytes);
byte[] read_internal_file(int offset, int read_len);
boolean uploadHexExeFile();
byte[] readEliteSerial();
}

276
fine-sense4/src/Sense4/EliteLockIO32.java

@ -0,0 +1,276 @@
package Sense4;
import Sense4.Sense32.S4CREATEDIRINFO;
import Sense4.Sense32.S4OPENINFO;
import Sense4.Sense32.SENSE4_CONTEXT;
import com.sun.jna.ptr.IntByReference;
import java.io.File;
import java.io.FileInputStream;
/**
* @author Lanlan
* @date 2018/11/25
*/
public class EliteLockIO32 implements EliteLockIO {
public static final int MAX_BUFF_SIZE = 0xf0;
public static final byte WRITE = 0;
public static final byte READ = 1;
public SENSE4_CONTEXT ctx= new SENSE4_CONTEXT();//[] = new Sense4.SENSE4_CONTEXT[2];
public Sense32 lib = Sense32.instance;
public EliteLockIO32() {}
public void initS4(boolean changeDir) {
IntByReference pSize = new IntByReference(0);
int ret = lib.S4Enum(ctx, pSize);
ret = lib.S4Enum(ctx, pSize);
if(ret!=0)
{
System.out.println("列举设备失败!");
}
ret = lib.S4Open(ctx);
if(ret!=0)
{
System.out.println("打开设备失败!");
}
if (changeDir) {
ret = lib.S4ChangeDir(ctx, "\\");
if(ret!=0)
{
System.out.println("切换目录失败!");
lib.S4Close(ctx);
}
ret = lib.S4VerifyPin(ctx, "12345678", 8, lib.S4_USER_PIN);
if(ret!=0)
{
System.out.println("校验用户pin失败!");
lib.S4Close(ctx);
}
}
}
public void closeS4() {
int ret = lib.S4Close(ctx);
if(ret!=0)
{
System.out.println("关闭设备失败!");
}
}
public boolean write_internal_file(int offset, int write_len, byte[] write_bytes) {
int write_offset = offset;
int old_offset = write_offset;
byte inBuffer[]=new byte[0xf8];
byte outBuffer[]=new byte[0xf8];
IntByReference pdwByteOut = new IntByReference(0);
inBuffer[0]=WRITE;
while (write_len > 0) {
old_offset = write_offset;
inBuffer[2]=(byte)((write_offset >> 8) & 0xFF);
inBuffer[3]=(byte)(write_offset & 0xFF);
if (write_len <= MAX_BUFF_SIZE) {
System.arraycopy(write_bytes, old_offset - offset, inBuffer, 4, write_len);
inBuffer[1] = (byte)(write_len & 0xFF);
write_len = 0;
write_offset += write_len;
} else {
System.arraycopy(write_bytes, old_offset - offset, inBuffer, 4, MAX_BUFF_SIZE);
inBuffer[1] = (byte)MAX_BUFF_SIZE;
write_len -= MAX_BUFF_SIZE;
write_offset += MAX_BUFF_SIZE;
}
int ret = lib.S4Execute(ctx,"ef21",inBuffer,0xf8,outBuffer,0xf8, pdwByteOut);
if(ret!=0)
{
System.out.println("执行锁内程序失败!");
lib.S4Close(ctx);
return false;
}
}
return true;
}
public byte[] read_internal_file(int offset, int read_len) {
if (read_len < 0) {
throw new IllegalArgumentException();
}
int read_offset = offset;
int old_offset = read_offset;
byte[] out = new byte[read_len];
IntByReference pdwByteOut = new IntByReference(0);
byte inBuffer[]=new byte[0xf8];
byte outBuffer[]=new byte[0xf8];
inBuffer[0]=READ;
while (read_len > 0) {
old_offset = read_offset;
// big-edian
inBuffer[2]=(byte)((read_offset >> 8) & 0xFF);
inBuffer[3]=(byte)(read_offset & 0xFF);
if (read_len <= MAX_BUFF_SIZE) {
inBuffer[1] = (byte)read_len;
read_len = 0;
read_offset += read_len;
} else {
inBuffer[1] = (byte)MAX_BUFF_SIZE;
read_len -= MAX_BUFF_SIZE;
read_offset += MAX_BUFF_SIZE;
}
int ret = lib.S4Execute(ctx, "ef21",inBuffer,0xf8,outBuffer,0xf8,pdwByteOut);
if(ret!=0 || pdwByteOut.getValue() < inBuffer[1])
{
System.out.println("执行锁内程序失败!");
lib.S4Close(ctx);
} else {
System.arraycopy(outBuffer, 0, out, old_offset - offset, pdwByteOut.getValue());
}
}
return out;
}
public boolean uploadHexExeFile() {
Sense32 lib = Sense32.instance;
IntByReference pSize = new IntByReference(0);
int ret = 0;
long errorCount = 0;
IntByReference lpBytesReturned = new IntByReference(0);
SENSE4_CONTEXT[] s4_context = new SENSE4_CONTEXT[0];
ret = lib.S4Enum(null, pSize);
s4_context = new SENSE4_CONTEXT[pSize.getValue() / 92];
for (int i = 0;i< pSize.getValue() / 92; i++){
s4_context[i] = new SENSE4_CONTEXT();
}
ret = lib.S4Enum(s4_context[0], pSize);
checkS4ExceptionResult(ret, "Enumerate Sense4");
errorCount += ret;
S4OPENINFO s4_OpenInfo = new S4OPENINFO();
s4_OpenInfo.dwS4OpenInfoSize = 8;
s4_OpenInfo.dwShareMode = lib.S4_EXCLUSIZE_MODE;
ret = lib.S4OpenEx(s4_context[0], s4_OpenInfo);
checkS4ExceptionResult(ret, "Open Sense4");
errorCount += ret;
byte [] frequency = {0x04};
ret = lib.S4Control(s4_context[0], lib.S4_LED_WINK, frequency, 1, null, 0, lpBytesReturned);
checkS4ExceptionResult(ret, "Sense4 LED wink");
errorCount += ret;
ret = lib.S4ChangeDir (s4_context[0], "\\");
checkS4ExceptionResult(ret, "Change Dir");
errorCount += ret;
ret = lib.S4VerifyPin(s4_context[0], "123456781234567812345678", 24, lib.S4_DEV_PIN);
checkS4ExceptionResult(ret, "Verify dev pin");
errorCount += ret;
ret = lib.S4EraseDir(s4_context[0], null);
checkS4ExceptionResult(ret, "Erase MF");
errorCount += ret;
S4CREATEDIRINFO s4_CreateDirInfo = new S4CREATEDIRINFO();
s4_CreateDirInfo.dwS4CreateDirInfoSize = 12;
s4_CreateDirInfo.szAtr[0] = (byte)0xFF;
s4_CreateDirInfo.szAtr[1] = (byte)0xFF;
s4_CreateDirInfo.szAtr[2] = (byte)0xFF;
s4_CreateDirInfo.szAtr[3] = (byte)0xFF;
s4_CreateDirInfo.szAtr[4] = (byte)0xFF;
s4_CreateDirInfo.szAtr[5] = (byte)0xFF;
s4_CreateDirInfo.szAtr[6] = (byte)0xFF;
s4_CreateDirInfo.szAtr[7] = (byte)0xFF;
ret = lib.S4CreateDirEx(s4_context[0], "\\", 0, lib.S4_CREATE_ROOT_DIR,s4_CreateDirInfo);
checkS4ExceptionResult(ret, "Create MF");
errorCount += ret;
ret = lib.S4VerifyPin (s4_context[0], "123456781234567812345678", 24, lib.S4_DEV_PIN );
checkS4ExceptionResult(ret, "Verify Dev Pin");
errorCount += ret;
// write bin file ef21
File demofile = new File("ReadData.bin");
long contentsize = demofile.length ();
byte [] content = new byte[1];
try
{
FileInputStream is = new FileInputStream (demofile);
content = new byte[(int)contentsize];
is.read(content, 0, (int)contentsize);
is.close();
}
catch(Exception e)
{
System.out.println("error: read hex bing file ");
}
ret = lib.S4WriteFile (s4_context[0], "ef21", 0, content, (int)contentsize, (int)contentsize + 20, lpBytesReturned,
lib.S4_CREATE_NEW , lib.S4_EXE_FILE );
checkS4ExceptionResult(ret, "Write hex bin file");
errorCount += ret;
// write data file bf21
byte[] data_file = new byte[0x6000];
ret = lib.S4WriteFile (s4_context[0], "bf21", 0, data_file, (int)data_file.length, (int)data_file.length + 20, lpBytesReturned,
lib.S4_CREATE_NEW , lib.S4_DATA_FILE );
checkS4ExceptionResult(ret, "Write data file");
errorCount += ret;
ret = lib.S4Control (s4_context[0], lib.S4_LED_DOWN, null, 0, null, 0, lpBytesReturned);
checkS4ExceptionResult(ret, "LED Down");
errorCount += ret;
ret = lib.S4Close(s4_context[0]);
checkS4ExceptionResult(ret, "Close Sense4");
errorCount += ret;
return errorCount == 0;
}
public byte[] readEliteSerial() {
byte[] serial = new byte[8];
int ret = lib.S4Control(ctx, lib.S4_GET_SERIAL_NUMBER, null, 0, serial, 8, null);
if (ret != 0) {
System.out.println("S4_GET_SERIAL_NUMBER: " + ret);
}
return serial;
}
private static void checkS4ExceptionResult(int ret, String info) {
if (ret != 0) {
System.out.println("Error Code: " + ret + " Info:" + info);
} else {
System.out.println("Success: " + info);
}
}
}

274
fine-sense4/src/Sense4/EliteLockIO64.java

@ -0,0 +1,274 @@
package Sense4;
import java.io.File;
import java.io.FileInputStream;
import Sense4.Sense64.S4CREATEDIRINFO;
import Sense4.Sense64.S4OPENINFO;
import Sense4.Sense64.SENSE4_CONTEXT;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.LongByReference;
/**
* @author Lanlan
* @date 2018/11/25
*/
public class EliteLockIO64 implements EliteLockIO {
public static final int MAX_BUFF_SIZE = 0xf0;
public static final byte WRITE = 0;
public static final byte READ = 1;
public SENSE4_CONTEXT ctx= new SENSE4_CONTEXT();//[] = new Sense4.SENSE4_CONTEXT[2];
public Sense64 lib = Sense64.instance;
public EliteLockIO64() {}
public void initS4(boolean changeDir) {
LongByReference pSize = new LongByReference(0);
long ret = lib.S4Enum(ctx, pSize);
ret = lib.S4Enum(ctx, pSize);
if(ret!=0)
{
System.out.println("List列举设备失败!" + ret);
}
ret = lib.S4Open(ctx);
if(ret!=0)
{
System.out.println("Open打开设备失败!" + ret);
}
if (changeDir) {
ret = lib.S4ChangeDir(ctx, "\\");
if(ret!=0)
{
System.out.println("Change切换目录失败!" + ret);
lib.S4Close(ctx);
}
ret = lib.S4VerifyPin(ctx, "12345678", 8, lib.S4_USER_PIN);
if(ret!=0)
{
System.out.println("Verify校验用户pin失败!" + ret);
lib.S4Close(ctx);
}
}
}
public void closeS4() {
long ret = lib.S4Close(ctx);
if(ret!=0)
{
System.out.println("Close关闭设备失败!" + ret);
}
}
public boolean write_internal_file(int offset, int write_len, byte[] write_bytes) {
int write_offset = offset;
int old_offset = write_offset;
byte inBuffer[]=new byte[0xf8];
byte outBuffer[]=new byte[0xf8];
IntByReference pdwByteOut = new IntByReference(0);
inBuffer[0]=WRITE;
while (write_len > 0) {
old_offset = write_offset;
inBuffer[2]=(byte)((write_offset >> 8) & 0xFF);
inBuffer[3]=(byte)(write_offset & 0xFF);
if (write_len <= MAX_BUFF_SIZE) {
System.arraycopy(write_bytes, old_offset - offset, inBuffer, 4, write_len);
inBuffer[1] = (byte)(write_len & 0xFF);
write_len = 0;
write_offset += write_len;
} else {
System.arraycopy(write_bytes, old_offset - offset, inBuffer, 4, MAX_BUFF_SIZE);
inBuffer[1] = (byte)MAX_BUFF_SIZE;
write_len -= MAX_BUFF_SIZE;
write_offset += MAX_BUFF_SIZE;
}
int ret = lib.S4Execute(ctx,"ef21",inBuffer,0xf8,outBuffer,0xf8, pdwByteOut);
if(ret!=0)
{
System.out.println("执行锁内程序失败!");
lib.S4Close(ctx);
return false;
}
}
return true;
}
public byte[] read_internal_file(int offset, int read_len) {
int read_offset = offset;
int old_offset = read_offset;
byte[] out = new byte[read_len];
IntByReference pdwByteOut = new IntByReference(0);
byte inBuffer[]=new byte[0xf8];
byte outBuffer[]=new byte[0xf8];
inBuffer[0]=READ;
while (read_len > 0) {
old_offset = read_offset;
inBuffer[2]=(byte)((read_offset >> 8) & 0xFF);
inBuffer[3]=(byte)(read_offset & 0xFF);
if (read_len <= MAX_BUFF_SIZE) {
inBuffer[1] = (byte)read_len;
read_len = 0;
read_offset += read_len;
} else {
inBuffer[1] = (byte)MAX_BUFF_SIZE;
read_len -= MAX_BUFF_SIZE;
read_offset += MAX_BUFF_SIZE;
}
long ret = lib.S4Execute(ctx, "ef21",inBuffer,0xf8,outBuffer,0xf8,pdwByteOut);
if(ret!=0 || pdwByteOut.getValue() < inBuffer[1])
{
System.out.println("执行锁内程序失败!");
lib.S4Close(ctx);
} else {
System.arraycopy(outBuffer, 0, out, old_offset - offset, (int)pdwByteOut.getValue());
}
}
return out;
}
public boolean uploadHexExeFile() {
Sense64 lib = Sense64.instance;
LongByReference pSize = new LongByReference(0);
long ret = 0;
long errorCount = 0;
LongByReference lpBytesReturned = new LongByReference(0);
SENSE4_CONTEXT[] s4_context = new SENSE4_CONTEXT[0];
ret = lib.S4Enum(null, pSize);
s4_context = new SENSE4_CONTEXT[(int)pSize.getValue() / 92];
for (int i = 0;i< pSize.getValue() / 92; i++){
s4_context[i] = new SENSE4_CONTEXT();
}
ret = lib.S4Enum(s4_context[0], pSize);
checkS4ExceptionResult(ret, "Enumerate Sense4");
errorCount += ret;
S4OPENINFO s4_OpenInfo = new S4OPENINFO();
s4_OpenInfo.dwS4OpenInfoSize = 8;
s4_OpenInfo.dwShareMode = lib.S4_EXCLUSIZE_MODE;
ret = lib.S4OpenEx(s4_context[0], s4_OpenInfo);
checkS4ExceptionResult(ret, "Open Sense4");
errorCount += ret;
byte [] frequency = {0x04};
ret = lib.S4Control(s4_context[0], lib.S4_LED_WINK, frequency, 1, null, 0, lpBytesReturned);
checkS4ExceptionResult(ret, "Sense4 LED wink");
errorCount += ret;
ret = lib.S4ChangeDir (s4_context[0], "\\");
checkS4ExceptionResult(ret, "Change Dir");
errorCount += ret;
ret = lib.S4VerifyPin(s4_context[0], "123456781234567812345678", 24, lib.S4_DEV_PIN);
checkS4ExceptionResult(ret, "Verify dev pin");
errorCount += ret;
ret = lib.S4EraseDir(s4_context[0], null);
checkS4ExceptionResult(ret, "Erase MF");
errorCount += ret;
S4CREATEDIRINFO s4_CreateDirInfo = new S4CREATEDIRINFO();
s4_CreateDirInfo.dwS4CreateDirInfoSize = 12;
s4_CreateDirInfo.szAtr[0] = (byte)0xFF;
s4_CreateDirInfo.szAtr[1] = (byte)0xFF;
s4_CreateDirInfo.szAtr[2] = (byte)0xFF;
s4_CreateDirInfo.szAtr[3] = (byte)0xFF;
s4_CreateDirInfo.szAtr[4] = (byte)0xFF;
s4_CreateDirInfo.szAtr[5] = (byte)0xFF;
s4_CreateDirInfo.szAtr[6] = (byte)0xFF;
s4_CreateDirInfo.szAtr[7] = (byte)0xFF;
ret = lib.S4CreateDirEx(s4_context[0], "\\", 0, lib.S4_CREATE_ROOT_DIR,s4_CreateDirInfo);
checkS4ExceptionResult(ret, "Create MF");
errorCount += ret;
ret = lib.S4VerifyPin (s4_context[0], "123456781234567812345678", 24, lib.S4_DEV_PIN );
checkS4ExceptionResult(ret, "Verify Dev Pin");
errorCount += ret;
// write bin file ef21
File demofile = new File("ReadData.bin");
long contentsize = demofile.length ();
byte [] content = new byte[1];
try
{
FileInputStream is = new FileInputStream (demofile);
content = new byte[(int)contentsize];
is.read(content, 0, (int)contentsize);
is.close();
}
catch(Exception e)
{
e.printStackTrace();
System.out.println("error: read hex bing file ");
}
ret = lib.S4WriteFile (s4_context[0], "ef21", 0, content, (int)contentsize, (int)contentsize + 20, lpBytesReturned,
lib.S4_CREATE_NEW , lib.S4_EXE_FILE );
checkS4ExceptionResult(ret, "Write hex bin file");
errorCount += ret;
// write data file bf21
byte[] data_file = new byte[0x6000];
ret = lib.S4WriteFile (s4_context[0], "bf21", 0, data_file, (int)data_file.length, (int)data_file.length + 20, lpBytesReturned,
lib.S4_CREATE_NEW , lib.S4_DATA_FILE );
checkS4ExceptionResult(ret, "Write data file");
errorCount += ret;
ret = lib.S4Control (s4_context[0], lib.S4_LED_DOWN, null, 0, null, 0, lpBytesReturned);
checkS4ExceptionResult(ret, "LED Down");
errorCount += ret;
ret = lib.S4Close(s4_context[0]);
checkS4ExceptionResult(ret, "Close Sense4");
errorCount += ret;
return errorCount == 0;
}
private static void checkS4ExceptionResult(long ret, String info) {
if (ret != 0) {
System.out.println("Error Code: " + ret + " Info:" + info);
} else {
System.out.println("Success: " + info);
}
}
public byte[] readEliteSerial() {
byte[] serial = new byte[8];
long ret = lib.S4Control(ctx, lib.S4_GET_SERIAL_NUMBER, null, 0, serial, 8, null);
if (ret != 0) {
System.out.println("S4_GET_SERIAL_NUMBER: " + ret);
}
return serial;
}
}

65
fine-sense4/src/Sense4/LockUtils.java

@ -0,0 +1,65 @@
package Sense4;
/**
* @author Lanlan
* @date 2018/11/25
*/
public abstract class LockUtils {
private static EliteLockIO intance;
public static boolean isJVMSystem32() {
String arch_model = System.getProperty("sun.arch.data.model");
return "32".equals(arch_model);
}
// big-endian
public static byte[] intToByteArray1(int i) {
byte[] result = new byte[4];
result[0] = (byte)((i >> 24) & 0xFF);
result[1] = (byte)((i >> 16) & 0xFF);
result[2] = (byte)((i >> 8) & 0xFF);
result[3] = (byte)(i & 0xFF);
return result;
}
// big-endian
public static int byteArray2Int(byte[] bytes) {
int res = 0;
res += (bytes[0] & 0xff) << 24;
res += (bytes[1] & 0xff) << 16;
res += (bytes[2] & 0xff)<< 8;
res += bytes[3] & 0xff;
return res;
}
public static String toHexString(byte[] b) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < b.length; i++) {
String hex = Integer.toHexString(b[i] & 0xFF);
if (hex.length() == 1) {
hex = "0" + hex;
}
sb.append(hex);
}
return sb.toString();
}
public static void main(String[] args) {
System.out.println("System is 32-bit: " + isJVMSystem32());
}
public static EliteLockIO getEliteLockIOInstance() {
if (intance == null) {
if (isJVMSystem32()) {
intance = new EliteLockIO32();
} else {
intance = new EliteLockIO64();
}
}
return intance;
}
}

218
fine-sense4/src/Sense4/Sense32.java

@ -0,0 +1,218 @@
package Sense4;
import com.sun.jna.Native;
import com.sun.jna.Structure;
import com.sun.jna.ptr.IntByReference;
import java.util.ArrayList;
import java.util.List;
public interface Sense32 extends com.sun.jna.Library
{
Sense32 instance = (Sense32) Native.loadLibrary("Sense32.dll", Sense32.class);
public static final int S4_USER_PIN = 0x000000a1;
public static final int S4_DEV_PIN = 0x000000a2;
public static final int S4_AUTHEN_PIN = 0x000000a3;
public static final int S4_CREATE_NEW = 0x000000a5;
public static final int S4_UPDATE_FILE = 0x000000a6;
// #define S4_EXE_FILE 0x00000008 /** executable file of virtual machine*/
public static final byte S4_EXE_FILE = 0x00000008;
public static final byte S4_DATA_FILE = 0x00000009;
public static final int S4_FILE_EXIST = 0x00006a80;
// #define S4_LED_DOWN 0x00000008 /** LED down*/
public static final int S4_LED_DOWN = 0x00000008;
// #define S4_LED_WINK 0x00000028 /** LED wink*/
public static final int S4_LED_WINK = 0x00000028;
public static final int S4_GET_SERIAL_NUMBER = 0x00000026;
// #define S4_EXCLUSIZE_MODE 0 /** exclusive mode*/
// #define S4_SHARE_MODE 1 /** sharable mode*/
public static final int S4_EXCLUSIZE_MODE = 0x00000000;
public static final int S4_SHARE_MODE = 0x00000001;
// #define S4_CREATE_ROOT_DIR 0x000000ab /** create root directory*/
public static final int S4_CREATE_ROOT_DIR = 0x000000ab;
public static class RTC_TIME_T extends Structure
{
public byte second; /* second (0-59) */
public byte minute; /* minute (0-59) */
public byte hour; /* hour (0-23) */
public byte day; /* day of month (1-31) */
public byte week; /* day of week (0-6, sunday is 0) */
public byte month; /* month (0-11) */
public short year; /* year (0- 138, 1900 - 2038) */
protected List<String> getFieldOrder() {
List<String> list = new ArrayList<String>();
list.add("second");
list.add("minute");
list.add("hour");
list.add("day");
list.add("week");
list.add("month");
list.add("year");
return list;
}
}
public static class SENSE4_CONTEXT extends Structure {
public int dwIndex; /** device index; index begins at zero*/
public int dwVersion; /** device version*/
public int hLock; /** device handle*/
public byte[] reserve = new byte[12*2]; /** reserved*/
public byte[] bAtr = new byte[56]; /** ATR*/
public byte[] bID = new byte[8]; /** device ID*/
public int dwAtrLen; /** ATR length*/
protected List<String> getFieldOrder() {
List<String> list = new ArrayList<String>();
list.add("dwIndex");
list.add("dwVersion");
list.add("hLock");
list.add("reserve");
list.add("bAtr");
list.add("bID");
list.add("dwAtrLen");
return list;
}
}
/** Netlock Module infomation definition*/
// typedef struct _S4MODULEINFO {
// WORD wModuleID; /* Module ID*/
// WORD wLicenseCount; /* License Count */
// } S4MODULEINFO;
public static class S4MODULEINFO extends Structure {
public short wModuleID;
public short wLicenseCount;
protected List<String> getFieldOrder() {
List<String> list = new ArrayList<String>();
list.add("wModuleID");
list.add("wLicenseCount");
return list;
}
}
// typedef struct _S4NETCONFIG {
// DWORD dwLicenseMode; /* License Mode */
// DWORD dwModuleCount; /* Module Count */
// S4MODULEINFO ModuleInfo[16]; /* Module detail infomation */
// } S4NETCONFIG;
public static class S4NETCONFIG extends Structure {
public int dwLicenseMode;
public int dwModuleCount;
public S4MODULEINFO[] ModuleInfo = new S4MODULEINFO[16];
protected List<String> getFieldOrder() {
List<String> list = new ArrayList<String>();
list.add("dwLicenseMode");
list.add("dwModuleCount");
list.add("ModuleInfo");
return list;
}
}
// S4CREATEDIRINFO structure definition
// typedef struct _S4CREATEDIRINFO {
// DWORD dwS4CreateDirInfoSize; /* size of the structure*/
// BYTE szAtr[8]; /* ATR information */
// S4NETCONFIG NetConfig; /* netlock config infomation */
// } S4CREATEDIRINFO;
public static class S4CREATEDIRINFO extends Structure {
public int dwS4CreateDirInfoSize;
public byte[] szAtr = new byte[8];
public S4NETCONFIG NetConfig;
protected List<String> getFieldOrder() {
List<String> list = new ArrayList<String>();
list.add("dwS4CreateDirInfoSize");
list.add("szAtr");
list.add("NetConfig");
return list;
}
}
// typedef struct _S4OPENINFO {
// DWORD dwS4OpenInfoSize; /* size of the structure*/
// DWORD dwShareMode; /* share mode*/
// } S4OPENINFO;
public static class S4OPENINFO extends Structure {
public int dwS4OpenInfoSize;
public int dwShareMode;
protected List<String> getFieldOrder() {
List<String> list = new ArrayList<String>();
list.add("dwS4OpenInfoSize");
list.add("dwShareMode");
return list;
}
}
public int S4Enum(SENSE4_CONTEXT ctx, IntByReference pSize);
public int S4Open(SENSE4_CONTEXT ctx);
// DWORD WINAPI S4Control(
// IN SENSE4_CONTEXT *pS4Ctx,
// IN DWORD dwCtlCode,
// IN VOID *pInBuffer,
// IN DWORD dwInBufferLen,
// OUT VOID *pOutBuffer,
// IN DWORD dwOutBufferLen,
// OUT DWORD *pdwBytesReturned
// );
public int S4Control(
SENSE4_CONTEXT ctx,
int dwCtlCode,
byte[] pInBuffer,
int dwInBufferLen,
byte[] pOutBuffer,
int dwOutBufferLen,
IntByReference pdwBytesReturned
);
public int S4ChangeDir(SENSE4_CONTEXT ctx, String dir);
//
public int S4EraseDir(SENSE4_CONTEXT ctx, String dir);
public int S4VerifyPin(SENSE4_CONTEXT ctx, String passwd, int passwdLen, int type);
public int S4WriteFile(SENSE4_CONTEXT ctx,
String lpszFileID,
int dwOffset,
byte lpBuffer[],
int dwBufferSize,
int dwFileSize,
IntByReference pdwBytesWritten,
int dwFlags,
byte bFileType);
public int S4Execute(SENSE4_CONTEXT ctx, String fileID, byte[] inputBuf, int inputSize, byte[] outputBuf, int outputSize, IntByReference pSize);
public int S4Close(SENSE4_CONTEXT ctx);
// DWORD WINAPI S4CreateDirEx(
// IN SENSE4_CONTEXT *pS4Ctx,
// IN LPCSTR lpszDirID,
// IN DWORD dwDirSize,
// IN DWORD dwFlags,
// IN S4CREATEDIRINFO *pCreateDirInfo
// );
public int S4CreateDirEx(
SENSE4_CONTEXT ctx,
String lpszDirID,
int dwDirSize,
int dwFlags,
S4CREATEDIRINFO pCreateDirInfo
);
// DWORD WINAPI S4OpenEx(
// IN OUT SENSE4_CONTEXT *pS4Ctx,
// IN S4OPENINFO *pS4OpenInfo
// );
public int S4OpenEx(SENSE4_CONTEXT ctx, S4OPENINFO pS4OpenInfo);
}

219
fine-sense4/src/Sense4/Sense64.java

@ -0,0 +1,219 @@
package Sense4;
import com.sun.jna.Native;
import com.sun.jna.Structure;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.LongByReference;
import java.util.ArrayList;
import java.util.List;
public interface Sense64 extends com.sun.jna.Library
{
Sense64 instance = (Sense64) Native.loadLibrary("Sense64.dll", Sense64.class);
public static final long S4_USER_PIN = 0x000000a1;
public static final long S4_DEV_PIN = 0x000000a2;
public static final long S4_AUTHEN_PIN = 0x000000a3;
public static final long S4_CREATE_NEW = 0x000000a5;
public static final long S4_UPDATE_FILE = 0x000000a6;
// #define S4_EXE_FILE 0x00000008 /** executable file of virtual machine*/
public static final byte S4_EXE_FILE = 0x00000008;
public static final byte S4_DATA_FILE = 0x00000009;
public static final long S4_FILE_EXIST = 0x00006a80;
// #define S4_LED_DOWN 0x00000008 /** LED down*/
public static final long S4_LED_DOWN = 0x00000008;
// #define S4_LED_WINK 0x00000028 /** LED wink*/
public static final long S4_LED_WINK = 0x00000028;
public static final long S4_GET_SERIAL_NUMBER = 0x00000026;
// #define S4_EXCLUSIZE_MODE 0 /** exclusive mode*/
// #define S4_SHARE_MODE 1 /** sharable mode*/
public static final long S4_EXCLUSIZE_MODE = 0x00000000;
public static final long S4_SHARE_MODE = 0x00000001;
// #define S4_CREATE_ROOT_DIR 0x000000ab /** create root directory*/
public static final long S4_CREATE_ROOT_DIR = 0x000000ab;
public static class RTC_TIME_T extends Structure
{
public byte second; /* second (0-59) */
public byte minute; /* minute (0-59) */
public byte hour; /* hour (0-23) */
public byte day; /* day of month (1-31) */
public byte week; /* day of week (0-6, sunday is 0) */
public byte month; /* month (0-11) */
public short year; /* year (0- 138, 1900 - 2038) */
protected List<String> getFieldOrder() {
List<String> list = new ArrayList<String>();
list.add("second");
list.add("minute");
list.add("hour");
list.add("day");
list.add("week");
list.add("month");
list.add("year");
return list;
}
}
public static class SENSE4_CONTEXT extends Structure {
public long dwIndex; /** device index; index begins at zero*/
public long dwVersion; /** device version*/
public long hLock; /** device handle*/
public byte[] reserve = new byte[12*2]; /** reserved*/
public byte[] bAtr = new byte[56]; /** ATR*/
public byte[] bID = new byte[8]; /** device ID*/
public long dwAtrLen; /** ATR length*/
protected List<String> getFieldOrder() {
List<String> list = new ArrayList<String>();
list.add("dwIndex");
list.add("dwVersion");
list.add("hLock");
list.add("reserve");
list.add("bAtr");
list.add("bID");
list.add("dwAtrLen");
return list;
}
}
/** Netlock Module infomation definition*/
// typedef struct _S4MODULEINFO {
// WORD wModuleID; /* Module ID*/
// WORD wLicenseCount; /* License Count */
// } S4MODULEINFO;
public static class S4MODULEINFO extends Structure {
public int wModuleID;
public int wLicenseCount;
protected List<String> getFieldOrder() {
List<String> list = new ArrayList<String>();
list.add("wModuleID");
list.add("wLicenseCount");
return list;
}
}
// typedef struct _S4NETCONFIG {
// DWORD dwLicenseMode; /* License Mode */
// DWORD dwModuleCount; /* Module Count */
// S4MODULEINFO ModuleInfo[16]; /* Module detail infomation */
// } S4NETCONFIG;
public static class S4NETCONFIG extends Structure {
public long dwLicenseMode;
public long dwModuleCount;
public S4MODULEINFO[] ModuleInfo = new S4MODULEINFO[16];
protected List<String> getFieldOrder() {
List<String> list = new ArrayList<String>();
list.add("dwLicenseMode");
list.add("dwModuleCount");
list.add("ModuleInfo");
return list;
}
}
// S4CREATEDIRINFO structure definition
// typedef struct _S4CREATEDIRINFO {
// DWORD dwS4CreateDirInfoSize; /* size of the structure*/
// BYTE szAtr[8]; /* ATR information */
// S4NETCONFIG NetConfig; /* netlock config infomation */
// } S4CREATEDIRINFO;
public static class S4CREATEDIRINFO extends Structure {
public long dwS4CreateDirInfoSize;
public byte[] szAtr = new byte[8];
public S4NETCONFIG NetConfig;
protected List<String> getFieldOrder() {
List<String> list = new ArrayList<String>();
list.add("dwS4CreateDirInfoSize");
list.add("szAtr");
list.add("NetConfig");
return list;
}
}
// typedef struct _S4OPENINFO {
// DWORD dwS4OpenInfoSize; /* size of the structure*/
// DWORD dwShareMode; /* share mode*/
// } S4OPENINFO;
public static class S4OPENINFO extends Structure {
public long dwS4OpenInfoSize;
public long dwShareMode;
protected List<String> getFieldOrder() {
List<String> list = new ArrayList<String>();
list.add("dwS4OpenInfoSize");
list.add("dwShareMode");
return list;
}
}
public long S4Enum(SENSE4_CONTEXT ctx, LongByReference pSize);
public long S4Open(SENSE4_CONTEXT ctx);
// DWORD WINAPI S4Control(
// IN SENSE4_CONTEXT *pS4Ctx,
// IN DWORD dwCtlCode,
// IN VOID *pInBuffer,
// IN DWORD dwInBufferLen,
// OUT VOID *pOutBuffer,
// IN DWORD dwOutBufferLen,
// OUT DWORD *pdwBytesReturned
// );
public long S4Control(
SENSE4_CONTEXT ctx,
long dwCtlCode,
byte[] pInBuffer,
long dwInBufferLen,
byte[] pOutBuffer,
long dwOutBufferLen,
LongByReference pdwBytesReturned
);
public long S4ChangeDir(SENSE4_CONTEXT ctx, String dir);
//
public long S4EraseDir(SENSE4_CONTEXT ctx, String dir);
public long S4VerifyPin(SENSE4_CONTEXT ctx, String passwd, long passwdLen, long type);
public long S4WriteFile(SENSE4_CONTEXT ctx,
String lpszFileID,
long dwOffset,
byte lpBuffer[],
long dwBufferSize,
long dwFileSize,
LongByReference pdwBytesWritten,
long dwFlags,
byte bFileType);
public int S4Execute(Sense64.SENSE4_CONTEXT ctx, String fileID, byte[] inputBuf, int inputSize, byte[] outputBuf, int outputSize, IntByReference pSize);
public long S4Close(SENSE4_CONTEXT ctx);
// DWORD WINAPI S4CreateDirEx(
// IN SENSE4_CONTEXT *pS4Ctx,
// IN LPCSTR lpszDirID,
// IN DWORD dwDirSize,
// IN DWORD dwFlags,
// IN S4CREATEDIRINFO *pCreateDirInfo
// );
public long S4CreateDirEx(
SENSE4_CONTEXT ctx,
String lpszDirID,
long dwDirSize,
long dwFlags,
S4CREATEDIRINFO pCreateDirInfo
);
// DWORD WINAPI S4OpenEx(
// IN OUT SENSE4_CONTEXT *pS4Ctx,
// IN S4OPENINFO *pS4OpenInfo
// );
public long S4OpenEx(SENSE4_CONTEXT ctx, S4OPENINFO pS4OpenInfo);
}

690
fine-sense4/src/Sense4/sense4.h

@ -0,0 +1,690 @@
/**************************************************************************************
* Copyright (c) 2008, Senselock Software Technology Co., Ltd
* All rights reserved.
*
* filename: sense4.h
*
* briefs: EliteIV library interface declaration, return value and some constant definition.
*
* date: 2008.04.08
* version: 3.1
*******************************************************************************************/
#ifndef __SENSE4_H__
#define __SENSE4_H__
#ifdef _MSC_VER
#pragma comment(linker, "/defaultlib:setupapi.lib")
#endif
#ifdef __cplusplus
extern "C" {
#endif
#if defined WIN32 || defined _WIN32 || defined _WIN64
#include <windows.h>
typedef HANDLE S4HANDLE;
#elif defined __MACH__
typedef io_connect_t S4HANDLE;
#else
typedef void* S4HANDLE;
#endif /* defined WIN32 || defined _WIN32 || defined _WIN64 */
#ifndef IN
#define IN
#endif
#ifndef OUT
#define OUT
#endif
#if !defined _WINDOWS_
#define WINAPI
#define CONST const
typedef unsigned char UCHAR;
typedef unsigned short USHORT;
typedef unsigned int UINT;
typedef unsigned long ULONG;
typedef char CHAR;
typedef char TCHAR;
typedef void VOID;
#ifndef _BYTE_DEFINED
#define _BYTE_DEFINED
typedef unsigned char BYTE;
#endif
#ifndef _WORD_DEFINED
#define _WORD_DEFINED
typedef unsigned short WORD;
#endif
#ifndef _DWORD_DEFINED
#define _DWORD_DEFINED
typedef unsigned long DWORD;
#endif
typedef VOID* LPVOID;
typedef CHAR* LPSTR;
typedef CONST CHAR* LPCSTR;
typedef CONST TCHAR* LPCTSTR;
typedef BYTE* LPBYTE;
typedef WORD* LPWORD;
typedef DWORD* LPDWORD;
#endif /* !defined _WINDOWS */
//@{
/**
device share mode definition
*/
#define S4_EXCLUSIZE_MODE 0 /** exclusive mode*/
#define S4_SHARE_MODE 1 /** sharable mode*/
//@}
//@{
/**
the control code value definition
*/
#define S4_LED_UP 0x00000004 /** LED up*/
#define S4_LED_DOWN 0x00000008 /** LED down*/
#define S4_LED_WINK 0x00000028 /** LED wink*/
#define S4_GET_DEVICE_TYPE 0x00000025 /** get the device type*/
#define S4_GET_SERIAL_NUMBER 0X00000026 /** get the device serial number*/
#define S4_GET_VM_TYPE 0X00000027 /** get the virtual machine type*/
#define S4_GET_DEVICE_USABLE_SPACE 0x00000029 /** get the total space of the device*/
#define S4_SET_DEVICE_ID 0x0000002a /** set the device ID*/
#define S4_RESET_DEVICE 0x00000002 /** reset the device*/
#define S4_DF_AVAILABLE_SPACE 0x00000031 /** get the free space of current directory*/
#define S4_EF_INFO 0x00000032 /** get specified file information in current directory*/
#define S4_SET_USB_MODE 0x00000041 /** set the device as a normal usb device*/
#define S4_SET_HID_MODE 0x00000042 /** set the device as a HID device*/
#define S4_GET_CUSTOMER_NAME 0x0000002b /** get the customer number*/
#define S4_GET_MANUFACTURE_DATE 0x0000002c /** get the manufacture date of the device*/
#define S4_GET_CURRENT_TIME 0x0000002d /** get the current time of the clock device*/
#define S4_SET_NET_CONFIG 0x00000030 /** set netlock config */
//@}
//@}
//@{
/**
device type definition
*/
#define S4_LOCAL_DEVICE 0x00 /** local device*/
#define S4_MASTER_DEVICE 0x01 /** net master device*/
#define S4_SLAVE_DEVICE 0x02 /** net slave device*/
//@}
//@{
/**
virtual machine type definition
*/
#define S4_VM_51 0x00 /** inter 51*/
#define S4_VM_251_BINARY 0x01 /** inter 251, binary mode*/
#define S4_VM_251_SOURCE 0X02 /** inter 251, source mode*/
//@}
//@{
/**
NetLock license mode
*/
#define S4_MODULE_MODE 0x00000000 /** Module mode*/
#define S4_IP_MODE 0x00000001 /** IP mode*/
//@}
//@{
/**
PIN and key type definition
*/
#define S4_USER_PIN 0x000000a1 /** user PIN*/
#define S4_DEV_PIN 0x000000a2 /** developer PIN*/
#define S4_AUTHEN_PIN 0x000000a3 /** authentication key of net device*/
//@}
//@{
/**
file type definition
*/
#define S4_RSA_PUBLIC_FILE 0x00000006 /** RSA public key file*/
#define S4_RSA_PRIVATE_FILE 0x00000007 /** RSA private key file*/
#define S4_EXE_FILE 0x00000008 /** executable file of virtual machine*/
#define S4_DATA_FILE 0x00000009 /** data file*/
#define S4_XA_EXE_FILE 0x0000000b /** executable file of XA User mode*/
//@}
//@{
/**
flag value definition
*/
#define S4_CREATE_NEW 0x000000a5 /** create a new file*/
#define S4_UPDATE_FILE 0x000000a6 /** write data to the specified file*/
#define S4_KEY_GEN_RSA_FILE 0x000000a7 /** generate RSA key pair files*/
#define S4_SET_LICENCES 0x000000a8 /** set the max license number of the current module for the net device*/
#define S4_CREATE_ROOT_DIR 0x000000ab /** create root directory*/
#define S4_CREATE_SUB_DIR 0x000000ac /** create child directory for current directory*/
#define S4_CREATE_MODULE 0x000000ad /** create a module directory for the net device */
/** the following three flags can only be used when creating a new executable file */
#define S4_FILE_READ_WRITE 0x00000000 /** the new executable file can be read and written by executable file */
#define S4_FILE_EXECUTE_ONLY 0x00000100 /** the new executable file can't be read or written by executable file*/
#define S4_CREATE_PEDDING_FILE 0x00002000 /** create a padding file*/
//@}
//@{
/**
execuable file executing mode definition
*/
#define S4_VM_EXE 0x00000000 /** executing on virtual machine*/
#define S4_XA_EXE 0x00000001 /** executing on XA User mode */
//@}
//@{
/**
return value definition
*/
#define S4_SUCCESS 0x00000000 /** success*/
#define S4_UNPOWERED 0x00000001 /** the device has been powered off*/
#define S4_INVALID_PARAMETER 0x00000002 /** invalid parameter*/
#define S4_COMM_ERROR 0x00000003 /** communication error*/
#define S4_PROTOCOL_ERROR 0x00000004 /** communication protocol error*/
#define S4_DEVICE_BUSY 0x00000005 /** the device is busy*/
#define S4_KEY_REMOVED 0x00000006 /** the device has been removed */
#define S4_INSUFFICIENT_BUFFER 0x00000011 /** the input buffer is insufficient*/
#define S4_NO_LIST 0x00000012 /** find no device*/
#define S4_GENERAL_ERROR 0x00000013 /** general error, commonly indicates not enough memory*/
#define S4_UNSUPPORTED 0x00000014 /** the function isn't supported*/
#define S4_DEVICE_TYPE_MISMATCH 0x00000020 /** the device type doesn't match*/
#define S4_FILE_SIZE_CROSS_7FFF 0x00000021 /** the execuable file crosses address 0x7FFF*/
#define S4_CURRENT_DF_ISNOT_MF 0x00000201 /** a net module must be child directory of the root directory*/
#define S4_INVAILABLE_MODULE_DF 0x00000202 /** the current directory is not a module*/
#define S4_FILE_SIZE_TOO_LARGE 0x00000203 /** the file size is beyond address 0x7FFF*/
#define S4_DF_SIZE 0x00000204 /** the specified directory size is too small*/
#define S4_DEVICE_UNSUPPORTED 0x00006a81 /** the request can't be supported by the device*/
#define S4_FILE_NOT_FOUND 0x00006a82 /** the specified file or directory can't be found */
#define S4_INSUFFICIENT_SECU_STATE 0x00006982 /** the security state doesn't match*/
#define S4_DIRECTORY_EXIST 0x00006901 /** the specified directory has already existed*/
#define S4_FILE_EXIST 0x00006a80 /** the specified file or directory has already existed*/
#define S4_INSUFFICIENT_SPACE 0x00006a84 /** the space is insufficient*/
#define S4_OFFSET_BEYOND 0x00006B00 /** the offset is beyond the file size*/
#define S4_PIN_BLOCK 0x00006983 /** the specified pin or key has been locked*/
#define S4_FILE_TYPE_MISMATCH 0x00006981 /** the file type doesn't match*/
#define S4_CRYPTO_KEY_NOT_FOUND 0x00009403 /** the specified pin or key cann't be found*/
#define S4_APPLICATION_TEMP_BLOCK 0x00006985 /** the directory has been temporarily locked*/
#define S4_APPLICATION_PERM_BLOCK 0x00009303 /** the directory has been locked*/
#define S4_DATA_BUFFER_LENGTH_ERROR 0x00006700 /** invalid data length*/
#define S4_CODE_RANGE 0x00010000 /** the PC register of the virtual machine is out of range*/
#define S4_CODE_RESERVED_INST 0x00020000 /** invalid instruction*/
#define S4_CODE_RAM_RANGE 0x00040000 /** internal ram address is out of range*/
#define S4_CODE_BIT_RANGE 0x00080000 /** bit address is out of range*/
#define S4_CODE_SFR_RANGE 0x00100000 /** SFR address is out of range*/
#define S4_CODE_XRAM_RANGE 0x00200000 /** external ram address is out of range*/
#define S4_ERROR_UNKNOWN 0xffffffff /** unknown error*/
//@}
#define MAX_ATR_LEN 56 /** max ATR length */
#define MAX_ID_LEN 8 /** max device ID length */
#define S4_RSA_MODULUS_LEN 128 /** RSA key modules length,in bytes */
#define S4_RSA_PRIME_LEN 64 /** RSA key prime length,in bytes*/
//@{
/**
structure definition
*/
/* file information definition*/
typedef struct{
WORD EfID; /* file ID*/
BYTE EfType; /* file type*/
WORD EfSize; /* file size*/
}EFINFO,*PEFINFO;
/* device production date structure definition*/
typedef struct {
WORD wYear; /* year*/
BYTE byMonth; /* month*/
BYTE byDay; /* the day of the month */
}S4_MANUFACTURE_DATE;
/* current time structure definition*/
#ifndef _TM_DEFINED
typedef struct {
int tm_sec; /* seconds after the minute - [0,59] */
int tm_min; /* minutes after the hour - [0,59] */
int tm_hour; /* hours since midnight - [0,23] */
int tm_mday; /* day of the month - [1,31] */
int tm_mon; /* months since January - [0,11] */
int tm_year; /* years since 1900 */
int tm_wday; /* days since Sunday - [0,6] */
int tm_yday; /* days since January 1 - [0,365] */
int tm_isdst; /* daylight savings time flag */
} TM;
#define _TM_DEFINED
#endif
/**
device version definition
*/
typedef enum{
SENSE4_CARD_TYPE_V2_00 = 0x00020000, /** version 2.00*/
SENSE4_CARD_TYPE_V2_01 = 0x00020001, /** version 2.10*/
SENSE4_CARD_TYPE_V2_02 = 0x00020002, /** version 2.20*/
SENSE4_CARD_TYPE_V2_05 = 0x00020005, /** version 2.05*/
SENSE4_CARD_TYPE_V2_30 = 0x00020300 /** version 2.30*/
}CARD_VERSION;
/**
device information structure definition
*/
typedef struct {
DWORD dwIndex; /** device index; index begins at zero*/
DWORD dwVersion; /** device version*/
S4HANDLE hLock; /** device handle*/
BYTE reserve[12]; /** reserved*/
BYTE bAtr[MAX_ATR_LEN]; /** ATR*/
BYTE bID[MAX_ID_LEN]; /** device ID*/
DWORD dwAtrLen; /** ATR length*/
}SENSE4_CONTEXT,*PSENSE4_CONTEXT;
/** RSA public key structure*/
typedef struct {
unsigned char modulus[S4_RSA_MODULUS_LEN]; /* modulus*/
unsigned char exponent[S4_RSA_MODULUS_LEN]; /* public exponent*/
} S4_RSA_PUBLIC_KEY;
/** RSA private key structure*/
typedef struct {
unsigned char modulus[S4_RSA_MODULUS_LEN]; /* modulus*/
unsigned char publicExponent[S4_RSA_MODULUS_LEN]; /* public exponent*/
unsigned char exponent[S4_RSA_MODULUS_LEN]; /* private exponent*/
unsigned char prime[2][S4_RSA_PRIME_LEN]; /* prime factors*/
unsigned char primeExponent[2][S4_RSA_PRIME_LEN]; /* exponents for CRT*/
unsigned char coefficient[S4_RSA_PRIME_LEN]; /* CRT coefficient*/
} S4_RSA_PRIVATE_KEY;
/** Netlock Module infomation definition*/
typedef struct _S4MODULEINFO {
WORD wModuleID; /* Module ID*/
WORD wLicenseCount; /* License Count */
} S4MODULEINFO;
typedef struct _S4NETCONFIG {
DWORD dwLicenseMode; /* License Mode */
DWORD dwModuleCount; /* Module Count */
S4MODULEINFO ModuleInfo[16]; /* Module detail infomation */
} S4NETCONFIG;
/** S4CREATEDIRINFO structure definition*/
typedef struct _S4CREATEDIRINFO {
DWORD dwS4CreateDirInfoSize; /* size of the structure*/
BYTE szAtr[8]; /* ATR information */
S4NETCONFIG NetConfig; /* netlock config infomation */
} S4CREATEDIRINFO;
/** S4OPENINFO structure definition*/
typedef struct _S4OPENINFO {
DWORD dwS4OpenInfoSize; /* size of the structure*/
DWORD dwShareMode; /* share mode*/
} S4OPENINFO;
//@}
//@{
/**
@function interface
*/
/*
reserved
*/
unsigned long WINAPI S4Startup(
VOID
);
/*
reserved
*/
unsigned long WINAPI S4Cleanup(
VOID
);
/**
enumerate all EliteIV devices plugged in the computer.
if pS4CtxList is NULL, the pdwCtxListSize will return the required buffer size
@paramter pS4CtxList [out] return the device list
@paramter pdwCtxListSize [in][out] return the amount of storage of device list, in bytes.
@return value
if the function succeeds,the return vlaue is S4_SUCCESS, otherwise return other defined return value.
*/
DWORD WINAPI S4Enum(
OUT SENSE4_CONTEXT *pS4CtxList,
IN OUT DWORD *pdwCtxListSize
);
/**
open the EliteIV device with sharable mode
@paramter pS4Ctx [in][out] the context pointer of the device
@return value
if the function succeeds,the return vlaue is S4_SUCCESS, otherwise return other defined return value.
*/
DWORD WINAPI S4Open(
IN OUT SENSE4_CONTEXT *pS4Ctx
);
/**
close the EliteIV device
@parameter pS4Ctx [in] the context pointer of the device
@return value
if the function succeeds,the return vlaue is S4_SUCCESS, otherwise return other defined return value.
*/
DWORD WINAPI S4Close(
IN SENSE4_CONTEXT *pS4Ctx
);
/**
Send control command to device
@parameter pS4Ctx [in] the context pointer of the device, the device must has been opened
@parameter dwCtlCode [in] control code
@parameter pInBuffer [in] input buffer
@parameter dwInBufferLen [in] the length of input data,in bytes
@parameter pOutBuffer [out] return output data
@parameter dwOutBufferLen [in] output buffer size, in bytes
@parameter pdwBytesReturned [out] the length of output data, cannot be NULL
@return value
if the function succeeds,the return vlaue is S4_SUCCESS, otherwise return other defined return value.
*/
DWORD WINAPI S4Control(
IN SENSE4_CONTEXT *pS4Ctx,
IN DWORD dwCtlCode,
IN VOID *pInBuffer,
IN DWORD dwInBufferLen,
OUT VOID *pOutBuffer,
IN DWORD dwOutBufferLen,
OUT DWORD *pdwBytesReturned
);
/**
create a new child directory for the current directory, and set current directory to the new directory
@parameter pS4Ctx [in] the context pointer of the device, the device must has been opened
@parameter lpszDirID [in] ID of the new directory
@parameter dwDirSize [in] size of the new directory
@parameter dwFlags [in] flag
@return value
if the function succeeds,the return vlaue is S4_SUCCESS, otherwise return other defined return value.
*/
DWORD WINAPI S4CreateDir(
IN SENSE4_CONTEXT *pS4Ctx,
IN LPCSTR lpszDirID,
IN DWORD dwDirSize,
IN DWORD dwFlags
);
/**
set the current directory
@parameter pS4Ctx [in] the context pointer of the device, the device must has been opened
@parameter lpszPath [in] ID of the specified directory
@return value
if the function succeeds,the return vlaue is S4_SUCCESS, otherwise return other defined return value.
*/
DWORD WINAPI S4ChangeDir(
IN SENSE4_CONTEXT *pS4Ctx,
IN LPCSTR lpszPath
);
/**
erase the root and empty the device if the specified direcotry is the device root,
otherwise erase all files or child direcotries of the specified directory.
@parameter pS4Ctx [in] the context pointer of the device, the device must has been opened
@parameter lpszDirID [in] reserved, must be NULL
@return value
if the function succeeds,the return vlaue is S4_SUCCESS, otherwise return other defined return value.
*/
DWORD WINAPI S4EraseDir(
IN SENSE4_CONTEXT *pS4Ctx,
IN LPCTSTR lpszDirID
);
/**
verify the pin, to reach a security status before call S4CreateDir,S4EraseDir,S4Execute,S4WriteFile.
@parameter pS4Ctx [in] the context pointer of the device, the device must has been opened
@parameter pbPin [in] PIN value
@parameter dwPinLen [in] the PIN value length, the length of User PIN is 8 bytesthe length of developer PIN is 24 bytes
@parameter dwPinType [in] PIN type
@return value
if the function succeeds,the return vlaue is S4_SUCCESS, otherwise return other defined return value.
*/
DWORD WINAPI S4VerifyPin(
IN SENSE4_CONTEXT *pS4Ctx,
IN BYTE *pbPin,
IN DWORD dwPinLen,
IN DWORD dwPinType
);
/**
change PIN or key value
@parameter pS4Ctx [in] the context pointer of the device, the device must has been opened
@parameter pbOldPin [in] old PIN or key value
@parameter dwOldPinLen [in] the length of old PIN or key value
@parameter pbNewPin [in] new PIN or key value
@parameter dwNewPinLen [in] the legnth of new PIN or key value
@parameter dwPinType [in] PIN or key type
@return value
if the function succeeds,the return vlaue is S4_SUCCESS, otherwise return other defined return value.
*/
DWORD WINAPI S4ChangePin(
IN SENSE4_CONTEXT *pS4Ctx,
IN BYTE *pbOldPin,
IN DWORD dwOldPinLen,
IN BYTE *pbNewPin,
IN DWORD dwNewPinLen,
IN DWORD dwPinType
);
/**
create a new file or update file data
@parameter pS4Ctx [in] the context pointer of the device, the device must has been opened
@parameter lpszFileID [in] ID of the specified file
@parameter dwOffset [in] offset to write the file
@parameter pBuffer [in] input data buffer
@parameter dwBufferSize [in] input data length
@parameter dwFileSize [in] file size
@parameter pdwBytesWritten [out] return the length of data written into the file
@parameter dwFlags [in] flag
@parameter bFileType [in] file type
@return value
if the function succeeds,the return vlaue is S4_SUCCESS, otherwise return other defined return value.
*/
DWORD WINAPI S4WriteFile(
IN SENSE4_CONTEXT *pS4Ctx,
IN LPCSTR lpszFileID,
IN DWORD dwOffset,
IN VOID *pBuffer,
IN DWORD dwBufferSize,
IN DWORD dwFileSize,
OUT DWORD *pdwBytesWritten,
IN DWORD dwFlags,
IN BYTE bFileType
);
/**
execute the specified executable file of current directory on virtual machine
@parameter pS4Ctx [in] the context pointer of the device, the device must has been opened
@parameter lpszFileID [in] ID of the executable file
@parameter pInBuffer [in] input data buffer
@parameter dwInbufferSize [in] input data length
@parameter pOutBuffer [out] output data buffer
@parameter dwOutBufferSize [in] output data buffer size
@parameter pdwBytesReturned [out] output data length
@return value
if the function succeeds,the return vlaue is S4_SUCCESS, otherwise return other defined return value.
*/
DWORD WINAPI S4Execute(
IN SENSE4_CONTEXT *pS4Ctx,
IN LPCSTR lpszFileID,
IN VOID *pInBuffer,
IN DWORD dwInbufferSize,
OUT VOID *pOutBuffer,
IN DWORD dwOutBufferSize,
OUT DWORD *pdwBytesReturned
);
/**
execute the specified executable file of current directory on virtual machine
or on XA User mode
@parameter pS4Ctx [in] the context pointer of the device, the device must has been opened
@parameter lpszFileID [in] ID of the executable file
@parameter dwFlag [in] executing mode
@parameter pInBuffer [in] input data buffer
@parameter dwInbufferSize [in] input data length
@parameter pOutBuffer [out] output data buffer
@parameter dwOutBufferSize [in] output data buffer size
@parameter pdwBytesReturned [out] output data length
@return value
if the function succeeds,the return vlaue is S4_SUCCESS, otherwise return other defined return value.
*/
DWORD WINAPI S4ExecuteEx(
IN SENSE4_CONTEXT *pS4Ctx,
IN LPCSTR lpszFileID,
IN DWORD dwFlag,
IN VOID *pInBuffer,
IN DWORD dwInbufferSize,
OUT VOID *pOutBuffer,
IN DWORD dwOutBufferSize,
OUT DWORD *pdwBytesReturned
);
/**
create a new child directory for the current directory, and set the new
directory to current directory. if creating the root directory, the function
will create a ATR file at the same time.
@parameter pS4Ctx [in] the context pointer of the device, the device must has been opened
@parameter lpszDirID [in] ID of the new directory
@parameter dwDirSize [in] size of the new directory
@parameter dwFlags [in] flag
@parameter pCreateDirInfo [in] S4CREATEDIRINFO structure pointer
@return value
if the function succeeds,the return vlaue is S4_SUCCESS, otherwise return other defined return value.
*/
DWORD WINAPI S4CreateDirEx(
IN SENSE4_CONTEXT *pS4Ctx,
IN LPCSTR lpszDirID,
IN DWORD dwDirSize,
IN DWORD dwFlags,
IN S4CREATEDIRINFO *pCreateDirInfo
);
/**
open the EliteIV device using specific mode
@paramter pS4Ctx [in][out] the context pointer of the device
@paramter pS4OpenInfo [in] S4OPENINFO structure pointer
@return value
if the function succeeds,the return vlaue is S4_SUCCESS, otherwise return other defined return value.
*/
DWORD WINAPI S4OpenEx(
IN OUT SENSE4_CONTEXT *pS4Ctx,
IN S4OPENINFO *pS4OpenInfo
);
//@}
#ifdef __cplusplus
}
#endif
#endif //__SENSE4_H__
Loading…
Cancel
Save