frida / frida-clr

Frida .NET bindings
Other
82 stars 36 forks source link

.Net 4.0 frida-clr-12.9.4 Exception #9

Closed FuzzySecurity closed 4 years ago

FuzzySecurity commented 4 years ago

I wanted to create a small C# utility but I'm getting a file not found exception at runtime. I grabbed the latest x64 clr release from Github and added it as a reference in my project.

Environment: Win10 x64, .NET 4.0, frida 12.9.4, build-arch x64

Repro test-case:

using System;
using Frida;

namespace Londor
{
    class Program
    {
        public static void FridaGetDevices()
        {
            DeviceManager dm = new DeviceManager(System.Windows.Threading.Dispatcher.CurrentDispatcher);
            Device[] devices = dm.EnumerateDevices();
            foreach(Device d in devices)
            {
                Console.WriteLine("Device: " + d.Name);
            }
        }

        static void Main(string[] args)
        {
            FridaGetDevices();
        }
    }
}

Compile:

1>------ Rebuild All started: Project: Londor, Configuration: Release x64 ------
1>  Londor -> C:\Users\b33f\Tools\Dev\Frida-CLR-Test\Londor\Londor\bin\x64\Release\Londor.exe
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

Runtime:

C:\Users\b33f>C:\Users\b33f\Tools\Dev\Frida-CLR-Test\Londor\Londor\bin\x64\Release\Londor.exe

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'Frida, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.
   at Londor.Program.FridaGetDevices()
   at Londor.Program.Main(String[] args) in C:\Users\b33f\Tools\Dev\Frida-CLR-Test\Londor\Londor\Program.cs:line 26

Am I missing a dependency here?

FuzzySecurity commented 4 years ago

I had some time and did a bit of investigating, I looked at "NAME NOT FOUND" events in procmon and I saw that the process looks for "frida.dll" in the release folder at runtime.

image

However VS copies the resource with it's original name (csproj) to the build folder, eg "frida-clr-12.9.4-windows-x86_64.dll", once I changed this, the test-case runs fine.

image

I would have thought that the build would take care of this name resolution. Anyway, maybe Frida can publish a nuget package, I think people would really like that and it would simplify the development process.

Feel free to tag this as a feature request or close the issue.

oleavr commented 4 years ago

Thanks for looking into this!

maybe Frida can publish a nuget package

That's a great idea 👌 I've sadly got way too much on my plate to get to this anytime soon, but PRs are most welcome 😊 The Windows CI build steps are here.