From eb25f617604ba6df0af8e559f4d78083363dccce Mon Sep 17 00:00:00 2001 From: tuxuser Date: Mon, 5 Feb 2018 15:50:51 +0100 Subject: [PATCH 1/4] More descriptive error msg when laf_crypto fails to import, py2 compat, pytest for crypto --- laf_crypto.py | 21 +++++++++++++-------- lglaf.py | 17 +++++++++++------ tests/conftest.py | 5 +++++ tests/test_crypto.py | 17 +++++++++++++++++ 4 files changed, 46 insertions(+), 14 deletions(-) create mode 100644 tests/conftest.py create mode 100644 tests/test_crypto.py diff --git a/laf_crypto.py b/laf_crypto.py index 16d87eb..fa7ea19 100644 --- a/laf_crypto.py +++ b/laf_crypto.py @@ -1,11 +1,16 @@ -from Crypto.Cipher import AES +import struct +from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes +from cryptography.hazmat.backends import default_backend from lglaf import int_as_byte def key_transform(old_key): new_key = b'' for x in range(32, 0, -1): - new_key += int_as_byte(old_key[x-1] - (x % 0x0C)) + c = old_key[x-1] + if not isinstance(c, int): + c = ord(c) + new_key += int_as_byte(c - (x % 0x0C)) return new_key @@ -13,11 +18,10 @@ def xor_key(key, kilo_challenge): # Reserve key key_xor = b'' pos = 0 + challenge = struct.unpack('>I', kilo_challenge)[0] for i in range(8): - key_xor += int_as_byte(key[pos] ^ kilo_challenge[3]) - key_xor += int_as_byte(key[pos + 1] ^ kilo_challenge[2]) - key_xor += int_as_byte(key[pos + 2] ^ kilo_challenge[1]) - key_xor += int_as_byte(key[pos + 3] ^ kilo_challenge[0]) + k = struct.unpack(' Date: Mon, 12 Mar 2018 22:38:41 +0100 Subject: [PATCH 2/4] README: Add link to cryptography lib, update Windows LG USB driver link --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 231c589..b0ad961 100644 --- a/README.md +++ b/README.md @@ -20,10 +20,11 @@ LGLAF.py depends on: - Python 2.7 or 3: https://www.python.org/ - (Windows) LG driver, - [LGMobileDriver\_WHQL\_Ver\_4.0.3.exe](http://18d5a.wpc.azureedge.net/8018D5A/tool/dn/downloader.dev?fileKey=UW00120120425) - (12986920 bytes, - sha256sum: 86e893b7f5da7f7d2656d9ce2563f082271983bb63903d0ed5cb279c560db459) + [LGMobileDriver\_WHQL\_Ver\_4.2.0.exe](http://oceanhost.eu/wylc5rg7a8ou/LGMobileDriver_WHQL_Ver_4.2.0.exe.htm) + (16691672 bytes, + sha256sum: d78ae6dfe7d34b9cabb8c4de5c6e734b6fed20b513d0da0183871bd77abba56c) - (Linux) PyUSB: https://walac.github.io/pyusb/ + - Cryptography library: https://cryptography.io/en/latest/ On Linux, you must also install [rules.d/42-usb-lglaf.rules](rules.d/42-usb-lglaf.rules) to `/etc/udev/rules.d/` From d459dfe7192c200a76897d11f6419c251e9086ed Mon Sep 17 00:00:00 2001 From: tuxuser Date: Sat, 17 Mar 2018 11:31:44 +0100 Subject: [PATCH 3/4] Suggested fix by @Lekensteyn --- laf_crypto.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/laf_crypto.py b/laf_crypto.py index fa7ea19..bb025a2 100644 --- a/laf_crypto.py +++ b/laf_crypto.py @@ -6,10 +6,9 @@ from lglaf import int_as_byte def key_transform(old_key): new_key = b'' + old_key = bytearray(old_key) for x in range(32, 0, -1): c = old_key[x-1] - if not isinstance(c, int): - c = ord(c) new_key += int_as_byte(c - (x % 0x0C)) return new_key From a8b4514bbbd4a909df392329328afdda92c0a410 Mon Sep 17 00:00:00 2001 From: tuxuser Date: Sat, 17 Mar 2018 12:06:12 +0100 Subject: [PATCH 4/4] Add note about origin of LG Mobile Windows driver --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b0ad961..f9ced3f 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,8 @@ LGLAF.py depends on: - (Windows) LG driver, [LGMobileDriver\_WHQL\_Ver\_4.2.0.exe](http://oceanhost.eu/wylc5rg7a8ou/LGMobileDriver_WHQL_Ver_4.2.0.exe.htm) (16691672 bytes, - sha256sum: d78ae6dfe7d34b9cabb8c4de5c6e734b6fed20b513d0da0183871bd77abba56c) + sha256sum: d78ae6dfe7d34b9cabb8c4de5c6e734b6fed20b513d0da0183871bd77abba56c), + **WARNING**: This file was found via google search, it's not downloaded directly from LG servers - (Linux) PyUSB: https://walac.github.io/pyusb/ - Cryptography library: https://cryptography.io/en/latest/