本文整理汇总了C#中Reader.ReadBytes方法的典型用法代码示例。如果您正苦于以下问题:C# Reader.ReadBytes方法的具体用法?C# Reader.ReadBytes怎么用?C# Reader.ReadBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Reader
的用法示例。
在下文中一共展示了Reader.ReadBytes方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Parse
public override void Parse(byte[] buffer)
{
Reader reader = new Reader(new MemoryStream(buffer));
reader.ReadByte(); // Id
SessionId = reader.ReadInt32();
Protocol = reader.ReadInt32();
EncKey = reader.ReadBytes(128);
//got the encoded key in enckey
// step 4 : xor last 0x40 bytes with first 0x40 bytes
for (int i = 0; i < 0x40; i++)
EncKey[0x40 + i] = (byte)(EncKey[0x40 + i] ^ EncKey[i]);
// step 3 : xor bytes 0x0d-0x10 with bytes 0x34-0x38
for (int i = 0; i < 4; i++)
EncKey[0x0d + i] = (byte)(EncKey[0x0d + i] ^ EncKey[0x34 + i]);
// step 2 : xor first 0x40 bytes with last 0x40 bytes
for (int i = 0; i < 0x40; i++)
EncKey[i] = (byte)(EncKey[i] ^ EncKey[0x40 + i]);
// step 1 : 0x4d-0x50 <-> 0x00-0x04
for (int i = 0; i < 4; i++)
{
byte temp = EncKey[i];
EncKey[i] = EncKey[0x4d + i];
EncKey[0x4d + i] = temp;
}
}
示例2: Parse
public override void Parse(byte[] buffer)
{
Reader reader = new Reader(new MemoryStream(buffer));
reader.ReadByte(); // Id
GameKey = reader.ReadBytes(8);
}
示例3: Parse
public override void Parse(byte[] buffer)
{
Reader reader = new Reader(new MemoryStream(buffer));
reader.ReadByte(); // Id
CrestId = reader.ReadInt32();
Content = reader.ReadBytes(reader.ReadInt32());
}
示例4: DecryptWrite
private string DecryptWrite(string path, Reader reader)
{
int multiplicator = 65536;
byte[] encryptData = new byte[AESKeys.Length * multiplicator];
byte[] decryptData = new byte[AESKeys.Length * multiplicator];
byte[] dataRiv = new byte[16];
Array.Copy(PackageData.pkg_data_riv, dataRiv, PackageData.pkg_data_riv.Length);
if (File.Exists(path + ".cache"))
File.Delete(path + ".cache");
FileStream streamWrite = new FileStream(path + ".cache", FileMode.CreateNew, FileAccess.ReadWrite, FileShare.ReadWrite);
Writer write = new Writer(streamWrite, Endian.Little);
reader.Position = (uint)PackageData.data_offset;
reader.CurrentEndian = Endian.Little;
double split = (double)PackageData.data_size / (double)(AESKeys.Length * multiplicator);
UInt64 pieces = (UInt64)Math.Floor(split);
UInt64 data = (UInt64)PackageData.data_size % (UInt64)(AESKeys.Length * multiplicator);
if (data > 0)
pieces += 1;
ProgressBar.ValueInvoke(0);
for (UInt64 i = 0; i < pieces; i++)
{
if ((data > 0) && (i == (pieces - 1)))
{
encryptData = new byte[data];
decryptData = new byte[data];
}
encryptData = reader.ReadBytes(encryptData.Length);
byte[] key = new byte[encryptData.Length];
byte[] xor = new byte[encryptData.Length];
for (int pos = 0; pos < encryptData.Length; pos += AESKeys.Length)
{
Array.Copy(dataRiv, 0, key, pos, PackageData.pkg_data_riv.Length);
IncrementArray(ref dataRiv, PackageData.pkg_data_riv.Length - 1);
}
xor = Security.Rijndael.Encrypt(key, AESKeys, AESKeys, CipherMode.ECB, PaddingMode.None);
decryptData = XOR(encryptData, 0, xor.Length, xor);
write.Write(decryptData);
ProgressBar.ValueInvoke((int)((100 * i) / pieces));
}
write.Close();
streamWrite.Close();
ProgressBar.ValueInvoke(100);
return string.Format("{0}.{1}", path, "cache");
}
示例5: IsValidPKG
public static bool IsValidPKG(string path)
{
FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read);
Reader reader = new Reader(stream, Endian.Little);
byte[] magic = reader.ReadBytes(0x04);
if (magic[0] == 0x7F && magic[1] == 0x50 && magic[2] == 0x4B && magic[3] == 0x47) // Check String
return true;
return false;
}
示例6: ReadHeader
public PackageHeader ReadHeader(Reader reader)
{
PackageHeader header = new PackageHeader();
header.magic = reader.ReadBytes(0x04);
Array.Reverse(header.magic);
reader.Position = 0x07;
header.pkg_type = reader.ReadByte();
reader.Position = 0x08;
header.pkg_info_offset = reader.ReadUInt32();
reader.Position = 0x0C;
header.pkg_info_count = reader.ReadUInt32();
reader.Position = 0x10;
header.header_size = reader.ReadUInt32();
reader.Position = 0x14;
header.item_count = reader.ReadUInt32();
reader.Position = 0x18;
header.total_size = reader.ReadUInt64();
reader.Position = 0x20;
header.data_offset = reader.ReadUInt64();
reader.Position = 0x28;
header.data_size = reader.ReadUInt64();
reader.Position = 0x30;
header.contentid = reader.ReadString(0x24);
reader.Position = 0x60;
header.digest = reader.ReadBytes(0x10);
Array.Reverse(header.digest);
reader.Position = 0x70;
header.pkg_data_riv = reader.ReadBytes(0x10);
Array.Reverse(header.pkg_data_riv);
reader.Position = 0x80;
header.header_cmac_hash = reader.ReadBytes(0x10);
Array.Reverse(header.header_cmac_hash);
reader.Position = 0x90;
header.header_npdrm_signature = reader.ReadBytes(0x28);
Array.Reverse(header.header_npdrm_signature);
reader.Position = 0xB8;
header.header_sha1_hash = reader.ReadBytes(0x08);
Array.Reverse(header.header_sha1_hash);
return header;
}
示例7: Test_PdfImportStream_01
public static void Test_PdfImportStream_01(string inputPdfFile, string outputPdfFile, string streamFile)
{
_tr.WriteLine("import stream for object TPL1 of pdf file \"{0}\" from \"{1}\" and save pdf to \"{2}\"", inputPdfFile, streamFile, outputPdfFile);
PB_Pdf.PdfReader pr = null;
Reader r = null;
PB_Pdf.PdfWriter pw = null;
try
{
pr = new PB_Pdf.PdfReader(inputPdfFile);
//IPdfObject obj = ReadPdfObject(pr, idObject, "Object");
r = new Reader(streamFile);
//obj.stream = r.ReadBytes((int)r.Length);
//PdfNValue length = obj.value["Length"];
//if (length == null || !length.value.isInt()) throw new PBException("error wrong /Length of object {0}", idObject);
//length.value.valueInt = obj.stream.Length;
pw = new PB_Pdf.PdfWriter(outputPdfFile, FileMode.Create);
pw.reader = pr;
IPdfObject info = ReadPdfObject(pr, pr.Trailer["Info"].value.valueObjectId, "Info");
pw.WriteObject(info, "Info");
IPdfObject root = ReadPdfObject(pr, pr.Trailer["Root"].value.valueObjectId, "Root");
pw.WriteObject(root, "Root");
IPdfObject pages = ReadPdfObject(pr, root.value["Pages"].value.valueObjectId, "Pages");
pw.WriteObject(pages);
IPdfObject page1 = ReadPdfObject(pr, pages.value["Kids"].value[0].valueObjectId, "Page 1");
pw.WriteObject(page1);
IPdfObject page1Content = ReadPdfObject(pr, page1.value["Contents"].value.valueObjectId, "Contents page 1");
pw.WriteObject(page1Content);
IPdfObject page1Ressource = ReadPdfObject(pr, page1.value["Resources"].value.valueObjectId, "Resources page 1");
pw.WriteObject(page1Ressource);
IPdfObject page1Ressource_01 = ReadPdfObject(pr, page1Ressource.value["XObject"].value["TPL1"].value.valueObjectId, "Resources page 1 /TPL1");
// import stream from file
page1Ressource_01.stream = r.ReadBytes((int)r.Length);
PdfNValue length = page1Ressource_01.value["Length"];
if (length == null || !length.value.isInt()) throw new PBException("error wrong /Length of object {0}", page1Ressource_01.id);
length.value.valueInt = page1Ressource_01.stream.Length;
pw.WriteObjectWithChilds(page1Ressource_01);
}
finally
{
if (pr != null) pr.Close();
if (r != null) r.Close();
if (pw != null) pw.Close();
}
}
示例8: Test_PdfUpdateStream_01
public static void Test_PdfUpdateStream_01(string pdfFile, int objectId, string streamFile)
{
_tr.WriteLine("update stream for object {0} with \"{1}\" of pdf file \"{2}\"", objectId, streamFile, pdfFile);
PB_Pdf.PdfWriter pw = null;
Reader r = null;
try
{
pw = new PB_Pdf.PdfWriter(pdfFile, updatePdf: true);
IPdfObject obj = pw.reader.ReadObject(objectId);
r = new Reader(streamFile);
obj.stream = r.ReadBytes((int)r.Length);
PdfNValue length = obj.value["Length"];
if (length == null || !length.value.isInt()) throw new PBException("error wrong /Length of object {0}", obj.id);
length.value.valueInt = obj.stream.Length;
pw.UpdateObject(obj);
}
finally
{
if (r != null) r.Close();
if (pw != null) pw.Close();
}
}