diff --git a/lglaf.lua b/lglaf.lua index 896efd9..bcb5b57 100644 --- a/lglaf.lua +++ b/lglaf.lua @@ -95,5 +95,6 @@ end function lglaf.init() local usb_product = DissectorTable.get("usb.product"); - usb_product:add(0x1004633e, lglaf) + usb_product:add(0x1004633e, lglaf) -- LG G3 D855 + usb_product:add(0x1004627f, lglaf) -- LG G3 VS985 end diff --git a/lglaf.py b/lglaf.py index 6df8099..6e56aae 100755 --- a/lglaf.py +++ b/lglaf.py @@ -13,7 +13,7 @@ import argparse, logging, re, struct, sys try: import readline except ImportError: pass # Try USB interface -try: import usb.core +try: import usb.core, usb.util except ImportError: pass # Windows registry for serial port detection try: import winreg @@ -192,13 +192,31 @@ class FileCommunication(Communication): class USBCommunication(Communication): EP_IN = 0x85 EP_OUT = 3 + VENDOR_ID_LG = 0x1004 # Read timeout. Set to 0 to disable timeouts READ_TIMEOUT_MS = 0 def __init__(self): super(USBCommunication, self).__init__() - self.usbdev = usb.core.find(idVendor=0x1004, idProduct=0x633e) + # Match device using heuristics on the interface/endpoint descriptors, + # this avoids hardcoding idProduct. + self.usbdev = usb.core.find(idVendor=self.VENDOR_ID_LG, + custom_match = self._match_device) if self.usbdev is None: raise RuntimeError("USB device not found") + def _match_device(self, device): + return any( + usb.util.find_descriptor(cfg, bInterfaceClass=255, + bInterfaceSubClass=255, bInterfaceProtocol=255, + custom_match=self._match_interface) + for cfg in device + ) + def _match_interface(self, intf): + return intf.bNumEndpoints == 2 and all( + ep.bEndpointAddress in (self.EP_IN, self.EP_OUT) and + usb.util.endpoint_type(ep.bmAttributes) == + usb.util.ENDPOINT_TYPE_BULK + for ep in intf + ) def _read(self, n): # device seems to use 16 KiB buffers. array = self.usbdev.read(self.EP_IN, 2**14, timeout=self.READ_TIMEOUT_MS) diff --git a/rules.d/42-usb-lglaf.rules b/rules.d/42-usb-lglaf.rules index b49fff1..86fdee4 100644 --- a/rules.d/42-usb-lglaf.rules +++ b/rules.d/42-usb-lglaf.rules @@ -1,3 +1,5 @@ # /etc/udev/rules.d/42-usb-lglaf.rules -# LG G3 in download mode +# LG G3 (D855) in download mode SUBSYSTEM=="usb", ATTRS{idVendor}=="1004", ATTRS{idProduct}=="633e", TAG+="uaccess" +# LG G3 (VS985) in download mode +SUBSYSTEM=="usb", ATTRS{idVendor}=="1004", ATTRS{idProduct}=="627f", TAG+="uaccess"