TrevTV / mb_ScrobbleItem

MusicBee plugin that allows you to scrobble any album or track in your library without fully playing it.
Apache License 2.0
6 stars 0 forks source link

Question about the reflection used #5

Closed fiso64 closed 1 day ago

fiso64 commented 1 day ago

I'm trying to understand how to better control musicbee from my plugin (the limited api is bumming me out).

I've noticed that you have used reflection to execute a method that isn't exposed via the api here: https://github.com/TrevTV/mb_ScrobbleItem/blob/9a9760854b6665e2d81b20651699b4ecf2d87d74/Plugin.cs#L77

And I'm wondering how you have discovered the signature of that method. As you mention, MusicBee is obfuscated, so I'm having trouble figuring out anything in the decompiled code. de4dot wasn't of much use as it only renamed the obfuscated class and method names to human-readable ones like Class1059, but nothing more. I haven't been able to debug MusicBee.exe either.

I realize this isn't strictly related to this plugin, apologies for that.

TrevTV commented 1 day ago

I got a bit lucky with what I was trying to do having an easily searchable string related to it. The main thing I did was open MusicBee in dnSpy, and since I knew I was trying to figure out where scrobbling occurred, I searched for the string "track.scrobble" as that's the last.fm endpoint used for scrobbling. Once I had some ideas which function(s) it could be, I used a library called Harmony to hook it, both so I could read the data that went into it, and know when it's called to see if it makes any sense at all. Once I had the exact method I needed, I just worked backwards to create that messy foreach so that it (theoretically) work between versions with different obfuscations.

fiso64 commented 1 day ago

Thanks for the info! I was not aware of Harmony, it looks super useful.

fiso64 commented 1 day ago

Also, I was able to use the debugger. The breakpoints wouldn't be hit in dnspy for the cleaned version, but it worked for the original obfuscated binary.