Skip to content

Instantly share code, notes, and snippets.

@LordJZ
Created July 1, 2014 00:34
Show Gist options
  • Select an option

  • Save LordJZ/e5530a6458bc6009843e to your computer and use it in GitHub Desktop.

Select an option

Save LordJZ/e5530a6458bc6009843e to your computer and use it in GitHub Desktop.
MicrosoftGitProviderPatch
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Microsoft.VisualStudio.Shell.Interop;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Collections.Generic;
using MethodBody = Mono.Cecil.Cil.MethodBody;
namespace MicrosoftGitProviderPatch
{
class Program
{
public int GetGlyphTipText(object phierHierarchy, uint itemidNode,
out string pbstrTooltipText)
{
pbstrTooltipText = "";
return 0;
}
public int GetSccGlyph(int cFiles, string[] rgpszFullPaths, VsStateIcon[] rgsiGlyphs, uint[] rgdwSccStatus)
{
if (rgpszFullPaths == null || rgdwSccStatus == null)
{
return -2147467261;
}
for (int i = 0; i < cFiles; i++)
{
rgsiGlyphs[i] = VsStateIcon.STATEICON_BLANK;
rgdwSccStatus[i] = 0;
}
return 0;
}
static void Main()
{
// Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\
const string assemblyName = "Microsoft.TeamFoundation.Git.Provider.dll";
string[] replacements =
{
"SccService/Microsoft.VisualStudio.Shell.Interop.IVsSccManagerTooltip.GetGlyphTipText",
"SccService/GetSccGlyph"
};
AssemblyDefinition assembly = AssemblyDefinition.ReadAssembly(assemblyName);
Collection<TypeDefinition> types = assembly.MainModule.Types;
Collection<MethodDefinition> injectedMethods =
AssemblyDefinition.ReadAssembly(Assembly.GetExecutingAssembly().Location)
.MainModule.GetType(typeof(Program).FullName)
.Methods;
foreach (string replacement in replacements)
{
string[] parts = replacement.Split('/');
string className = parts.First();
string methodName = parts.Last();
string injectedMethodName = methodName.Split('.').Last();
MethodBody body =
types.First(td => td.Name.Equals(className, StringComparison.Ordinal))
.Methods.First(md => md.Name.Equals(methodName, StringComparison.Ordinal)).Body;
Collection<Instruction> instructions = body.Instructions;
Collection<VariableDefinition> variables = body.Variables;
MethodBody injectedBody =
injectedMethods.First(md => md.Name.Equals(injectedMethodName, StringComparison.Ordinal)).Body;
Collection<Instruction> injectedInsns = injectedBody.Instructions;
Collection<VariableDefinition> injectedVariables = injectedBody.Variables;
CopyTo(injectedVariables, variables);
CopyTo(injectedInsns, instructions);
}
assembly.Write(Path.GetFileNameWithoutExtension(assemblyName) + ".patched.dll");
}
static void CopyTo<T>(IEnumerable<T> from, ICollection<T> to)
{
to.Clear();
foreach (T item in from)
to.Add(item);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment