Giter VIP home page Giter VIP logo

coc-messages's Introduction

Protocol Definition Files

Clash messages are passed between client and server in PDUs containing an integer message identifier and a binary payload. The files in this package are used to map the identifier to a message structure definition so that the binary payload can be parsed.

Each message structure is defined in an individual JSON file. The name of the file is not significant, but generally it corresponds to the type name of the message.

Type System

Each file defines a type. Types are referred to by their name attribute or, for top level messages, by their id attribute (the identifier passed in the PDU).

Using just the name and id attributes we can define simple structures such as the KeepAlive message:

{
  "id": 10108,
  "name": "KeepAlive"
}

To read more complex messages we need to define the field list that makes up the payload. For example, the EndClientTurn message comprises three fields; tick (the time that the command was issued), checksum (the game state checksum), and commands, an array of CommandComponent structures:

{
  "id": 14102,
  "name": "EndClientTurn",
  "fields": [
    {"name": "tick", "type": "INT"},
    {"name": "checksum", "type": "INT"},
    {"name": "commands", "type": "CommandComponent[]"}
  ]
}

Each field has a name attribute that is used to refer to it and a type attribute that defines its serialized structure. The type can refer to another structure or a built in primitive, or an array of structures or primitives.

Primitives

Five primitive types are defined.

  • BOOLEAN: A single bit, read in little endian order. All other primitives are read from byte boundaries.

  • BYTE: One byte.

  • INT: Four bytes, big-endian

  • LONG: Eight bytes, big-endian

  • STRING: An integer length, then a UTF-8 encoded string.

  • ZIP_STRING: An integer length, then a little-endian integer unzipped length, then a zlib compressed UTF-8 encoded string.

Arrays

Arrays types are defined by appending square brackets to a type name, e.g. "INT[5]" defines an array of five ints. If the size specifier is omitted the size of the array will be read/written as an integer before the array contents. E.g. a field of type "CommandComponent[]" would be written as an INT (the array size), followed by the contents of the array, a list of command components.

Optionals

There is one other specialized structure, the optional field. Optionals are defined by prefixing a type name with "?", e.g. "?LONG". They are serialized as a BOOLEAN (indicating the presence of the value), followed by the value if it is present.

Extensions

Some structures have additional trailing fields that are conditionally included. Extension fields are read when their id attribute matches the id field of the structure that they extend (note: the field with the name "id" is matched against, not the id attribute of the structure). For example, the CommandComponent has extensions that are conditional on the command id:

{
  "name": "CommandComponent",
  "fields": [
    {"name": "id", "type": "INT"}
  ],
  "extensions": [
    {
      "id": 4,
      "comment": "Donate unit in response to troop request",
      "fields": [
        {"type": "INT"},
        {"name": "messageId", "type": "INT"},
        {"name": "unitId", "type": "INT"},
        {"type": "INT"},
        {"name": "tick", "type": "INT"}
      ]
    },
    {
      "id": 10,
      "comment": "Donate unit to clan war castle",
      "fields": [
        {"type": "INT"},
        {"name": "homeId", "type": "INT"},
        {"name": "unitId", "type": "INT"},
        {"name": "index", "type": "INT"},
        {"name": "tick", "type": "INT"}
      ]
    },

Default Values

Fields with primitive values may have a default attribute to indicate the value that should be used if the field is not set.

Comments

Messages and Fields may have a comment attribute to document their use.

coc-messages's People

Contributors

clugh avatar d3death avatar waqasrana avatar xyzwarrior avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

coc-messages's Issues

WarsTeamMemberUnknownComponent needs update

AllianceWarData has WarTeam which has which has WarTeamMembers which has WarsTeamMemberUnknownComponent.

This is broken and needs update. its supposed to print name but prints something like following

"unknown_20": {
          "name": "0016fd640100000000......

versions with debug symbols

Hi clugh,

in another issue you said that there is an old version of Clash of Clans with symbols.
Can you give me a hint where I could get this old version? I looked at the newest ~50 Android versions I could get my hands on but they are all stripped.

Also, is there a way to get in touch with you? I would like to talk about clash of clans and if possible then also contribute to your reversing and documentation efforts.

Kind regards,
Mark

How to debug libg.so

Hey,

I've been working on writing command specs for 24113.
Staring at the hex is a bit limited as the structure of that message seems much more complicated than simpler ones like 24403/24413/24405 which I have working (but not clean enough for a PR yet).

I've been trying to debug the game with ida but struggling a bit.
I can decompile the libg.so and locate the place parsing the message (I think sub_A66C4 on ARM), but without seeing some actual data going through to inspect and step through I'm a bit stuck on writing my own parser.

I've tried to debug the game by loading the apk/classes.dex in ida, which work fine, but i can't find how to step into the libg.so. I've spent hours on google trying to find how to do it with no success (closest I've found was someone suggesting having 2 instances, one for the dex and the other for the .so, but no explanation on how to link the two).

If you could spend a few minutes explaining how you do it, it would allow me to contribute more message specs too.

Thanks

AllianceWarData (24335) needs to be updated

This is last known WarDonations i had that worked before coc changed encryption.

{
  "id":24335,
  "name": "WarDonations",
  "fields": [
    {"type": "INT"},
    {"type": "INT"},
    {"name": "ownTeam", "type": "WarTeam"},
    {"name": "enemyTeam", "type": "?WarTeam"},
    {"type": "?LONG"},
    {"type": "WarEvent[]"}  
  ]
}

There are some other issues (i think) with 24335 and proxy which i posted here

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.