123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627 |
- using System;
- using System.Text;
- using System.Runtime.InteropServices;
- namespace WindowsApplication1
- {
-
-
-
-
- public class SoftKey
- {
- [DllImport ("Lyfz32.dll")]
- public static extern short FindPort(int start, StringBuilder sKeyPath);
- [DllImport ("Lyfz32.dll")]
- public static extern short FindPort_2(int start, byte[] InByte, int InLen, StringBuilder sKeyPath);
- [DllImport ("Lyfz32.dll")]
- public static extern short CalEx(byte [] InByte,int in_len,ref int D0,ref int D1,ref int D2,ref int D3,ref int D4,ref int D5,ref int D6,ref int D7,
- ref double F0,ref double F1,ref double F2,ref double F3,ref double F4,ref double F5,ref double F6,ref double F7,
- StringBuilder S0, StringBuilder S1, StringBuilder S2, StringBuilder S3, StringBuilder S4, StringBuilder S5, StringBuilder S6, StringBuilder S7, String sKeyPath, int over_count);
- [DllImport ("Lyfz32.dll")]
- public static extern short CalPubByFile(string InFile,ref int D0,ref int D1,ref int D2,ref int D3,ref int D4,ref int D5,ref int D6,ref int D7,
- ref double F0,ref double F1,ref double F2,ref double F3,ref double F4,ref double F5,ref double F6,ref double F7,
- StringBuilder S0, StringBuilder S1, StringBuilder S2, StringBuilder S3, StringBuilder S4, StringBuilder S5, StringBuilder S6, StringBuilder S7, String sKeyPath, int over_count);
- [DllImport ("Lyfz32.dll")]
- public static extern short EdcByFile(string Key, string InbinFile, string OutbinFile, String KeyPath);
- [DllImport ("Lyfz32.dll")]
- public static extern short ReadKeyFormEpm(StringBuilder OutAuthCode, short Addr, string HKey, string LKey, String KeyPath);
- [DllImport ("Lyfz32.dll")]
- public static extern short GetIDVersion(ref uint ID, ref short version, String KeyPath);
- [DllImport ("Lyfz32.dll")]
- public static extern bool GetAuthFromFile(string InFile,StringBuilder HKey,StringBuilder LKey,StringBuilder OutSetTime,ref uint id);
- [DllImport ("Lyfz32.dll")]
- public static extern short GetRunTimer(StringBuilder Year, StringBuilder Month, StringBuilder Day, StringBuilder Hour, StringBuilder Minuts, StringBuilder Second, String KeyPath);
- [DllImport ("Lyfz32.dll")]
- public static extern bool WriteIniSetting(string FileName,string HKey,string LKey,string Time,uint id);
- [DllImport ("Lyfz32.dll")]
- public static extern short AddConnectNew(byte InFunNum, short Addr, bool IfClose, StringBuilder OutVerCode, String KeyPath);
- [DllImport ("Lyfz32.dll")]
- public static extern short AddConnectEx(byte InFunNum, short Addr, bool IfClose, String KeyPath);
- [DllImport ("Lyfz32.dll")]
- public static extern short GetIpCountByFunNum (byte FunNum );
- [DllImport ("Lyfz32.dll")]
- public static extern short GetConCountByFunNum (byte FunNum ) ;
- [DllImport ("Lyfz32.dll")]
- public static extern short GetSetCount(short Addr, ref int count, ref bool IsMachine, ref byte OutFum, String KeyPath);
- [DllImport ("Lyfz32.dll")]
- public static extern short ConnectServer (string ServerName , int Port );
- [DllImport ("Lyfz32.dll")]
- public static extern short DisconnectServer () ;
- [DllImport("Lyfz32.dll")]
- public static extern unsafe void AutoDisConnect(int timer, bool biao);
- public String KeyPath;
- public SoftKey()
- {
-
-
-
- }
- public static string GetFullFileName(string InFilName)
- {
- string path=System.Windows.Forms.Application.StartupPath;
- if(path.Substring(path.Length-1,1)!="\\" && path.Substring(path.Length-1,1)!="/")path=path+"\\";
- return path+InFilName;
- }
-
- public static string ByteConvertString(byte[] buffer)
- {
- char []null_string={'\0','\0'};
- System.Text.Encoding encoding = System.Text.Encoding.Default;
- return encoding.GetString(buffer).TrimEnd(null_string);
- }
-
- public static bool StringConvertByte(byte[] buffer,string InS)
- {
- byte []temp;int n;
- temp=System.Text.Encoding.Default.GetBytes(InS);
- if (temp.Length>50)return false;
- for (n=1;n<=temp.Length;n++)
- {
- buffer[n-1]=temp[n-1];
- }
- return true;
- }
-
-
-
-
-
- public short ConnectSvr(string ServerName,int Port)
- {
- return ConnectServer(ServerName,Port);
- }
-
-
-
-
- public short ConnectAddNew(short Addr,ref string OutVerCode)
- {
-
-
-
-
-
-
- short ret; StringBuilder VerCode = new StringBuilder("", 20);
- ret = AddConnectNew(0, Addr, false, VerCode, KeyPath);
- OutVerCode = VerCode.ToString();
- AutoDisConnect(60000, true);
- return ret;
-
-
- }
-
-
- public short ConnectAdd(short Addr)
- {
-
-
-
-
-
- {
- return AddConnectEx(0, Addr, false,KeyPath);
- }
-
-
- }
-
-
- public int GetKeySetCount(short Addr)
- {
- int count=0;bool IsMachine=false;byte OutFum=0;int ret;
- {
- ret=GetSetCount(Addr,ref count,ref IsMachine,ref OutFum,KeyPath);
- }
- if(ret!=0)return ret;
- return count;
- }
-
- public short SGetIpCount()
- {
-
- return GetIpCountByFunNum(0);
- }
-
- public short GetConCount()
- {
-
- return GetConCountByFunNum(0);
- }
-
- public short DisConnect()
- {
- return DisconnectServer();
- }
-
-
- public short Reg(string Key)
- {
- short n, ret;
- string FilePath_Ini,FilePath, RegFilePath_Ini,RegFilePath;
- int [] D=new int[8];double [] F=new double[8];
- StringBuilder s0=new StringBuilder("",50),s1=new StringBuilder("",50),s2=new StringBuilder("",50),s3=new StringBuilder("",50);
- StringBuilder s4=new StringBuilder("",50),s5=new StringBuilder("",50),s6=new StringBuilder("",50),s7=new StringBuilder("",50);
-
-
-
- FilePath_Ini=GetFullFileName("JMGTest_Ini.enc");RegFilePath_Ini=GetFullFileName("JMGTest_Ini.enc.lll");
-
-
-
- for(n=0;n<256;n++)
- {
- {
- StringBuilder sKeyPath = new StringBuilder("", 260);
- ret=FindPort(n,sKeyPath);
- KeyPath = sKeyPath.ToString();
- if(ret!=0 && n>0 )return -1052;
- if(ret!=0)return ret;
-
-
- ret=EdcByFile(Key,FilePath_Ini,RegFilePath_Ini,KeyPath);
- if(ret!=0)return ret;
- ret=CalPubByFile(RegFilePath_Ini,ref D[0],ref D[1],ref D[2],ref D[3],ref D[4],ref D[5],ref D[6],ref D[7],
- ref F[0],ref F[1],ref F[2],ref F[3],ref F[4],ref F[5],ref F[6],ref F[7],
- s0,s1,s2,s3,s4,s5,s6,s7,KeyPath,20000);
-
- if((ret==0) && (D[0]==123) && (D[1]==123) && (D[2]==123) && (D[3]==123))
- {
-
-
- FilePath=GetFullFileName("JMGTest.enc");RegFilePath=GetFullFileName("JMGTest.enc.lll");
- ret=EdcByFile(Key,FilePath,RegFilePath,KeyPath);
-
- if(ret!=0)return ret;
- return 0;
- }
- }
-
- }
- return -53;
- }
-
- public short RegByEpm(short Addr,string HKey,string LKey)
- {
- short n, ret;
- string FilePath_Ini,FilePath, RegFilePath_Ini,RegFilePath;
- int [] D=new int[8];double [] F=new double[8];
- StringBuilder s0=new StringBuilder("",50),s1=new StringBuilder("",50),s2=new StringBuilder("",50),s3=new StringBuilder("",50);
- StringBuilder s4=new StringBuilder("",50),s5=new StringBuilder("",50),s6=new StringBuilder("",50),s7=new StringBuilder("",50);
-
-
-
- FilePath_Ini=GetFullFileName("JMGTest_Ini.enc");RegFilePath_Ini=GetFullFileName("JMGTest_Ini.enc.lll");
- StringBuilder Key=new StringBuilder("",300);
-
-
- for(n=0;n<256;n++)
- {
- {
- StringBuilder sKeyPath = new StringBuilder("", 260);
- ret=FindPort(n,sKeyPath);
- KeyPath = sKeyPath.ToString();
- if(ret!=0 && n>0 )return -1052;
- if(ret!=0)return ret;
-
- ret=ReadKeyFormEpm(Key,Addr,HKey,LKey,KeyPath);
- if(ret!=0)return ret;
-
-
-
- ret = EdcByFile(Key.ToString(), FilePath_Ini, RegFilePath_Ini, KeyPath);
- if(ret!=0)return ret;
- ret=CalPubByFile(RegFilePath_Ini,ref D[0],ref D[1],ref D[2],ref D[3],ref D[4],ref D[5],ref D[6],ref D[7],
- ref F[0],ref F[1],ref F[2],ref F[3],ref F[4],ref F[5],ref F[6],ref F[7],
- s0,s1,s2,s3,s4,s5,s6,s7,KeyPath,20000);
-
- if((ret==0) && (D[0]==123) && (D[1]==123) && (D[2]==123) && (D[3]==123))
- {
-
-
- FilePath=GetFullFileName("JMGTest.enc");RegFilePath=GetFullFileName("JMGTest.enc.lll");
- ret = EdcByFile(Key.ToString(), FilePath, RegFilePath, KeyPath);
-
- if(ret!=0)return ret;
- return 0;
- }
- }
-
- }
- return -53;
- }
-
-
-
- public short Ini()
- {
- short n, ret;string RegFilePath_Ini;
- int [] D=new int[8];double [] F=new double[8];
- StringBuilder s0=new StringBuilder("",50),s1=new StringBuilder("",50),s2=new StringBuilder("",50),s3=new StringBuilder("",50);
- StringBuilder s4=new StringBuilder("",50),s5=new StringBuilder("",50),s6=new StringBuilder("",50),s7=new StringBuilder("",50);
-
- RegFilePath_Ini=GetFullFileName("JMGTest_Ini.enc.lll");
-
- for(n=0;n<256;n++)
- {
- {
- StringBuilder sKeyPath = new StringBuilder("", 260);
- ret = FindPort(n, sKeyPath);
- KeyPath = sKeyPath.ToString();
- if(ret!=0 && n==0)return -1053;
- if(ret!=0)return ret;
-
- ret=CalPubByFile(RegFilePath_Ini,ref D[0],ref D[1],ref D[2],ref D[3],ref D[4],ref D[5],ref D[6],ref D[7],
- ref F[0],ref F[1],ref F[2],ref F[3],ref F[4],ref F[5],ref F[6],ref F[7],
- s0,s1,s2,s3,s4,s5,s6,s7,KeyPath,20000);
- }
- if(ret==-63)return ret;
-
- if((ret==0) && (D[0]==123) && (D[1]==123) && (D[2]==123) && (D[3]==123))return 0;
- }
- return -53;
- }
- public short GetJMGTest(ref int D0,ref int D1,ref int D2,ref int D3,ref int D4,ref int D5,ref int D6,ref int D7,
- ref double F0,ref double F1,ref double F2,ref double F3,ref double F4,ref double F5,ref double F6,ref double F7,
- ref string S0,ref string S1,ref string S2,ref string S3,ref string S4,ref string S5,ref string S6,ref string S7)
- {
- short ret;
-
- if (S0.Length > 49) return -36; if (S1.Length > 49) return -36;
- if (S2.Length > 49) return -36; if (S3.Length > 49) return -36;
- if (S4.Length > 49) return -36; if (S5.Length > 49) return -36;
- if (S6.Length > 49) return -36; if (S7.Length > 49) return -36;
- StringBuilder s0 = new StringBuilder(S0, 50), s1 = new StringBuilder(S1, 50), s2 = new StringBuilder(S2, 50), s3 = new StringBuilder(S3, 50);
- StringBuilder s4 = new StringBuilder(S4, 50), s5 = new StringBuilder(S5, 50), s6 = new StringBuilder(S6, 50), s7 = new StringBuilder(S7, 50);
-
- string RegFilePath;
- RegFilePath=GetFullFileName("JMGTest.enc.lll");
-
-
-
- {
- ret=CalPubByFile(RegFilePath, ref D0,ref D1,ref D2,ref D3,ref D4,ref D5,ref D6,ref D7,
- ref F0,ref F1,ref F2,ref F3,ref F4,ref F5,ref F6,ref F7,
- s0,s1,s2,s3,s4,s5,s6,s7,KeyPath,20000);
-
- if( ret==-43) ret=0;
- if (ret==0)
- {
- S0=s0.ToString();S1=s1.ToString();S2=s2.ToString();S3=s3.ToString();
- S4=s4.ToString();S5=s5.ToString();S6=s6.ToString();S7=s7.ToString();
- }
- }
-
- return ret;
- }
-
- public bool GetAuthFromFileEx(string IniFile,ref string OutHKey,ref string OutLKey,ref string OutSetTime,ref uint OutID)
- {
- StringBuilder HKey;
- StringBuilder LKey;
- StringBuilder SetTime;
- HKey=new StringBuilder("",50);LKey=new StringBuilder("",50);SetTime=new StringBuilder("",100);
-
- {
- if(!GetAuthFromFile(IniFile,HKey,LKey,SetTime,ref OutID))return false;
- }
- OutHKey=HKey.ToString();
- OutLKey=LKey.ToString();
- OutSetTime=SetTime.ToString();
- return true;
- }
- public short GetRunTimerEx(ref string OutYear,ref string OutMonth,ref string OutDay,
- ref string OutHour,ref string OutMinuts,ref string OutSecond)
- {
- short ret;
- StringBuilder year=new StringBuilder("",10),month=new StringBuilder("",10),day=new StringBuilder("",10),hour=new StringBuilder("",10);
- StringBuilder minuts=new StringBuilder("",10),second=new StringBuilder("",10);
- {
- ret=GetRunTimer(year,month,day,hour,minuts,second,KeyPath);
- if(ret!=0)return ret;
- }
- OutYear=year.ToString();OutMonth=month.ToString();
- OutDay=day.ToString();OutHour=hour.ToString();
- OutMinuts=minuts.ToString();OutSecond=second.ToString();
- return ret;
- }
-
- public short GetIDVersionEx(ref uint id,ref short ver)
- {
- {
- return GetIDVersion(ref id,ref ver,KeyPath);
- }
- }
-
- public short FindPortEx(int start)
- {
- StringBuilder sKeyPath = new StringBuilder("", 260);
- {
- short ret = FindPort(start, sKeyPath);
- KeyPath = sKeyPath.ToString();
- return ret;
- }
- }
- public string GetErrInfo(short err )
- {
- switch(err)
- {
- case -1:
- return "未找到返回结果变量";
- case -2:
- return "未找到 = 符号";
-
- case -3:
- return "代表没有找到相应常数";
-
- case -5:
- return "代表找不到字符串的第一个双引号";
-
- case -6:
- return "代表找不到字符串的第二个双引号";
-
- case -7:
- return "IF语句没有找到goto字符";
-
- case -8:
- return "IF语句没有找到第一个比较字符";
-
- case -9:
- return "IF语句没有找到比较符号";
-
- case -10:
- return "两边变量类型不相符";
-
- case -11:
- return "没有找到NOT符号";
-
- case -12:
- return "不是整形变量";
-
- case -13:
- return "代表没有找到相应整形常数";
-
- case -14:
- return "代表没有找到相应字符串常数";
-
- case -15:
- return "代表没有找到相应浮点常数";
-
- case -16:
- return "代表不支持这个运算";
-
- case -17:
- return "代表没有左边括号";
-
- case -18:
- return "代表没有变量";
-
- case -19:
- return "代表没“,”";
-
- case -20:
- return "代表没有右边括号";
-
- case -21:
- return "代表常数超过指这定的范围";
-
- case -22:
- return "代表储存器的地址超过指定的范围,整数不能超过EEPROM_LEN-4,浮点不能超过30720-8";
-
- case -23:
- return "代表储存器的地址超过指定的范围,字符串不能超过EEPROM_LEN-LEN,其中LEN为字符串的长度";
-
- case -24:
- return "除法中,被除数不能为0";
-
- case -25:
- return "未知错误";
-
- case -26:
- return "第二个变量不在指定的位置";
-
- case -27:
- return "字符串常量超过指定的长度";
-
- case -28:
- return "不是字符串变量";
-
- case -29:
- return "没有第三个变量";
-
- case -30:
- return "GOTO的标识语句不能全为数字";
-
- case -31:
- return "不能打开ENC文件";
-
- case -32:
- return "不能读ENC文件";
-
- case -33:
- return "GOTO CALL不能找到指定的跳转位置";
-
- case -34:
- return "智能卡运算中,未知数据类型";
-
- case -35:
- return "智能卡运算中,未知代码类型";
-
- case -36:
- return "字符串长度超出50";
-
- case -37:
- return "RIGHT操作时超长,负长";
-
- case -38:
- return "标识重复";
-
- case -39:
- return "程序堆栈溢出";
-
- case -40:
- return "堆栈溢出";
-
- case -41:
- return "不能建立编译文件,请查看文件是否有只读属性,或被其它文件打开";
-
- case -42:
- return "不能写文件,请查看文件是否有只读属性,或被其它文件打开";
-
- case -43:
- return "程序被中途使用END语句结束";
-
- case -44:
- return "程序跳转到外部的空间";
-
- case -45:
- return "传送数据失败";
-
- case -46:
- return "程序超出运算次数,可能是死循环";
-
- case -47:
- return "写密码不正确";
-
- case -48:
- return "读密码不正确";
-
- case -49:
- return "读写EEPROM时,地址溢出";
-
- case -50:
- return "USB操作失败,可能是没有找到相关的指令";
-
- case -51:
- return "打开USB文件句柄失败";
-
- case -52:
- return "使用加密锁加密自定义表达式,生成加密代码时生产错误";
-
- case -53:
- return "无法打开usb设备,可能驱动程序没有安装或没有插入加密锁。";
- case -63 :
- return "不能打开指定的文件。";
- case -64:
- return "不能建立指定的文件。";
- case -65:
- return "验证码错误,可能是输入解密密钥错误,或注册授权码错误";
- case -66:
- return "执行TIMEOUT函数或UPDATE函数时,输入的ID与锁ID不相符";
- case -67:
- return "执行TIMEOUT函数时,智能卡运行函数已到期";
- case -68:
- return "操作浮点运算时,输入的参数将会导致返回值是一个无穷值";
- case -69:
- return "代表没足够的变量参数";
- case -70:
- return "返回变量与函数不相符";
- case -71:
- return "浮点数转换字符串时,要转换的数据太大。";
- case -72:
- return "初始化服务器错误";
- case -73:
- return "对缓冲区进行MD5运算时错误";
- case -74 :
- return "MD5验证IPVAR错误";
- case -75 :
- return "MD5验证IPCount错误";
- case -76 :
- return "没有找到对应的SOCKET连接";
- case -77:
- return "没有找到要删除的对应的SOCKET连接";
- case -78 :
- return "没有找到要删除的对应的功能模块号连接";
- case -79:
- return "没有找到要增加的对应的功能模块号连接";
- case -80:
- return "用户数已超过限制的授权数量";
- case -81:
- return "找不到对应的INI文件条目";
- case -82:
- return "没有进行初始化服务工作。";
- case -252:
- return "密码不正确";
- case -1088:
- return "发送数据错误";
- case -1089:
- return "获取数据错误";
- case -1092:
- return "找不到对应的服务端操作码";
- case -1093:
- return "表示连接服务时错误";
- case -1095:
- return "获取主机名称失败";
- case -1097:
- return "建立套字接错误";
- case -1098:
- return "绑定套字节端口错误";
- case -1099:
- return "表示无效连接,不能进行相关的操作。";
- case -2002:
- return "表示监听时产生错误";
- case -2003:
- return "表示发送的数据长度与接收的数据长度不相符";
- case -2005:
- return "表示当前服务不存在任何连接";
- case -2006:
- return "表示当前查询节点超出集合范范围";
- case -2009:
- return "表示关闭连接错误";
- case -1052:
- return "可能是输入的授权号不正确。";
- case -1053:
- return "系统上没有任何智能锁。";
- default:
- return "未知错误代码";
- }
- }
- }
- }
|