public uint readData(out Data data,uint size) { byte [] buffer = new byte[size]; uint red = theReader.read(buffer, 0, (ulong)size); data = new Data(buffer, size); return red; }
public DataReader(Data date) { data = date; }
public bool initFromData(ByteReader versionReader) { WrapperReader reader = new WrapperReader(versionReader); uint red = 0; reader.align(4); reader.mark(); byte[] buffer = new byte[6]; uint ret = reader.read(buffer,0,6); if (ret == 0xFFFFffff || ret < 6) return false; header = new Header(buffer); red += ret; red += reader.readString(out key); red += (uint)reader.align(4); if (header.wValueLength != 0) { if (header.wType == 0) { values = new Data(null, (uint)header.wValueLength); red += reader.readData(out values, (uint)header.wValueLength); } else if (header.wType == 1) { values = new Data(null, (uint)header.wValueLength << 1); //buffer = new byte[header.wValueLength << 1]; //red += reader.read(buffer, 0, (ulong)header.wValueLength << 1); //values = new Data(buffer, (uint)header.wValueLength << 1); red += reader.readData(out values, (uint)header.wValueLength << 1); } else throw new ResourceException(); } if (header.wLength > red) { buffer = new byte[header.wLength - red]; reader.read(buffer, 0, header.wLength - red); rest = new Data(buffer, header.wLength - red); } reader.reset(); buffer = new byte[header.wLength]; reader.read(buffer, 0, header.wLength); allData = new Data(buffer, header.wLength); //dump(); if (rest != null && rest.size() != 0) { bool bContinue = false; DataReader childReader = new DataReader(rest); do { VersionInfo pNew = new VersionInfo(); bContinue = pNew.initFromData(childReader); //pNew->dump(); if(bContinue) children.Add(pNew); } while (bContinue); } return true; }
public Data(Data data) { theSize = data.theSize; buffer = new byte[theSize]; }
public String[] loadResource(object obj,ref Bitmap bitmap) { if (obj is ResEntry) { ResEntry entry = (ResEntry)obj; UInt64 handle = initSeasons(); UInt32 size = 0; int bRet = openResModule(handle, path); getResourceSize(handle, ref entry, ref size); byte[] buffer = new byte[size]; for(int i = 0; i < size; ++i) { buffer[i] = (byte)(i % 256); } getResource(handle, ref entry, size ,buffer); closeResModule(handle); freeSeasons(handle); Data data = new Data(buffer, size); ArrayList list = data.toHex(); String[] ar = new String[ list.Count ]; int j = 0; foreach(String s in list) { ar[j++] = s; } byte[] obuf = new byte[buffer.Length + 6 + 16]; int k = 0; /* typedef struct { DWORD DataSize; DWORD HeaderSize; DWORD TYPE; Unicode If the first WORD in the member is equal to the value 0xffff,it is ordinal otherwise unicode DWORD NAME; Unicode Padding; DWORD DataVersion; WORD MemoryFlags; MOVEABLE(0x0010) FIXED(~MOVEABLE) PURE(0x0020) IMPURE(~PURE) PRELOAD(0x0040) LOADONCALL(~PRELOAD) DISCARDABLE(0x1000) WORD LanguageId; DWORD Version; DWORD Characteristics; } https://msdn.microsoft.com/en-us/library/windows/desktop/ms648027(v=vs.85).aspx RESOURCEHEADER;*/ // directory obuf[k++] = 0; obuf[k++] = 0; obuf[k++] = 1; // Icon = 1 ; Cursor = 2 obuf[k++] = 0; obuf[k++] = 1; // 1 icon in file obuf[k++] = 0; // end directory Copy(buffer, 0, obuf, 6, buffer.Length ); File.WriteAllBytes("my.ico", obuf); return ar; } return new String[0]; }
private void filename_TextChanged(object sender, EventArgs e) { path = filename.Text; if(!File.Exists(path)) { return; } baseTree.Nodes.Clear(); XmlReader xml = XmlReader.Create(path); Stack<String> backStack = new Stack<String>(); Stack<TreeNode> nodeStack = new Stack<TreeNode>(); TreeNode node = new TreeNode("ROOT"); TreeNode oldnode = null; baseTree.Nodes.Add(node); while (xml.Read()) { switch (xml.NodeType) { case XmlNodeType.Element: oldnode = node; if (oldnode != null) nodeStack.Push(oldnode); node = new TreeNode(xml.Name); node.Tag = new Dictionary<String, String>(); oldnode.Nodes.Add(node); backStack.Push(xml.Name); if (xml.HasAttributes) { xml.MoveToFirstAttribute(); do { ((Dictionary<String, String>)node.Tag).Add(xml.Name, xml.Value); } while (xml.MoveToNextAttribute()); } break; case XmlNodeType.Text: node.Nodes.Add("Text").Tag = xml.Value; break; case XmlNodeType.Attribute: ((Dictionary<String, String>)node.Tag).Add(xml.Name, xml.Value); break; case XmlNodeType.CDATA: node.Nodes.Add("CDATA").Tag = xml.Value; break; case XmlNodeType.Comment: node.Nodes.Add("Comment").Tag = xml.Value; break; case XmlNodeType.EndElement: String nodeX = backStack.Pop(); if (nodeX != xml.Name) throw new SyntaxErrorException(); node = nodeStack.Pop(); break; case XmlNodeType.ProcessingInstruction: break; default: break; } } xml.Close(); baseTree.ExpandAll(); return; byte[] buffer = version.getFileVersion(path); Data data = new Data(buffer, (uint)buffer.Length); DataReader reader = new DataReader(data); VersionInfo info = new VersionInfo(); info.initFromData(reader); TreeNode vTree = info.makeNodes(); if (vTree != null) baseTree.Nodes.Add(vTree); baseTree.Nodes.Add("ResourceTypes"); }