9

Good day all. I need get C# source code from an apk, I tried a few days ways, but they give me java code.

I built a little game in c# xamarin. I stopped working on it for a while, and now I want continue building it, but I've lost the source code. I have an apk file but cannot get the source code. If there is any way get the source code? Please help me.

DiplomacyNotWar
  • 31,605
  • 6
  • 57
  • 75
Levani Titberia
  • 115
  • 1
  • 1
  • 6

2 Answers2

17

first, extract apk using 7zip or winrar. you can also use APKTool

then go to the assemblies folder and open {appname}.dll with dnSpy or dotPeek. if you're not using Microsoft Windows, there's a cross-platform tool called AvaloniaILSpy.

if you don't see the dll file (only .so files) you need to unpack it with this tool.

I opened with dnSpy

Image

Erfan Azhdari
  • 181
  • 1
  • 6
  • 1
    What if there are only `.so` files? – vrwim Feb 12 '20 at 09:31
  • in unity they are compiled by il2cpp and you have to load the so files in a disassembler like IDA or Ghidra. – Erfan Azhdari Feb 13 '20 at 10:53
  • 3
    Since 2020, Xamarin DLLs might be compressed with LZ4 (it was introduced in this PR: https://github.com/xamarin/xamarin-android/pull/4686), so decompilers like dotPeek are not able to read them (yet). You have to decompress them manually first. This is described here: https://www.x41-dsec.de/security/news/working/research/2020/09/22/xamarin-dll-decompression/ – Andreas Fröwis Aug 09 '21 at 11:25
1

First use apktools to unpack apk

then use "https://github.com/tjg1/mono_unbundle" to unpack "libmonodroid_bundle_app.so"

then you will get <your_app_name>.dll

open it by dnSpy

simonkimi
  • 19
  • 1