Clash Royale .sc files decrypt

Extraction and unpacking of game archives and compression, encryption, obfuscation, decoding of unknown files
eslindsey
Posts: 1
Joined: Tue Apr 25, 2017 4:53 am

Re: Clash Royale .sc files decrypt

Post by eslindsey »

I'm trying to use the dumpsc.py script on the latest APK for Clash of Clans (com.supercell.clashofclans_v8.709.24-844_Android-4.0.3.apk) to try and extract ui_tex.sc, and it is failing with the following message:
$ python3.5 ~/dumpsc.py ui_tex.sc
ui_tex.sc
Traceback (most recent call last):
File "/home/eric/dumpsc.py", line 129, in <module>
process_sc(baseName, data[26:], path)
File "/home/eric/dumpsc.py", line 52, in process_sc
decompressed = lzma.LZMADecompressor().decompress(data)
_lzma.LZMAError: Input format not supported by decoder

But, it does work on some of the other files (info_babydragon_tex.sc for example).

I'll attach a ZIP containing the offending file. Can anybody help me extract the assets from it and convert them to PNG? It would be a bonus if the appropriate graphics could be extracted individually (with the polygons masked out, etc.), but I'll do that work manually if I have to.

EDIT: I tried the "Magic Editor" in the previous thread (in a VM of course), and it seems to work: it offers much more functionality than dumpsc.py including the ability to parse the information (the regular .sc file that ISN'T _tex.sc) about polygons and export resources and so on. However, it fails on the above files as well.

EDIT #2: I have come to the conclusion that it is simply a decompression problem--it seems that Supercell has switched to LZHAM compression, and I've downloaded the source code from richgel999's GitHub and compiled a test application, applied the header corrections from dumpsc.py to the target file (along with changing the first four bytes to 'LZH0') and I have successfully decompressed ui_tex.sc. I will post more information as I come across it.

EDIT #3: Success WITH BOTH FILES! I chopped the first 26 bytes from the beginning of each and added 4 bytes of 0x00 at position 9 (thanks for that info, dumpsc.py), altered the first four bytes to read "LZH0" in ASCII, ran them through the LZHAM test program which I compiled on Ubuntu 17.04 to decompress them without a problem, then loaded up the uncompressed files in Barbarianland's Magic Editor. The results are extremely satisfying. I can directly export any UI asset in the game, with full polygon, masking, and alpha channel support. It makes my custom Discord emojis look dope. Here's a screenshot for the curious:
Image

Thanks to ., @barbossa42, and @Mr Hacker for helping me make this happen. If/when I publish this amateur fankit (don't want to run into Supercell's legal teams... :D), I'll post a link here.
GaLaXy1036
Posts: 35
Joined: Tue Jan 17, 2017 6:30 pm

Re: Clash Royale .sc files decrypt

Post by GaLaXy1036 »

eslindsey wrote:I'm trying to use the dumpsc.py script on the latest APK for Clash of Clans (com.supercell.clashofclans_v8.709.24-844_Android-4.0.3.apk) to try and extract ui_tex.sc, and it is failing with the following message:
$ python3.5 ~/dumpsc.py ui_tex.sc
ui_tex.sc
Traceback (most recent call last):
File "/home/eric/dumpsc.py", line 129, in <module>
process_sc(baseName, data[26:], path)
File "/home/eric/dumpsc.py", line 52, in process_sc
decompressed = lzma.LZMADecompressor().decompress(data)
_lzma.LZMAError: Input format not supported by decoder

But, it does work on some of the other files (info_babydragon_tex.sc for example).

I'll attach a ZIP containing the offending file. Can anybody help me extract the assets from it and convert them to PNG? It would be a bonus if the appropriate graphics could be extracted individually (with the polygons masked out, etc.), but I'll do that work manually if I have to.

EDIT: I tried the "Magic Editor" in the previous thread (in a VM of course), and it seems to work: it offers much more functionality than dumpsc.py including the ability to parse the information (the regular .sc file that ISN'T _tex.sc) about polygons and export resources and so on. However, it fails on the above files as well.

EDIT #2: I have come to the conclusion that it is simply a decompression problem--it seems that Supercell has switched to LZHAM compression, and I've downloaded the source code from richgel999's GitHub and compiled a test application, applied the header corrections from dumpsc.py to the target file (along with changing the first four bytes to 'LZH0') and I have successfully decompressed ui_tex.sc. I will post more information as I come across it.

EDIT #3: Success WITH BOTH FILES! I chopped the first 26 bytes from the beginning of each and added 4 bytes of 0x00 at position 9 (thanks for that info, dumpsc.py), altered the first four bytes to read "LZH0" in ASCII, ran them through the LZHAM test program which I compiled on Ubuntu 17.04 to decompress them without a problem, then loaded up the uncompressed files in Barbarianland's Magic Editor. The results are extremely satisfying. I can directly export any UI asset in the game, with full polygon, masking, and alpha channel support. It makes my custom Discord emojis look dope. Here's a screenshot for the curious:
Image

Thanks to ., @barbossa42, and @Mr Hacker for helping me make this happen. If/when I publish this amateur fankit (don't want to run into Supercell's legal teams... :D), I'll post a link here.


You're problem is lzma decompression for ui_tex ( i don't really understand all) ?
CookieKing24
Posts: 5
Joined: Sun Apr 30, 2017 1:20 pm

Re: Clash Royale .sc files decrypt

Post by CookieKing24 »

Can QuickBms Encrypt the sc files?
GaLaXy1036
Posts: 35
Joined: Tue Jan 17, 2017 6:30 pm

Re: Clash Royale .sc files decrypt

Post by GaLaXy1036 »

CookieKing24 wrote:Can QuickBms Encrypt the sc files?

I think No
CookieKing24
Posts: 5
Joined: Sun Apr 30, 2017 1:20 pm

Re: Clash Royale .sc files decrypt

Post by CookieKing24 »

oh ok
CookieKing24
Posts: 5
Joined: Sun Apr 30, 2017 1:20 pm

Re: Clash Royale .sc files decrypt

Post by CookieKing24 »

but do you know how to encrypt a sc file?
GaLaXy1036
Posts: 35
Joined: Tue Jan 17, 2017 6:30 pm

Re: Clash Royale .sc files decrypt

Post by GaLaXy1036 »

CookieKing24 wrote:but do you know how to encrypt a sc file?

Yeah that's pretty easy for Clash Royale sc , for some COC Sc this is a little bit more difficult (LZHAM compression)
GaLaXy1036
Posts: 35
Joined: Tue Jan 17, 2017 6:30 pm

Re: Clash Royale .sc files decrypt

Post by GaLaXy1036 »

CookieKing24 wrote:but do you know how to encrypt a sc file?

But do you mean re-encrypt tex.sc(Png -> Tex.sc) or just recompress with LZMÀ
CookieKing24
Posts: 5
Joined: Sun Apr 30, 2017 1:20 pm

Re: Clash Royale .sc files decrypt

Post by CookieKing24 »

Yes thats What i mean
peacemaker_of_war
Posts: 12
Joined: Mon Feb 20, 2017 6:05 pm

Re: Clash Royale .sc files decrypt

Post by peacemaker_of_war »

Greetings, members of the forum! I was able to convert sc to png and vice versa png to sc. Only now there was one problem: when I put the edited files in the application, it crashes when opened. How then do I replace the original with a fake?
Moon Arts
Posts: 10
Joined: Sun Jan 15, 2017 7:32 pm

Re: Clash Royale .sc files decrypt

Post by Moon Arts »

Ahah so you failed, is your application crash because of the new texture or because you forgot to sign it ?
peacemaker_of_war
Posts: 12
Joined: Mon Feb 20, 2017 6:05 pm

Re: Clash Royale .sc files decrypt

Post by peacemaker_of_war »

Moon Arts wrote:Ahah so you failed, is your application crash because of the new texture or because you forgot to sign it ?

App crash because i load a new tex to apk with WinRar & with program for mobile "Apk editor".
peacemaker_of_war
Posts: 12
Joined: Mon Feb 20, 2017 6:05 pm

Re: Clash Royale .sc files decrypt

Post by peacemaker_of_war »

Moon Arts wrote:Ahah so you failed, is your application crash because of the new texture or because you forgot to sign it ?

How I can load my own texture?
GaLaXy1036
Posts: 35
Joined: Tue Jan 17, 2017 6:30 pm

Re: Clash Royale .sc files decrypt

Post by GaLaXy1036 »

peacemaker_of_war wrote:
Moon Arts wrote:Ahah so you failed, is your application crash because of the new texture or because you forgot to sign it ?

How I can load my own texture?

After re-build your APK with modded texture have you re-sign it ?
peacemaker_of_war
Posts: 12
Joined: Mon Feb 20, 2017 6:05 pm

Re: Clash Royale .sc files decrypt

Post by peacemaker_of_war »

GaLaXy1036 wrote:
peacemaker_of_war wrote:
Moon Arts wrote:Ahah so you failed, is your application crash because of the new texture or because you forgot to sign it ?

How I can load my own texture?

After re-build your APK with modded texture have you re-sign it ?

How to sign it?


Speak directly, how do I embed the texture in the application, sign it and run it without crashing?
GaLaXy1036
Posts: 35
Joined: Tue Jan 17, 2017 6:30 pm

Re: Clash Royale .sc files decrypt

Post by GaLaXy1036 »

Speak directly, how do I embed the texture in the application, sign it and run it without crashing?

Just sign it with ApkTool Advanced by bdfreak, But i think you decompile the application dont do that just open it with 7zip or winrar and drop your modded texture in sc directory
peacemaker_of_war
Posts: 12
Joined: Mon Feb 20, 2017 6:05 pm

Re: Clash Royale .sc files decrypt

Post by peacemaker_of_war »

GaLaXy1036 wrote:
Speak directly, how do I embed the texture in the application, sign it and run it without crashing?

Just sign it with ApkTool Advanced by bdfreak, But i think you decompile the application dont do that just open it with 7zip or winrar and drop your modded texture in sc directory

I don't know how to use this program
Moon Arts
Posts: 10
Joined: Sun Jan 15, 2017 7:32 pm

Re: Clash Royale .sc files decrypt

Post by Moon Arts »

Dude, you need to learn by yourself, stop asking for everything
DARK DYNAMO
Posts: 1
Joined: Thu May 18, 2017 11:50 am

Re: Clash Royale .sc files decrypt

Post by DARK DYNAMO »

Watch this
https://youtu.be/Y6yl7nZRI-8


Before supercell makes it down
imblyzzard
Posts: 28
Joined: Mon Jan 09, 2017 8:50 pm

Re: Clash Royale .sc files decrypt

Post by imblyzzard »

DARK DYNAMO wrote:Watch this
https://youtu.be/Y6yl7nZRI-8


Before supercell makes it down


Remove it plz