本文整理汇总了C#中Buffer.GetByte方法的典型用法代码示例。如果您正苦于以下问题:C# Buffer.GetByte方法的具体用法?C# Buffer.GetByte怎么用?C# Buffer.GetByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Buffer
的用法示例。
在下文中一共展示了Buffer.GetByte方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Picture
/** Picture:
* @param b payload buffer
* @param d decoder of the picture
*
* The b buffer should only point to the payload data section of
* the picture (not the header). The only methods that would ever need
* to be called are parse(), decode(), and getImage(). However,
* one should check wether the error variable is set before and after
* calling a method. One should not call them in any other order than that
* just specified. Each can be called without arguments and should not be
* called twice. */
public Picture(Buffer b, Decoder d)
{
num = b.GetInt(13);
code = b.GetByte(4);
buf = b;
dec = d;
par = new Parameters(code);
coeffs = new SubBand[3][];
coeffs[0] = new SubBand[19];
coeffs[1] = new SubBand[19];
coeffs[2] = new SubBand[19];
motion_buffers = new Buffer[9];
status = Decoder.Status.NULL;
}
示例2: Send_kexinit
/// <exception cref="System.Exception"></exception>
private void Send_kexinit()
{
if (in_kex)
{
return;
}
string cipherc2s = GetConfig("cipher.c2s");
string ciphers2c = GetConfig("cipher.s2c");
string[] not_available = CheckCiphers(GetConfig("CheckCiphers"));
if (not_available != null && not_available.Length > 0)
{
cipherc2s = Util.DiffString(cipherc2s, not_available);
ciphers2c = Util.DiffString(ciphers2c, not_available);
if (cipherc2s == null || ciphers2c == null)
{
throw new JSchException("There are not any available ciphers.");
}
}
in_kex = true;
kex_start_time = Runtime.CurrentTimeMillis();
// byte SSH_MSG_KEXINIT(20)
// byte[16] cookie (random bytes)
// string kex_algorithms
// string server_host_key_algorithms
// string encryption_algorithms_client_to_server
// string encryption_algorithms_server_to_client
// string mac_algorithms_client_to_server
// string mac_algorithms_server_to_client
// string compression_algorithms_client_to_server
// string compression_algorithms_server_to_client
// string languages_client_to_server
// string languages_server_to_client
Buffer buf = new Buffer();
// send_kexinit may be invoked
Packet packet = new Packet(buf);
// by user thread.
packet.Reset();
buf.PutByte(unchecked((byte)SSH_MSG_KEXINIT));
lock (random)
{
random.Fill(buf.buffer, buf.index, 16);
buf.Skip(16);
}
buf.PutString(Util.Str2byte(GetConfig("kex")));
buf.PutString(Util.Str2byte(GetConfig("server_host_key")));
buf.PutString(Util.Str2byte(cipherc2s));
buf.PutString(Util.Str2byte(ciphers2c));
buf.PutString(Util.Str2byte(GetConfig("mac.c2s")));
buf.PutString(Util.Str2byte(GetConfig("mac.s2c")));
buf.PutString(Util.Str2byte(GetConfig("compression.c2s")));
buf.PutString(Util.Str2byte(GetConfig("compression.s2c")));
buf.PutString(Util.Str2byte(GetConfig("lang.c2s")));
buf.PutString(Util.Str2byte(GetConfig("lang.s2c")));
buf.PutByte(unchecked((byte)0));
buf.PutInt(0);
buf.SetOffSet(5);
I_C = new byte[buf.GetLength()];
buf.GetByte(I_C);
Write(packet);
if (JSch.GetLogger().IsEnabled(Logger.INFO))
{
JSch.GetLogger().Log(Logger.INFO, "SSH_MSG_KEXINIT sent");
}
}
示例3: Receive_kexinit
/// <exception cref="System.Exception"></exception>
private KeyExchange Receive_kexinit(Buffer buf)
{
int j = buf.GetInt();
if (j != buf.GetLength())
{
// packet was compressed and
buf.GetByte();
// j is the size of deflated packet.
I_S = new byte[buf.index - 5];
}
else
{
I_S = new byte[j - 1 - buf.GetByte()];
}
System.Array.Copy(buf.buffer, buf.s, I_S, 0, I_S.Length);
if (!in_kex)
{
// We are in rekeying activated by the remote!
Send_kexinit();
}
guess = KeyExchange.Guess(I_S, I_C);
if (guess == null)
{
throw new JSchException("Algorithm negotiation fail");
}
if (!isAuthed && (guess[KeyExchange.PROPOSAL_ENC_ALGS_CTOS].Equals("none") || (guess
[KeyExchange.PROPOSAL_ENC_ALGS_STOC].Equals("none"))))
{
throw new JSchException("NONE Cipher should not be chosen before authentification is successed."
);
}
KeyExchange kex = null;
try
{
Type c = Sharpen.Runtime.GetType(GetConfig(guess[KeyExchange.PROPOSAL_KEX_ALGS]));
kex = (KeyExchange)(System.Activator.CreateInstance(c));
}
catch (Exception e)
{
throw new JSchException(e.ToString(), e);
}
kex.Init(this, V_S, V_C, I_S, I_C);
return kex;
}
示例4: Run
public virtual void Run()
{
thread = this;
byte[] foo;
Buffer buf = new Buffer();
Packet packet = new Packet(buf);
int i = 0;
Channel channel;
int[] start = new int[1];
int[] length = new int[1];
KeyExchange kex = null;
int stimeout = 0;
try
{
while (isConnected && thread != null)
{
try
{
buf = Read(buf);
stimeout = 0;
}
catch (ThreadInterruptedException ee)
{
if (!in_kex && stimeout < serverAliveCountMax)
{
SendKeepAliveMsg();
stimeout++;
continue;
}
throw;
}
int msgType = buf.GetCommand() & unchecked((int)(0xff));
if (kex != null && kex.GetState() == msgType)
{
kex_start_time = Runtime.CurrentTimeMillis();
bool result = kex.Next(buf);
if (!result)
{
throw new JSchException("verify: " + result);
}
continue;
}
switch (msgType)
{
case SSH_MSG_KEXINIT:
{
//System.err.println("KEXINIT");
kex = Receive_kexinit(buf);
break;
}
case SSH_MSG_NEWKEYS:
{
//System.err.println("NEWKEYS");
Send_newkeys();
Receive_newkeys(buf, kex);
kex = null;
break;
}
case SSH_MSG_CHANNEL_DATA:
{
buf.GetInt();
buf.GetByte();
buf.GetByte();
i = buf.GetInt();
channel = Channel.GetChannel(i, this);
foo = buf.GetString(start, length);
if (channel == null)
{
break;
}
if (length[0] == 0)
{
break;
}
try
{
channel.Write(foo, start[0], length[0]);
}
catch (Exception)
{
//System.err.println(e);
try
{
channel.Disconnect();
}
catch (Exception)
{
}
break;
}
int len = length[0];
channel.SetLocalWindowSize(channel.lwsize - len);
if (channel.lwsize < channel.lwsize_max / 2)
{
packet.Reset();
buf.PutByte(unchecked((byte)SSH_MSG_CHANNEL_WINDOW_ADJUST));
buf.PutInt(channel.GetRecipient());
buf.PutInt(channel.lwsize_max - channel.lwsize);
//.........这里部分代码省略.........
示例5: Dispatch
/* at this point, the buffer must be a complete dirac packet */
private void Dispatch(Buffer b)
{
if (b.GetInt(5) != b.Size())
throw new Exception("Incorrect buffer sizes");
byte c = b.GetByte(4);
switch(c) {
case 0x00:
VideoFormat tmp = new VideoFormat(b);
if(format == null) {
format = tmp;
status = Status.OK;
} else if(!tmp.Equals(format)) {
throw new Exception("Stream Error: Inequal Video Formats");
}
break;
case 0x10:
status = Status.DONE;
break;
case 0x20:
case 0x30:
break;
default:
if(format == null)
throw new Exception("Stream Error: Picture Before Header");
Picture pic = new Picture(b, this);
pic.Parse();
inQueue.Push(pic);
break;
}
}
示例6: Next
/// <exception cref="System.Exception"></exception>
public override bool Next(Buffer _buf)
{
int i;
int j;
switch (state)
{
case SSH_MSG_KEX_DH_GEX_GROUP:
{
// byte SSH_MSG_KEX_DH_GEX_GROUP(31)
// mpint p, safe prime
// mpint g, generator for subgroup in GF (p)
_buf.GetInt();
_buf.GetByte();
j = _buf.GetByte();
if (j != SSH_MSG_KEX_DH_GEX_GROUP)
{
System.Console.Error.WriteLine("type: must be SSH_MSG_KEX_DH_GEX_GROUP " + j);
return false;
}
p = _buf.GetMPInt();
g = _buf.GetMPInt();
dh.SetP(p);
dh.SetG(g);
// The client responds with:
// byte SSH_MSG_KEX_DH_GEX_INIT(32)
// mpint e <- g^x mod p
// x is a random number (1 < x < (p-1)/2)
e = dh.GetE();
packet.Reset();
buf.PutByte(unchecked((byte)SSH_MSG_KEX_DH_GEX_INIT));
buf.PutMPInt(e);
session.Write(packet);
if (JSch.GetLogger().IsEnabled(Logger.INFO))
{
JSch.GetLogger().Log(Logger.INFO, "SSH_MSG_KEX_DH_GEX_INIT sent");
JSch.GetLogger().Log(Logger.INFO, "expecting SSH_MSG_KEX_DH_GEX_REPLY");
}
state = SSH_MSG_KEX_DH_GEX_REPLY;
return true;
}
case SSH_MSG_KEX_DH_GEX_REPLY:
{
//break;
// The server responds with:
// byte SSH_MSG_KEX_DH_GEX_REPLY(33)
// string server public host key and certificates (K_S)
// mpint f
// string signature of H
j = _buf.GetInt();
j = _buf.GetByte();
j = _buf.GetByte();
if (j != SSH_MSG_KEX_DH_GEX_REPLY)
{
System.Console.Error.WriteLine("type: must be SSH_MSG_KEX_DH_GEX_REPLY " + j);
return false;
}
K_S = _buf.GetString();
// K_S is server_key_blob, which includes ....
// string ssh-dss
// impint p of dsa
// impint q of dsa
// impint g of dsa
// impint pub_key of dsa
//System.err.print("K_S: "); dump(K_S, 0, K_S.length);
byte[] f = _buf.GetMPInt();
byte[] sig_of_H = _buf.GetString();
dh.SetF(f);
K = dh.GetK();
//The hash H is computed as the HASH hash of the concatenation of the
//following:
// string V_C, the client's version string (CR and NL excluded)
// string V_S, the server's version string (CR and NL excluded)
// string I_C, the payload of the client's SSH_MSG_KEXINIT
// string I_S, the payload of the server's SSH_MSG_KEXINIT
// string K_S, the host key
// uint32 min, minimal size in bits of an acceptable group
// uint32 n, preferred size in bits of the group the server should send
// uint32 max, maximal size in bits of an acceptable group
// mpint p, safe prime
// mpint g, generator for subgroup
// mpint e, exchange value sent by the client
// mpint f, exchange value sent by the server
// mpint K, the shared secret
// This value is called the exchange hash, and it is used to authenti-
// cate the key exchange.
buf.Reset();
buf.PutString(V_C);
buf.PutString(V_S);
buf.PutString(I_C);
buf.PutString(I_S);
buf.PutString(K_S);
buf.PutInt(min);
buf.PutInt(preferred);
buf.PutInt(max);
buf.PutMPInt(p);
buf.PutMPInt(g);
buf.PutMPInt(e);
buf.PutMPInt(f);
//.........这里部分代码省略.........
示例7: Header
/// <exception cref="System.IO.IOException"></exception>
private ChannelHeader Header(Buffer buf, ChannelHeader header)
{
buf.Rewind();
int i = Fill(buf.buffer, 0, 9);
header.length = buf.GetInt() - 5;
header.type = buf.GetByte() & unchecked((int)(0xff));
header.rid = buf.GetInt();
return header;
}
示例8: Load
//.........这里部分代码省略.........
0));
if (xd)
{
len--;
}
len--;
continue;
}
if (buf[i_1] == '-')
{
break;
}
i_1++;
}
data = Util.FromBase64(buf, start, i_1 - start);
if (data.Length > 4 && data[0] == unchecked((byte)unchecked((int)(0x3f))) && data
[1] == unchecked((byte)unchecked((int)(0x6f))) && data[2] == unchecked((byte)unchecked(
(int)(0xf9))) && data[3] == unchecked((byte)unchecked((int)(0xeb))))
{
// FSecure
Buffer _buf = new Buffer(data);
_buf.GetInt();
// 0x3f6ff9be
_buf.GetInt();
byte[] _type = _buf.GetString();
//System.err.println("type: "+new String(_type));
byte[] _cipher = _buf.GetString();
string cipher = Util.Byte2str(_cipher);
//System.err.println("cipher: "+cipher);
if (cipher.Equals("3des-cbc"))
{
_buf.GetInt();
byte[] foo = new byte[data.Length - _buf.GetOffSet()];
_buf.GetByte(foo);
data = foo;
encrypted = true;
throw new JSchException("unknown privatekey format: " + prvkey);
}
else
{
if (cipher.Equals("none"))
{
_buf.GetInt();
_buf.GetInt();
encrypted = false;
byte[] foo = new byte[data.Length - _buf.GetOffSet()];
_buf.GetByte(foo);
data = foo;
}
}
}
if (pubkey != null)
{
try
{
file = new FilePath(pubkey);
fis = new FileInputStream(pubkey);
buf = new byte[(int)(file.Length())];
len = 0;
while (true)
{
i_1 = fis.Read(buf, len, buf.Length - len);
if (i_1 <= 0)
{
break;
}
示例9: Next
/// <exception cref="System.Exception"></exception>
public override bool Next(Buffer _buf)
{
int i;
int j;
switch (state)
{
case SSH_MSG_KEXDH_REPLY:
{
// The server responds with:
// byte SSH_MSG_KEXDH_REPLY(31)
// string server public host key and certificates (K_S)
// mpint f
// string signature of H
j = _buf.GetInt();
j = _buf.GetByte();
j = _buf.GetByte();
if (j != 31)
{
System.Console.Error.WriteLine("type: must be 31 " + j);
return false;
}
K_S = _buf.GetString();
// K_S is server_key_blob, which includes ....
// string ssh-dss
// impint p of dsa
// impint q of dsa
// impint g of dsa
// impint pub_key of dsa
//System.err.print("K_S: "); //dump(K_S, 0, K_S.length);
byte[] f = _buf.GetMPInt();
byte[] sig_of_H = _buf.GetString();
dh.SetF(f);
K = dh.GetK();
//The hash H is computed as the HASH hash of the concatenation of the
//following:
// string V_C, the client's version string (CR and NL excluded)
// string V_S, the server's version string (CR and NL excluded)
// string I_C, the payload of the client's SSH_MSG_KEXINIT
// string I_S, the payload of the server's SSH_MSG_KEXINIT
// string K_S, the host key
// mpint e, exchange value sent by the client
// mpint f, exchange value sent by the server
// mpint K, the shared secret
// This value is called the exchange hash, and it is used to authenti-
// cate the key exchange.
buf.Reset();
buf.PutString(V_C);
buf.PutString(V_S);
buf.PutString(I_C);
buf.PutString(I_S);
buf.PutString(K_S);
buf.PutMPInt(e);
buf.PutMPInt(f);
buf.PutMPInt(K);
byte[] foo = new byte[buf.GetLength()];
buf.GetByte(foo);
sha.Update(foo, 0, foo.Length);
H = sha.Digest();
//System.err.print("H -> "); //dump(H, 0, H.length);
i = 0;
j = 0;
j = ((K_S[i++] << 24) & unchecked((int)(0xff000000))) | ((K_S[i++] << 16) & unchecked(
(int)(0x00ff0000))) | ((K_S[i++] << 8) & unchecked((int)(0x0000ff00))) | ((K_S[i
++]) & unchecked((int)(0x000000ff)));
string alg = Util.Byte2str(K_S, i, j);
i += j;
bool result = false;
if (alg.Equals("ssh-rsa"))
{
byte[] tmp;
byte[] ee;
byte[] n;
type = RSA;
j = ((K_S[i++] << 24) & unchecked((int)(0xff000000))) | ((K_S[i++] << 16) & unchecked(
(int)(0x00ff0000))) | ((K_S[i++] << 8) & unchecked((int)(0x0000ff00))) | ((K_S[i
++]) & unchecked((int)(0x000000ff)));
tmp = new byte[j];
System.Array.Copy(K_S, i, tmp, 0, j);
i += j;
ee = tmp;
j = ((K_S[i++] << 24) & unchecked((int)(0xff000000))) | ((K_S[i++] << 16) & unchecked(
(int)(0x00ff0000))) | ((K_S[i++] << 8) & unchecked((int)(0x0000ff00))) | ((K_S[i
++]) & unchecked((int)(0x000000ff)));
tmp = new byte[j];
System.Array.Copy(K_S, i, tmp, 0, j);
i += j;
n = tmp;
NSch.SignatureRSA sig = null;
try
{
Type c = Sharpen.Runtime.GetType(session.GetConfig("signature.rsa"));
sig = (NSch.SignatureRSA)(System.Activator.CreateInstance(c));
sig.Init();
}
catch (Exception ex)
{
System.Console.Error.WriteLine(ex);
}
sig.SetPubKey(ee, n);
//.........这里部分代码省略.........
示例10: IdentityFile
//.........这里部分代码省略.........
if (xd)
{
len--;
}
len--;
continue;
}
if (buf[i] == '-')
{
break;
}
i++;
}
encoded_data = Util.FromBase64(buf, start, i - start);
if (encoded_data.Length > 4 && encoded_data[0] == unchecked((byte)unchecked((int)
(0x3f))) && encoded_data[1] == unchecked((byte)unchecked((int)(0x6f))) && encoded_data
[2] == unchecked((byte)unchecked((int)(0xf9))) && encoded_data[3] == unchecked((
byte)unchecked((int)(0xeb))))
{
// FSecure
Buffer _buf = new Buffer(encoded_data);
_buf.GetInt();
// 0x3f6ff9be
_buf.GetInt();
byte[] _type = _buf.GetString();
//System.err.println("type: "+new String(_type));
byte[] _cipher = _buf.GetString();
string cipher2 = Util.Byte2str(_cipher);
//System.err.println("cipher: "+cipher);
if (cipher2.Equals("3des-cbc"))
{
_buf.GetInt();
byte[] foo = new byte[encoded_data.Length - _buf.GetOffSet()];
_buf.GetByte(foo);
encoded_data = foo;
encrypted = true;
throw new JSchException("unknown privatekey format: " + identity);
}
else
{
if (cipher2.Equals("none"))
{
_buf.GetInt();
//_buf.getInt();
encrypted = false;
byte[] foo = new byte[encoded_data.Length - _buf.GetOffSet()];
_buf.GetByte(foo);
encoded_data = foo;
}
}
}
if (pubkey == null)
{
return;
}
buf = pubkey;
len = buf.Length;
if (buf.Length > 4 && buf[0] == '-' && buf[1] == '-' && buf[2] == '-' && buf[3] ==
'-')
{
// FSecure's public key
i = 0;
do
{
i++;
}