Esempio n. 1
0
        private bool PrintColoredMBRinSteps(ref Mbr anMbr, int StepNumber)
        {
            if (aStepsPrinter == null)
            {
                aStepsPrinter = new HexPrinter(ref richTextBox1, 32, anMbr.StartAddress, ref aLogger);
            }

            if (StepNumber == 1)
            {
                aStepsPrinter.Initialize();
            }

            var aUnit = (from u in anMbr.Structure
                         where u.Order == StepNumber
                         select u).FirstOrDefault();

            if (aUnit == null)
            {
                aLogger.LogMessage(
                    $"in {MethodBase.GetCurrentMethod().Name}, the structure unit @ stepnumber{StepNumber} returns null value. Exit Method.",
                    LogMsgType.Error);
                return(false);
            }

            aStepsPrinter.PrintValue(aUnit.Value, aUnit.UnitColor);
            return(true);
        }
Esempio n. 2
0
        private void FatTableBtn_Click(object sender, EventArgs e)
        {
            ParseBootSector();
            if (bootSectors.Count == 0)
            {
                aLogger.LogMessage($"{System.Reflection.MethodBase.GetCurrentMethod().Name.ToString()}:: Empty bootSectors list, operation terminated! ", LogMsgType.Error);
                return;
            }
            foreach (var bs in bootSectors)
            {
                int dataAreaStartLoc = bs.GetRootDirectoryStartByte();
                aLogger.LogMessage($"{System.Reflection.MethodBase.GetCurrentMethod().Name}:: Data Area starts at 0x{dataAreaStartLoc:X8} ", LogMsgType.Verbose);
                while (true)
                {
                    //var directory= Filesystems.FatDirectoryArea.ParseDirectoryArea(dataAreaStartLoc, fileName, bs, ref aLogger);
                    var directory = Common.Common.GetUnit <FatDirectoryArea>(fileName, ref aLogger, dataAreaStartLoc,
                                                                             "DirectoryArea-" + bs.Description, null);
                    //printing hex table
                    HexPrinter aHexPrinter = new HexPrinter(ref richTextBox1, 32, dataAreaStartLoc, ref aLogger);
                    aHexPrinter.PrintColoredStructure(directory);
                    //printing values
                    Printer.PrintStructureValues(directory.Structure, ref richTextBox1, ref aLogger);

                    richTextBox1.AppendText("\n\n\n");
                    dataAreaStartLoc += Common.Common.FatDirectoryAreaSizeBytes;
                    if (directory.IsEmpty)
                    {
                        break;
                    }
                }
            }
        }
Esempio n. 3
0
        /// <summary cref="Packet.ToString(StringOutputType)" />
        public override string ToString(StringOutputType outputFormat)
        {
            var    buffer      = new StringBuilder();
            string color       = "";
            string colorEscape = "";

            if (outputFormat == StringOutputType.Colored || outputFormat == StringOutputType.VerboseColored)
            {
                color       = Color;
                colorEscape = AnsiEscapeSequences.Reset;
            }

            if (outputFormat == StringOutputType.Normal || outputFormat == StringOutputType.Colored)
            {
                // build the output string
                buffer.AppendFormat("{0}[ARPPacket: Operation={2}, SenderHardwareAddress={3}, TargetHardwareAddress={4}, SenderProtocolAddress={5}, TargetProtocolAddress={6}]{1}",
                                    color,
                                    colorEscape,
                                    Operation,
                                    HexPrinter.PrintMACAddress(SenderHardwareAddress),
                                    HexPrinter.PrintMACAddress(TargetHardwareAddress),
                                    SenderProtocolAddress,
                                    TargetProtocolAddress);
            }

            if (outputFormat == StringOutputType.Verbose || outputFormat == StringOutputType.VerboseColored)
            {
                // collect the properties and their value
                Dictionary <string, string> properties = new Dictionary <string, string>();
                properties.Add("hardware type", HardwareAddressType.ToString() + " (0x" + HardwareAddressType.ToString("x") + ")");
                properties.Add("protocol type", ProtocolAddressType.ToString() + " (0x" + ProtocolAddressType.ToString("x") + ")");
                properties.Add("operation", Operation.ToString() + " (0x" + Operation.ToString("x") + ")");
                properties.Add("source hardware address", HexPrinter.PrintMACAddress(SenderHardwareAddress));
                properties.Add("destination hardware address", HexPrinter.PrintMACAddress(TargetHardwareAddress));
                properties.Add("source protocol address", SenderProtocolAddress.ToString());
                properties.Add("destination protocol address", TargetProtocolAddress.ToString());

                // calculate the padding needed to right-justify the property names
                int padLength = Utils.RandomUtils.LongestStringLength(new List <string>(properties.Keys));

                // build the output string
                buffer.AppendLine("ARP:  ******* ARP - \"Address Resolution Protocol\" - offset=? length=" + TotalPacketLength);
                buffer.AppendLine("ARP:");
                foreach (var property in properties)
                {
                    buffer.AppendLine("ARP: " + property.Key.PadLeft(padLength) + " = " + property.Value);
                }
                buffer.AppendLine("ARP:");
            }

            // append the base string output
            buffer.Append(base.ToString(outputFormat));

            return(buffer.ToString());
        }
Esempio n. 4
0
        private void PrintColoredMBR(ref Mbr anMbr)
        {
            var aPrinter = new HexPrinter(ref richTextBox1, 32, anMbr.StartAddress, ref aLogger);

            aPrinter.Initialize();
            foreach (var unit in anMbr.Structure)
            {
                aPrinter.PrintValue(unit.Value, unit.UnitColor);
            }

            richTextBox1.AppendText(Environment.NewLine);
        }
Esempio n. 5
0
        public override string ToString()
        {
            TransactionRepresentation tr = this._transactionRepresentation;

            return("Transaction #" + _transactionId + (_logPosition != null ? " at log position " + _logPosition : " (no log position)") +
                   " {started " + date(tr.TimeStarted) +
                   ", committed " + date(tr.TimeCommitted) +
                   ", with " + CountCommands() + " commands in this transaction" +
                   ", authored by " + tr.AuthorId +
                   ", with master id " + tr.MasterId +
                   ", lock session " + tr.LockSessionId +
                   ", latest committed transaction id when started was " + tr.LatestCommittedTxWhenStarted +
                   ", additional header bytes: " + HexPrinter.hex(tr.AdditionalHeader(), int.MaxValue, "") + "}");
        }
Esempio n. 6
0
        /// <summary cref="Packet.ToString(StringOutputType)" />
        public override string ToString(StringOutputType outputFormat)
        {
            var    buffer      = new StringBuilder();
            string color       = "";
            string colorEscape = "";

            if (outputFormat == StringOutputType.Colored || outputFormat == StringOutputType.VerboseColored)
            {
                color       = Color;
                colorEscape = AnsiEscapeSequences.Reset;
            }

            if (outputFormat == StringOutputType.Normal || outputFormat == StringOutputType.Colored)
            {
                // build the output string
                buffer.AppendFormat("{0}[EthernetPacket: SourceHwAddress={2}, DestinationHwAddress={3}, Type={4}]{1}",
                                    color,
                                    colorEscape,
                                    HexPrinter.PrintMACAddress(SourceHwAddress),
                                    HexPrinter.PrintMACAddress(DestinationHwAddress),
                                    Type.ToString());
            }

            if (outputFormat == StringOutputType.Verbose || outputFormat == StringOutputType.VerboseColored)
            {
                // collect the properties and their value
                Dictionary <string, string> properties = new Dictionary <string, string>();
                properties.Add("destination", HexPrinter.PrintMACAddress(DestinationHwAddress));
                properties.Add("source", HexPrinter.PrintMACAddress(SourceHwAddress));
                properties.Add("type", Type.ToString() + " (0x" + Type.ToString("x") + ")");

                // calculate the padding needed to right-justify the property names
                int padLength = Utils.RandomUtils.LongestStringLength(new List <string>(properties.Keys));

                // build the output string
                buffer.AppendLine("Eth:  ******* Ethernet - \"Ethernet\" - offset=? length=" + TotalPacketLength);
                buffer.AppendLine("Eth:");
                foreach (var property in properties)
                {
                    buffer.AppendLine("Eth: " + property.Key.PadLeft(padLength) + " = " + property.Value);
                }
                buffer.AppendLine("Eth:");
            }

            // append the base output
            buffer.Append(base.ToString(outputFormat));

            return(buffer.ToString());
        }
Esempio n. 7
0
        /// <summary cref="Packet.ToString(StringOutputType)" />
        public override string ToString(StringOutputType outputFormat)
        {
            var buffer      = new StringBuilder();
            var color       = "";
            var colorEscape = "";

            if ((outputFormat == StringOutputType.Colored) || (outputFormat == StringOutputType.VerboseColored))
            {
                color       = Color;
                colorEscape = AnsiEscapeSequences.Reset;
            }

            if ((outputFormat == StringOutputType.Normal) || (outputFormat == StringOutputType.Colored))
            {
                buffer.AppendFormat("[{0}WakeOnLanPacket{1}: DestinationAddress={2}]",
                                    color,
                                    colorEscape,
                                    DestinationAddress);
            }

            if ((outputFormat == StringOutputType.Verbose) || (outputFormat == StringOutputType.VerboseColored))
            {
                // collect the properties and their value
                var properties = new Dictionary <string, string>
                {
                    { "destination", HexPrinter.PrintMACAddress(DestinationAddress) }
                };

                // calculate the padding needed to right-justify the property names
                var padLength = RandomUtils.LongestStringLength(new List <string>(properties.Keys));

                // build the output string
                buffer.AppendLine("WOL:  ******* WOL - \"Wake-On-Lan\" - offset=? length=" + TotalPacketLength);
                buffer.AppendLine("WOL:");
                foreach (var property in properties)
                {
                    buffer.AppendLine("WOL: " + property.Key.PadLeft(padLength) + " = " + property.Value);
                }

                buffer.AppendLine("WOL:");
            }

            // append the base string output
            buffer.Append(base.ToString(outputFormat));

            return(buffer.ToString());
        }
Esempio n. 8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") private <T extends org.neo4j.bolt.messaging.ResponseMessage> T unpack(BoltResponseMessageReader reader, RecordingByteChannel channel)
        private T Unpack <T>(BoltResponseMessageReader reader, RecordingByteChannel channel) where T : Org.Neo4j.Bolt.messaging.ResponseMessage
        {
            // Unpack
            string serialized = HexPrinter.hex(channel.Bytes);
            BoltResponseMessageRecorder messages = new BoltResponseMessageRecorder();

            try
            {
                reader.Read(messages);
            }
            catch (Exception e)
            {
                throw new AssertionError("Failed to unpack message, wire data was:\n" + serialized + "[" + channel.Bytes.Length + "b]", e);
            }

            return(( T )messages.AsList()[0]);
        }
Esempio n. 9
0
        protected internal static string BeginningOfBufferAsHexString(ChannelBuffer buffer, int maxBytesToPrint)
        {
            // read buffer from pos 0 - writeIndex
            int prevIndex = buffer.readerIndex();

            buffer.readerIndex(0);
            try
            {
                MemoryStream byteArrayStream = new MemoryStream(buffer.readableBytes());
                PrintStream  stream          = new PrintStream(byteArrayStream);
                HexPrinter   printer         = (new HexPrinter(stream)).withLineNumberDigits(4);
                for (int i = 0; buffer.readable() && i < maxBytesToPrint; i++)
                {
                    printer.append(buffer.readByte());
                }
                stream.flush();
                return(byteArrayStream.ToString());
            }
            finally
            {
                buffer.readerIndex(prevIndex);
            }
        }
Esempio n. 10
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void testPermutation(byte[] unfragmented, io.netty.buffer.ByteBuf[] fragments) throws Exception
        private void TestPermutation(sbyte[] unfragmented, ByteBuf[] fragments)
        {
            // Given
            _channel = new EmbeddedChannel();
            BoltChannel boltChannel = NewBoltChannel(_channel);

            BoltStateMachine          machine        = mock(typeof(BoltStateMachine));
            SynchronousBoltConnection boltConnection = new SynchronousBoltConnection(machine);
            NullLogService            logging        = NullLogService.Instance;
            BoltProtocol boltProtocol = new BoltProtocolV1(boltChannel, (ch, s) => boltConnection, (v, ch) => machine, logging);

            boltProtocol.Install();

            // When data arrives split up according to the current permutation
            foreach (ByteBuf fragment in fragments)
            {
                _channel.writeInbound(fragment.readerIndex(0).retain());
            }

            // Then the session should've received the specified messages, and the protocol should be in a nice clean state
            try
            {
                RequestMessage run = new RunMessage("Mjölnir", EMPTY_MAP);
                verify(machine).process(eq(run), any(typeof(BoltResponseHandler)));
            }
            catch (AssertionError e)
            {
                throw new AssertionError("Failed to handle fragmented delivery.\n" + "Messages: " + Arrays.ToString(_messages) + "\n" + "Chunk size: " + _chunkSize + "\n" + "Serialized data delivered in fragments: " + DescribeFragments(fragments) + "\n" + "Unfragmented data: " + HexPrinter.hex(unfragmented) + "\n", e);
            }
        }
Esempio n. 11
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private String serialized(org.neo4j.values.AnyValue object) throws java.io.IOException
        private string Serialized(AnyValue @object)
        {
            RecordMessage message = new RecordMessage(record(@object));

            return(HexPrinter.hex(serialize(_neo4jPack, message), 4, " "));
        }
Esempio n. 12
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public static org.neo4j.bolt.messaging.ResponseMessage responseMessage(org.neo4j.bolt.messaging.Neo4jPack neo4jPack, byte[] bytes) throws java.io.IOException
        public static ResponseMessage ResponseMessage(Neo4jPack neo4jPack, sbyte[] bytes)
        {
            BoltResponseMessageReader   unpacker = ResponseReader(neo4jPack, bytes);
            BoltResponseMessageRecorder consumer = new BoltResponseMessageRecorder();

            try
            {
                unpacker.Read(consumer);
                return(consumer.AsList()[0]);
            }
            catch (Exception e)
            {
                throw new IOException("Failed to deserialize response, '" + e.Message + "'.\n" + "Raw data: \n" + HexPrinter.hex(bytes), e);
            }
        }
Esempio n. 13
0
        private void fatTablesBtn_Click(object sender, EventArgs e)
        {
            if (bootSectors == null)
            {
                ParseBootSector();
            }
            int counter = 1;

            foreach (var bootSector in bootSectors)
            {
                richTextBox1.AppendText($"Printing FAT TABLEs for Boot Secort [{counter++}]\n\n");
                for (int i = 0; i < bootSector.GetNumberOfFats(); i++)
                {
                    FatTable aFatTable = new FatTable(fileName, bootSector, $"Fat Table {i}", i);

                    richTextBox1.AppendText($"Printing FAT TABLE{i}\n\n");
                    HexPrinter aHexPrinter = new HexPrinter(ref richTextBox1, 32, aFatTable.StartAddress, ref aLogger);
                    richTextBox1.AppendText($"\tFirst 32 bytes of FAT table {i} \n");
                    aHexPrinter.PrintValue(aFatTable.RawValue.Substring(0, 64), Color.White);

                    aHexPrinter = new HexPrinter(ref richTextBox1, 32, aFatTable.StartAddress + (aFatTable.RawValue.Length / 2) - 32, ref aLogger);
                    richTextBox1.AppendText($"\n\tLast 32 bytes of FAT table {i} \n");
                    aHexPrinter.PrintValue(aFatTable.RawValue.Substring(aFatTable.RawValue.Length - 64, 64), Color.White);

                    richTextBox1.SuspendLayout();
                    for (int index = 0; index < aFatTable.ParsedEntries.Count; index++)
                    {
                        var parsedEntry = aFatTable.ParsedEntries[index];
                        if (parsedEntry != "000000")
                        {
                            //richTextBox1.AppendText("\n"+parsedEntry);
                            //0 1 2 3 4 5
                            //u v w x y z
                            // xuv & yzw
                            string fisrtEntry = parsedEntry[3].ToString() + parsedEntry[0].ToString() +
                                                parsedEntry[1].ToString();

                            var firstEntryType = CehckFat12EntryValue(fisrtEntry);

                            string secondEntry = parsedEntry[4].ToString() + parsedEntry[5].ToString() +
                                                 parsedEntry[2].ToString();

                            var firstdatalocByte = aFatTable.ParentBootSector.FirstDataSectorByte() +
                                                   (index * 2) *
                                                   aFatTable.ParentBootSector.GetNumberOfSectorsPerCluser() *
                                                   aFatTable.ParentBootSector.BytesPerSector();
                            richTextBox1.AppendText(
                                $"\n [{index}] {fisrtEntry}:\t {firstEntryType}  \t Data Loca={firstdatalocByte.ToString("X8")}");

                            var seconddatalocByte = aFatTable.ParentBootSector.FirstDataSectorByte() +
                                                    (index * 2 + 1) *
                                                    aFatTable.ParentBootSector.GetNumberOfSectorsPerCluser() *
                                                    aFatTable.ParentBootSector.BytesPerSector();
                            var secondEntryType = CehckFat12EntryValue(secondEntry);
                            richTextBox1.AppendText(
                                $"\n [{index + 1}] {secondEntry}:\t {secondEntryType}  \t Data Loca={seconddatalocByte.ToString("X8")}");
                        }
                        else
                        {
                            richTextBox1.AppendText(
                                $"\n reached last file (stopped to save space), two vals ={parsedEntry} ");
                            break;
                        }
                    }
                    richTextBox1.ResumeLayout();
                    richTextBox1.AppendText("\n\n");
                }
            }
        }
Esempio n. 14
0
        private void FatTableBtn_Click(object sender, EventArgs e)
        {
            ParseBootSector();
            if (bootSectors.Count == 0)
            {
                aLogger.LogMessage($"{System.Reflection.MethodBase.GetCurrentMethod().Name.ToString()}:: Empty bootSectors list, operation terminated! ", LogMsgType.Error);
                return;
            }
            ParseRootDirectoryEntries();

            foreach (var directory in RootDirectoryEntries)
            {
                if (directory.IsThisEntryaDirectory())
                {
                    richTextBox1.AppendText("\n[DIRECTORY]\n");
                }
                else if (directory.IsThisEntryanArchive())
                {
                    richTextBox1.AppendText("\n[NORMAL FILE]\n");
                }

                //printing hex table
                HexPrinter aHexPrinter = new HexPrinter(ref richTextBox1, 32, directory.StartAddress, ref aLogger);
                aHexPrinter.PrintColoredStructure(directory);


                //printing values
                Printer.PrintStructureValues(directory.Structure, ref richTextBox1, ref aLogger);



                aLogger.LogMessage($"DATA IS LOCATED @{directory.GetDataLocation().ToString("X8")}", LogMsgType.Debug);


                if (directory.LongFileNames?.Count > 0)
                {
                    richTextBox1.AppendText($"\n [START]******************** Printing long file name entries for the previous one ************ \n", Color.Red);
                    int counter = 1;
                    foreach (var longNameEntry in directory.LongFileNames)
                    {
                        richTextBox1.AppendText($"|---- Printing Long Name Entry [{counter}] \n");
                        //printing hex table
                        HexPrinter aHexPrinter2 = new HexPrinter(ref richTextBox1, 32, longNameEntry.StartAddress, ref aLogger);
                        aHexPrinter2.PrintColoredStructure(longNameEntry);

                        //printing values
                        Printer.PrintStructureValues(longNameEntry.Structure, ref richTextBox1, ref aLogger);
                        richTextBox1.AppendText($"|---- [DONE] Printing Long Name Entry [{counter}] \n");
                        counter++;
                    }
                    richTextBox1.AppendText($"\n [END]******************** Printing long file name entries  ************ \n", Color.Red);
                }


                if (directory.ChildrenList?.Count > 0)
                {
                    richTextBox1.AppendText($"\n [START]******************** Printing subfolder entries ************ \n", Color.Violet);
                    int counter = 1;
                    foreach (var child in directory.ChildrenList)
                    {
                        richTextBox1.AppendText($"|---- Printing subfolder Entry [{counter}] \n");
                        //printing hex table
                        HexPrinter aHexPrinter2 = new HexPrinter(ref richTextBox1, 32, child.StartAddress, ref aLogger);
                        aHexPrinter2.PrintColoredStructure(child);

                        //printing values
                        Printer.PrintStructureValues(child.Structure, ref richTextBox1, ref aLogger);

                        aLogger.LogMessage($"DATA IS LOCATED @{child.GetDataLocation().ToString("X8")}", LogMsgType.Debug);


                        richTextBox1.AppendText($"|---- [DONE] Printing subfolder Entry [{counter}] \n");
                        counter++;
                    }
                    richTextBox1.AppendText($"\n [END]******************** Printing long file name entries  ************ \n", Color.Violet);
                }
                richTextBox1.AppendText("\n\n\n");
            }
        }