ウェブゲームの外挂けの补助AMFシミュレーションの通信は必ず必要です
16740 ワード
class AMF_Post_Data
{
public List<byte> message;
/// <summary>
/// Message
/// </summary>
/// <param name="at"></param>
/// <param name="headers"></param>
/// <param name="bodies"></param>
public AMF_Post_Data(AMFType at, int headers, int bodies)
{
//AMF
if (at == AMFType.AMF0)
{
message = new List<byte>(new byte[] { 0x00, 0x00 });
}
else if (at == AMFType.AMF3)
{
message = new List<byte>(new byte[] { 0x00, 0x03 });
}
//header
message.Add(BitConverter.GetBytes(headers)[1]);
message.Add(BitConverter.GetBytes(headers)[0]);
//body
message.Add(BitConverter.GetBytes(bodies)[1]);
message.Add(BitConverter.GetBytes(bodies)[0]);
}
/// <summary>
/// Target
/// </summary>
/// <param name="target"></param>
/// <param name="Response"></param>
public void AddTargetAndResponse(string target, string Response)
{
// Target
message.Add(BitConverter.GetBytes(target.Length)[1]);
message.Add(BitConverter.GetBytes(target.Length)[0]);
// Target
message.AddRange(Encoding.Default.GetBytes(target));
// Response
message.Add(BitConverter.GetBytes(Response.Length)[1]);
message.Add(BitConverter.GetBytes(Response.Length)[0]);
// Response
message.AddRange(Encoding.Default.GetBytes(Response));
}
/// <summary>
/// Body
/// </summary>
/// <param name="length"></param>
/// <param name="Content"></param>
public void AddBody(AMF_Post_Data_Body apdb)
{
message.AddRange(apdb.getLength());
message.AddRange(apdb.Content.ToArray());
}
}
class AMF_Post_Data_Body
{
private byte[] length = new byte[4];
public List<byte> Content = new List<byte>();
/// <summary>
/// Body
/// </summary>
/// <param name="dt"></param>
/// <param name="ArrayLength"></param>
public AMF_Post_Data_Body(DataType dt, int ArrayLength)
{
//
Content.Add((byte)dt);
//
if (dt == DataType.Array)
{
Content.Add(BitConverter.GetBytes(ArrayLength)[3]);
Content.Add(BitConverter.GetBytes(ArrayLength)[2]);
Content.Add(BitConverter.GetBytes(ArrayLength)[1]);
Content.Add(BitConverter.GetBytes(ArrayLength)[0]);
}
}
public void AddData(DataType dt, string value)
{
//
Content.Add((byte)dt);
switch (dt)
{
case DataType.Number:
AddData_Number(double.Parse(value));
break;
case DataType.String:
AddData_String(value);
break;
case DataType.Boolean:
AddData_Boolean(Boolean.Parse(value));
break;
}
}
#region
/// <summary>
/// Boolean
/// </summary>
/// <param name="p"></param>
private void AddData_Boolean(bool p)
{
if (p)
Content.Add(0x01);
else
Content.Add(0x00);
}
/// <summary>
/// String
/// </summary>
/// <param name="value"></param>
private void AddData_String(string value)
{
//
Content.Add(BitConverter.GetBytes(value.Length)[1]);
Content.Add(BitConverter.GetBytes(value.Length)[0]);
//
Content.AddRange(Encoding.Default.GetBytes(value));
}
/// <summary>
/// Number
/// </summary>
/// <param name="p"></param>
private void AddData_Number(double p)
{
byte[] b = new byte[8];
b = BitConverter.GetBytes(p);
for (int i = 7; i > -1; i--)
{
Content.Add(b[i]);
}
}
#endregion
public byte[] getLength()
{
length[0] = BitConverter.GetBytes(Content.Count)[3];
length[1] = BitConverter.GetBytes(Content.Count)[2];
length[2] = BitConverter.GetBytes(Content.Count)[1];
length[3] = BitConverter.GetBytes(Content.Count)[0];
return length;
}
}
#region
public enum AMFType
{
AMF0,
AMF3
}
public enum DataType
{
Number = 0,
Boolean = 1,
String = 2,
UntypedObject = 3,
MovieClip = 4,
Null = 5,
Undefined = 6,
ReferencedObject = 7,
MixedArray = 8,
End = 9,
Array = 10,//0x0A
Date = 11,//0x0B
LongString = 12,//0x0C
TypeAsObject = 13,//0x0D
Recordset = 14,//0x0E
Xml = 15,//0x0F
TypedObject = 16,//0x10
AMF3data = 17//0x11
}
#endregion