コード例 #1
0
        private bool TryCreateNewAssembler(out FileTransfer.FileStreamAssembler assembler, FileTransfer.FileStreamAssemblerList fileStreamAssemblerList, Packets.TftpPacket tftpPacket, NetworkHost sourceHost, ushort sourcePort, NetworkHost destinationHost)  //destinationPort is not needed
        {
            assembler = null;

            //create new assembler if it is a RRQ or WRQ
            if (tftpPacket.OpCode == Packets.TftpPacket.OpCodes.ReadRequest)
            {
                try {
                    FiveTuple tmpFiveTuple = new FiveTuple(destinationHost, Packets.TftpPacket.DefaultUdpPortNumber, sourceHost, sourcePort, FiveTuple.TransportProtocol.UDP);
                    assembler = new FileTransfer.FileStreamAssembler(fileStreamAssemblerList, tmpFiveTuple, true, FileTransfer.FileStreamTypes.TFTP, tftpPacket.Filename, "", tftpPacket.OpCode.ToString() + " " + tftpPacket.Mode.ToString() + " " + tftpPacket.Filename, tftpPacket.ParentFrame.FrameNumber, tftpPacket.ParentFrame.Timestamp);
                    fileStreamAssemblerList.Add(assembler);
                }
                catch (Exception e) {
                    SharedUtils.Logger.Log("Error creating assembler for TFTP file transfer in " + tftpPacket.ParentFrame.ToString() + ". " + e.ToString(), SharedUtils.Logger.EventLogEntryType.Information);
                    //throw new Exception("Error creating assembler for TFTP file transfer", e);
                    //this.parentForm.ShowError("Error creating assembler for TFTP file transfer: "+e.Message);
                    if (assembler != null)
                    {
                        assembler.Clear();
                        assembler = null;
                    }
                    return(false);
                }
                return(true);
            }
            else if (tftpPacket.OpCode == Packets.TftpPacket.OpCodes.WriteRequest)
            {
                try {
                    FiveTuple tmpFiveTuple = new FiveTuple(sourceHost, sourcePort, destinationHost, Packets.TftpPacket.DefaultUdpPortNumber, FiveTuple.TransportProtocol.UDP);
                    assembler = new FileTransfer.FileStreamAssembler(fileStreamAssemblerList, tmpFiveTuple, true, FileTransfer.FileStreamTypes.TFTP, tftpPacket.Filename, "", tftpPacket.OpCode.ToString() + " " + tftpPacket.Mode.ToString() + " " + tftpPacket.Filename, tftpPacket.ParentFrame.FrameNumber, tftpPacket.ParentFrame.Timestamp);
                    fileStreamAssemblerList.Add(assembler);
                }
                catch (Exception e) {
                    SharedUtils.Logger.Log("Error creating assembler for TFTP file transfer in " + tftpPacket.ParentFrame.ToString() + ". " + e.ToString(), SharedUtils.Logger.EventLogEntryType.Information);
                    //throw new Exception("Error creating assembler for TFTP file transfer", e);
                    //this.parentForm.ShowError("Error creating assembler for TFTP file transfer: "+e.Message);
                    if (assembler != null)
                    {
                        assembler.Clear();
                        assembler = null;
                    }
                    return(false);
                }
                return(true);
            }
            else
            {
                assembler = null;
                return(false);
            }
        }
コード例 #2
0
        private void ExtractFileData(FileTransfer.FileStreamAssembler assembler, FileTransfer.FileStreamAssemblerList fileStreamAssemblerList, NetworkHost sourceHost, ushort sourcePort, NetworkHost destinationHost, ushort destinationPort, Packets.TftpPacket tftpPacket)
        {
            if (tftpPacket.OpCode == Packets.TftpPacket.OpCodes.Data)
            {
                if (!assembler.IsActive)
                {
                    //create a new active assembler if ports need to be changed!
                    if (assembler.SourcePort != sourcePort || assembler.DestinationPort != destinationPort)
                    {
                        fileStreamAssemblerList.Remove(assembler, true);
                        //now change the port number in the AssemblerPool
                        FiveTuple tmpFiveTuple = new FiveTuple(sourceHost, sourcePort, destinationHost, destinationPort, FiveTuple.TransportProtocol.UDP);
                        assembler = new FileTransfer.FileStreamAssembler(fileStreamAssemblerList, tmpFiveTuple, true, FileTransfer.FileStreamTypes.TFTP, assembler.Filename, assembler.FileLocation, assembler.Details, tftpPacket.ParentFrame.FrameNumber, tftpPacket.ParentFrame.Timestamp);
                        fileStreamAssemblerList.Add(assembler);
                    }
                    //activate the assembler
                    assembler.TryActivate();
                }

                if (assembler.SourceHost == sourceHost && assembler.SourcePort == sourcePort && assembler.DestinationHost == destinationHost && assembler.DestinationPort == destinationPort)
                {
                    assembler.AddData(tftpPacket.DataBlock, tftpPacket.DataBlockNumber);
                    if (tftpPacket.DataBlockIsLast)
                    {
                        assembler.FinishAssembling();//we now have the complete file
                    }
                }
            }
        }