Broadlink-e-control-db-dump bug fix

This script will “parse” the broadlink e-Control Android application **rmt.db database** and dump the IR / RF codes (in HEX format) for selected accessories into a text file which can be later used with broadlink-python to send the codes to the RM PRO hub.

这个东西在处理逻辑上有bug,如果出现查询为空的情况,就挂了。

我修复了一下,修复代码如下:

import sqlite3 as lite
from binascii import hexlify

# This script will "parse" the broadlink e-Control Android application database and dump the IR / RF codes for selected accessories into a text file which can be later used with broadlink-python to send the codes to the RM PRO hub
# You need to get the "rmt.db" file from your (rooted) android device or emulator (ARM), the file is located in "/data/data/com.broadlink.rmt/databases/rmt.db" and put it in the same folder as this script.
# adb pull /data/data/com.broadlink.rmt/databases/rmt.db

buttonIDS = []
buttonNames = []

# e-Control Database file
con = lite.connect('rmt.db')

# Get All Accessories
with con:
    cur = con.cursor()
    cur.execute("SELECT id, name FROM subIRTable")

    rows = cur.fetchall()

    for row in rows:
        print "Accessory ID: " + str(row[0]) + " | Accessory Name: " + row[1]

# Choose Accessory

accessory = input("Select Accessory ID: ")

cur.execute("SELECT name FROM subIRTable where id =" + str(accessory))

accessory_name = cur.fetchone()[0]

print "[+] You selected: " + accessory_name
print "[+] Dumping codes to " + accessory_name + ".txt"


# Get Buttons id
with con:
    cur = con.cursor()
    cur.execute("SELECT name, id FROM buttonTable where subIRId=" + str(accessory))
    rows = cur.fetchall()

    for row in rows:
        buttonIDS.append(row[1])
        buttonNames.append(row[0])

    codesFile = open(accessory_name + '.txt', 'w')

    # Get Codes

    for i in range(0, len(buttonIDS)):
        cur.execute("SELECT irCode FROM codeTable where buttonId=" + str(buttonIDS[i]))
        #print str((cur.fetchall()[0])[0]).encode('hex')
        code = cur.fetchone()
        if code:
            cod = code[0]
        else:
            continue
        hexlify(cod)
        result = "Button Name: " + buttonNames[i] + "| Button ID: " + str(buttonIDS[i]) + " | Code: " + str(cod).encode('hex') + "\n"
        codesFile.writelines(result.encode('utf-8'))
    codesFile.close()
☆版权☆

* 网站名称:obaby@mars
* 网址:https://oba.by/
* 个性:https://oba.by/
* 本文标题: 《Broadlink-e-control-db-dump bug fix》
* 本文链接:https://zhongxiaojie.com/2017/12/6018
* 短链接:https://oba.by/?p=6018
* 转载文章请标明文章来源,原文标题以及原文链接。请遵从 《署名-非商业性使用-相同方式共享 2.5 中国大陆 (CC BY-NC-SA 2.5 CN) 》许可协议。


You may also like

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注