Extraction des ressources graphiques au sein de l'.apk Xiaomi Home /media/screenshots/screenshot-xiaomi-icons.png

Etapes

  • Télécharger le fichier .apk en ligne (par ex. depuis un site au hasard - les manipulations ci-dessous, à effectuer dans un shell sous linux, sont sans danger) :
curl -sLo mi-home.apk "<url>"
  • Extraire le fichier se trouvant sous assets/plugin_config/plugin_config_cn.json
unzip -p mi-home.apk assets/plugin_config/plugin_config_cn.json > plugin_config_cn.json
  • Tester via jq que le fichier est correct :
cat plugin_config_cn.json | jq
  • Utiliser jq pour naviguer au sein de toutes les balises. Si l’URL n’est pas vide, alors télécharger le fichier dans un sous-répertoire avec un nom adéquat (basé sur le nom de l’objet et le type d’URL). Pour ne pas télécharger toutes les images, il suffit de retirer les tokens non souhaités de la boucle for.
DESTINATION="xiaomi-icons/"
for TOKEN in icon_real icon_on icon_off icon_offline icon_smartconfig icon_smartconfig_off icon_lock_screen_on icon_lock_screen_off icon_bluetooth_pairing ; do
  cat plugin_config_cn.json|jq -r '.result|.list|.[]|"" + (.pd_id|tostring) + "|" + .'$TOKEN' + "|" + .model' | while IFS="|" read ID URL NAME ; do
    if [[ ! -z "$URL" ]] ; then
      FILE="${NAME}-${TOKEN}.png"
      echo $ID $URL $NAME $FILE
      [[ ! -f "${DESTINATION}/${FILE}" ]] && wget "$URL" -O "${DESTINATION}/${FILE}"
    fi
  done
done
  • Création des packages : une archive avec toutes les icones, puis une archive séparée par type d’icones.
cd $DESTINATION
zip -9 ../xiaomi-icons-all.zip *
for TOKEN in icon_real icon_on icon_off icon_offline icon_smartconfig icon_smartconfig_off icon_lock_screen_on icon_lock_screen_off icon_bluetooth_pairing ; do
  zip -9 ../xiaomi-icons-${TOKEN}.zip *"${TOKEN}.png"*
done

Explications

Le fichier .apk contient certes un certain nombre d’images, mais aucune images des devices (capteurs aqara, webcam, etc.). Par contre, un fichier .json est présent et liste l’ensemble de ces ressources, avec pour chacune d’entre elle différent types d’images : l’image principale, mais aussi des images “on”, “off”, etc.

Le fichier json possède le format (entête) suivant :

{
  "code": 0,
  "message": "ok",
  "result": {
    "type": "delta",
    "last_modify": 1533892454,
    "list": [
      {
        ...
      }
    ]

Chaque entrée de la liste list comprend ensuite les clés suivantes :

{
  "pd_id": 10,
  "icon_on": "http://static.home.mi.com/app/image/get/file/developer_152091044345y41r37.png",
  "icon_off": "http://static.home.mi.com/app/image/get/file/developer_1520910449em9pu0nh.png",
  "icon_offline": "http://static.home.mi.com/app/image/get/file/developer_15209104525u8huyqj.png",
  "icon_smartconfig": "",
  "icon_lock_screen_on": "http://static.home.mi.com/app/image/get/file/developer_152091045507yra7u8.png",
  "icon_lock_screen_off": "http://static.home.mi.com/app/image/get/file/developer_1520910459bvkdd7hn.png",
  "status": 2,
  "ios_status": 0,
  "change_time": 1532074044,
  "min_app_version": 0,
  "bind_confirm": 0,
  "model": "xiaomi.plug.test1",
  "name": "测试模拟插座",
  "subcategory_id": "4",
  "desc": "测试模拟插座",
  "pid": 0,
  "model_regex": "",
  "icon_bluetooth_pairing": "http://static.home.mi.com/app/image/get/file/developer_15009738626ypcr5r1.png",
  "icon_real": "http://static.home.mi.com/app/image/get/file/developer_1520910437p08u3re7.png",
  "name_smartconfig": "",
  "brand_name": "",
  "bt_bind_style": 0,
  "wexin_share": 0,
  "permission_control": 0,
  "bt_match": 0,
  "bt_rssi": "",
  "sc_failed": 0,
  "voice_control": 0,
  "voice_ctrl_ed": 0,
  "op_history": 0,
  "sc_type": 5,
  "sc_status": 0,
  "sc_type_more": [],
  "sc_type_more_v2": [],
  "fiveG_wifi": 1,
  "icon_smartconfig_off": "http://static.home.mi.com/app/image/get/file/developer_1520910491j1ke1xsf.jpg",
  "relations": [],
  "ct_offline_enter": 0,
  "cate_name": "电源开关"
}

Il est donc possible de parser ce contenu avec jq (https://stedolan.github.io/jq/) via, par exemple :

cat plugin_config_cn.json|jq -r '.result|.list|.[]|.model + " => " +.icon_real'

Ressources

Liens vers les ressources extraites (au 14/08/2018) :

yED palette

Palette yED correspondante : https://github.com/SR-G/xiaomi-devices-palette-for-yed

Script permettant de resynchroniser la liste des noms avec un fichier palette .graphml déjà créé manuellement :

INPUT_FILE="Xiaomi devices.graphml"
TEMP_FILE="processing.tmp"
ls -1 *.png|while read F ; do
  LABEL="${F%%-icon_real.png}"
  echo $LABEL
  sed '0,/<data key="d4"\/>/{s/<data key="d4"\/>/<data key="d4"><![CDATA['${LABEL}']]><\/data>/}' "$INPUT_FILE" > "$TEMP_FILE"
  mv "$TEMP_FILE" "$INPUT_FILE"
done

Liens supplémentaires