Exemple #1
0
	"euc-jp":              japanese.EUCJP,
	"x-euc-jp":            japanese.EUCJP,
	"csiso2022jp":         japanese.ISO2022JP,
	"iso-2022-jp":         japanese.ISO2022JP,
	"csshiftjis":          japanese.ShiftJIS,
	"ms_kanji":            japanese.ShiftJIS,
	"shift-jis":           japanese.ShiftJIS,
	"shift_jis":           japanese.ShiftJIS,
	"sjis":                japanese.ShiftJIS,
	"windows-31j":         japanese.ShiftJIS,
	"x-sjis":              japanese.ShiftJIS,
	"cseuckr":             korean.EUCKR,
	"csksc56011987":       korean.EUCKR,
	"euc-kr":              korean.EUCKR,
	"iso-ir-149":          korean.EUCKR,
	"korean":              korean.EUCKR,
	"ks_c_5601-1987":      korean.EUCKR,
	"ks_c_5601-1989":      korean.EUCKR,
	"ksc5601":             korean.EUCKR,
	"ksc_5601":            korean.EUCKR,
	"windows-949":         korean.EUCKR,
	"csiso2022kr":         replacementEncoding{},
	"iso-2022-kr":         replacementEncoding{},
	"iso-2022-cn":         replacementEncoding{},
	"iso-2022-cn-ext":     replacementEncoding{},
	"utf-16be":            unicode.UTF16(unicode.BigEndian, unicode.IgnoreBOM),
	"utf-16":              unicode.UTF16(unicode.LittleEndian, unicode.IgnoreBOM),
	"utf-16le":            unicode.UTF16(unicode.LittleEndian, unicode.IgnoreBOM),
	"x-user-defined":      charmap.XUserDefined,
}
Exemple #2
0
func Encoding(charset string) encoding.Encoding {
	charset = strings.Replace(charset, "-", "", -1)
	charset = strings.ToLower(charset)

	switch charset {
	case "sjis", "cp932":
		return japanese.ShiftJIS
	case "eucjp":
		return japanese.EUCJP
	case "iso2022jp":
		return japanese.ISO2022JP

	case "euckr", "cp949":
		return korean.EUCKR
	case "koi8r":
		return charmap.KOI8R
	case "koi8u":
		return charmap.KOI8U

	case "macintosh":
		return charmap.Macintosh
	case "macintoshcyrillic":
		return charmap.MacintoshCyrillic

	case "gb18030":
		return simplifiedchinese.GB18030
	case "gbk", "cp936":
		return simplifiedchinese.GBK
	case "hzgb2312":
		return simplifiedchinese.HZGB2312
	case "big5", "cp950":
		return traditionalchinese.Big5

	case "cp437":
		return charmap.CodePage437
	case "cp866":
		return charmap.CodePage866
	case "iso8859_2":
		return charmap.ISO8859_2
	case "iso8859_3":
		return charmap.ISO8859_3
	case "iso8859_4":
		return charmap.ISO8859_4
	case "iso8859_5":
		return charmap.ISO8859_5
	case "iso8859_6":
		return charmap.ISO8859_6
	case "iso8859_7":
		return charmap.ISO8859_7
	case "iso8859_8":
		return charmap.ISO8859_8
	case "iso8859_10":
		return charmap.ISO8859_10
	case "iso8859_13":
		return charmap.ISO8859_13
	case "iso8859_14":
		return charmap.ISO8859_14
	case "iso8859_15":
		return charmap.ISO8859_15
	case "iso8859_16":
		return charmap.ISO8859_16

	case "windows1250":
		return charmap.Windows1250
	case "windows1251":
		return charmap.Windows1251
	case "windows1252", "latin1":
		return charmap.Windows1252
	case "windows1253":
		return charmap.Windows1253
	case "windows1254":
		return charmap.Windows1254
	case "windows1255":
		return charmap.Windows1255
	case "windows1256":
		return charmap.Windows1256
	case "windows1257":
		return charmap.Windows1257
	case "windows1258":
		return charmap.Windows1258
	case "windows874":
		return charmap.Windows874

	case "utf16be":
		return unicode.UTF16(unicode.BigEndian, unicode.IgnoreBOM)
	case "utf16le":
		return unicode.UTF16(unicode.LittleEndian, unicode.IgnoreBOM)
	}
	return nil
}
Exemple #3
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
	}
}
		utf8:    "Heļlo",
	},
	{
		e:       charmap.Windows1258,
		encoded: "Hell\xf5",
		utf8:    "Hellơ",
	},
	{
		e:       charmap.XUserDefined,
		encoded: "\x00\x40\x7f\x80\xab\xff",
		utf8:    "\u0000\u0040\u007f\uf780\uf7ab\uf7ff",
	},

	// UTF-16 tests.
	{
		e:       unicode.UTF16(unicode.BigEndian, unicode.IgnoreBOM),
		encoded: "\x00\x57\x00\xe4\xd8\x35\xdd\x65",
		utf8:    "\x57\u00e4\U0001d565",
	},
	{
		e:         unicode.UTF16(unicode.BigEndian, unicode.ExpectBOM),
		encPrefix: "\xfe\xff",
		encoded:   "\x00\x57\x00\xe4\xd8\x35\xdd\x65",
		utf8:      "\x57\u00e4\U0001d565",
	},
	{
		e:       unicode.UTF16(unicode.LittleEndian, unicode.IgnoreBOM),
		encoded: "\x57\x00\xe4\x00\x35\xd8\x65\xdd",
		utf8:    "\x57\u00e4\U0001d565",
	},
	{