From 8d7136fcb34a4cf99d86aac426411aa66af4e13c Mon Sep 17 00:00:00 2001 From: lumina37 Date: Mon, 17 Feb 2025 20:36:34 +0800 Subject: [PATCH 1/2] chore: use LLVM style --- .clang-format | 10 ++----- aiotieba/helper/crypto/crypto.pyi | 3 +++ aiotieba/helper/crypto/src/base32/base32.c | 3 +-- aiotieba/helper/crypto/src/crc/crc32.c | 3 +-- aiotieba/helper/crypto/src/tbcrypto/cuid.c | 29 +++++++++------------ aiotieba/helper/crypto/src/tbcrypto/lib.c | 12 +++------ aiotieba/helper/crypto/src/tbcrypto/rc442.c | 19 +++++--------- aiotieba/helper/crypto/src/tbcrypto/sign.c | 14 +++++----- 8 files changed, 36 insertions(+), 57 deletions(-) diff --git a/.clang-format b/.clang-format index 93c0ec2b..fcc9ff50 100644 --- a/.clang-format +++ b/.clang-format @@ -1,14 +1,8 @@ -BasedOnStyle: LLVM +BasedOnStyle: Google IndentWidth: 4 ColumnLimit: 120 --- Language: Cpp AccessModifierOffset: -4 -PointerAlignment: Left IndentPPDirectives: AfterHash -RequiresExpressionIndentation: OuterScope -BreakBeforeBraces: Custom -BraceWrapping: - AfterClass: true - AfterControlStatement: Never - AfterFunction: true +IncludeBlocks: Preserve diff --git a/aiotieba/helper/crypto/crypto.pyi b/aiotieba/helper/crypto/crypto.pyi index 0a277221..b33e262e 100644 --- a/aiotieba/helper/crypto/crypto.pyi +++ b/aiotieba/helper/crypto/crypto.pyi @@ -15,6 +15,7 @@ def cuid_galaxy2(android_id: str) -> str: 此实现与12.x版本及以前的官方实现一致 """ + def c3_aid(android_id: str, uuid: str) -> str: """ 使用给定的android_id和uuid生成c3_aid @@ -33,6 +34,7 @@ def c3_aid(android_id: str, uuid: str) -> str: 此实现与12.x版本及以前的官方实现一致 """ + def rc4_42(xyus_md5_str: str, aes_cbc_sec_key: bytes) -> bytes: """ RC4加密的变体 一次额外的42异或 @@ -45,6 +47,7 @@ def rc4_42(xyus_md5_str: str, aes_cbc_sec_key: bytes) -> bytes: bytes """ + def sign(data: list[tuple[str, str | int]]) -> str: """ 为参数元组列表计算贴吧客户端签名 diff --git a/aiotieba/helper/crypto/src/base32/base32.c b/aiotieba/helper/crypto/src/base32/base32.c index 7d12fb2b..16a630d7 100644 --- a/aiotieba/helper/crypto/src/base32/base32.c +++ b/aiotieba/helper/crypto/src/base32/base32.c @@ -20,8 +20,7 @@ static unsigned char base32_table[] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '2', '3', '4', '5', '6', '7'}; -void tbc_base32_encode(const unsigned char* src, int srcLen, unsigned char* dst) -{ +void tbc_base32_encode(const unsigned char* src, int srcLen, unsigned char* dst) { int count = 0; int buffer = src[0]; int next = 1; diff --git a/aiotieba/helper/crypto/src/crc/crc32.c b/aiotieba/helper/crypto/src/crc/crc32.c index 89db3e80..5ce0ed98 100644 --- a/aiotieba/helper/crypto/src/crc/crc32.c +++ b/aiotieba/helper/crypto/src/crc/crc32.c @@ -44,8 +44,7 @@ static uint32_t tbc_crc32Table[] = { 0x24B4A3A6L, 0xBAD03605L, 0xCDD70693L, 0x54DE5729L, 0x23D967BFL, 0xB3667A2EL, 0xC4614AB8L, 0x5D681B02L, 0x2A6F2B94L, 0xB40BBE37L, 0xC30C8EA1L, 0x5A05DF1BL, 0x2D02EF8DL}; -uint32_t tbc_crc32(const unsigned char* src, size_t srcLen, uint32_t prev_val) -{ +uint32_t tbc_crc32(const unsigned char* src, size_t srcLen, uint32_t prev_val) { uint32_t crc32_val = ~prev_val; unsigned char* cursor = (unsigned char*)src; diff --git a/aiotieba/helper/crypto/src/tbcrypto/cuid.c b/aiotieba/helper/crypto/src/tbcrypto/cuid.c index c1aeb2fc..d518b02e 100644 --- a/aiotieba/helper/crypto/src/tbcrypto/cuid.c +++ b/aiotieba/helper/crypto/src/tbcrypto/cuid.c @@ -1,5 +1,5 @@ -#include // memset memcpy -#include // bool +#include // memset memcpy +#include // bool #include "base32/base32.h" #include "crc/crc32.h" @@ -21,8 +21,7 @@ static const char CUID2_PERFIX[] = {'c', 'o', 'm', '.', 'b', 'a', 'i', 'd', 'u'}; static const char CUID3_PERFIX[] = {'c', 'o', 'm', '.', 'h', 'e', 'l', 'i', 'o', 's'}; -static inline void __tbc_update(uint64_t* sec, uint64_t hashVal, uint64_t start, bool flag) -{ +static inline void __tbc_update(uint64_t* sec, uint64_t hashVal, uint64_t start, bool flag) { uint64_t end = start + HASH_SIZE_IN_BIT; uint64_t secTemp = *sec; uint64_t var9 = ((uint64_t)1 << end) - 1; @@ -46,8 +45,7 @@ static inline void __tbc_update(uint64_t* sec, uint64_t hashVal, uint64_t start, *sec = secTemp; } -static inline void __tbc_writeBuffer(unsigned char* buffer, const uint64_t sec) -{ +static inline void __tbc_writeBuffer(unsigned char* buffer, const uint64_t sec) { uint64_t tmpSec = sec; for (uint64_t i = 0; i < STEP_SIZE; i++) { buffer[i] = (unsigned char)((uint64_t)UINT8_MAX & tmpSec); @@ -55,20 +53,19 @@ static inline void __tbc_writeBuffer(unsigned char* buffer, const uint64_t sec) } } -void tbc_heliosHash(const unsigned char* src, size_t srcSize, unsigned char* dst) -{ +void tbc_heliosHash(const unsigned char* src, size_t srcSize, unsigned char* dst) { // init uint32_t crc32Val; uint32_t xxhash32Val; - uint64_t sec = ((uint64_t)1 << 40) - 1; // equals to `-1L>>>-40L` in java + uint64_t sec = ((uint64_t)1 << 40) - 1; // equals to `-1L>>>-40L` in java unsigned char buffer[HASHER_NUM * STEP_SIZE]; - memset(buffer, -1, STEP_SIZE); // Now buffer is [-1 * 5, ...] + memset(buffer, -1, STEP_SIZE); // Now buffer is [-1 * 5, ...] // 1st hash with CRC32 crc32Val = tbc_crc32(src, srcSize, 0); crc32Val = tbc_crc32(buffer, STEP_SIZE, crc32Val); __tbc_update(&sec, (uint64_t)crc32Val, 8, false); - __tbc_writeBuffer(buffer + STEP_SIZE, sec); // Now buffer is [-1 * 5, crcrc, ...] + __tbc_writeBuffer(buffer + STEP_SIZE, sec); // Now buffer is [-1 * 5, crcrc, ...] // 2nd hash with xxHash32 XXH32_state_t xxState4StepTwo, xxState4StepThree; @@ -78,13 +75,13 @@ void tbc_heliosHash(const unsigned char* src, size_t srcSize, unsigned char* dst XXH32_copyState(&xxState4StepThree, &xxState4StepTwo); xxhash32Val = XXH32_digest(&xxState4StepTwo); __tbc_update(&sec, xxhash32Val, 0, true); - __tbc_writeBuffer(buffer + STEP_SIZE * 2, sec); // Now buffer is [-1[5], crc[5], xxxxx, ...] + __tbc_writeBuffer(buffer + STEP_SIZE * 2, sec); // Now buffer is [-1[5], crc[5], xxxxx, ...] // 3rd hash with xxHash32 XXH32_update(&xxState4StepThree, buffer + STEP_SIZE * 2, STEP_SIZE); xxhash32Val = XXH32_digest(&xxState4StepThree); __tbc_update(&sec, xxhash32Val, 1, true); - __tbc_writeBuffer(buffer + STEP_SIZE * 3, sec); // Now buffer is [-1[5], crc[5], xx[5], xx[5]] + __tbc_writeBuffer(buffer + STEP_SIZE * 3, sec); // Now buffer is [-1[5], crc[5], xx[5], xx[5]] // 4th hash with CRC32 crc32Val = tbc_crc32(buffer + STEP_SIZE, STEP_SIZE * 3, crc32Val); @@ -94,8 +91,7 @@ void tbc_heliosHash(const unsigned char* src, size_t srcSize, unsigned char* dst __tbc_writeBuffer(dst, sec); } -void tbc_cuid_galaxy2(const unsigned char* androidID, unsigned char* dst) -{ +void tbc_cuid_galaxy2(const unsigned char* androidID, unsigned char* dst) { // step 1: build src buffer and compute md5 unsigned char md5Buffer[sizeof(CUID2_PERFIX) + TBC_ANDROID_ID_SIZE]; @@ -133,8 +129,7 @@ void tbc_cuid_galaxy2(const unsigned char* androidID, unsigned char* dst) tbc_base32_encode(heHash, TBC_HELIOS_HASH_SIZE, (dst + dstOffset)); } -void tbc_c3_aid(const unsigned char* androidID, const unsigned char* uuid, unsigned char* dst) -{ +void tbc_c3_aid(const unsigned char* androidID, const unsigned char* uuid, unsigned char* dst) { // step 1: set prefix // dst will be ['A00-', ...] dst[0] = 'A'; diff --git a/aiotieba/helper/crypto/src/tbcrypto/lib.c b/aiotieba/helper/crypto/src/tbcrypto/lib.c index f2285ddd..00cde763 100644 --- a/aiotieba/helper/crypto/src/tbcrypto/lib.c +++ b/aiotieba/helper/crypto/src/tbcrypto/lib.c @@ -6,8 +6,7 @@ #include "tbcrypto/rc442.h" #include "tbcrypto/sign.h" -PyObject* cuid_galaxy2(PyObject* Py_UNUSED(self), PyObject* args) -{ +PyObject* cuid_galaxy2(PyObject* Py_UNUSED(self), PyObject* args) { unsigned char dst[TBC_CUID_GALAXY2_SIZE]; const unsigned char* androidID; Py_ssize_t androidIDSize; @@ -27,8 +26,7 @@ PyObject* cuid_galaxy2(PyObject* Py_UNUSED(self), PyObject* args) return PyUnicode_FromKindAndData(PyUnicode_1BYTE_KIND, dst, TBC_CUID_GALAXY2_SIZE); } -PyObject* c3_aid(PyObject* Py_UNUSED(self), PyObject* args) -{ +PyObject* c3_aid(PyObject* Py_UNUSED(self), PyObject* args) { unsigned char dst[TBC_C3_AID_SIZE]; const unsigned char* androidID; Py_ssize_t androidIDSize; @@ -54,8 +52,7 @@ PyObject* c3_aid(PyObject* Py_UNUSED(self), PyObject* args) return PyUnicode_FromKindAndData(PyUnicode_1BYTE_KIND, dst, TBC_C3_AID_SIZE); } -PyObject* rc4_42(PyObject* Py_UNUSED(self), PyObject* args) -{ +PyObject* rc4_42(PyObject* Py_UNUSED(self), PyObject* args) { unsigned char dst[TBC_RC4_SIZE]; const unsigned char* xyusMd5Str; Py_ssize_t xyusMd5Size; @@ -91,8 +88,7 @@ static PyMethodDef crypto_methods[] = { static PyModuleDef crypto_module = {PyModuleDef_HEAD_INIT, "crypto", NULL, -1, crypto_methods}; -PyMODINIT_FUNC PyInit_crypto(void) -{ +PyMODINIT_FUNC PyInit_crypto(void) { PyObject* mod = PyModule_Create(&crypto_module); if (mod == NULL) { return NULL; diff --git a/aiotieba/helper/crypto/src/tbcrypto/rc442.c b/aiotieba/helper/crypto/src/tbcrypto/rc442.c index cd515d01..6945145f 100644 --- a/aiotieba/helper/crypto/src/tbcrypto/rc442.c +++ b/aiotieba/helper/crypto/src/tbcrypto/rc442.c @@ -1,4 +1,4 @@ -#include // size_t +#include // size_t #include "tbcrypto/const.h" #include "tbcrypto/error.h" @@ -11,8 +11,7 @@ typedef struct rc4_42_context { unsigned char m[256]; } rc4_42_context; -static inline void rc4_42_setup(rc4_42_context* ctx, const unsigned char* key, unsigned int keyLen) -{ +static inline void rc4_42_setup(rc4_42_context* ctx, const unsigned char* key, unsigned int keyLen) { int i, j, a; unsigned int k; unsigned char* m; @@ -21,14 +20,12 @@ static inline void rc4_42_setup(rc4_42_context* ctx, const unsigned char* key, u ctx->y = 0; m = ctx->m; - for (i = 0; i < 256; i++) - m[i] = (unsigned char)i; + for (i = 0; i < 256; i++) m[i] = (unsigned char)i; j = k = 0; for (i = 0; i < 256; i++, k++) { - if (k >= keyLen) - k = 0; + if (k >= keyLen) k = 0; a = m[i]; j = (j + a + key[k]) & 0xFF; @@ -37,8 +34,7 @@ static inline void rc4_42_setup(rc4_42_context* ctx, const unsigned char* key, u } } -static inline void rc4_42_crypt(rc4_42_context* ctx, const unsigned char* src, size_t srcLen, unsigned char* dst) -{ +static inline void rc4_42_crypt(rc4_42_context* ctx, const unsigned char* src, size_t srcLen, unsigned char* dst) { int x, y, a, b; size_t i; unsigned char* m; @@ -57,15 +53,14 @@ static inline void rc4_42_crypt(rc4_42_context* ctx, const unsigned char* src, s m[y] = (unsigned char)a; dst[i] = (unsigned char)(src[i] ^ m[(unsigned char)(a + b)]); - dst[i] = dst[i] ^ 42; // different from general RC4 + dst[i] = dst[i] ^ 42; // different from general RC4 } ctx->x = x; ctx->y = y; } -void tbc_rc4_42(const unsigned char* xyusMd5Str, const unsigned char* cbcSecKey, unsigned char* dst) -{ +void tbc_rc4_42(const unsigned char* xyusMd5Str, const unsigned char* cbcSecKey, unsigned char* dst) { rc4_42_context rc442Ctx; rc4_42_setup(&rc442Ctx, xyusMd5Str, TBC_MD5_STR_SIZE); diff --git a/aiotieba/helper/crypto/src/tbcrypto/sign.c b/aiotieba/helper/crypto/src/tbcrypto/sign.c index 1703c334..e3b34b3b 100644 --- a/aiotieba/helper/crypto/src/tbcrypto/sign.c +++ b/aiotieba/helper/crypto/src/tbcrypto/sign.c @@ -1,5 +1,5 @@ -#include // memset memcpy -#include // strlen +#include // memset memcpy +#include // strlen #include "mbedtls/md5.h" #include "rapidjson/itoa.h" @@ -10,8 +10,7 @@ static const unsigned char SIGN_SUFFIX[] = {'t', 'i', 'e', 'b', 'a', 'c', 'l', 'i', 'e', 'n', 't', '!', '!', '!'}; -static inline void __tbc_pyStr2UTF8(const char** dst, size_t* dstSize, PyObject* pyoStr) -{ +static inline void __tbc_pyStr2UTF8(const char** dst, size_t* dstSize, PyObject* pyoStr) { if (PyUnicode_1BYTE_KIND == PyUnicode_KIND(pyoStr)) { (*dst) = PyUnicode_DATA(pyoStr); (*dstSize) = PyUnicode_GET_LENGTH(pyoStr); @@ -21,8 +20,7 @@ static inline void __tbc_pyStr2UTF8(const char** dst, size_t* dstSize, PyObject* } } -PyObject* sign(PyObject* Py_UNUSED(self), PyObject* args) -{ +PyObject* sign(PyObject* Py_UNUSED(self), PyObject* args) { PyObject* items; if (!PyArg_ParseTuple(args, "O", &items)) { @@ -51,7 +49,7 @@ PyObject* sign(PyObject* Py_UNUSED(self), PyObject* args) PyObject* pyoKey = PyTuple_GetItem(item, 0); if (!pyoKey) { - return NULL; // IndexError + return NULL; // IndexError } char* key; @@ -66,7 +64,7 @@ PyObject* sign(PyObject* Py_UNUSED(self), PyObject* args) PyObject* pyoVal = PyTuple_GetItem(item, 1); if (!pyoVal) { - return NULL; // IndexError + return NULL; // IndexError } if (PyUnicode_Check(pyoVal)) { From 6f8247d9e9b940e3993866c8e7e5d310f331f64b Mon Sep 17 00:00:00 2001 From: lumina37 Date: Fri, 21 Feb 2025 09:56:59 +0800 Subject: [PATCH 2/2] chore: update readme --- README.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 10e97e81..831cbd67 100644 --- a/README.md +++ b/README.md @@ -47,10 +47,9 @@ asyncio.run(main()) *输出样例* ```log ---- tid=8537603600 text=一人发一句最喜欢的游戏台词 楼主先来 -很喜欢lol布隆说的“夜晚越黑暗,星星就越明亮”,尤其在当下这个有着诸多缺点的世界里,这句话让我感觉舒服了很多在人们已不再相信理想主义的至暗时刻,高擎炬火之人便显得更加重要,至少我会坚持我的理想 +很喜欢lol布隆说的“夜晚越黑暗,星星就越明亮”,尤其在当下这个有着诸多缺点的世界里,这句话让我感觉舒服了很多。在人们已不再相信理想主义的至暗时刻,高擎炬火之人便显得更加重要,至少我会坚持我的理想 --- tid=8093410706 text=大概是剪切板里的一些有意思的话 今天看自己的剪切板快满了,稍微翻翻突然发现以前存的一些话还挺有意思,就放在这里啦 @@ -73,7 +72,9 @@ tid=8537699088 text=记录一下自己人生第一次当“老师”的经历^_^ ## 友情链接 + [TiebaManager(吧务管理器 有用户界面)](https://github.com/dog194/TiebaManager) -+ [基于aiotieba的高弹性吧务审查框架](https://github.com/lumina37/aiotieba-reviewer) ++ [基于aiotieba的tieba bot](https://github.com/adk23333/BungleCat) ++ [基于aiotieba的贴吧管理器](https://github.com/adk23333/tieba-admin) ++ [C#版本的贴吧接口库](https://github.com/BaWuZhuShou/AioTieba4DotNet) + [贴吧protobuf定义文件合集(更新至12.51.7.1)](https://github.com/n0099/tbclient.protobuf) + [TiebaLite 第三方安卓客户端(已停更)](https://github.com/HuanCheng65/TiebaLite/tree/4.0-dev)