From a7818e7e0f0e1aebfdc341c4c686b647d139d60f Mon Sep 17 00:00:00 2001 From: Denis Manherz Date: Mon, 26 Aug 2024 23:01:11 +0200 Subject: [PATCH] Update --- hexdump_analysis/hexdump_analysis.txt | 41 +++-- src/main.cpp | 209 ++++++++++++++++++++++---- 2 files changed, 208 insertions(+), 42 deletions(-) diff --git a/hexdump_analysis/hexdump_analysis.txt b/hexdump_analysis/hexdump_analysis.txt index 3229ef1..1946be5 100644 --- a/hexdump_analysis/hexdump_analysis.txt +++ b/hexdump_analysis/hexdump_analysis.txt @@ -1,4 +1,5 @@ First Part + 0 1 2 3 4 5 6 7 8 9 a b c d e f 0000 08 21 00 92 00 00 00 00 64 17 04 15 00 0c 00 0f 0010 00 13 00 17 00 1b 00 00 00 00 00 00 00 00 00 00 @@ -34,25 +35,33 @@ First Part 01f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0200 00 00 00 00 00 00 00 00 -0x98 ist ende von data ??? +2 Hex Dumps for 1 Profile wenn makros dann mehr -0x03 maybe if 0x92 -> set report 0x00 -> get report +0x98 0xa5 ist ende von data ??? -0x08-0x09 0x63 0x17 Profil 1, 0x63 0x01 Profil 2 ????? -2 Hex Dumps for 1 Profile +0x00 ? +0x01 wired 11 and 12, wireless 21 and 22 +0x02 ? +0x03 maybe if 0x92 -> set report 0x00 -> get report +0x04-0x07 ?? +0x08-0x09 0x64 0x17 Profil 1, 0x64 0x01 Profil 2 ????? +0x0a USB Polling Rate [0x01-0x04]->[125,250,500,1000] +0x0b 0x11-0x15 wert für häckchen bei dpi, erstes 0x11 zweites 0x12 usw.. +0x0c ? +0x0d-0x16 jeweils 2 byte most significant byte last, * 50 -> annäherung an dpi -50 +0x17-0x44 ??? +0x45 Lighting Mode, 02 Steady, 01 Colorful Streaming, 03 Breathing +0x46 0-4 Brightness und 0-4 Speed bei breathing 0x(br)(sp) +0x47 ? +0x48 Brightness bei colorful 00-40 +0x49-0x4b ? +0x4c 0-4 Brightness und 0-4 Speed bei steady 0x(br)(sp) +0x4d ??? +0x4e-0x62 Bei Breathing RGB * 7 +0x63-0x66 ?? +0x67-0x7a Bei Steady RGB * 7 +0x7b-ende ???? -FUCK ICH GLAUB ICH HABE HEX FALSCH GEZÄHLT HAB MANCHMAL VON 1 ANGEFANGEN LOL - -0x0a USB Polling Rate [0x01-0x04]->[125,250,500,1000] -0x0b9 0x11-0x15 wert für häckchen bei dpi, erstes 0x11 zweites 0x12 usw.. -0x0d-0x16 jeweils 2 byte most significant byte last, * 50 -> annäherung an dpi -50 - -0x45 -> Lighting Mode, 02 Steady, 01 Colorful Streaming, 03 Breathing -0x47 -> 0-4 Brightness und 0-4 Speed bei breathing 0x(br)(sp) -0x48 -> Brightness bei colorful 00-40 -0x4c -> 0-4 Brightness und 0-4 Speed bei steady 0x(br)(sp) -0x4e-0x63 -> Bei Breathing RGB * 7 -0x67-0x7a -> Bei Steady RGB * 7 bei einem modus wechsel ändert sich brightness und speed nicht auser man ändert sie nochmal explizit diff --git a/src/main.cpp b/src/main.cpp index 1848f83..f26849e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,8 +10,162 @@ #include #include +struct keystuff +{ + char type; // 0x21 -> keycode + char _mods : 4; + char mods : 4; // 1111 -> all 4 mods +}; + +struct col_rgb +{ + uint8_t r; + uint8_t g; + uint8_t b; +}; + +struct dpi +{ + uint16_t a; + uint16_t b; + uint16_t c; + uint16_t d; + uint16_t e; +}; + +struct col_7 +{ + col_rgb a; + col_rgb b; + col_rgb c; + col_rgb d; + col_rgb e; + col_rgb f; + col_rgb g; +}; + +struct conf_1 +{ + uint8_t __u1; // 0x00 0x08 + uint8_t con; // wired 21 22 wireless 11 12 + uint8_t __u2; // 0x02 zero + uint8_t req_type; // 0x92, 0x50 maybe for if write or read 0x00 + uint8_t __u3[0x8-0x4]; // 0x04-0x07 zeroes + uint8_t __64; // 0x08 + uint8_t profile; // 0x17 profile 1, 0x01 profile 2 + uint8_t polling_rate; // 0x0a, 0x01-0x04->[125,250,500,1000] + uint8_t dpi_modes; // 0x0b, 0x11-0x15 erste 4 welches ist aktiv? dann welhce für conf?? + uint8_t __u4; // 0x0c zero + dpi hdpi; // 0x0 0x0d-0x16 jeweils 2 byte most significant byte last, * 50 -> annäherung an dpi -50 + uint8_t __u5[0x44-0x17]; // 0x17 - 0x44 ????? zeros + uint8_t light_mode; // 0x45 Lighting Mode, 02 Steady, 01 Colorful Streaming, 03 Breathing + uint8_t br_brightness_speed; // 0x46 0-4 Brightness und 0-4 Speed bei breathing 0x(br)(sp) + uint8_t __u8; // 0x47 ??? + uint8_t col_brightness; // 0x48 Brightness bei colorful 00-40 + uint8_t __u9; // 0x49-0x4b ??? + uint8_t __u10; + uint8_t __u11; + uint8_t st_brightness_speed; // 0x4c 0-4 Brightness und 0-4 Speed bei steady 0x(br)(sp) + uint8_t __u12; // 0x4d ?? + col_7 col_breathing; // 0x4e-0x62Bei Breathing RGB * 7 + uint32_t __u13; // 0x63-066 ?? + col_7 col_steady; // 0x67-0x7a Bei Steady RGB * 7 + uint8_t __rest[397]; //???? +}; + int main(int argc, char *argv[]) { + unsigned char data[520]; + unsigned char data2[520]; + unsigned char deviceData[520]; + memset(deviceData, 0, 520 * sizeof(unsigned char)); + std::string data01 = + "082100920000000064170445000c000f" + "00130017001b00000000000000000000" + "00000000000000000000000000000000" + "0000ff00ffffff00ffff9b0000ff00ff" + "ffffff460001430036ff00003207ffff" + "ff000000ffffff000000ffffff000000" + "ffffff020200ff000000ff000000ff00" + "000000ffffff4600ff00ffffffffff00" + "00ff000001020304050607424202ff00" + "0027400102ff0000a500000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "0000000000000000"; + std::string data02 = + "08220050000000001101000011020000" + "11040000110800001110000021006100" + "41000000500600001102000021005a00" + "21005b0021005c0021005d0021005e00" + "21005f00210060005001000050010000" + "50010000500100000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "00000000000000000000000000000000" + "0000000000000000"; + for (int i = 0; i < 1040; i += 2) + { + data[i / 2] = std::stoi(data01.substr(i, 2), (std::size_t *)0, 16); + data2[i / 2] = std::stoi(data02.substr(i, 2), (std::size_t *)0, 16); + } + const char *asd = (char *)data; + conf_1 *bsd = (conf_1 *)asd; + const char *asd2 = (char *)data2; + conf_1 *bsd2 = (conf_1 *)asd2; + std::cout << std::hex << (int)(data[0x45]) << std::endl; + std::cout << std::hex << (int)(bsd->light_mode) << std::endl; + bsd->light_mode = 0x3; + std::cout << std::hex << (int)(data[0x45]) << std::endl; + std::cout << std::hex << (int)(bsd->light_mode) << std::endl; + + bsd->col_breathing.a.r = 0xff; + bsd->col_breathing.a.g = 0x00; + bsd->col_breathing.a.b = 0x00; + KIconTheme::initTheme(); // this is not available in nixpkgs version of // KiconTheme QApplication app(argc, argv); @@ -72,17 +226,6 @@ int main(int argc, char *argv[]) if ((r = libusb_open(found, &handle)) < 0) std::cout << "libusb_open: " << libusb_error_name(r) << std::endl; - unsigned char data[520]; - unsigned char data2[520]; - unsigned char deviceData[520]; - memset(deviceData, 0, 520 * sizeof(unsigned char)); - std::string data01 = "081100920000000064170445000c000f00130017001b00000000000000000000000000000000000000000000000000000000ff00ffffff00ffff9b0000ff00ffffffff460002430036ff00003207ffffff000000ffffff000000ffffff000000ffffff020200ff000000ff000000ff00000000ffffff4600ff00ffffffffff0000ff000001020304050607424202ff000027400102ff0000a500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"; - std::string data02 = "081200500000000011010000110200001104000011080000111000002100610041000000500600001102000021005a0021005b0021005c0021005d0021005e0021005f002100600050010000500100005001000050010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"; - for (int i = 0; i < 1040; i += 2) - { - data[i / 2] = std::stoi(data01.substr(i, 2), (std::size_t *)0, 16); - data2[i / 2] = std::stoi(data02.substr(i, 2), (std::size_t *)0, 16); - } /* self.set_report(0x0305, [5, 0x80, 0, 0, 0, 0, 0, 0]) self.get_report(0x0305, 8) @@ -102,25 +245,16 @@ int main(int argc, char *argv[]) memset(send_data0, 0, 8 * sizeof(unsigned char)); send_data0[0] = 0x05; send_data0[1] = 0x21; + + // get config before write new config + // conf_1 if ((r = libusb_control_transfer(handle, 0x21, 0x09, 0x0305, 1, send_data0, 8, 5000)) < 0) std::cout << "libusb_control_transfer1: " << libusb_error_name(r) << std::endl; - /*if ((r = libusb_control_transfer(handle, 0xa1, 0x01, 0x0305, 1, send_data0, 8, 5000)) < 0) - std::cout << "libusb_control_transfer2: " << libusb_error_name(r) << std::endl; - for(int i = 0; i < 8; ++i) - std::cout << std::hex << (int)send_data0[i] << ", "; - std::cout << std::endl; - memset(send_data0, 0, 8 * sizeof(unsigned char)); - send_data0[0] = 0x05; - send_data0[1] = 0x21; - if ((r = libusb_control_transfer(handle, 0x21, 0x09, 0x0305, 1, send_data0, 8, 5000)) < 0) - std::cout << "libusb_control_transfer3: " << libusb_error_name(r) << std::endl; - */ if ((r = libusb_control_transfer(handle, 0xa1, 0x01, 0x0308, 1, deviceData, 520, 5000)) < 0) std::cout << "libusb_control_transfer2: " << libusb_error_name(r) << std::endl; for (int i = 0; i < 520; ++i) { - std::cout << std::hex << (int)deviceData[i] << "|" << (int)data[i] << "\t"; - + // std::cout << std::hex << (int)deviceData[i] << "|" << (int)data[i] << "\t"; } std::cout << std::endl; std::cout << std::endl; @@ -130,24 +264,47 @@ int main(int argc, char *argv[]) send_data0[1] = 0x22; memset(deviceData, 0, 520 * sizeof(unsigned char)); + // conf_2 if ((r = libusb_control_transfer(handle, 0x21, 0x09, 0x0305, 1, send_data0, 8, 5000)) < 0) std::cout << "libusb_control_transfer3: " << libusb_error_name(r) << std::endl; if ((r = libusb_control_transfer(handle, 0xa1, 0x01, 0x0308, 1, deviceData, 520, 5000)) < 0) std::cout << "libusb_control_transfer4: " << libusb_error_name(r) << std::endl; for (int i = 0; i < 520; ++i) { - std::cout << std::hex << (int)deviceData[i] << "|" << (int)data2[i] << "\t"; - + // std::cout << std::hex << (int)deviceData[i] << "|" << (int)data2[i] << "\t"; } std::cout << std::endl; std::cout << std::endl; + bsd->light_mode = 0x3; + bsd->st_brightness_speed = 0x44; + // write new conf + // conf_1 if ((r = libusb_control_transfer(handle, 0x21, 0x09, 0x0308, 1, data, 520, 5000)) < 0) std::cout << "libusb_control_transfer5: " << libusb_error_name(r) << std::endl; + // conf_2 if ((r = libusb_control_transfer(handle, 0x21, 0x09, 0x0308, 1, data2, 520, 5000)) < 0) std::cout << "libusb_control_transfer6: " << libusb_error_name(r) << std::endl; + // get config after write new config + // conf_1 + memset(send_data0, 0, 8 * sizeof(unsigned char)); + send_data0[0] = 0x05; + send_data0[1] = 0x21; + memset(deviceData, 0, 520 * sizeof(unsigned char)); + if ((r = libusb_control_transfer(handle, 0x21, 0x09, 0x0305, 1, send_data0, 8, 5000)) < 0) + std::cout << "libusb_control_transfer1: " << libusb_error_name(r) << std::endl; + if ((r = libusb_control_transfer(handle, 0xa1, 0x01, 0x0308, 1, deviceData, 520, 5000)) < 0) + std::cout << "libusb_control_transfer2: " << libusb_error_name(r) << std::endl; + // compare written and read + for (int i = 0; i < 520; ++i) + { + // std::cout << std::hex << (int)deviceData[i] << "|" << "\t"; + } + + std::cout << std::endl; + std::cout << std::dec << deviceData[0x45] << "|" << bsd->light_mode << std::endl; if ((r = libusb_release_interface(handle, 1)) < 0) std::cout << "libusb_release_interface: " << libusb_error_name(r) << std::endl; if ((r = libusb_attach_kernel_driver(handle, 1)) < 0)