Example #1
0
//注册指纹
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
}
Example #2
0
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)))
	}
}
Example #3
0
//注册指纹
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))
	}
}
Example #4
0
//获取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)))
	}

}
Example #5
0
//获取指纹
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))
	}
}
Example #6
0
//调用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))
	}

}
Example #7
0
//调用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)))
	}

}
Example #8
0
func (jst *IDCGeneral) genIDC(port string, timeout int, readtype int) ([]byte, error) {
	os.Remove(string(wzfile))
	os.Remove(string(bmfile))

	//获得端口描述
	s, p, err := driverlayer.GetPortDescription(port)
	if err != nil {
		utils.Error("receive shensi port error %s  ", port)
		return nil, err
	}
	utils.Debug("begin to open port %s %d", s, p)
	var r uintptr
	if strings.EqualFold(s, "COM") {
		r, _, _ = dllinterop.CallProc(uintptr(jst.initcomm), uintptr(p))
	} else if strings.EqualFold(s, "USB") {
		p = p + 1000
		r, _, _ = dllinterop.CallProc(uintptr(jst.initcomm), uintptr(p))
	}
	if int32(r) != 144 {
		utils.Error("shensi init com error %d", int32(r))
		return nil, err
	}

	//关闭端口
	defer dllinterop.CallProc(uintptr(jst.closecomm), uintptr(p))
	var punc int32
	var punsn int64
	step := 1
	timed, _ := time.ParseDuration(strconv.Itoa(timeout) + "ms")

	remiantime := timed * time.Millisecond

	var (
		basemsg []byte
		bmpmsg  []byte
	)

	//检查二代证的放置位置
	for {
		switch step {
		case 1:
			{
				r, _, _ = dllinterop.CallProc(uintptr(jst.findcard), uintptr(p), uintptr(unsafe.Pointer(&punc)), uintptr(0))
				utils.Debug("start find card result %d", int32(r))
				if r == 159 {
					utils.Debug("find card success")
					step = 2
				}
			}
			break
		case 2:
			{
				r, _, _ = dllinterop.CallProc(uintptr(jst.selectcard), uintptr(p), uintptr(unsafe.Pointer(&punsn)), uintptr(0))
				if r == 144 {
					utils.Debug("select card success")
					step = 3
				} else {
					utils.Debug("start select card result %d", int32(r))
				}
			}
		case 3:
			{
				var (
					wzlen int
					bmlen int
				)
				basemsg = make([]byte, 1024, 1024)
				bmpmsg = make([]byte, 1024, 1024)
				r, _, _ = dllinterop.CallProc(uintptr(jst.readbasemsg), uintptr(p),
					uintptr(unsafe.Pointer(&basemsg[0])),
					uintptr(unsafe.Pointer(&wzlen)),
					uintptr(unsafe.Pointer(&bmpmsg[0])),
					uintptr(unsafe.Pointer(&bmlen)),
					uintptr(0))
				if r == 144 {
					utils.Debug("end idc card read")
					basemsg = basemsg[0:wzlen]
					bmpmsg = bmpmsg[0:bmlen]
					goto readsuccess
				} else {
					utils.Debug("start select card result %d", int32(r))
				}
			}

		}

		remiantime = remiantime - 1000*time.Millisecond
		if remiantime <= 0 {
			break
		}
		time.Sleep(1000 * time.Millisecond)
		if remiantime <= 0 {
			return nil, driverlayer.ErrIOTimeOut
		}
	}

readsuccess:

	outinfo := make([]byte, 0, 1000)

	rInUTF8 := transform.NewReader(bytes.NewReader(basemsg[0:30]), unicode.UTF16(true, false).NewDecoder())
	out, _ := ioutil.ReadAll(rInUTF8)

	outinfo = append(outinfo, out[0:len(out)]...)
	outinfo = append(outinfo, '|')

	rInUTF8 = transform.NewReader(bytes.NewReader(basemsg[30:32]), unicode.UTF16(true, false).NewDecoder())
	out, _ = ioutil.ReadAll(rInUTF8)
	outinfo = append(outinfo, out[0:len(out)]...)
	outinfo = append(outinfo, '|')

	rInUTF8 = transform.NewReader(bytes.NewReader(basemsg[32:36]), unicode.UTF16(true, false).NewDecoder())
	out, _ = ioutil.ReadAll(rInUTF8)
	outinfo = append(outinfo, out[0:len(out)]...)
	outinfo = append(outinfo, '|')

	rInUTF8 = transform.NewReader(bytes.NewReader(basemsg[36:52]), unicode.UTF16(true, false).NewDecoder())
	out, _ = ioutil.ReadAll(rInUTF8)
	outinfo = append(outinfo, out[0:len(out)]...)
	outinfo = append(outinfo, '|')

	rInUTF8 = transform.NewReader(bytes.NewReader(basemsg[52:122]), unicode.UTF16(true, false).NewDecoder())
	out, _ = ioutil.ReadAll(rInUTF8)
	outinfo = append(outinfo, out[0:len(out)]...)
	outinfo = append(outinfo, '|')

	rInUTF8 = transform.NewReader(bytes.NewReader(basemsg[122:158]), unicode.UTF16(true, false).NewDecoder())
	out, _ = ioutil.ReadAll(rInUTF8)
	outinfo = append(outinfo, out[0:len(out)]...)
	outinfo = append(outinfo, '|')

	rInUTF8 = transform.NewReader(bytes.NewReader(basemsg[158:188]), unicode.UTF16(true, false).NewDecoder())
	out, _ = ioutil.ReadAll(rInUTF8)
	outinfo = append(outinfo, out[0:len(out)]...)
	outinfo = append(outinfo, '|')

	rInUTF8 = transform.NewReader(bytes.NewReader(basemsg[188:204]), unicode.UTF16(true, false).NewDecoder())
	out, _ = ioutil.ReadAll(rInUTF8)
	outinfo = append(outinfo, out[0:len(out)]...)
	outinfo = append(outinfo, '|')

	rInUTF8 = transform.NewReader(bytes.NewReader(basemsg[204:220]), unicode.UTF16(true, false).NewDecoder())
	out, _ = ioutil.ReadAll(rInUTF8)
	outinfo = append(outinfo, out[0:len(out)]...)

	//只读基础ixnxi
	if readtype == 1 {
		return outinfo, nil
	} else {
		outinfo = append(outinfo, '|')
		return outinfo, nil
	}
}