Skip to content

[split #103] edit text #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions docs/topics/localfiles_encrypt_decrypt.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,24 @@

Although Geometry Dash's install path is usually inside the user's `steamapps/common` folder (if the game was bought from Steam) the game will actually store all relevant user data inside the `AppData/Local` directory, in which a new folder will be created under the name of `GeometryDash`. This folder contains all custom songs that the user has downloaded but it also contains 2 important files, which are *CCGameManager.dat* and *CCLocalLevels.dat*; the first one contains all the information regarding the player's in-game stats and preferences while the latter contains the data for the game's user created levels.

On Android, saves are placed under `/data/data/{package name}` (replace `{package name}` with package name of game).

On MacOS, saves are placed under `~/Library/Application Support/GeometryDash`, and use completely different encoding from Windows one.

However when these files are written to the disk they are encrypted and have to be decrypted before they can be read or modified.
Both files share the same process for decryption and encryption.

Windows and Android Geometry Dash can load plain XML save files, but MacOS Geometry Dash can't.

## Decryption

### Windows
### Windows and Android

Local game files are decrypted in the following order: Apply XOR function with key `0xB` (`11`), then apply [B64 decoding](topics/encryption/base64), the resulting byte sequence will be a [gzip](https://zlib.net) compressed string which needs to be decompressed/inflated.
Local game files are decrypted in the following order: Apply XOR function with key `0xB` (`11`), then apply [B64 decoding](topics/encryption/base64), the resulting byte sequence will be a [gzip](https://en.wikipedia.org/wiki/Gzip) compressed string which needs to be decompressed/inflated.

Simple XOR function differs can be written like this:
If file size is not divisible by 4, last `file_size % 4` bytes are garbage.

Simple XOR function can be written like this:

<!-- tabs:start -->

Expand Down Expand Up @@ -48,14 +54,20 @@ def decrypt_data(data: str) -> str:
### MacOS

On MacOS, decryption is quite simpler. Saves are encrypted with
[AES](https://en.wikipedia.org/wiki/Advanced_Encryption_Standard), using `ECB` mode.
[AES](https://en.wikipedia.org/wiki/Advanced_Encryption_Standard), using [ECB](https://en.wikipedia.org/wiki/Block_cipher_mode_of_operation#Electronic_codebook_.28ECB.29) mode with [PKCS#7](https://en.wikipedia.org/wiki/Padding_%28cryptography%29#PKCS.235_and_PKCS.237) padding.

256-bit key for encryption looks like this:

<!-- tabs:start -->

### **Plain**

```plain
ipu9TUv54yv]isFMh5@;t.5w34E2Ry@{
```

### **Hex**

```plain
69 70 75 39 54 55 76 35 34 79 76 5d 69 73 46 4d 68 35 40 3b 74 2e 35 77 33 34 45 32 52 79 40 7b
```
Expand Down Expand Up @@ -97,9 +109,9 @@ def mac_decrypt(data: bytes) -> str:

## Encryption

### Windows
### Windows and Android

Encryption is done pretty much the same way but with opposite operations and order. So the sequence for encrypting can be defined as: [gzip](https://zlib.net) compress/deflate -> [Base64](topics/encryption/base64) encode -> XOR using `0xb` (`11`) as a key.
Encryption is done pretty much the same way but with opposite operations and order. So the sequence for encrypting can be defined as: [gzip](https://en.wikipedia.org/wiki/Gzip) compress/deflate &rarr; [Base64](topics/encryption/base64) encode &rarr; XOR using `0xb` (`11`) as a key.

<!-- tabs:start -->

Expand All @@ -116,7 +128,7 @@ def encrypt_data(data: str) -> str:

### MacOS

Like on Windows, encryption and decrypion are almost the same:
Like on Windows and Android, encryption and decryption are almost the same:

<!-- tabs:start -->

Expand Down