示例#1
0
        private InlineProcessingResult GetProcesses(Packet request, Packet response)
        {
            foreach (var process in Process.GetProcesses())
            {
                var processTlv = response.AddGroup(TlvType.StdapiProcessGroup);

                processTlv.Add(TlvType.StdapiProcessId, (uint)process.Id);
                processTlv.Add(TlvType.StdapiProcessName, process.ProcessName);

                var fileName = process.Pokemon(p => p.MainModule.FileName);
                if (fileName != null)
                {
                    processTlv.Add(TlvType.StdapiProcessPath, fileName);
                }

                var userName = process.GetUserName();
                if (userName != null)
                {
                    processTlv.Add(TlvType.StdapiUserName, userName);
                }
                processTlv.Add(TlvType.StdapiProcessSession, (uint)process.SessionId);

                var parent = process.GetParentProcess();
                if (parent != null)
                {
                    processTlv.Add(TlvType.StdapiProcessParentProcessId, (uint)parent.Id);
                }

                process.Pokemon(p => p.IsWow64(), r => processTlv.Add(TlvType.StdapiProcessArch, (uint)(r ? SystemArchictecture.X86 : SystemArchictecture.X64)));
            }

            response.Result = PacketResult.Success;
            return(InlineProcessingResult.Continue);
        }
示例#2
0
        private InlineProcessingResult ShowMount(Packet request, Packet response)
        {
            foreach (var drive in DriveInfo.GetDrives())
            {
                var mountTlv = response.AddGroup(TlvType.StdapiMount);

                mountTlv.Add(TlvType.StdapiMountName, drive.Name);
                mountTlv.Add(TlvType.StdapiMountType, (uint)drive.DriveType);

                if (drive.IsReady)
                {
                    mountTlv.Add(TlvType.StdapiMountSpaceTotal, drive.TotalSize);
                    mountTlv.Add(TlvType.StdapiMountSpaceUser, drive.AvailableFreeSpace);
                    mountTlv.Add(TlvType.StdapiMountSpaceFree, drive.TotalFreeSpace);
                }

                if (drive.DriveType == DriveType.Network)
                {
                    var universalName = GetUniversalName(drive.Name);
                    mountTlv.Add(TlvType.StdapiMountUncPath, universalName);
                }
            }

            response.Result = PacketResult.Success;
            return(InlineProcessingResult.Continue);
        }
示例#3
0
        private InlineProcessingResult GetInterfaces(Packet request, Packet response)
        {
            foreach (var ni in NetworkInterface.GetAllNetworkInterfaces())
            {
                var tlv = response.AddGroup(TlvType.StdapiNetworkInterface);
                tlv.Add(TlvType.StdapiMacName, ni.Description);

                var physical = ni.GetPhysicalAddress();
                tlv.Add(TlvType.StdapiMacAddr, physical.GetAddressBytes());

                var ip       = ni.GetIPProperties();
                var ip4Props = ip.GetIPv4Properties();
                if (ip4Props != null)
                {
                    tlv.Add(TlvType.StdapiInterfaceIndex, ip4Props.Index);
                    tlv.Add(TlvType.StdapiInterfaceMtu, ip4Props.Mtu);
                }

                foreach (var addr in ip.UnicastAddresses.OrderBy(a => (uint)a.Address.AddressFamily))
                {
                    if (addr.Address.AddressFamily != AddressFamily.InterNetwork &&
                        addr.Address.AddressFamily != AddressFamily.InterNetworkV6)
                    {
                        continue;
                    }

                    tlv.Add(TlvType.StdapiIpPrefix, addr.GetPrefixLength());
                    tlv.Add(TlvType.StdapiIp, addr.Address.GetAddressBytes());

                    if (addr.Address.AddressFamily == AddressFamily.InterNetworkV6)
                    {
                        var sid = (uint)addr.Address.ScopeId;

                        var b = new byte[]
                        {
                            (byte)(sid & 0xFF),
                            (byte)(sid >> 8 & 0xFF),
                            (byte)(sid >> 16 & 0xFF),
                            (byte)(sid >> 24 & 0xFF),
                        };
                        tlv.Add(TlvType.StdapiIp6Scope, b);
                    }
                    //else
                    //{
                    //    if (addr.IPv4Mask != null)
                    //    {
                    //        tlv.Add(TlvType.StdapiNetmask, addr.IPv4Mask.GetAddressBytes());
                    //    }
                    //}
                }
            }

            response.Result = PacketResult.Success;
            return(InlineProcessingResult.Continue);
        }
示例#4
0
        private InlineProcessingResult TransportList(Packet request, Packet response)
        {
            response.Add(TlvType.TransSessExp, (uint)(this.Session.Expiry - DateTime.UtcNow).TotalSeconds);

            for (var index = 0; index < this.Transports.Count; ++index)
            {
                var transport = this.Transports[(index + this.transportIndex) % this.Transports.Count];
                transport.GetConfig(response.AddGroup(TlvType.TransGroup));
            }

            response.Result = PacketResult.Success;

            return(InlineProcessingResult.Continue);
        }
示例#5
0
        private InlineProcessingResult GetEnv(Packet request, Packet response)
        {
            var tlvs = default(List <Tlv>);

            if (request.Tlvs.TryGetValue(TlvType.StdapiEnvVariable, out tlvs))
            {
                foreach (var envVar in tlvs.Select(t => t.ValueAsString()))
                {
                    var value    = Environment.GetEnvironmentVariable(envVar);
                    var envGroup = response.AddGroup(TlvType.StdapiEnvGroup);
                    envGroup.Add(TlvType.StdapiEnvVariable, envVar);
                    envGroup.Add(TlvType.StdapiEnvValue, value);
                }
            }

            response.Result = PacketResult.Success;
            return(InlineProcessingResult.Continue);
        }