-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathPrimitive_File.cs
67 lines (58 loc) · 2.54 KB
/
Primitive_File.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml;
namespace Primitive_File_Reader
{
public class Primitive_File
{
public void ReadPrimitives(BinaryReader reader, XmlNode element, XmlDocument xDoc)
{
int len = (int)reader.BaseStream.Length;
int data = (int)reader.BaseStream.Position + sizeof(int);
reader.BaseStream.Position = ((int)reader.BaseStream.Position + len - sizeof(int));
int indexLen = reader.ReadInt32();
int offset = len - (indexLen + sizeof(int));
reader.BaseStream.Position = offset;
long oldDataLen = 4;
while (offset < (len - 4))
{
int entryDataLen = 0;
int entryNameLen = 0;
for (int i = 0; i < (len - (int)reader.BaseStream.Position); i++)
{
if (reader.ReadByte() != 0x00)
{
reader.BaseStream.Position = (int)reader.BaseStream.Position - 1;
entryDataLen = reader.ReadInt32();
break;
}
}
for (int i = 0; i < (len - (int)reader.BaseStream.Position); i++)
{
if (reader.ReadByte() != 0x00)
{
reader.BaseStream.Position = (int)reader.BaseStream.Position - 1;
entryNameLen = reader.ReadInt32();
break;
}
}
string entryStr = new string(reader.ReadChars(entryNameLen), 0, entryNameLen);
XmlNode XentryStr = xDoc.CreateElement("primitive");
XmlAttribute attr = xDoc.CreateAttribute("id");
attr.InnerText = entryStr;
XentryStr.Attributes.Append(attr);
XmlNode XentryDataPos = xDoc.CreateElement("position");
XentryDataPos.InnerText = Convert.ToString(oldDataLen);
XmlNode XentryDataLen = xDoc.CreateElement("length");
XentryDataLen.InnerText = Convert.ToString(entryDataLen);
oldDataLen += (entryDataLen + 3) & (~3L);
XentryStr.AppendChild(XentryDataPos);
XentryStr.AppendChild(XentryDataLen);
offset = (int)reader.BaseStream.Position + entryNameLen;
element.AppendChild(XentryStr);
}
}
}
}