Perfare / AssetStudio

AssetStudio is a tool for exploring, extracting and exporting assets and assetbundles.
MIT License
13.26k stars 2.56k forks source link

How can decompiler MonoBehavior to C# #59

Closed takaaptech closed 7 years ago

takaaptech commented 7 years ago

When reading MonoBehavior I only see: PPtr m_GameObject int m_FileID = 9 int64 m_PathID = 0 UInt8 m_Enabled = 1 PPtr m_Script int m_FileID = 8 int64 m_PathID = 984 string m_Name = "5p L-Shape"

Or in MonoScript, i only see .dat file

How can i get C# code?

Thank so much!

UlyssesWu commented 7 years ago

I think scripts exist in dlls such as Assembly-CSharp.dll. Grab a decompiler and you can see them. What you see here is more like a reference, showing the connection of the script and the GameObject.

takaaptech commented 7 years ago

From ipa file (ios game), i only see:

Data/Managed/Resources/mscorlib.dll-resources.dat Data/Managed/Resources/Firebase.App.dll-resources.dat Data/Managed/Resources/System.dll-resources.dat Data/Managed/Resources/JsonFx.Json.dll-resources.dat

So where can i find more dll for source code?

Thank so much!

UlyssesWu commented 7 years ago

For iOS, if you can't find dll files (usually in Data/Managed/*.dll I'm not sure about the location.), they are likely compiled with IL2CPP, which means they are no longer C# but machine code (C++) now. In that case it's harder to look into it's code. Prefare's another repo Il2CppDumper might be useful.

takaaptech commented 7 years ago

Thank @UlyssesWu! I can find it now in the Android version, and in Managed folder that you mention above! Thank you so much! For dll decompiler, can you comment some tool that works great for unity dlls? I use ILSpy but after decode, there is so much unclear code like this: cIteratorA.<>fthis = this;

Thanks!

UlyssesWu commented 7 years ago

Those are anonymous types generated by C# compiler. You actually won't write those kind of code because there are syntax sugars to make codes clean, but when compiling those sugars turn into codes like above. All decompilers give similiar results because that's the fact. Don't feel confused, just try to figure out what they do. If you really want me to recommend a tool for you, I suggest JustDecompile because it outputs cleaner codes than ILSpy, and it's free, too. Just remember to enable "Show compiler generated types" in settings.

takaaptech commented 7 years ago

Thank so much! Cheer!