//注册指纹 func (jst *TCFinger) GetValidateFg(pin *driverlayer.DriverArg, timeout int) ([]byte, error) { var use int = 0 t := make([]byte, 513) err := make([]byte, 65) _, port, _ := driverlayer.GetPortDescription(pin.Port) r, _, _ := dllinterop.CallProc(jst.getValidteImage, uintptr(port), uintptr(unsafe.Pointer(&t[0])), uintptr(use), uintptr(unsafe.Pointer(&err[0]))) for i := 0; i < 512; i++ { if t[i] == 0 { use = i break } } if int(r) >= 0 { return t[0:use], nil } else { out, _ := utils.TransUTF8FromCode(err, utils.GBK) return nil, errors.New(string(out)) } return t, nil }
//注册指纹 func (jst *ZZFinger) GetValidateFg(pin *driverlayer.DriverArg, timeout int) ([]byte, error) { utils.Debug("receive ZZFinger GetRegisterFg request") var term_type int = 0 var func_id int = 1 var buf_size int = 1024 var func_arg int = 1 t := make([]byte, 1024) tty_name := make([]byte, 1) tty_name[0] = 0 var func_arg_pointer []*byte func_arg_pointer = make([]*byte, 1) _, port, _ := driverlayer.GetPortDescription(pin.Port) func_arg_pointer[0] = &([]byte("X"))[0] r, _, _ := dllinterop.CallProc(jst.read, uintptr(term_type), uintptr(unsafe.Pointer(&tty_name[0])), uintptr(port), uintptr(timeout), uintptr(func_id), uintptr(func_arg), uintptr(unsafe.Pointer(&func_arg_pointer[0])), uintptr(unsafe.Pointer(&t[0])), uintptr(buf_size)) if int(r) == 0 { return t, nil } else { empocc := utils.IndexByteRune(t, 0, 1) if empocc != -1 { t = t[0:empocc] } out, _ := utils.TransUTF8FromCode(t, utils.GBK) utils.Error("end ZZFinger GetRegisterFg request error %s", string(out)) return nil, errors.New(string(out)) } }
//获取指纹 func (jst *TCFinger) GetRegisterFg(pin *driverlayer.DriverArg, timeout int) ([]byte, error) { var use int = 0 t := make([]byte, 513) err := make([]byte, 65) _, port, _ := driverlayer.GetPortDescription(pin.Port) r, _, _ := dllinterop.CallProc(jst.getRegisterImage, uintptr(port), uintptr(unsafe.Pointer(&t[0])), uintptr(unsafe.Pointer(&use)), uintptr(unsafe.Pointer(&err[0]))) if int(r) >= 0 { return t[0:use], nil } else { out, _ := utils.TransUTF8FromCode(err, utils.GBK) return nil, errors.New(string(out)) } }
//调用winscard.dll实现 func (jst *STICCard) PowerOff(pin *driverlayer.DriverArg, timeout int) error { utils.Debug("receive STICCard PowerOff request") var term_type int = 0 var func_id int = 4 var buf_size int = 1024 var func_arg int = 1 t := make([]byte, 1024) tty_name := make([]byte, 1) tty_name[0] = 0 var func_arg_pointer []*byte func_arg_pointer = make([]*byte, 1) porttype, port, _ := driverlayer.GetPortDescription(pin.Port) switch porttype { case "USB": func_arg_pointer[0] = &([]byte("U"))[0] case "COM": func_arg_pointer[0] = &([]byte("C"))[0] } utils.Debug("port is %s,%d", pin.Port, port) r, _, _ := dllinterop.CallProc(jst.read, uintptr(term_type), uintptr(unsafe.Pointer(&tty_name[0])), uintptr(port), uintptr(timeout), uintptr(func_id), uintptr(func_arg), uintptr(unsafe.Pointer(&func_arg_pointer[0])), uintptr(unsafe.Pointer(&t[0])), uintptr(buf_size)) if int(r) == 0 { return nil } else { empocc := utils.IndexByteRune(t, 0, 1) if empocc != -1 { t = t[0:empocc] } out, _ := utils.TransUTF8FromCode(t, utils.GBK) utils.Error("end STICCard PowerOff request error %s", string(out)) return errors.New(string(out)) } }
//调用terms.dll func (jst *STIdr) ReadData(pin *driverlayer.DriverArg, timeout int) ([]byte, error) { utils.Debug("receive STIdr ReadData request") var term_type int = 0 var func_id int = 2 var buf_size int = 1024 var empty int = 0 t := make([]byte, 1024) tty_name := make([]byte, 1) tty_name[0] = 0 var func_arg_pointer []*byte func_arg_pointer = make([]*byte, 1) func_arg_pointer[0] = &([]byte("data/"))[0] _, port, _ := driverlayer.GetPortDescription(pin.Port) r, _, _ := dllinterop.CallProc(jst.read, uintptr(term_type), uintptr(unsafe.Pointer(&tty_name[0])), uintptr(port), uintptr(timeout), uintptr(func_id), uintptr(empty), uintptr(unsafe.Pointer(&func_arg_pointer[0])), uintptr(unsafe.Pointer(&t[0])), uintptr(buf_size)) if int(r) == 0 { out, err := utils.TransUTF8FromCode(t, utils.GBK) if err != nil { return nil, err } utils.Debug("end STIdr ReadData request %s", string(out)) empocc := utils.IndexByteRune(out, 0, 1) if empocc != -1 { out = out[0:empocc] } res := bytes.NewBufferString("") res.Write(out) firocc := utils.IndexByteRune(out, ',', 5) secocc := utils.IndexByteRune(out, ',', 6) if firocc == -1 || secocc == -1 { utils.Error("STIdr ReadData data error %s", string(out)) return nil, errors.New("not formatted data") } res.WriteByte('|') rb, ferr := ioutil.ReadFile(fmt.Sprintf(`data/%s%s`, string(out[firocc+1:secocc]), ".bmp")) if ferr != nil { utils.Error("can't read file %s", ferr.Error()) return nil, errors.New("can't read file") } var b bytes.Buffer we := base64.NewEncoder(base64.StdEncoding, &b) we.Write(rb) we.Close() res.WriteString(string(b.Bytes())) utils.Debug("process STIdr ReadData data %s", res.String()) return res.Bytes(), nil } else { utils.Error("end STIdr ReadData request error %s", int(r)) return nil, errors.New(fmt.Sprintf("%d", int(r))) } }