コード例 #1
0
        private void Write(byte[] binary, int length)
        {
            switch (binaryTextMode)
            {
            case BinaryTextMode.Base64:
                xml.WriteBase64(binary, 0, length);
                break;

            case BinaryTextMode.BinHex:
                xml.WriteBinHex(binary, 0, length);
                break;

            case BinaryTextMode.QuotedPrintable:
                xml.WriteString(QuotedPrintable.Encode(binary, 0, length));
                break;

            case BinaryTextMode.AsciiHexSwitch:
                xml.WriteString(AsciiHexSwitch.Encode(binary, 0, length));
                break;
            }
        }
コード例 #2
0
 public override void WriteBinHex(Byte[] buffer, Int32 index, Int32 count)
 {
     base.WriteBinHex(buffer, index, count);
     _logWriter.WriteBinHex(buffer, index, count);
 }
コード例 #3
0
    public static bool ExportStrategy(string fileName, IList strategyList)
    {
        FileStream fileStream = null;
        bool       bRet       = false;

        try
        {
            fileStream = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write);
            fileStream.SetLength(0L);
            XmlTextWriter writer = new XmlTextWriter(fileStream, Encoding.Default);
            byte[]        strategyBytes;

            //声明
            writer.WriteStartDocument();
            writer.WriteWhitespace("\n");

            writer.WriteStartElement("StrategyList");
            foreach (Strategy strategy in strategyList)
            {
                writer.WriteWhitespace("\n\t");
                writer.WriteStartElement("Strategy");
                writer.WriteWhitespace("\n\t\t");

                writer.WriteElementString("Name", strategy.SecurityObject.Name);
                writer.WriteWhitespace("\n\t\t");

                writer.WriteElementString("Comment", strategy.SecurityObject.Comment);
                writer.WriteWhitespace("\n\t\t");

                writer.WriteElementString("Event", ((int)strategy.Event).ToString());
                writer.WriteWhitespace("\n\t\t");

                writer.WriteStartElement("Automation");
                strategyBytes = AdminServer.TheInstance.AutomationManager.Save(strategy.Automation);
                writer.WriteBinHex(strategyBytes, 0, strategyBytes.Length);
                writer.WriteEndElement();
                writer.WriteWhitespace("\n\t\t");

                writer.WriteElementString("Enable", strategy.Enabled ? "1" : "0");
                writer.WriteWhitespace("\n\t");

                writer.WriteEndElement();
            }
            writer.WriteWhitespace("\n");
            writer.WriteEndElement();

            writer.Flush();
            bRet = true;
        }
        catch (Exception)
        {
            bRet = false;
        }
        finally
        {
            if (fileStream != null)
            {
                fileStream.Close();
            }
        }
        return(bRet);
    }
コード例 #4
0
        //SAVE ----------------------------------------------------------------------
        public static bool SaveXml(string inFileName, string outDir)
        {
            byte[]        inFile = File.ReadAllBytes(inFileName);
            XmlTextWriter writer = new XmlTextWriter(outDir, null);

            writer.Formatting = Formatting.Indented;

            writer.WriteStartElement("PACK");
            writer.WriteStartElement("SARC");
            //SARC header 0x00 - 0x13
            if (inFile[0] != 'S' || inFile[1] != 'A' || inFile[2] != 'R' || inFile[3] != 'C')
            {
                return(false);
            }
            int    pos = 4;                                     //0x04
            ushort hdr = Makeu16(inFile[pos], inFile[pos + 1]); //SARC Header length

            writer.WriteElementString("HeaderLengthBytes", hdr.ToString());
            pos += 2;                                           //0x06
            ushort bom = Makeu16(inFile[pos], inFile[pos + 1]); //Byte Order Mark

            writer.WriteElementString("ByteOrderMark", "0x" + bom.ToString("X"));
            if (bom != 65279) //Check 0x06 for Byte Order Mark (if not 0xFEFF)
            {
                return(false);
            }
            pos += 2; //0x08
            uint fileSize = Makeu32(inFile[pos], inFile[pos + 1], inFile[pos + 2], inFile[pos + 3]);

            writer.WriteElementString("FileSizeBytes", Convert.ToString(fileSize));
            pos += 4;                                                                                  //0x0C
            uint dataOffset = Makeu32(inFile[pos], inFile[pos + 1], inFile[pos + 2], inFile[pos + 3]); //Data offset start position

            writer.WriteElementString("DataTableOffset", "0x" + dataOffset.ToString("X"));
            pos += 4;                                                                               //0x10
            uint unknown = Makeu32(inFile[pos], inFile[pos + 1], inFile[pos + 2], inFile[pos + 3]); //unknown, always 0x01?

            writer.WriteElementString("Unknown", "0x" + unknown.ToString("X"));
            pos += 4;                 //0x14
            writer.WriteEndElement(); //</SARC>

            writer.WriteStartElement("SFAT");
            //SFAT header 0x14 - 0x1F
            if (inFile[pos] != 'S' || inFile[pos + 1] != 'F' || inFile[pos + 2] != 'A' || inFile[pos + 3] != 'T')
            {
                return(false);
            }
            pos += 4;                                            //0x18
            ushort hdr2 = Makeu16(inFile[pos], inFile[pos + 1]); //SFAT Header length

            writer.WriteElementString("HeaderLengthBytes", hdr2.ToString());
            pos += 2;                                                 //0x1A
            ushort nodeCount = Makeu16(inFile[pos], inFile[pos + 1]); //Node Cluster count

            writer.WriteElementString("NodeCount", Convert.ToString(nodeCount));
            pos += 2;                                                                             //0x1C
            uint hashr = Makeu32(inFile[pos], inFile[pos + 1], inFile[pos + 2], inFile[pos + 3]); //Hash multiplier, always 0x65

            writer.WriteElementString("HashMultiplier", "0x" + hashr.ToString("X"));
            pos += 4; //0x20
            SarcNode[] nodes   = new SarcNode[nodeCount];
            SarcNode   tmpnode = new SarcNode();

            for (int i = 0; i < nodeCount; i++) //Node cluster
            {
                writer.WriteStartElement("NodeInfo" + i);
                tmpnode.hash = Makeu32(inFile[pos], inFile[pos + 1], inFile[pos + 2], inFile[pos + 3]);
                writer.WriteElementString("Hash", "0x" + (tmpnode.hash).ToString("X"));
                pos            += 4;                                                                     //0x?4
                tmpnode.unknown = inFile[pos];                                                           //unknown, always 0x01? (not used in this case)
                writer.WriteElementString("Unknown", "0x" + (tmpnode.unknown).ToString("X"));
                pos           += 1;                                                                      //0x?5
                tmpnode.offset = Makeu32(0, inFile[pos], inFile[pos + 1], inFile[pos + 2]);              //Node SFNT filename offset divided by 4
                writer.WriteElementString("FileNameOffset", "0x" + ((tmpnode.offset * 4) + hdr + hdr2 + (nodeCount * 0x10) + 8).ToString("X"));
                pos          += 3;                                                                       //0x?8
                tmpnode.start = Makeu32(inFile[pos], inFile[pos + 1], inFile[pos + 2], inFile[pos + 3]); //Start Data offset position
                writer.WriteElementString("DataStartOffset", "0x" + (tmpnode.start + dataOffset).ToString("X"));
                pos        += 4;                                                                         //0x?C
                tmpnode.end = Makeu32(inFile[pos], inFile[pos + 1], inFile[pos + 2], inFile[pos + 3]);   //End Data offset position
                writer.WriteElementString("DataEndOffset", "0x" + (tmpnode.end + dataOffset).ToString("X"));
                pos     += 4;                                                                            //0x?0
                nodes[i] = tmpnode;                                                                      //Store node data into array
                writer.WriteEndElement();                                                                //</NodeInfo>
            }
            writer.WriteEndElement();                                                                    //</SFAT>

            writer.WriteStartElement("SFNT");
            if (inFile[pos] != 'S' || inFile[pos + 1] != 'F' || inFile[pos + 2] != 'N' || inFile[pos + 3] != 'T')
            {
                return(false);
            }
            pos += 4;                                            //0x?4
            ushort hdr3 = Makeu16(inFile[pos], inFile[pos + 1]); //SFNT Header length

            writer.WriteElementString("HeaderLength", hdr3.ToString("X"));
            pos += 2;                                            //0x?6
            ushort unk2 = Makeu16(inFile[pos], inFile[pos + 1]); //unknown, always 0x00?

            writer.WriteElementString("Unknown", unk2.ToString("X"));
            pos += 2;                 //0x?8
            writer.WriteEndElement(); //</SFNT>

            string[] fileNames = new string[nodeCount];
            string   tempName;

            for (int i = 0; i < nodeCount; i++) //Get file names for each node
            {
                tempName = "";                  //reset for each file
                while (inFile[pos] != 0)
                {
                    tempName = tempName + ((char)inFile[pos]).ToString(); //Build temp string for each letter
                    pos     += 1;
                }
                while (inFile[pos] == 0) //ignore every 0 byte, because why bother calculating the SFNT header offset anyway?
                {
                    pos += 1;
                }
                fileNames[i] = tempName; //Take built string and store it in the array
                writer.WriteElementString("NodeFile" + i, tempName);
            }


            for (int i = 0; i < nodeCount; i++) //Write files based from node information
            {
                writer.WriteStartElement("NodeHexData" + i);
                writer.WriteBinHex(inFile, (int)(nodes[i].start + dataOffset), (int)(nodes[i].end - nodes[i].start));
                writer.WriteEndElement(); //</NodeData>
            }


            writer.WriteEndElement(); //</PACKfile>
            writer.Close();
            GC.Collect();
            return(true);
        } //--------------------------------------------------------------------------------------------------------------------------------------------
コード例 #5
0
ファイル: WebUtil.cs プロジェクト: viticm/pap2
    public static bool ExportStrategy(string fileName, IList strategyList)
    {
        FileStream fileStream = null;
        bool bRet = false;
        try
        {
            fileStream = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write);
            fileStream.SetLength(0L);
            XmlTextWriter writer = new XmlTextWriter(fileStream, Encoding.Default);
            byte[] strategyBytes;

            //声明
            writer.WriteStartDocument();
            writer.WriteWhitespace("\n");

            writer.WriteStartElement("StrategyList");
            foreach (Strategy strategy in strategyList)
            {                
                writer.WriteWhitespace("\n\t");
                writer.WriteStartElement("Strategy");
                writer.WriteWhitespace("\n\t\t");

                writer.WriteElementString("Name", strategy.SecurityObject.Name);
                writer.WriteWhitespace("\n\t\t");

                writer.WriteElementString("Comment", strategy.SecurityObject.Comment);
                writer.WriteWhitespace("\n\t\t");

                writer.WriteElementString("Event", ((int)strategy.Event).ToString());
                writer.WriteWhitespace("\n\t\t");

                writer.WriteStartElement("Automation");
                strategyBytes = AdminServer.TheInstance.AutomationManager.Save(strategy.Automation);
                writer.WriteBinHex(strategyBytes, 0, strategyBytes.Length);
                writer.WriteEndElement();
                writer.WriteWhitespace("\n\t\t");

                writer.WriteElementString("Enable", strategy.Enabled ? "1" : "0");
                writer.WriteWhitespace("\n\t");

                writer.WriteEndElement();
                
            }
            writer.WriteWhitespace("\n");
            writer.WriteEndElement();

            writer.Flush();
            bRet = true;
        }
        catch (Exception)
        {
            bRet = false;
        }
        finally
        {
            if (fileStream != null) fileStream.Close();
        }
        return bRet;
    }
コード例 #6
0
ファイル: WebUtil.cs プロジェクト: viticm/pap2
    public static bool ExportScheduledTask(string fileName, IList taskList)
    {
        FileStream fileStream = null;
        bool bRet = false;
        try
        {
            fileStream = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write);
            fileStream.SetLength(0L);
            XmlTextWriter writer = new XmlTextWriter(fileStream, Encoding.Default);            
            IFormatter formatter = new BinaryFormatter();
            MemoryStream taskDataStream;

            //声明
            writer.WriteStartDocument();
            writer.WriteWhitespace("\n");

            writer.WriteStartElement("TaskList");
            foreach (ScheduledTaskUnit taskUnit in taskList)
            {
                taskDataStream = new MemoryStream();
                formatter.Serialize(taskDataStream, taskUnit.Task);

                writer.WriteWhitespace("\n\t");
                writer.WriteStartElement("Task");
                writer.WriteWhitespace("\n\t\t");
                
                writer.WriteElementString("Name", taskUnit.Task.SecurityObject.Name);
                writer.WriteWhitespace("\n\t\t");

                writer.WriteElementString("Comment", taskUnit.Task.SecurityObject.Comment);
                writer.WriteWhitespace("\n\t\t");

                writer.WriteStartElement("Data");
                writer.WriteBinHex(taskDataStream.ToArray(), 0, (int)taskDataStream.Length);
                writer.WriteEndElement();
                writer.WriteWhitespace("\n\t");

                writer.WriteEndElement();
            }

            writer.WriteWhitespace("\n");
            writer.WriteEndElement();

            writer.Flush();            
        }
        catch (Exception)
        {
            bRet = false;
        }
        finally
        {
            if (fileStream != null) fileStream.Close();
        }
        return bRet;
    }