mirror of
https://github.com/vxunderground/MalwareSourceCode.git
synced 2024-12-19 09:56:10 +00:00
f2ac1ece55
add
293 lines
8.9 KiB
C#
293 lines
8.9 KiB
C#
// Decompiled with JetBrains decompiler
|
|
// Type: Microsoft.InfoCards.Request
|
|
// Assembly: infocard, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
|
|
// MVID: 516D8B44-4448-4D2C-8B8E-FFBB3FFE472B
|
|
// Assembly location: C:\Users\Administrateur\Downloads\Virusshare-00000-msil\Virus.Win32.Expiro.w-69bb73081eac86b8cf86f45e33515d0095855636967076e2b593d7a30cd80a07.exe
|
|
|
|
using Microsoft.InfoCards.Diagnostics;
|
|
using System;
|
|
using System.ComponentModel;
|
|
using System.IO;
|
|
using System.Net;
|
|
using System.Security.Principal;
|
|
|
|
namespace Microsoft.InfoCards
|
|
{
|
|
internal abstract class Request : IDisposable
|
|
{
|
|
private static Request.RequestHandleDictionary s_existingClientRequests = new Request.RequestHandleDictionary();
|
|
private static ExceptionTranslationTable s_exceptionToHResultTable = ExceptionTranslationTable.Instance;
|
|
private Stream m_inArgs;
|
|
private Stream m_outArgs;
|
|
private int m_requestHandle;
|
|
private static object s_syncRoot = new object();
|
|
private IWebProxy m_proxy;
|
|
private object m_syncRoot;
|
|
private IntPtr m_rpcHandle;
|
|
private Exception m_processingException;
|
|
private ExceptionList m_recoverableExceptions;
|
|
private WindowsImpersonationContext m_impersonationContext;
|
|
private int m_initHResult;
|
|
private string m_extendedErrorMessage;
|
|
private int m_lcid = -1;
|
|
|
|
protected Request(
|
|
IntPtr rpcHandle,
|
|
Stream inArgs,
|
|
Stream outArgs,
|
|
ExceptionList recoverableExceptions)
|
|
{
|
|
this.m_inArgs = inArgs;
|
|
this.m_outArgs = outArgs;
|
|
this.m_rpcHandle = rpcHandle;
|
|
this.m_recoverableExceptions = recoverableExceptions;
|
|
this.m_syncRoot = new object();
|
|
this.m_initHResult = 0;
|
|
this.InsertThisRequestIntoDictionary();
|
|
}
|
|
|
|
public Exception ProcessingException
|
|
{
|
|
get => this.m_processingException;
|
|
set => this.m_processingException = value;
|
|
}
|
|
|
|
public IWebProxy UserProxy
|
|
{
|
|
get
|
|
{
|
|
if (this.m_proxy == null)
|
|
this.m_proxy = WebRequest.GetSystemWebProxy();
|
|
return this.m_proxy;
|
|
}
|
|
}
|
|
|
|
public int UserLanguage
|
|
{
|
|
get
|
|
{
|
|
InfoCardTrace.Assert(this.m_lcid >= 0, " The user language has not been set in the service");
|
|
return this.m_lcid;
|
|
}
|
|
set => this.m_lcid = value;
|
|
}
|
|
|
|
protected Stream InArgs => this.m_inArgs;
|
|
|
|
public Stream OutArgs => this.m_outArgs;
|
|
|
|
protected object SyncRoot => this.m_syncRoot;
|
|
|
|
protected IntPtr RpcHandle => this.m_rpcHandle;
|
|
|
|
public int RequestHandle => this.m_requestHandle;
|
|
|
|
public abstract WindowsIdentity RequestorIdentity { get; }
|
|
|
|
internal void Initialize()
|
|
{
|
|
try
|
|
{
|
|
this.OnInitializeAsSystem();
|
|
this.ImpersonateRequestor();
|
|
this.OnInitializeAsUser();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
this.m_initHResult = this.HandleException(ex, true);
|
|
}
|
|
}
|
|
|
|
private void ImpersonateRequestor()
|
|
{
|
|
InfoCardTrace.Assert(null != this.RequestorIdentity, "RequestorIdentity can not be null, the derived class should have populated this on initialize");
|
|
this.m_impersonationContext = !this.RequestorIdentity.IsSystem ? this.RequestorIdentity.Impersonate() : throw InfoCardTrace.ThrowHelperError((Exception) new CommunicationException(SR.GetString("UserIdentityEqualSystemNotSupported")));
|
|
}
|
|
|
|
private int GetHResultFromException(Exception e)
|
|
{
|
|
int hresultFromException = 0;
|
|
Type type = e.GetType();
|
|
if (Request.s_exceptionToHResultTable.ContainsKey(type))
|
|
hresultFromException = Request.s_exceptionToHResultTable[type];
|
|
else if (e is Win32Exception)
|
|
hresultFromException = ((Win32Exception) e).NativeErrorCode;
|
|
else
|
|
InfoCardService.Crash(e);
|
|
return hresultFromException;
|
|
}
|
|
|
|
protected int HandleException(Exception e) => this.HandleException(e, false);
|
|
|
|
protected int HandleException(Exception e, bool isInitializing)
|
|
{
|
|
int errorCode = 0;
|
|
if (InfoCardTrace.IsFatal(e))
|
|
{
|
|
InfoCardTrace.TraceAndLogException(e);
|
|
InfoCardService.Crash(e);
|
|
}
|
|
Exception exception = !(e is InfoCardRequestException) ? e : e.InnerException;
|
|
if (isInitializing || !this.OnHandleException(exception, out errorCode))
|
|
{
|
|
if (exception is InfoCardBaseException)
|
|
{
|
|
errorCode = ((InfoCardBaseException) exception).NativeHResult;
|
|
this.m_extendedErrorMessage = ((InfoCardBaseException) exception).ExtendedMessage;
|
|
}
|
|
else if (this.m_recoverableExceptions == ExceptionList.AllNonFatal)
|
|
{
|
|
CommunicationException e1 = new CommunicationException(SR.GetString("ClientAPIInfocardError"), exception);
|
|
InfoCardTrace.TraceAndLogException((Exception) e1);
|
|
errorCode = e1.NativeHResult;
|
|
}
|
|
else if (this.m_recoverableExceptions.Contains(exception.GetType()))
|
|
{
|
|
errorCode = this.GetHResultFromException(exception);
|
|
}
|
|
else
|
|
{
|
|
InfoCardTrace.TraceAndLogException(e);
|
|
InfoCardService.Crash(e);
|
|
}
|
|
}
|
|
return errorCode;
|
|
}
|
|
|
|
protected virtual void PreProcessRequest()
|
|
{
|
|
this.ProcessingException = (Exception) null;
|
|
this.OnMarshalInArgs();
|
|
if (this.ProcessingException != null)
|
|
{
|
|
Exception processingException = this.ProcessingException;
|
|
this.ProcessingException = (Exception) null;
|
|
throw InfoCardTrace.ThrowHelperError((Exception) new InfoCardRequestException(processingException.Message, processingException));
|
|
}
|
|
if (this.InArgs.Position != this.InArgs.Length)
|
|
throw InfoCardTrace.ThrowHelperError((Exception) new CommunicationException(SR.GetString("ServiceInvalidDataInRequest")));
|
|
this.InArgs.Close();
|
|
}
|
|
|
|
protected virtual void PostProcessRequest()
|
|
{
|
|
this.ProcessingException = (Exception) null;
|
|
this.OutArgs.Flush();
|
|
this.OnMarshalOutArgs();
|
|
if (this.ProcessingException != null)
|
|
{
|
|
Exception processingException = this.ProcessingException;
|
|
this.ProcessingException = (Exception) null;
|
|
throw InfoCardTrace.ThrowHelperError((Exception) new InfoCardRequestException(processingException.Message, processingException));
|
|
}
|
|
}
|
|
|
|
protected virtual void ProcessRequest()
|
|
{
|
|
this.ProcessingException = (Exception) null;
|
|
this.OnProcess();
|
|
if (this.ProcessingException != null)
|
|
{
|
|
Exception processingException = this.ProcessingException;
|
|
this.ProcessingException = (Exception) null;
|
|
throw InfoCardTrace.ThrowHelperError((Exception) new InfoCardRequestException(processingException.Message, processingException));
|
|
}
|
|
}
|
|
|
|
public int DoProcessRequest(out string extendedMessage)
|
|
{
|
|
int num = this.m_initHResult;
|
|
if (num == 0)
|
|
{
|
|
try
|
|
{
|
|
this.PreProcessRequest();
|
|
this.ProcessRequest();
|
|
this.PostProcessRequest();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
num = this.HandleException(ex);
|
|
}
|
|
}
|
|
extendedMessage = this.m_extendedErrorMessage;
|
|
return num;
|
|
}
|
|
|
|
public static Request FindRequestByHandle(int requestHandle)
|
|
{
|
|
lock (Request.s_syncRoot)
|
|
return Request.s_existingClientRequests[requestHandle];
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
this.OnDisposeAsUser();
|
|
if (this.m_impersonationContext != null)
|
|
{
|
|
this.m_impersonationContext.Undo();
|
|
this.m_impersonationContext = (WindowsImpersonationContext) null;
|
|
}
|
|
this.OnDisposeAsSystem();
|
|
this.RemoveThisRequestFromDictionary();
|
|
GC.SuppressFinalize((object) this);
|
|
}
|
|
|
|
protected virtual void OnInitializeAsSystem()
|
|
{
|
|
}
|
|
|
|
protected virtual void OnInitializeAsUser()
|
|
{
|
|
}
|
|
|
|
protected virtual void OnDisposeAsUser()
|
|
{
|
|
}
|
|
|
|
protected abstract void OnMarshalInArgs();
|
|
|
|
protected abstract void OnProcess();
|
|
|
|
protected abstract void OnMarshalOutArgs();
|
|
|
|
protected virtual void OnDisposeAsSystem()
|
|
{
|
|
}
|
|
|
|
protected virtual bool OnHandleException(Exception e, out int errorCode)
|
|
{
|
|
errorCode = 0;
|
|
return false;
|
|
}
|
|
|
|
private void InsertThisRequestIntoDictionary()
|
|
{
|
|
lock (Request.s_syncRoot)
|
|
{
|
|
int newHandle;
|
|
try
|
|
{
|
|
newHandle = Request.s_existingClientRequests.GetNewHandle();
|
|
}
|
|
catch (IndexOutOfRangeException ex)
|
|
{
|
|
throw InfoCardTrace.ThrowHelperError((Exception) new ServiceBusyException(SR.GetString("TooManyClientRequests"), (Exception) ex));
|
|
}
|
|
this.m_requestHandle = newHandle;
|
|
Request.s_existingClientRequests[this.m_requestHandle] = this;
|
|
}
|
|
}
|
|
|
|
private void RemoveThisRequestFromDictionary()
|
|
{
|
|
lock (Request.s_syncRoot)
|
|
Request.s_existingClientRequests.Remove(this.m_requestHandle);
|
|
}
|
|
|
|
private class RequestHandleDictionary : HandleDictionary<Request>
|
|
{
|
|
}
|
|
}
|
|
}
|