<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jérémie Laval</title>
    <description>The latest articles on DEV Community by Jérémie Laval (@garuma).</description>
    <link>https://dev.to/garuma</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F151162%2Fe1587bb3-02ea-4340-8f9c-a55ab88d8bb7.jpeg</url>
      <title>DEV Community: Jérémie Laval</title>
      <link>https://dev.to/garuma</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/garuma"/>
    <language>en</language>
    <item>
      <title>Using DirectManipulation with WPF</title>
      <dc:creator>Jérémie Laval</dc:creator>
      <pubDate>Sun, 31 Mar 2019 02:16:00 +0000</pubDate>
      <link>https://dev.to/garuma/using-directmanipulation-with-wpf-247k</link>
      <guid>https://dev.to/garuma/using-directmanipulation-with-wpf-247k</guid>
      <description>&lt;p&gt;Or said differently, how to enjoy smooth pinch-to-zoom gestures on a legacy platform that’s not UWP (no pun intended).&lt;/p&gt;

&lt;p&gt;If you have done any UI developement on Windows, chances are you have used a &lt;code&gt;ScrollViewer&lt;/code&gt; at some point. If you use the UWP version of &lt;code&gt;ScrollViewer&lt;/code&gt; you will notice that in addition to, well, scroll events the control also natively handles zooming. In the case of WPF however, this capability is completely absent.&lt;/p&gt;

&lt;p&gt;The main reason for this is that WPF was created at a time where neither precision trackpad nor touchscreen were ubiquitous (touch was just starting with Windows 8 after all). Rather it was designed with stylus support in mind and some initial iteration for inking recognition. Since WPF has been put on ice &lt;a href="https://devblogs.microsoft.com/dotnet/net-core-3-and-support-for-windows-desktop-applications/"&gt;until recently&lt;/a&gt;, it never got a fresh coat of paint on its input APIs and things have indeed quite changed since then.&lt;/p&gt;

&lt;p&gt;For starter, the low-level input strategy on Windows is now different. Under the hood of Win32, input events coming from trackpad, touch, stylus and others are now all unified under a single &lt;code&gt;WM_POINTER&lt;/code&gt; event type where previously they were separate. If the app doesn’t have support for it however, the OS will try to convert those events and gestures into a somewhat equivalent combination that the app might recognize.&lt;/p&gt;

&lt;p&gt;For our case (zooming and more precisely pinch to zoom gestures), that compatibility combination is a “Ctrl + Mouse Wheel Up/Down” event which is a standard pattern that apps could implement before. The trouble is that the mouse wheel event that’s sent is only in increment/decrement of &lt;a href="https://docs.microsoft.com/en-us/dotnet/api/system.windows.input.mouse.mousewheeldeltaforoneline?view=netframework-4.7.2"&gt;a default value&lt;/a&gt; which means you can only implement “jagged” zoom behaviors (least you feel like animating everything yourself). This would look a little bit like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;container.PreviewMouseWheel += HandleZoomGesture;

void HandleZoomGesture (object sender, MouseWheelEventArgs e)
{
    // Input emulation will make it look like the Ctrl key is pressed
    // when converting the pinch-to-zoom gesture
    if ((Keyboard.Modifiers &amp;amp; ModifierKeys.Control) == 0)
        return;

    var zoomDelta = ZoomGestureDelta * (((double)e.Delta) / Mouse.MouseWheelDeltaForOneLine);
    SetZoom (currentZoom + zoomDelta);
    e.Handled = true;
}

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This compatibility behavior might work for your case and, as an example, is what some browsers still implement (at least Firefox as I’m writing this) or also the Visual Studio text editor. If you would like something better however read on.&lt;/p&gt;

&lt;p&gt;As it turns out, WPF &lt;em&gt;did&lt;/em&gt; have &lt;a href="https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/mitigation-pointer-based-touch-and-stylus-support"&gt;its input subsystem updated&lt;/a&gt; to use this new unified &lt;code&gt;WM_POINTER&lt;/code&gt; event type but it was never enabled by default and still today sits under an appcontext switch (&lt;code&gt;Switch.System.Windows.Input.Stylus.EnablePointerSupport&lt;/code&gt;). Despite using the new events, that updated stack also willingly filters out scenario that are not strictly coming from touch or stylus thus completely bypassing the added support for precision trackpad.&lt;/p&gt;

&lt;p&gt;Fortunately, there is a way out. Likely to allow external apps that are not UWP based to still benefit from this gesture support (aka browsers), a generic low-level API does exists going by the name of &lt;a href="https://docs.microsoft.com/en-us/windows/desktop/api/_directmanipulation/"&gt;DirectManipulation&lt;/a&gt;. This API operates at the HWND level and works by having you pass on those &lt;code&gt;WM_POINTER&lt;/code&gt; messages who then get processed on a different thread with DirectManipulation handling all the heavy lifting of recognizing gestures and calculating the right transformation to apply.&lt;/p&gt;

&lt;p&gt;It’s normally supposed to be used together with &lt;a href="https://docs.microsoft.com/en-us/windows/desktop/directcomp/directcomposition-concepts"&gt;DirectComposition&lt;/a&gt; which is another low-level API to interact with Windows compositor but you can still make it work manually by simply extracting the values you need (aka content scale).&lt;/p&gt;

&lt;p&gt;The DirectManipulation API is not provided out of the box on the framework but you can use &lt;a href="https://github.com/sharpdx/SharpDX"&gt;SharpDX&lt;/a&gt; which has bindings for it or a tool like &lt;code&gt;tlbimp&lt;/code&gt; on the IDL of the library. Or you can trust me with &lt;a href="https://gist.github.com/garuma/0c25992777c19f5239c73e5b6d66a074"&gt;this binding I made&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For your convenience, here is a “minimal” wrapper class, inspired from &lt;a href="https://github.com/chromium/chromium/blob/master/content/browser/renderer_host/direct_manipulation_win.cc"&gt;Chrome’s usage&lt;/a&gt;, that implements and use a subset of DirectManipulation so that you can plug it into your WPF application (including the support to understand &lt;code&gt;WM_POINTER&lt;/code&gt; events):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using System;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
using DirectManipulation;

class PointerBasedManipulationHandler : IDirectManipulationViewportEventHandler, IDisposable
{
    const int ContentMatrixSize = 6;
    // Actual values don't matter
    static tagRECT DefaultViewport = new tagRECT { top = 0, left = 0, right = 1000, bottom = 1000 };

    HwndSource hwndSource;
    IDirectManipulationManager manager;
    IDirectManipulationViewport viewport;
    Size viewportSize;

    uint viewportEventHandlerRegistration;
    float lastScale;
    float[] matrix = new float[ContentMatrixSize];
    IntPtr matrixContent;

    float lastTranslationX, lastTranslationY;

    public PointerBasedManipulationHandler ()
    {
        matrixContent = Marshal.AllocCoTaskMem (sizeof (float) * ContentMatrixSize);
    }

    public event Action&amp;lt;float&amp;gt; ScaleUpdated;
    public event Action&amp;lt;float, float&amp;gt; TranslationUpdated;

    public HwndSource HwndSource {
        get =&amp;gt; hwndSource;
        set {
            var first = hwndSource == null &amp;amp;&amp;amp; value != null;
            var oldHwndSource = hwndSource;
            if (oldHwndSource != null)
                oldHwndSource.RemoveHook (WndProcHook);
            if (value != null)
                value.AddHook (WndProcHook);
            this.hwndSource = value;
            if (first &amp;amp;&amp;amp; value != null)
                InitializeDirectManipulation ();
        }
    }

    IntPtr Window =&amp;gt; hwndSource.Handle;

    void InitializeDirectManipulation ()
    {
        this.manager = (IDirectManipulationManager)Activator.CreateInstance (typeof (DirectManipulationManagerClass));
        var riid = typeof (IDirectManipulationUpdateManager).GUID;
        riid = typeof (IDirectManipulationViewport).GUID;
        this.viewport = manager.CreateViewport (null, Window, ref riid) as IDirectManipulationViewport;

        var configuration = DIRECTMANIPULATION_CONFIGURATION.DIRECTMANIPULATION_CONFIGURATION_INTERACTION
            | DIRECTMANIPULATION_CONFIGURATION.DIRECTMANIPULATION_CONFIGURATION_SCALING
            | DIRECTMANIPULATION_CONFIGURATION.DIRECTMANIPULATION_CONFIGURATION_TRANSLATION_X
            | DIRECTMANIPULATION_CONFIGURATION.DIRECTMANIPULATION_CONFIGURATION_TRANSLATION_Y
            | DIRECTMANIPULATION_CONFIGURATION.DIRECTMANIPULATION_CONFIGURATION_TRANSLATION_INERTIA;
        viewport.ActivateConfiguration (configuration);
        viewportEventHandlerRegistration = viewport.AddEventHandler (Window, this);
        viewport.SetViewportRect (ref DefaultViewport);
        viewport.Enable ();
    }

    public void Dispose ()
    {
        viewport.RemoveEventHandler (viewportEventHandlerRegistration);
        Marshal.FreeCoTaskMem (matrixContent);
        HwndSource = null;
    }

    public void SetSize (Size size)
    {
        this.viewportSize = size;
        viewport.Stop ();
        var rect = new tagRECT {
            left = 0,
            top = 0,
            right = (int)size.Width,
            bottom = (int)size.Height
        };
        viewport.SetViewportRect (ref rect);
    }

    // Our custom hook to process WM_POINTER event
    IntPtr WndProcHook (IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
    {
        if (msg == WM_POINTERDOWN || msg == DM_POINTERHITTEST) {
            var pointerID = GetPointerId (wParam);
            var pointerInfo = default (POINTER_INFO);
            if (!GetPointerInfo (pointerID, ref pointerInfo))
                return IntPtr.Zero;
            if (pointerInfo.pointerType != POINTER_INPUT_TYPE.PT_TOUCHPAD &amp;amp;&amp;amp;
                pointerInfo.pointerType != POINTER_INPUT_TYPE.PT_TOUCH)
                return IntPtr.Zero;

            viewport.SetContact (pointerID);
        } else if (msg == WM_SIZE &amp;amp;&amp;amp; manager != null) {
            if (wParam == SIZE_MAXHIDE
                || wParam == SIZE_MINIMIZED)
                manager.Deactivate (Window);
            else
                manager.Activate (Window);
        }
        return IntPtr.Zero;
    }

    void ResetViewport (IDirectManipulationViewport viewport)
    {
        viewport.ZoomToRect (0, 0, (float)viewportSize.Width, (float)viewportSize.Height, 0);
        lastScale = 1.0f;
        lastTranslationX = lastTranslationY = 0;
    }

    public void OnViewportStatusChanged ([In, MarshalAs (UnmanagedType.Interface)] IDirectManipulationViewport viewport, [In] DIRECTMANIPULATION_STATUS current, [In] DIRECTMANIPULATION_STATUS previous)
    {
        if (previous == current)
            return;

        if (current == DIRECTMANIPULATION_STATUS.DIRECTMANIPULATION_READY)
            ResetViewport (viewport);
    }

    public void OnViewportUpdated ([In, MarshalAs (UnmanagedType.Interface)] IDirectManipulationViewport viewport)
    {
    }

    public void OnContentUpdated ([In, MarshalAs (UnmanagedType.Interface)] IDirectManipulationViewport viewport, [In, MarshalAs (UnmanagedType.Interface)] IDirectManipulationContent content)
    {
        content.GetContentTransform (matrixContent, ContentMatrixSize);
        Marshal.Copy (matrixContent, matrix, 0, ContentMatrixSize);

        float scale = matrix[0];
        float newX = matrix[4];
        float newY = matrix[5];

        if (scale == 0.0f)
            return;

        var deltaX = (newX - lastTranslationX);
        var deltaY = (newY - lastTranslationY);

        bool ShallowFloatEquals (float f1, float f2)
            =&amp;gt; Math.Abs (f2 - f1) &amp;lt; float.Epsilon;

        if ((ShallowFloatEquals (scale, 1.0f) || ShallowFloatEquals (scale, lastScale))
            &amp;amp;&amp;amp; (Math.Abs (deltaX) &amp;gt; 1.0f || Math.Abs (deltaY) &amp;gt; 1.0f)) {
            TranslationUpdated?.Invoke (-deltaX, -deltaY);
        } else if (!ShallowFloatEquals (lastScale, scale)) {
            ScaleUpdated?.Invoke (scale);
        }

        lastScale = scale;
        lastTranslationX = newX;
        lastTranslationY = newY;
    }

    #region Native methods
    const int WM_POINTERDOWN = 0x0246;
    const int DM_POINTERHITTEST = 0x0250;
    const int WM_SIZE = 0x0005;

    static readonly IntPtr SIZE_MAXHIDE = new IntPtr (4);
    static readonly IntPtr SIZE_MINIMIZED = new IntPtr (1);

    uint GetPointerId (IntPtr wParam) =&amp;gt; (uint)(unchecked((int)wParam.ToInt64 ()) &amp;amp; 0xFFFF);

    [DllImport ("user32.dll", EntryPoint = "GetPointerInfo", SetLastError = true)]
    internal static extern bool GetPointerInfo ([In] uint pointerId, [In, Out] ref POINTER_INFO pointerInfo);

    [StructLayout (LayoutKind.Sequential, CharSet = CharSet.Unicode)]
    internal struct POINTER_INFO
    {
        internal POINTER_INPUT_TYPE pointerType;
        internal uint pointerId;
        internal uint frameId;
        internal POINTER_FLAGS pointerFlags;
        internal IntPtr sourceDevice;
        internal IntPtr hwndTarget;
        internal POINT ptPixelLocation;
        internal POINT ptHimetricLocation;
        internal POINT ptPixelLocationRaw;
        internal POINT ptHimetricLocationRaw;
        internal uint dwTime;
        internal uint historyCount;
        internal int inputData;
        internal uint dwKeyStates;
        internal ulong PerformanceCount;
        internal POINTER_BUTTON_CHANGE_TYPE ButtonChangeType;
    }

    [StructLayout (LayoutKind.Sequential, CharSet = CharSet.Unicode)]
    internal struct POINT
    {
        internal int X;
        internal int Y;
    }

    internal enum POINTER_INPUT_TYPE : uint
    {
        PT_POINTER = 0x00000001,
        PT_TOUCH = 0x00000002,
        PT_PEN = 0x00000003,
        PT_MOUSE = 0x00000004,
        PT_TOUCHPAD = 0x00000005
    }

    [Flags]
    internal enum POINTER_FLAGS : uint
    {
        POINTER_FLAG_NONE = 0x00000000,
        POINTER_FLAG_NEW = 0x00000001,
        POINTER_FLAG_INRANGE = 0x00000002,
        POINTER_FLAG_INCONTACT = 0x00000004,
        POINTER_FLAG_FIRSTBUTTON = 0x00000010,
        POINTER_FLAG_SECONDBUTTON = 0x00000020,
        POINTER_FLAG_THIRDBUTTON = 0x00000040,
        POINTER_FLAG_FOURTHBUTTON = 0x00000080,
        POINTER_FLAG_FIFTHBUTTON = 0x00000100,
        POINTER_FLAG_PRIMARY = 0x00002000,
        POINTER_FLAG_CONFIDENCE = 0x000004000,
        POINTER_FLAG_CANCELED = 0x000008000,
        POINTER_FLAG_DOWN = 0x00010000,
        POINTER_FLAG_UPDATE = 0x00020000,
        POINTER_FLAG_UP = 0x00040000,
        POINTER_FLAG_WHEEL = 0x00080000,
        POINTER_FLAG_HWHEEL = 0x00100000,
        POINTER_FLAG_CAPTURECHANGED = 0x00200000,
        POINTER_FLAG_HASTRANSFORM = 0x00400000,
    }

    internal enum POINTER_BUTTON_CHANGE_TYPE : uint
    {
        POINTER_CHANGE_NONE,
        POINTER_CHANGE_FIRSTBUTTON_DOWN,
        POINTER_CHANGE_FIRSTBUTTON_UP,
        POINTER_CHANGE_SECONDBUTTON_DOWN,
        POINTER_CHANGE_SECONDBUTTON_UP,
        POINTER_CHANGE_THIRDBUTTON_DOWN,
        POINTER_CHANGE_THIRDBUTTON_UP,
        POINTER_CHANGE_FOURTHBUTTON_DOWN,
        POINTER_CHANGE_FOURTHBUTTON_UP,
        POINTER_CHANGE_FIFTHBUTTON_DOWN,
        POINTER_CHANGE_FIFTHBUTTON_UP
    }
    #endregion
}

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;To use the helper, instantiate it somewhere and pass it the &lt;code&gt;HwndSource&lt;/code&gt; where your zoomable content is hosted. You can do so using the &lt;a href="https://docs.microsoft.com/en-us/dotnet/api/system.windows.presentationsource.addsourcechangedhandler?view=netframework-4.7.2"&gt;PresentationSource.AddSourceChangedHandler&lt;/a&gt; method like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;PointerBasedManipulationHandler manipulationHandler = new PointerBasedManipulationHandler ();

PresentationSource.AddSourceChangedHandler (container, HandleSourceUpdated);

void HandleSourceUpdated (object sender, SourceChangedEventArgs e)
{
    if (manipulationHandler != null &amp;amp;&amp;amp; e.NewSource is System.Windows.Interop.HwndSource newHwnd)
        manipulationHandler.HwndSource = newHwnd;
}

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Finally, subscribe to the handler’s &lt;code&gt;ScaleUpdated&lt;/code&gt; / &lt;code&gt;TranslationUpdated&lt;/code&gt; events to react to DirectManipulation changes. For instance you can use a &lt;a href="https://docs.microsoft.com/en-us/dotnet/api/system.windows.media.scaletransform?view=netframework-4.7.2"&gt;ScaleTransform&lt;/a&gt; as your container &lt;a href="https://docs.microsoft.com/en-us/dotnet/api/system.windows.uielement.rendertransform?view=netframework-4.7.2"&gt;RenderTransform&lt;/a&gt; and set the corresponding values when you receive the event. Also don’t forget to set the size of your canvas by calling the &lt;code&gt;SetSize&lt;/code&gt; method (for instance wired up from a &lt;code&gt;SizeChanged&lt;/code&gt; event).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now (at the end of the post) here is the final important caveat&lt;/strong&gt;. If you want any of this DirectManipulation integration to work you are going to have to do one of two things. Because of the way DirectManipulation employs input delegation, you cannot have the legacy WPF stylus input stack run inside your application (which is the default). As such you have two options:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Disable native stylus/touch support and instead only rely on DirectManipulation: set the &lt;code&gt;Switch.System.Windows.Input.Stylus.DisableStylusAndTouchSupport=true&lt;/code&gt; switch in you app.config or programmatically.&lt;/li&gt;
&lt;li&gt;Enable the pointer-based stylus/touch input stack which is compatible with DirectManipulation: set the &lt;code&gt;Switch.System.Windows.Input.Stylus.EnablePointerSupport=true&lt;/code&gt; switch in your app.config or programmatically (early on).&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>XML parsing in the Roslyn era</title>
      <dc:creator>Jérémie Laval</dc:creator>
      <pubDate>Wed, 21 Mar 2018 13:00:00 +0000</pubDate>
      <link>https://dev.to/garuma/xml-parsing-in-the-roslyn-era-44je</link>
      <guid>https://dev.to/garuma/xml-parsing-in-the-roslyn-era-44je</guid>
      <description>&lt;p&gt;Roslyn was a revolution in the .NET world when it came out. For the first time we had Microsoft release their compiler implementation of C# under an open-source license. Not only that, the way in which this compiler had been constructed would open the doors to numerous improvements in the ecosystem in the forms of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A complete API to manipulate code as data&lt;/li&gt;
&lt;li&gt;A compiler platform that is easy to hack on&lt;/li&gt;
&lt;li&gt;A backend that is adapted for editor/language service usage&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This enabled faster evolutions of the C# language, a plethora of tools and analyzers that can fully understand your code and intellisense that’s better than ever.&lt;/p&gt;

&lt;p&gt;In my day to day job I work on visual tools at Microsoft for our Xamarin platform. As part of this we integrate with both Visual Studio Mac and Visual Studio where we, of course, use Roslyn for most of our user code interactions.&lt;/p&gt;

&lt;p&gt;However, those visual tools all have another thing in common: they work on some dialect of XML (be it XAML, Android layout XML, XML resources or others). In a lot of ways working with that XML medium in the context of an editor presents the same challenges than Roslyn solved for code:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You need high-fidelity parsing of your document preserving user modifications&lt;/li&gt;
&lt;li&gt;You need to react to and create changes applied to specific text subsets&lt;/li&gt;
&lt;li&gt;You need a representation that is easy to manipulate and pass around&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Existing XML solutions (&lt;code&gt;System.Xml&lt;/code&gt;, &lt;code&gt;System.Xml.Linq&lt;/code&gt;, …) tend to fall short because they weren’t created with an editor usage in mind. Their use case is more about exposing a document content than caring much about the way it’s written and evolved.&lt;/p&gt;

&lt;p&gt;So basically what we need is Roslyn but for XML. Fortunately &lt;a href="https://twitter.com/KirillOsenkov"&gt;Kirill&lt;/a&gt; thought the same and a few years ago started working on bringing an existing morsel of Roslyn, namely the VB XML literal parser, and transform it into a fully fledged XML parser and syntax representation.&lt;/p&gt;

&lt;p&gt;That project is (originally) named &lt;a href="https://github.com/KirillOsenkov/XmlParser"&gt;XmlParser&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In a nutshell, XmlParser brings the Roslyn SyntaxTree AST model (immutable, full-fidelity, error-tolerant) and the parsing infrastructure that can create it to the point that its usage should feel familiar to someone who is used to work with Roslyn already.&lt;/p&gt;

&lt;p&gt;As part of ongoing work, I spent a bit of time myself during the last few weeks bringing some improvements to the project to make it even better for an editor use case:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Proper &lt;a href="https://blogs.msdn.microsoft.com/ericlippert/2012/06/08/persistence-facades-and-roslyns-red-green-trees/"&gt;red-green node separation&lt;/a&gt; which is a key to Roslyn performance while retaining immutability&lt;/li&gt;
&lt;li&gt;Parsing incrementality: the ability to reuse existing syntax tree nodes when only a portion of the text buffer has changed&lt;/li&gt;
&lt;li&gt;The start of proper syntax factories and modification APIs&lt;/li&gt;
&lt;li&gt;More Roslyn code import where it made sense (common utilities, caching, …)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Albeit part of this is still a work-in-progress, we published updated NuGet packages (now under the &lt;a href="https://www.nuget.org/packages/GuiLabs.Language.Xml"&gt;GuiLabs.Language.Xml&lt;/a&gt; NuGet ID) with the latest code so that you can try it for yourself.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Computation Expressions in C# using async/await</title>
      <dc:creator>Jérémie Laval</dc:creator>
      <pubDate>Thu, 11 Jan 2018 13:30:21 +0000</pubDate>
      <link>https://dev.to/garuma/computation-expressions-in-c-using-async-await-1jdn</link>
      <guid>https://dev.to/garuma/computation-expressions-in-c-using-async-await-1jdn</guid>
      <description>&lt;p&gt;I have had some fun already using C# 7.1 new customizable async/await pipeline to do interesting things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://dev.to/blog/2017/05/22/activitytask-async-await-android-cornercases/"&gt;ActivityTask, an helper for async/await on Android&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://dev.to/blog/2017/04/26/maybe-computation-expression-csharp/"&gt;Recreating F# maybe computation expression in C#&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this post I’ll be describing how I took on those past experiences and generalized the core idea of the second entry to provide a somewhat equivalent construct to F# computation expressions in C# by (ab)using the async/await machinery.&lt;/p&gt;

&lt;p&gt;If you have never heard of F# computations expressions before I recommend reading the &lt;a href="https://fsharpforfunandprofit.com/posts/computation-expressions-intro/"&gt;F# for fun and profit serie&lt;/a&gt; on it. Otherwise the TL;DR is that, without the monadic baggage, computation expressions essentially allow you to customize how a series of “statement” are chained together and plug your own logic in-between.&lt;/p&gt;

&lt;p&gt;A famous example of such computation expression is the &lt;a href="https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/asynchronous-workflows"&gt;async workflow&lt;/a&gt; that lead to the creation of C# async/await in the first place (C# async/await being a more specialized/optimized form of its computation expression parent).&lt;/p&gt;

&lt;p&gt;In a way what I’m describing in this post is basically how we can manage to return to the original definition of F# computation expressions using the more specialized C# async/await interface that was derived from it.&lt;/p&gt;

&lt;p&gt;If you want to jump straight to the code &lt;a href="https://github.com/garuma/Neteril.ComputationExpression"&gt;grab it on GitHub&lt;/a&gt;. The repository also contains a &lt;a href="https://github.com/garuma/Neteril.ComputationExpression/blob/master/Examples.workbook"&gt;Workbook file&lt;/a&gt; with a few examples utilizing the API so that you can get a feel of what it allows you to do.&lt;/p&gt;

&lt;p&gt;For the others, here is the example given in the repository README of what the API looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Option&amp;lt;int&amp;gt; TryDivide (int up, int down)
    =&amp;gt; down == 0 ? None&amp;lt;int&amp;gt;.Value : Some.Of (up / down);

class MaybeBuilder : IMonadExpressionBuilder
{
    IMonad&amp;lt;T&amp;gt; IMonadExpressionBuilder.Bind&amp;lt;U, T&amp;gt; (IMonad&amp;lt;U&amp;gt; m, Func&amp;lt;U, IMonad&amp;lt;T&amp;gt;&amp;gt; f)
    {
        switch ((Option&amp;lt;U&amp;gt;)m) {
          case Some&amp;lt;U&amp;gt; some: return f (some.Item);
          case None&amp;lt;U&amp;gt; none:
          default: return None&amp;lt;T&amp;gt;.Value;
        }
    }

    public IMonad&amp;lt;T&amp;gt; Return&amp;lt;T&amp;gt; (T v) =&amp;gt; Some.Of (v);
    public IMonad&amp;lt;T&amp;gt; Zero&amp;lt;T&amp;gt; () =&amp;gt; None&amp;lt;T&amp;gt;.Value;
    // We don't have optional interface methods in C# quite yet
    public IMonad&amp;lt;T&amp;gt; Combine&amp;lt;T&amp;gt; (IMonad&amp;lt;T&amp;gt; m, IMonad&amp;lt;T&amp;gt; n) =&amp;gt; throw new NotSupportedException ();
}

// Returns `Some 15`
ComputationExpression.Run&amp;lt;int, Option&amp;lt;int&amp;gt;&amp;gt; (new OptionExpressionBuilder (), async () =&amp;gt; {
    var val1 = await TryDivide (120, 2);
    var val2 = await TryDivide (val1, 2);
    var val3 = await TryDivide (val2, 2);
    return val3;
})

// Returns `None`
ComputationExpression.Run&amp;lt;int, Option&amp;lt;int&amp;gt;&amp;gt; (new OptionExpressionBuilder (), async () =&amp;gt; {
    var val1 = await TryDivide (120, 2);
    var val2 = await TryDivide (val1, 0);
    var val3 = await TryDivide (val2, 2);
    return val3;
})
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In this snippet I’m lifting &lt;a href="https://dev.to/blog/2017/04/26/maybe-computation-expression-csharp/"&gt;the example of the Maybe/Option monad&lt;/a&gt; I had talked about previously and encoding it via the computation expression mechanism to arrive at the same result. In that case the &lt;code&gt;await&lt;/code&gt; keyword is used to represent the equivalent F# &lt;code&gt;let!&lt;/code&gt; keyword which is a shortand for the &lt;code&gt;Bind&lt;/code&gt; method of the computation expression builder (&lt;code&gt;Bind&lt;/code&gt; is the core monadic operation that allows all those “statements” to be chained together).&lt;/p&gt;

&lt;p&gt;To implement a custom computation expression you have to do two things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Define a type that implements the empty &lt;code&gt;IMonad&lt;/code&gt; interface. This simply acts as a marker to be able to use the custom async machinery of the library.&lt;/li&gt;
&lt;li&gt;More interestingly, provide an implementation of the &lt;code&gt;IMonadExpressionBuilder&lt;/code&gt; interface which is where you can put the code to customize the execution behavior of the computation expression block.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In the example above, the main customization is in the &lt;code&gt;Bind&lt;/code&gt; method where we grab the result of executing the previous statement and then depending on the outcome either pass the result down the chain or short-circuit everything by returning &lt;code&gt;None&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Another case where C# did a specialized implementation of what in F# is also encoded as a computation expression is &lt;code&gt;IEnumerable&amp;lt;T&amp;gt;&lt;/code&gt; state machines via the &lt;code&gt;yield&lt;/code&gt; operator.&lt;/p&gt;

&lt;p&gt;With the library we can instead express this using the &lt;code&gt;Combine&lt;/code&gt; method of the builder to achieve something like this (lifted from the examples workbook):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using static Neteril.ComputationExpression.ComputationExpression;
// The Enumerable monad is given in the library
using Neteril.ComputationExpression.Instances;

var result = ComputationExpression.Run&amp;lt;int, EnumerableMonad&amp;lt;int&amp;gt;&amp;gt; (new EnumerableExpressionBuilder (), async () =&amp;gt; {
    var item = await (EnumerableMonad&amp;lt;int&amp;gt;)new [] { 1, 2, 3 };
    var item2 = await (EnumerableMonad&amp;lt;int&amp;gt;)new [] { 100, 200 };
    // We want back a enumeration containing the concatenation of (item, item2, item1 * item2)
    // for all successive values of item1 and item2
    await Yield (item);
    await Yield (item2);
    return item * item2;
});
string.Join (", ", result.Select (i =&amp;gt; i.ToString ()));
// =&amp;gt; [1, 100, 100, 1, 200, 200, 2, 100, 200, 2, 200, 400, 3, 100, 300, 3, 200, 600]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In this new sample, the monad is implemented in a way that the first &lt;code&gt;await&lt;/code&gt; (again equivalent to F# &lt;code&gt;let!&lt;/code&gt;) binds to each successive element of the given collections. The result is a &lt;code&gt;EnumerableMonad&amp;lt;T&amp;gt;&lt;/code&gt; that is itself a &lt;code&gt;IEnumerable&amp;lt;T&amp;gt;&lt;/code&gt; (i.e. you can further use LINQ on it).&lt;/p&gt;

&lt;p&gt;Because in this case there is no way to hijack the C# &lt;code&gt;yield&lt;/code&gt; operator directly (like F# would) this is instead represented here with the expression &lt;code&gt;await Yield&lt;/code&gt; for intermediary values and &lt;code&gt;return&lt;/code&gt; for the last one.&lt;/p&gt;

&lt;p&gt;Here is the implementation of the builder for the sample to work (note the now implemented &lt;code&gt;Combine&lt;/code&gt; method):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class EnumerableExpressionBuilder : IMonadExpressionBuilder
{
    IMonad&amp;lt;T&amp;gt; IMonadExpressionBuilder.Bind&amp;lt;U, T&amp;gt; (IMonad&amp;lt;U&amp;gt; m, Func&amp;lt;U, IMonad&amp;lt;T&amp;gt;&amp;gt; f)
    {
       var previousEnumerableMonad = (EnumerableMonad&amp;lt;U&amp;gt;)m;
       return new EnumerableMonad&amp;lt;T&amp;gt; (previousEnumerableMonad.SelectMany (u =&amp;gt; (EnumerableMonad&amp;lt;T&amp;gt;)f (u)));
    }

    IMonad&amp;lt;T&amp;gt; IMonadExpressionBuilder.Return&amp;lt;T&amp;gt; (T v) =&amp;gt; new EnumerableMonad&amp;lt;T&amp;gt; (Enumerable.Repeat (v, 1));
    IMonad&amp;lt;T&amp;gt; IMonadExpressionBuilder.Zero&amp;lt;T&amp;gt; () =&amp;gt; new EnumerableMonad&amp;lt;T&amp;gt; (Enumerable.Empty&amp;lt;T&amp;gt; ());

    IMonad&amp;lt;T&amp;gt; IMonadExpressionBuilder.Combine&amp;lt;T&amp;gt; (IMonad&amp;lt;T&amp;gt; m, IMonad&amp;lt;T&amp;gt; n)
    {
       var enumerableMonad1 = (EnumerableMonad&amp;lt;T&amp;gt;)m;
       var enumerableMonad2 = (EnumerableMonad&amp;lt;T&amp;gt;)n;
       // Simply use LINQ Concat method
       return new EnumerableMonad&amp;lt;T&amp;gt; (enumerableMonad1.Concat (enumerableMonad2));
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Interestingly of the early writings I remember reading about Monads and how it related to C#, the LINQ &lt;code&gt;SelectMany&lt;/code&gt; operator was given as an example of a &lt;code&gt;Bind&lt;/code&gt; operation in the monadic sense. With this we have the proof it’s indeed true.&lt;/p&gt;

&lt;p&gt;The actual code enabling all of this is a fairly straightforward &lt;a href="https://github.com/garuma/Neteril.ComputationExpression/blob/master/Neteril.ComputationExpression/MonadAsyncMethodBuilder.cs"&gt;async method builder implementation&lt;/a&gt;. If you have read any of my previous articles I mentioned at the beginning of this post, it’s essentially doing the same thing with a bunch more hacks to cope with the added indirection of generic types in the &lt;code&gt;IMonad&amp;lt;T&amp;gt;&lt;/code&gt; interface.&lt;/p&gt;

&lt;p&gt;It also peeks a bit deeper into the internal structure of the async state machine generated by the compiler via the &lt;a href="https://github.com/garuma/Neteril.ComputationExpression/blob/master/Neteril.ComputationExpression/Machinist.cs"&gt;&lt;code&gt;Machinist&lt;/code&gt; class&lt;/a&gt; so that it can control the actual stepping and awaiter values that are stored in it. This for instance allows the same state machine to be “rewinded” which is essential to support cases like the above Enumerable sample.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>ActivityTask, an helper for async/await on Android</title>
      <dc:creator>Jérémie Laval</dc:creator>
      <pubDate>Mon, 22 May 2017 13:30:21 +0000</pubDate>
      <link>https://dev.to/garuma/activitytask-an-helper-for-async-await-on-android-1ifi</link>
      <guid>https://dev.to/garuma/activitytask-an-helper-for-async-await-on-android-1ifi</guid>
      <description>&lt;p&gt;While at I/O last week, we happened to attend the &lt;a href="https://events.google.com/io/schedule/?section=may-18&amp;amp;sid=006961f0-030f-4dca-8277-a479083c208d"&gt;Architecture Component talk on Android lifecycle&lt;/a&gt; (which I recommend you watch). While the solutions presented there are definitely interesting and, in some cases, map to patterns we already have in .NET, it definitely resonated with us present on how those Android lifecycle nitpicks make one specific C# feature more cumbersome to use: async/await.&lt;/p&gt;

&lt;p&gt;With async/await, the two main nitpicks that are pertaining to Android developers are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Because of Android resource system works, a change of configuration (e.g. screen rotation) will recreate &lt;code&gt;Activity&lt;/code&gt; instances by default&lt;/li&gt;
&lt;li&gt;Because &lt;code&gt;await&lt;/code&gt; is oblivious to an &lt;code&gt;Activity&lt;/code&gt; lifecycle, it may execute continuations while in an undesired state causing an &lt;code&gt;IllegateStateException&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Note that we already introduced something that partially address those qualms in the form of the &lt;a href="https://forums.xamarin.com/discussion/84221/announcing-android-activity-controller-preview"&gt;ActivityController&lt;/a&gt; with the added bonus of providing convenient asynchronous wrapper methods for &lt;code&gt;StartActivityForResult&lt;/code&gt;-based workflows.&lt;/p&gt;

&lt;p&gt;In this case, based on some &lt;a href="https://dev.to/blog/2017/04/26/maybe-computation-expression-csharp/"&gt;other fun I had previously&lt;/a&gt;, I figured there was potentially a way to leverage C# 7 new customizable async state machines drivers to achieve something that could help mitigate those two issues without requiring too much changes in your code.&lt;/p&gt;

&lt;p&gt;Enter &lt;a href="https://github.com/garuma/LibActivityTask"&gt;ActivityTask&lt;/a&gt; (also on &lt;a href="https://www.nuget.org/packages/Neteril.ActivityTask"&gt;NuGet&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;This little library has two main primitives:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;ActivityScope&lt;/code&gt; allows to track the most recent instance of one of your Activity subclass so that potential underlying re-creations are transparent to you&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ActivityTask&lt;/code&gt; acts as a standard &lt;code&gt;Task&lt;/code&gt; return value in an async method but customize the state machine driver (in cooperation with &lt;code&gt;ActivityScope&lt;/code&gt;) to make continuation scheduling aware of the activity lifecycle.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Under the hood, &lt;code&gt;ActivityScope&lt;/code&gt; simply registers a listener at the &lt;code&gt;Application&lt;/code&gt; level to listen to global activity lifecycle events. When it detects the activity it’s tracking is about to die, it will mark it so that when it’s respawned it can re-associate with it. Because it implements an implicit conversion operator to &lt;code&gt;Activity&lt;/code&gt;, you can pass the scope wherever an activity instance is needed to ensure you always use a valid value.&lt;/p&gt;

&lt;p&gt;As for &lt;code&gt;ActivityTask&lt;/code&gt; the implementation is pretty boring (it pretty much defers to a &lt;code&gt;TaskCompletionSource&lt;/code&gt;), the interesting portion is with &lt;code&gt;ActivityScopeMethodBuilder&lt;/code&gt; that drives the async state machine. For all intent and purpose, it will behave like the default driver for &lt;code&gt;Task&lt;/code&gt;. However, thanks to the extra &lt;code&gt;ActivityScope&lt;/code&gt; method argument, it will additionally make sure that any continuation is only executed when the activity tracked by the scope is in a usable state at that moment. If not, it will simply keep the continuation queued up until the tracked activity is resumed.&lt;/p&gt;

&lt;p&gt;To see how all of this fits together, here is the code for the activity of the test app in the GitHub repository:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[Activity(Label = "ActivityTaskTest", MainLauncher = true, Icon = "@mipmap/icon")]
public class MainActivity : Activity
{
    static bool launched = false;

    protected override async void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);

        // Set our view from the "main" layout resource
        SetContentView(Resource.Layout.Main);

        if (!launched)
        {
            launched = true;
            using (var scope = ActivityScope.Of(this))
                await DoAsyncStuff(scope);
        }
    }

    TextView MyLabel(Activity activity) =&amp;gt; activity.FindViewById&amp;lt;TextView&amp;gt;(Resource.Id.myLabel);

    async ActivityTask DoAsyncStuff(ActivityScope scope)
    {
        await Task.Delay(3000); // Medium network call
        MyLabel(scope).Text = "Step 1";
        await Task.Delay(5000); // Big network call
        MyLabel(scope).Text = "Step 2";
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This example simulates launching a series of asynchronous operations the very first time an activity is created. Beforehand though, it creates an &lt;code&gt;ActivityScope&lt;/code&gt; to track the lifetime of the current activity and pass it down. Between each asynchronous substep, the activity instance is used to fetch the label onscreen and update its text.&lt;/p&gt;

&lt;p&gt;The idea is to trigger a damaging event during one of those &lt;code&gt;Task.Delay&lt;/code&gt; calls. Some that you can test are rotating your device (thus killing and re-creating the activity) or pressing the home button to pause the activity and reopen it after the delay expired.&lt;/p&gt;

&lt;p&gt;For instance, if rotating the screen after “Step 1” is shown, you should see the original text of the label briefly re-appears (because the layout was inflated from scratch) and soon after see “Step 2” be set meaning the async method used the correct new activity instance to locate the label.&lt;/p&gt;

&lt;p&gt;If pausing the activity after “Step 1” is shown, resuming the activity after the second delay expires should result in “Step 2” being displayed immediately as the callback got executed during the resume process instead of running while the activity was in the background.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Diverting functions in Windows with IAT patching</title>
      <dc:creator>Jérémie Laval</dc:creator>
      <pubDate>Fri, 23 Dec 2016 10:00:21 +0000</pubDate>
      <link>https://dev.to/garuma/diverting-functions-in-windows-with-iat-patching-p8d</link>
      <guid>https://dev.to/garuma/diverting-functions-in-windows-with-iat-patching-p8d</guid>
      <description>&lt;p&gt;Recently I was stuck with a blocking issue that was putting a feature I worked on in jeopardy. To summarize the problem, the entire feature relied on a specific way a library is initialized, the library in question providing two different functions (that we will call &lt;code&gt;Init&lt;/code&gt; and &lt;code&gt;InitExtended&lt;/code&gt;) to initialize itself.&lt;/p&gt;

&lt;p&gt;The code responsible for this initialization hardcodes calling one of the variant and is in a DLL that is not modifiable. To make things harder, the two initialization functions I mentioned have slightly different parameters which complicated things as it can’t be a simple function pointer swap.&lt;/p&gt;

&lt;p&gt;For exploitation purposes, an important aspect is that the initialization function is not actually referenced directly in the DLL but instead it is located dynamically using the standard &lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms684175.aspx"&gt;LoadLibrary&lt;/a&gt;/&lt;a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms683212.aspx"&gt;GetProcAddress&lt;/a&gt; combo.&lt;/p&gt;

&lt;p&gt;When something is using &lt;code&gt;LoadLibrary&lt;/code&gt;, the obvious thing to try first is to take advantage of the DLL loader lookup mechanism and provide a modified DLL that can be loaded instead of the original one. In this case though, &lt;code&gt;LoadLibrary&lt;/code&gt; was used with a hardcoded path in a system directory which made this option impossible.&lt;/p&gt;

&lt;p&gt;Which leaves trying to use &lt;code&gt;GetProcAddress&lt;/code&gt; to masquerade things up. To do this there is a more exotic technique called IAT patching that relies on the way the PE (Portable Executable) format work for dynamic libraries.&lt;/p&gt;

&lt;h2&gt;
  
  
  What’s in a DLL
&lt;/h2&gt;

&lt;p&gt;Like most other dynamically loadable libraries format, a DLL contains more than just the code that’s executed. The file is split between different sections that references several other type of data in addition to the code section.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YuCW3IF0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.neteril.org/wp-content/uploads/iat_patching/pe_format.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YuCW3IF0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.neteril.org/wp-content/uploads/iat_patching/pe_format.png" alt="PE format diagram"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For instance the data section will contain a bunch of interesting tables, things like strings literals, the constant data in the program, thread local storage and so on.&lt;/p&gt;

&lt;p&gt;When a DLL is loaded, those tables and sections are mapped into the calling process memory space and are accessible from user code although in practice you will always be using some system API instead of querying those parts of the memory yourself.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Import Table
&lt;/h2&gt;

&lt;p&gt;The table we are going to be interested in here is the &lt;strong&gt;Import Address Table&lt;/strong&gt; (abbreviated IAT). The role of this table is to list all the external functions a DLL references from other libraries in a dictionary form keyed by library name (e.g. “user32.dll”) and values as function pointer thunks.&lt;/p&gt;

&lt;p&gt;For instance, here is a snippet of the content of this table from a random DLL (the hint/ordinal values are used by the loader for faster processing):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ pedump -I freetype.dll 

=== IMPORTS ===

MODULE_NAME HINT ORD FUNCTION_NAME
KERNEL32.dll 1cb GetCurrentThreadId
KERNEL32.dll 15b FlsSetValue
KERNEL32.dll 18c GetCommandLineA
KERNEL32.dll 425 RtlUnwindEx
KERNEL32.dll 2d3 HeapAlloc
KERNEL32.dll 208 GetLastError
KERNEL32.dll 2da HeapReAlloc
KERNEL32.dll 2d7 HeapFree
KERNEL32.dll ee EncodePointer
KERNEL32.dll 15a FlsGetValue
KERNEL32.dll 159 FlsFree
KERNEL32.dll 480 SetLastError
KERNEL32.dll 158 FlsAlloc
KERNEL32.dll 4c0 Sleep
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In our case, both of &lt;code&gt;LoadLibrary&lt;/code&gt; and &lt;code&gt;GetProcAddress&lt;/code&gt; would be in this table keyed under the library they come from aka &lt;strong&gt;kernel32.dll&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The reason for this table is explained by the way dynamic libraries and the Windows DLL loader works. When compiling code to a DLL that depends on some other libraries, the actual memory layout where the dependencies are going to be loaded is not known in advance. Maybe that dependency has already been loaded by the program, maybe the DLL will be the one to load it, in any case the real locations for all those functions will ultimately be determined by the running context.&lt;/p&gt;

&lt;p&gt;Thus, when some code references an external function, what the compiler will do is insert a &lt;code&gt;call&lt;/code&gt; instruction that is not pointing directly to the real address of the function but instead will load the address pointed to by the thunk I mentioned earlier from the Import Address Table.&lt;/p&gt;

&lt;p&gt;By doing so, the code contained inside the DLL is always valid and the Windows loader simply has to modify one piece of the overall loaded DLL (the IAT thunk) to point to the right function address at runtime instead of going throughout the entire code section and patch one-by-one every &lt;code&gt;call&lt;/code&gt; instructions.&lt;/p&gt;

&lt;p&gt;Below is an example of how the same DLL we saw earlier is calling the &lt;code&gt;GetCommandLineA&lt;/code&gt; Win32 function contained in kernel32. Notice how the address for the call instruction is retrieved (&lt;code&gt;qword&lt;/code&gt;) from a location in the data segment (&lt;code&gt;ds&lt;/code&gt;) and how the disassembler is smart enough to name the thunk with a &lt;code&gt;imp_&lt;/code&gt; prefix:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vrf24J9h--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.neteril.org/wp-content/uploads/iat_patching/hopper-call.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vrf24J9h--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.neteril.org/wp-content/uploads/iat_patching/hopper-call.png" alt="Indirect IAT calling"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And here is a view of the actual array containing all the thunks for kernel32 functions that will be patched by the Windows loader when the DLL is processed at run-time:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aCvANtIQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.neteril.org/wp-content/uploads/iat_patching/hopper-datasegment.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aCvANtIQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://blog.neteril.org/wp-content/uploads/iat_patching/hopper-datasegment.png" alt="IAT thunks"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Patching the Import Address Table
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Reminder:&lt;/em&gt; we are trying to influence a program execution by manipulating &lt;code&gt;GetProcAddress&lt;/code&gt; so that instead of calling an &lt;code&gt;Init&lt;/code&gt; function it calls a different &lt;code&gt;InitExtended&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;Now that we know how external functions are called it’s easy to see that taking control of this IAT indirection is the key to do what we want. By patching the IAT thunk for the function we want to modify, we ensure the relevant code will be redirected to use our modifications.&lt;/p&gt;

&lt;p&gt;Provided you have already the ability to load custom code in the process via another mean (if not lookup DLL injection techniques), the recipe to hijack a IAT thunk is as follow:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create your custom function in your own code that mimics the prototype of the real one&lt;/li&gt;
&lt;li&gt;Prevent or delay the codepath you are trying to change from accessing the function before your patching is done&lt;/li&gt;
&lt;li&gt;Retrieve a pointer to the module (containing all the tables) of the DLL/executable that you are trying to hijack&lt;/li&gt;
&lt;li&gt;Locate the Import Address Table&lt;/li&gt;
&lt;li&gt;Iterate over it to find the right thunk&lt;/li&gt;
&lt;li&gt;Overwrite the value given by the DLL loader with your own custom function address&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Below is the translated and annotated version of this recipe in C using the imagehlp library (that defines all the right C structs to modelize the IAT table layout):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Our custom Init function that will now internally
// call the InitExtended function we wanted to use
static void MyCustomInitFunction (/* parameters */)
{
  InitExtended (/* other parameters */);
}

// Our hooked version of GetProcAddress with the
// same prototype (and same calling convention)
static FARPROC MyGetProcAddress (HMODULE hModule, LPCSTR lpProcName)
{
  if (strcmp (lpProcName, "Init") == 0)
    return (FARPROC)MyCustomInitFunction;
  return GetProcAddress (hModule, lpProcName);
}

static BOOL HackGetProcAddress ()
{
  // Get the handle to the module we want to divert 
  HMODULE module = GetModuleHandle (L"TheDllToHijack.dll");
  if (module == NULL)
    return FALSE;

  // Get a reference to the import table to locate the kernel32 entry
  ULONG size;
  PIMAGE_IMPORT_DESCRIPTOR importDescriptor = (PIMAGE_IMPORT_DESCRIPTOR)ImageDirectoryEntryToDataEx (module, TRUE, IMAGE_DIRECTORY_ENTRY_IMPORT, &amp;amp;size, NULL);

  // In the import table find the entry that corresponds to kernel32
  BOOL found = FALSE;
  while (importDescriptor-&amp;gt;Characteristics &amp;amp;&amp;amp; importDescriptor-&amp;gt;Name) {
    PSTR importName = (PSTR)((PBYTE)module + importDescriptor-&amp;gt;Name);
    if (_stricmp (importName, "kernel32.dll") == 0) {
      found = TRUE;
      break;
    }
    importDescriptor++;
  }
  if (!found)
    return FALSE;

  // We use this value as a comparison
  PROC baseGetProcAddress = (PROC)GetProcAddress (GetModuleHandle (L"kernel32.dll"), "GetProcAddress");

  // From the kernel32 import descriptor, go over its IAT thunks to
  // find the one used by the rest of the code to call GetProcAddress
  PIMAGE_THUNK_DATA thunk = (PIMAGE_THUNK_DATA)((PBYTE)module + importDescriptor-&amp;gt;FirstThunk);
  while (thunk-&amp;gt;u1.Function) {
    PROC* funcStorage = (PROC*)&amp;amp;thunk-&amp;gt;u1.Function;
    // Found it, now let's patch it
    if (*funcStorage == baseGetProcAddress) {
      // Get the memory page where the info is stored
      MEMORY_BASIC_INFORMATION mbi;
      VirtualQuery (funcStorage, &amp;amp;mbi, sizeof (MEMORY_BASIC_INFORMATION));

      // Try to change the page to be writable if it's not already
      if (!VirtualProtect (mbi.BaseAddress, mbi.RegionSize, PAGE_READWRITE, &amp;amp;mbi.Protect))
        return FALSE;

      // Store our hook
      *funcStorage = (PROC)MyGetProcAddress;

      // Restore the old flag on the page
      DWORD dwOldProtect;
      VirtualProtect (mbi.BaseAddress, mbi.RegionSize, mbi.Protect, &amp;amp;dwOldProtect);

      // Profit
      return TRUE;
    }

    thunk++;
  }

  return FALSE;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This was an example of how you can use IAT patching to circumvent legacy code without having to recompile or otherwise damage the original binary.&lt;/p&gt;

&lt;p&gt;This technique is well known so if you want to do something more complicated/reliable you can always use an existing library like &lt;a href="https://easyhook.github.io/"&gt;EasyHook&lt;/a&gt; or something as full-featured as Microsoft’s Detours.&lt;/p&gt;

&lt;p&gt;References:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.dematte.org/2006/03/04/InterceptingWindowsAPIs.aspx"&gt;Intercepting Windows APIs - Coding for fun&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.codeproject.com/Articles/2082/API-hooking-revealed"&gt;API hooking revealed - CodeProject&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://sandsprite.com/CodeStuff/Understanding_imports.html"&gt;Understanding the Import Address Table&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://msdn.microsoft.com/en-us/library/ms809762.aspx"&gt;Peering inside the PE - Matt Pietrek&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
    <item>
      <title>Custom controls in the Xamarin Android Designer</title>
      <dc:creator>Jérémie Laval</dc:creator>
      <pubDate>Sat, 17 Dec 2016 16:00:21 +0000</pubDate>
      <link>https://dev.to/garuma/custom-controls-in-the-xamarin-android-designer-55ed</link>
      <guid>https://dev.to/garuma/custom-controls-in-the-xamarin-android-designer-55ed</guid>
      <description>&lt;p&gt;&lt;em&gt;aka an introductory look at the internals of our Android ecosystem&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In the latest stable release of the Xamarin platform, one specific feature I worked on is custom controls support in the Android designer (both Mac with Xamarin Studio and Windows on Visual Studio).&lt;/p&gt;

&lt;p&gt;Our iOS designer has long enjoyed this kind of support, actually from day 1. Being part of that team at the time, I can confirm we were quite excited (and relieved!) to see that pie chart renders on stage when Miguel &lt;a href="https://www.youtube.com/watch?v=XVdqjGDkv9s#t=58m" rel="noopener noreferrer"&gt;introduced the feature&lt;/a&gt; at Evolve 2013:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.neteril.org%2Fwp-content%2Fuploads%2Fandroid-designer-custom-controls%2Fios-designer.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.neteril.org%2Fwp-content%2Fuploads%2Fandroid-designer-custom-controls%2Fios-designer.png" alt="iOS designer custom controls"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;However, because the rendering strategy is quite different between the two designers, attaining the same level of support for custom controls on Android was much more challenging.&lt;/p&gt;

&lt;p&gt;In this post I want to highlight how the Android designer and, more generally, Xamarin.Android work and how implementing custom controls fitted into this.&lt;/p&gt;

&lt;h3&gt;
  
  
  Designer Architecture
&lt;/h3&gt;

&lt;p&gt;The Android designer is roughly split into two main parts. The first one is written in C# and constitute the bulk of the code. It’s a cross-IDE library that implements all the visual pieces of a modern designer like a surface canvas or a property panel and all the plumbing to make those work including a full DOM for Android layouts.&lt;/p&gt;

&lt;p&gt;The second part is implemented in Java and, unlike the previous part that is run together with Xamarin Studio or Visual Studio, the Java layer is run into its own dedicated process. To summarize what it does, let’s say that it mostly handles the heavy-lifting of parsing resources and rendering Android layouts.&lt;/p&gt;

&lt;p&gt;That last duty specifically (rendering layouts) is actually accomplished by using an existing Google library called &lt;a href="https://android.googlesource.com/platform/tools/base/+/master/layoutlib-api/" rel="noopener noreferrer"&gt;layoutlib&lt;/a&gt;. It’s the same underlying library that powers the designer in Android Studio. Its goal is to take an XML layout, inflate it, layout it and render it to an image buffer.&lt;/p&gt;

&lt;p&gt;Layoutlib is pretty nifty, it works by reusing an existing &lt;strong&gt;android.jar&lt;/strong&gt; (which only contains the raw unimplemented Android API surface) and dynamically wires up enough implementation for classes and methods to be able to run a part of the Android experience on desktop. Key APIs are re-implemented using standard JRE libraries, a good example being the Android Canvas API that is translated to equivalent AWT calls for instance.&lt;/p&gt;

&lt;p&gt;This process is done dynamically behind the scenes when you instantiate the library. It will automatically fetch the &lt;strong&gt;android.jar&lt;/strong&gt; archive corresponding to the API level you want to use and plug it with the desktop implementation that is contained in another archive in the platform (aptly named &lt;strong&gt;layoutlib.jar&lt;/strong&gt; ). If you are curious, you can also &lt;a href="https://android.googlesource.com/platform/frameworks/base/+/master/tools/layoutlib/bridge/src/android/" rel="noopener noreferrer"&gt;view that code online&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The end result is a Java &lt;code&gt;ClassLoader&lt;/code&gt; instance that allow you to retrieve and instantiate all of the Android framework classes like &lt;code&gt;android.view.View&lt;/code&gt;. This &lt;code&gt;ClassLoader&lt;/code&gt; isolation is actually very handy because it allows to load several version of the platform at the same time (i.e. different &lt;code&gt;android.view.View&lt;/code&gt; definitions) without polluting the main process class space.&lt;/p&gt;

&lt;p&gt;In addition to this, layoutlib uses a system of callback to let consumers of the library provide additional input. One of such callback is invoked when layoutlib tries to inflate an item in a layout that it doesn’t know about because it doesn’t come from the framework &lt;code&gt;ClassLoader&lt;/code&gt; I described above. As you probably guessed, those items are the custom user views.&lt;/p&gt;

&lt;h3&gt;
  
  
  Tying in Custom Controls
&lt;/h3&gt;

&lt;p&gt;Because &lt;a href="https://github.com/xamarin/xamarin-android" rel="noopener noreferrer"&gt;Xamarin.Android&lt;/a&gt; lets you use both Java and .NET based components (the former being wrapped into bindings, including our &lt;a href="https://github.com/xamarin/AndroidSupportComponents" rel="noopener noreferrer"&gt;Android support libraries components&lt;/a&gt;), it was essential to support both of them in the designer.&lt;/p&gt;

&lt;p&gt;Java components are actually fairly easy since the rendering process is already running in a JVM. You simply have to reference the custom component &lt;code&gt;.jar&lt;/code&gt; code (usually distributed as part of an Android library project in a &lt;code&gt;.aar&lt;/code&gt; file) into something like a &lt;code&gt;URLClassLoader&lt;/code&gt; instance and wire the loading in the layoutlib callback I mentioned.&lt;/p&gt;

&lt;p&gt;The fun stuff is obviously to include the managed components. But before we dwelve into that too much, let’s make a quick recap on how Xamarin.Android works or, more precisely, how it integrates with the Java virtual machine it’s running on.&lt;/p&gt;

&lt;h3&gt;
  
  
  Putting some C# in your Java
&lt;/h3&gt;

&lt;p&gt;What I am going to describe here mostly relates to our legacy implementation in &lt;a href="https://github.com/xamarin/xamarin-android" rel="noopener noreferrer"&gt;Xamarin.Android&lt;/a&gt; although much of the same ideas still live on in our new &lt;a href="https://github.com/xamarin/Java.Interop" rel="noopener noreferrer"&gt;Java.Interop library&lt;/a&gt; (essentially in a cleaned up way).&lt;/p&gt;

&lt;p&gt;The goal of Xamarin.Android &lt;em&gt;in fine&lt;/em&gt; is to allow managed code to be run inside an existing Java runtime and ensure both of them can talk to each other. To accomplish this, it embeds the Mono runtime inside the process and allows it to coexist with the existing Java VM.&lt;/p&gt;

&lt;p&gt;To allow communication between the two worlds, it uses the concept of &lt;em&gt;bridged objects&lt;/em&gt;. Everytime a Java object is surfaced to the managed world (e.g. a overriden method parameter) or when a managed (likely autogenerated) wrapper to a Java object is created, a peering process happens whereby the managed instance and the Java instance become linked to each other, sharing their lifetime (meaning one can’t be collected without the other) until the link is cut.&lt;/p&gt;

&lt;p&gt;To call Java code from the managed world, the &lt;a href="http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/functions.html#wp16656" rel="noopener noreferrer"&gt;JNI invocation API&lt;/a&gt; is used. To let Java code call into the managed world (due to subclassing or callbacks), a Java wrapper class is automatically generated.&lt;/p&gt;

&lt;p&gt;Those wrappers (called ACW/JCW for Android/Java Callable Wrappers) contain a bunch of &lt;code&gt;native&lt;/code&gt; methods definition to act as thunks. The thunks are then dynamically plugged using the &lt;code&gt;RegisterNatives&lt;/code&gt; &lt;a href="http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/functions.html#wp5833" rel="noopener noreferrer"&gt;JNI call&lt;/a&gt; with a function pointer into essentially a &lt;code&gt;mono_runtime_invoke&lt;/code&gt; call.&lt;/p&gt;

&lt;p&gt;For instance, take the following &lt;code&gt;MyCustomView&lt;/code&gt; subclass written in C# like this with its &lt;code&gt;OnDraw&lt;/code&gt; method overriden:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class MyCustomView: Android.Views.View
{
    public override OnDraw (Canvas c)
    {}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;During build, an equivalent Java file will be generated, compiled and packaged in your APK:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;package md55d31ab91effba0f9ed7ec79c59c38391;

public class MyCustomView
       extends android.view.View
       implements mono.android.IGCUserPeer
{
        public void onDraw (android.graphics.Canvas p0)
        {
                n_onDraw (p0);
        }

        private native void n_onDraw (android.graphics.Canvas p0);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you reference that custom view in your XML layout you will likely do it in this fashion:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;MyNamespace.MyCustomView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" /&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With some extra Xamarin.Android processing, this will tell the Android layout inflater to load the Java class previously generated and, when trying to draw the view, will end up calling the managed implementation of the &lt;code&gt;OnDraw&lt;/code&gt; method through its native thunk.&lt;/p&gt;

&lt;h3&gt;
  
  
  Back to custom controls
&lt;/h3&gt;

&lt;p&gt;Now that we have a clearer picture on how managed C# views are instantiated in an Android environment, it’s very easy to get them loaded into the designer. Simply add their generated ACW to the special &lt;code&gt;URLClassLoader&lt;/code&gt; I mentioned beforehand and they will get processed like any other standard Java custom views.&lt;/p&gt;

&lt;p&gt;Only thing left to do was to port our Xamarin.Android/Mono runtime to be able to run natively inside a standard Java desktop VM (in the same fashion than layoutlib with the Android API) so that it could execute the other side of that shim custom view. That code is also now open-source and you can &lt;a href="https://github.com/xamarin/xamarin-android/tree/master/src/monodroid/jni" rel="noopener noreferrer"&gt;view it on GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;As part of this porting work some dusting off of our AppDomain implementation was required, especially to ensure it worked reliably in a “mobile” context. AppDomains are used as a natural complement to Java’s class loaders allowing the same silo’ed approach on both the Java and managed side.&lt;/p&gt;

&lt;p&gt;Thanks to this association, the designer can create several context where multiple version of Android can be run together in an isolated fashion and refreshed binaries can be reloaded without the need for the renderer process itself to be torn down.&lt;/p&gt;

&lt;h3&gt;
  
  
  Finishing up
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.neteril.org%2Fwp-content%2Fuploads%2Fandroid-designer-custom-controls%2Fxs_custom_controls.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fblog.neteril.org%2Fwp-content%2Fuploads%2Fandroid-designer-custom-controls%2Fxs_custom_controls.png" alt="Android designer custom controls"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The layout rendered above extracted from &lt;a href="https://github.com/garuma/Buzzeroid" rel="noopener noreferrer"&gt;one of my demo project&lt;/a&gt; contains a lot of different type of custom controls like AppBarLayout, Toolbar, RecyclerView, CoordinatorLayout and custom views for FloatingActionButton. By the way, the same feature is what’s also used in our Xamarin.Forms previewer to display the Android rendering of a layout.&lt;/p&gt;

&lt;p&gt;There are more things that could be covered here, specifically I never mentioned how we handle error cases or even critical runtime failures which are bound to happen when you load external user code anywhere. Suffice to say we need some good error handling and process resurrection mechanisms which were definitely some of the hardest aspects to implement in the project (and still are).&lt;/p&gt;

&lt;p&gt;Not all the code for what’s here is open-source but there are a quite few more things to look at if you are interested:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Some (old but still relevant) &lt;a href="https://vimeo.com/43529195" rel="noopener noreferrer"&gt;presentation of Xamarin.Android internals&lt;/a&gt; at NDC Oslo by &lt;a href="https://twitter.com/sh4na" rel="noopener noreferrer"&gt;@shana&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;The &lt;a href="https://github.com/xamarin/Java.Interop" rel="noopener noreferrer"&gt;Java.Interop repository&lt;/a&gt; is a good look at how Xamarin.Android plumbing work (also has documention in eponymous folder).&lt;/li&gt;
&lt;li&gt;Xamarin developer portal has a lot of content 

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://developer.xamarin.com/guides/android/advanced_topics/java_integration_overview/working_with_jni/" rel="noopener noreferrer"&gt;Working With JNI&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://developer.xamarin.com/guides/android/under_the_hood/" rel="noopener noreferrer"&gt;Under The Hood guides&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;The &lt;a href="https://github.com/xamarin/xamarin-android" rel="noopener noreferrer"&gt;Xamarin.Android open-source repository&lt;/a&gt;
&lt;/li&gt;

&lt;/ul&gt;

</description>
    </item>
  </channel>
</rss>
