Fake Visual Studio being installed for EazFuscator for .NET5 and up obfuscation (in progress)
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
140
VisualStudioMock/SetupConfiguration.cs
Normal file
140
VisualStudioMock/SetupConfiguration.cs
Normal file
@@ -0,0 +1,140 @@
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace VisualStudioMock
|
||||
{
|
||||
[ComVisible(true)]
|
||||
[Guid("177F0C4A-1CD3-4DE7-A32C-71DBBB9FA36D")]
|
||||
[ClassInterface(ClassInterfaceType.None)]
|
||||
public sealed class SetupConfiguration : ISetupConfiguration, ISetupConfiguration2
|
||||
{
|
||||
private readonly SetupInstance _singleInstance;
|
||||
|
||||
public SetupConfiguration()
|
||||
{
|
||||
Ext.LogCall(nameof(SetupConfiguration), ".ctor");
|
||||
|
||||
ComProxy proxy = new ComProxy(new SetupConfiguration(false));
|
||||
object proxyCcw = proxy.GetIUnknown();
|
||||
|
||||
// Copy managed object
|
||||
GCHandle hThis = GCHandle.Alloc(this, GCHandleType.WeakTrackResurrection);
|
||||
IntPtr pThis = Marshal.ReadIntPtr(GCHandle.ToIntPtr(hThis));
|
||||
GCHandle hProxy = GCHandle.Alloc(proxyCcw, GCHandleType.WeakTrackResurrection);
|
||||
IntPtr pProxy = Marshal.ReadIntPtr(GCHandle.ToIntPtr(hProxy));
|
||||
byte[] buffer = new byte[IntPtr.Size * 3];
|
||||
Marshal.Copy(pProxy - IntPtr.Size, buffer, 0, buffer.Length);
|
||||
Marshal.Copy(buffer, 0, pThis - IntPtr.Size, buffer.Length);
|
||||
|
||||
/*
|
||||
Ext.Log("Casting to ISetupConfiguration");
|
||||
proxyCcw = this;
|
||||
ISetupConfigurationTest wrapper = (ISetupConfigurationTest)proxyCcw;
|
||||
GC.KeepAlive(wrapper.GetInstanceForCurrentProcess());
|
||||
*/
|
||||
|
||||
Ext.LogExit(nameof(SetupConfiguration), ".ctor");
|
||||
}
|
||||
|
||||
private SetupConfiguration(bool any)
|
||||
{
|
||||
this._singleInstance = new SetupInstance();
|
||||
}
|
||||
|
||||
#region ISetupConfiguration Members
|
||||
|
||||
public IEnumSetupInstances EnumInstances()
|
||||
{
|
||||
Ext.LogCall(nameof(SetupConfiguration), nameof(EnumInstances));
|
||||
return new Enum(this).ComBarrier<Enum, IEnumSetupInstances>();
|
||||
}
|
||||
|
||||
public ISetupInstance GetInstanceForCurrentProcess()
|
||||
{
|
||||
Ext.LogCall(nameof(SetupConfiguration), nameof(GetInstanceForCurrentProcess));
|
||||
return _singleInstance.ComBarrier<SetupInstance, ISetupInstance>();
|
||||
}
|
||||
|
||||
public ISetupInstance GetInstanceForPath([In, MarshalAs(UnmanagedType.LPWStr)] string path)
|
||||
{
|
||||
Ext.LogCall(nameof(SetupConfiguration), nameof(GetInstanceForPath));
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region ISetupConfiguration2 Members
|
||||
|
||||
public IEnumSetupInstances EnumAllInstances()
|
||||
{
|
||||
Ext.LogEnter(nameof(SetupConfiguration), nameof(EnumAllInstances));
|
||||
IEnumSetupInstances result = new Enum(this).ComBarrier<Enum, IEnumSetupInstances>();
|
||||
Ext.LogExit(nameof(SetupConfiguration), nameof(EnumAllInstances));
|
||||
return result;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
sealed class Enum : IEnumSetupInstances
|
||||
{
|
||||
private readonly SetupConfiguration _owner;
|
||||
private int _idx;
|
||||
|
||||
internal Enum(SetupConfiguration owner)
|
||||
{
|
||||
this._owner = owner;
|
||||
}
|
||||
|
||||
public IEnumSetupInstances Clone()
|
||||
{
|
||||
Ext.LogCall(nameof(Enum), nameof(Clone));
|
||||
return ((Enum)MemberwiseClone()).ComBarrier<Enum, IEnumSetupInstances>();
|
||||
}
|
||||
|
||||
public void Next([In, MarshalAs(UnmanagedType.U4)] int celt, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.Interface), Out] ISetupInstance[] rgelt, [MarshalAs(UnmanagedType.U4)] out int pceltFetched)
|
||||
{
|
||||
Ext.LogEnter(nameof(Enum), nameof(Next));
|
||||
if (_idx == 0 && celt > 0)
|
||||
{
|
||||
rgelt[0] = _owner._singleInstance.ComBarrier<SetupInstance, ISetupInstance>();
|
||||
pceltFetched = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
pceltFetched = 0;
|
||||
}
|
||||
Ext.LogExit(nameof(Enum), nameof(Next));
|
||||
}
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
Ext.LogCall(nameof(Enum), nameof(Reset));
|
||||
_idx = 0;
|
||||
}
|
||||
|
||||
public void Skip([In, MarshalAs(UnmanagedType.U4)] int celt)
|
||||
{
|
||||
Ext.LogEnter(nameof(Enum), nameof(Skip));
|
||||
if (celt < 0)
|
||||
throw new ArgumentOutOfRangeException();
|
||||
_idx += celt;
|
||||
Ext.LogExit(nameof(Enum), nameof(Skip));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
[ComImport]
|
||||
[Guid("42843719-DB4C-46C2-8E7C-64F1816EFD5B")]
|
||||
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
|
||||
public interface ISetupConfigurationTest
|
||||
{
|
||||
[return: MarshalAs(UnmanagedType.Interface)]
|
||||
IEnumSetupInstances EnumInstances();
|
||||
[return: MarshalAs(UnmanagedType.Interface)]
|
||||
ISetupInstance GetInstanceForCurrentProcess();
|
||||
[return: MarshalAs(UnmanagedType.Interface)]
|
||||
ISetupInstance GetInstanceForPath([In] [MarshalAs(UnmanagedType.LPWStr)] string path);
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user