10

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.

ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
Levani Titberia
  • 125
  • 1
  • 1
  • 7

3 Answers3

19

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
  • 301
  • 2
  • 6
  • 2
    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
0

Unfortunately, the above solutions are deprecated after compression APK with the LZ4 algorithm. [more detail][1]

The best solution I could find is in this GitHub project. After applying the steps on the GitHub link, I could obtain the DLLs and finally decompile them with dotPeek or another app.

malik masis
  • 487
  • 1
  • 6
  • 15