[StructLayout(LayoutKind.Sequential, Pack=4)] public struct JJ_HEADER_tag { public UInt32 time; public UInt32 index; public UInt32 cmd; public UInt32 option; public UInt32 unk; public UInt32 datalength; }其余的自己慢慢数吧
不要挑最简单的啊,我之所以发这部分出来,是因为下面的转换要用到这个结构体。多一行 //BYTE Data[sizeof(JJ_HEADER)+8] = {0}; int lengthOfData = Marshal.SizeOf(typeof(JJ_HEADER_tag)) + 8; Byte[] DATA = new Byte[lengthOfData]; Array.Clear(DATA, 0, DATA.Length);
一个结构体,结构体赋值,然后异或加密。
最后得到 (char *)Data 的值。
反正辛辛苦苦写半天,lz来一个不能用,无满意答案结贴这种事情我遇到多了,现在不浪费感情了。跟扶老人然后被老人讹一样的道理吧?
目测lz不是一无所知,可以自己稍微修改调试下的,给点代码,还有就是这个需求比较通用的,能帮助很多人的,写一写。别的现在基本不写了。
除了大学时的C++基础,一直没再用过了。我之前一直用VB.NET的,昨天拿到这代码,查了一整天资料,真转换不了才发帖求助的。VB.NET版块发了没人气才来求C#的。已发猪八戒去了,愿意帮忙的可以到猪八戒去接。
http://task.zhubajie.com/3511945/
[StructLayout(LayoutKind.Sequential, Pack=4)]
public struct JJ_HEADER_tag
{
public UInt32 time;
public UInt32 index;
public UInt32 cmd;
public UInt32 option;
public UInt32 unk;
public UInt32 datalength;
}其余的自己慢慢数吧
不要挑最简单的啊,我之所以发这部分出来,是因为下面的转换要用到这个结构体。多一行 //BYTE Data[sizeof(JJ_HEADER)+8] = {0}; int lengthOfData = Marshal.SizeOf(typeof(JJ_HEADER_tag)) + 8;
Byte[] DATA = new Byte[lengthOfData];
Array.Clear(DATA, 0, DATA.Length);
先转换,实在没办法再弄成DLL调用,DLL调用是最后的选择。
先转换,实在没办法再弄成DLL调用,DLL调用是最后的选择。
这个建议不错~
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;namespace ConsoleApplication1
{
[StructLayout(LayoutKind.Sequential, Pack=4)]
public class JJ_HEADER_tag
{
public uint Time { get; set; }
public uint Index { get; set; }
public uint Command { get; set; }
public uint Option { get; set; }
public uint UNK { get; set; }
public uint DataLength { get; set; }
} class Program
{
static void Main(string[] args)
{
PacketData();
Console.ReadLine();
} static uint m_PacketIndex = 0x00000000; static int PacketData()
{
JJ_HEADER_tag header = new JJ_HEADER_tag();
int nLen = Marshal.SizeOf(typeof(JJ_HEADER_tag)) + 8;
header.Time = 0;
header.Index = m_PacketIndex++;
header.Command = 0x44C;
header.Option = 0x24800;
header.DataLength = 8;
byte[] data = new byte[nLen];
string sTemp = DataToString(header);
data = Encoding.Default.GetBytes(sTemp);
return XorEncrypt(data, nLen);
} static int XorEncrypt(byte[] data, int len)
{
if (len > 0x14)
{
string str = System.Text.Encoding.ASCII.GetString(data);
JJ_HEADER_tag header = StringToData(str);
if (header.DataLength > 0 && ((header.Option & 0x40000000) == 0x00000000))
{
header.Option |= 0x40000000; GCHandle hObject = GCHandle.Alloc(data, GCHandleType.Pinned);
IntPtr pData = hObject.AddrOfPinnedObject();
pData += Marshal.SizeOf(typeof(JJ_HEADER_tag));
printPackets("pData", pData, len); for (uint i = 0; i < header.DataLength; i++)
{
byte key = data[(header.Index ^ i) % 4];
data[i] ^= key;
}
}
}
return 0;
} static JJ_HEADER_tag StringToData(string ss)
{
if (ss != null)
{
string[] arrTemp = ss.Split('\t');
if (arrTemp != null && arrTemp.Length > 5)
{
JJ_HEADER_tag data = new JJ_HEADER_tag();
string sTime = arrTemp[0];
data.Time = UInt32.Parse(sTime);
string sIndex = arrTemp[1];
data.Index = UInt32.Parse(sIndex);
string sCommand = arrTemp[2];
data.Command = UInt32.Parse(sCommand);
string sOption = arrTemp[3];
data.Option = UInt32.Parse(sOption);
string sUNK = arrTemp[4];
data.UNK = UInt32.Parse(sUNK);
string sDataLength = arrTemp[5];
data.DataLength = UInt32.Parse(sDataLength);
return data;
}
}
return null;
} static string DataToString(JJ_HEADER_tag data)
{
if (data != null)
{
StringBuilder strBuilder = new StringBuilder();
strBuilder.Append(data.Time.ToString() + "\t");
strBuilder.Append(data.Index.ToString() + "\t");
strBuilder.Append(data.Command.ToString() + "\t");
strBuilder.Append(data.Option.ToString() + "\t");
strBuilder.Append(data.UNK.ToString() + "\t");
strBuilder.Append(data.DataLength.ToString());
return strBuilder.ToString();
}
return "";
} static void printPackets(string sData, IntPtr pData, int len)
{
Console.WriteLine(sData+"\t"+pData.ToString()+"\t"+len.ToString());
}
}
}
测试过了,没问题。你再看看是不是符合需求吧。
http://task.zhubajie.com/3511945/
可不是 0 哦