コード例 #1
0
ファイル: sticcard.go プロジェクト: kity-xu/xuxiaodong
func (jst *STICCard) CtrScriptData(pin *driverlayer.DriverArg, timeout int, taglist []byte, lpicappdata []byte, arpc []byte) ([]byte, error) {
	utils.Debug("receive STICCard CtrScriptData request")

	var term_type int = 0
	var func_id int = 2
	var buf_size int = 4096
	var func_arg int = 4

	t := make([]byte, 4096)
	tty_name := make([]byte, 1)
	tty_name[0] = 0

	var func_arg_pointer []*byte
	func_arg_pointer = make([]*byte, 4)

	if taglist == nil || len(taglist) == 0 {
		taglist = tty_name
	}
	if lpicappdata == nil || len(lpicappdata) == 0 {
		lpicappdata = tty_name
	}
	if arpc == nil || len(arpc) == 0 {
		arpc = tty_name
	}

	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]
	}
	//taglist
	func_arg_pointer[2] = &lpicappdata[0]
	func_arg_pointer[1] = &taglist[0]
	func_arg_pointer[3] = &arpc[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 {
		var empocc int
		empocc = utils.IndexByteRune(t, 0, 1)
		if empocc != -1 {
			t = t[0:empocc]
		}

		empocc = utils.IndexByteRune(t, '|', 2)
		if empocc != -1 {
			t = t[empocc+1 : len(t)]
		}

		utils.Debug("end STICCard GenARQC request ,data [%s]", string(t))
		return t, nil
	} else {
		utils.Error("end STICCard GenARQC request error %s", int(r))
		return nil, errors.New(fmt.Sprintf("%d", int(r)))
	}
}
コード例 #2
0
ファイル: sticcard.go プロジェクト: kity-xu/xuxiaodong
//获取arqc
func (jst *STICCard) GetTransDetail(pin *driverlayer.DriverArg, timeout int, path []byte) ([]byte, error) {
	utils.Debug("receive STICCard GetTransDetail request")

	var term_type int = 0
	var func_id int = 3
	var buf_size int = 4096
	var func_arg int = 1

	t := make([]byte, 4096)
	tty_name := make([]byte, 1)
	tty_name[0] = 0

	var func_arg_pointer []*byte
	func_arg_pointer = make([]*byte, 1)

	if path == nil || len(path) == 0 {
		path = tty_name
	}

	_, port, _ := driverlayer.GetPortDescription(pin.Port)

	//taglist
	func_arg_pointer[0] = &path[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 {
		var empocc int
		empocc = utils.IndexByteRune(t, 0, 1)
		if empocc != -1 {
			t = t[0:empocc]
		}

		empocc = utils.IndexByteRune(t, '|', 2)
		if empocc != -1 {
			t = t[empocc+1 : len(t)]
		}

		utils.Debug("end STICCard GetTransDetail request ,data [%s]", string(t))
		return t, nil
	} else {
		utils.Error("end STICCard GetTransDetail request error %s", int(r))
		return nil, errors.New(fmt.Sprintf("%d", int(r)))
	}

}
コード例 #3
0
ファイル: zzfinger.go プロジェクト: kity-xu/xuxiaodong
//注册指纹
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))
	}
}
コード例 #4
0
ファイル: sticcard.go プロジェクト: kity-xu/xuxiaodong
//调用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))
	}

}
コード例 #5
0
ファイル: stidr.go プロジェクト: kity-xu/xuxiaodong
//调用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)))
	}

}