Skip to content

Instantly share code, notes, and snippets.

View jbevain's full-sized avatar

Jb Evain jbevain

View GitHub Profile
@jbevain
jbevain / README.md
Last active November 16, 2023 12:11
pdb2mdb for Visual Studio 2015

The Visual Studio Tools for Unity are able to convert .NET debug symbol files (namely pdb files) to debug symbols files that are understood by Unity's scripting engine (namely .dll.mdb files) when importing both the .dll and the .pdb in the Assets folder.

If you prefer to handle the conversion yourself you need to call a tool named pdb2mdb on the .dll associated with the .pdb:

pdb2mdb MyLibrary.dll

Will produce a MyLibrary.dll.mdb usable on Unity if MyLibrary.pdb is present.

@jbevain
jbevain / MethodBaseRocks.cs
Created April 29, 2009 19:37
A reflection based disassembler
//
// MethodBaseRocks.cs
//
// Author:
// Jb Evain (jbevain@novell.com)
//
// WARNING: code now lives in http://github.com/jbevain/mono.reflection
//
// (C) 2009 Novell, Inc. (http://www.novell.com)
//
@jbevain
jbevain / BackingFieldResolver.cs
Created April 29, 2009 19:42
Code to resolve a property's backing field.
//
// BackingFieldResolver.cs
//
// Author:
// Jb Evain (jbevain@novell.com)
//
// WARNING: code now lives in http://github.com/jbevain/mono.reflection
//
// (C) 2009 Novell, Inc. (http://www.novell.com)
//
@jbevain
jbevain / of-rewrite.cs
Created May 5, 2010 15:08
A rewriter to support methodof and fieldof operations
using System;
using System.Collections.Generic;
using System.Linq;
using Mono.Cecil;
using Mono.Cecil.Cil;
class MethodProcessor {
readonly MethodBody body;
@jbevain
jbevain / Image.cs
Created December 8, 2009 16:38
A class to test whether a file is a PE file and a managed assembly
//
// Image.cs
//
// Author:
// Jb Evain (jbevain@novell.com)
//
// WARNING: code now lives in http://github.com/jbevain/mono.reflection
//
// (C) 2009 Novell, Inc. (http://www.novell.com)
//
@jbevain
jbevain / sizeof.cs
Created July 14, 2014 20:01
SizeOf
using System;
using System.Reflection.Emit;
static class SizeOf<TStruct> where TStruct : struct
{
public static readonly int Value;
static SizeOf()
{
var method = new DynamicMethod("", typeof(int), Type.EmptyTypes);
@jbevain
jbevain / gist:933a81871c55e716f208
Last active July 16, 2023 06:42
Allocating strings from unmanaged memory
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Reflection;
using System.Reflection.Emit;
using System.Text;
namespace StringPool
{
using System;
using System.Reflection;
using System.Reflection.Emit;
static class TypedRef
{
public static TClass RoundTrip<TClass>(TClass instance) where TClass : class
{
var method = new DynamicMethod("", typeof(TClass), new [] {typeof(TClass)}, true);
var il = method.GetILGenerator();
using System;
class Program
{
static void Main()
{
Console.WriteLine("Hello, CoreCLR!");
}
}
using System;
using Mono.Cecil;
class AssemblyRenamer
{
private static void Main(string[] args)
{
var file = args[0];
var newName = args[1];