Skip to content

Commit

Permalink
Merge pull request #260 from lumina37/develop
Browse files Browse the repository at this point in the history
update readme
  • Loading branch information
lumina37 authored Feb 21, 2025
2 parents 6676f53 + 6f8247d commit c3dedcb
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 60 deletions.
10 changes: 2 additions & 8 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -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
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ asyncio.run(main())
*输出样例*

```log
---
tid=8537603600 text=一人发一句最喜欢的游戏台词
楼主先来
很喜欢lol布隆说的“夜晚越黑暗,星星就越明亮”,尤其在当下这个有着诸多缺点的世界里,这句话让我感觉舒服了很多在人们已不再相信理想主义的至暗时刻,高擎炬火之人便显得更加重要,至少我会坚持我的理想
很喜欢lol布隆说的“夜晚越黑暗,星星就越明亮”,尤其在当下这个有着诸多缺点的世界里,这句话让我感觉舒服了很多。在人们已不再相信理想主义的至暗时刻,高擎炬火之人便显得更加重要,至少我会坚持我的理想
---
tid=8093410706 text=大概是剪切板里的一些有意思的话
今天看自己的剪切板快满了,稍微翻翻突然发现以前存的一些话还挺有意思,就放在这里啦
Expand All @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions aiotieba/helper/crypto/crypto.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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异或
Expand All @@ -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:
"""
为参数元组列表计算贴吧客户端签名
Expand Down
3 changes: 1 addition & 2 deletions aiotieba/helper/crypto/src/base32/base32.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions aiotieba/helper/crypto/src/crc/crc32.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
29 changes: 12 additions & 17 deletions aiotieba/helper/crypto/src/tbcrypto/cuid.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <memory.h> // memset memcpy
#include <stdbool.h> // bool
#include <memory.h> // memset memcpy
#include <stdbool.h> // bool

#include "base32/base32.h"
#include "crc/crc32.h"
Expand All @@ -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;
Expand All @@ -46,29 +45,27 @@ 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);
tmpSec >>= 8;
}
}

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;
Expand All @@ -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);
Expand All @@ -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];

Expand Down Expand Up @@ -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';
Expand Down
12 changes: 4 additions & 8 deletions aiotieba/helper/crypto/src/tbcrypto/lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
19 changes: 7 additions & 12 deletions aiotieba/helper/crypto/src/tbcrypto/rc442.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <stddef.h> // size_t
#include <stddef.h> // size_t

#include "tbcrypto/const.h"
#include "tbcrypto/error.h"
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand Down
14 changes: 6 additions & 8 deletions aiotieba/helper/crypto/src/tbcrypto/sign.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <memory.h> // memset memcpy
#include <string.h> // strlen
#include <memory.h> // memset memcpy
#include <string.h> // strlen

#include "mbedtls/md5.h"
#include "rapidjson/itoa.h"
Expand All @@ -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);
Expand All @@ -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)) {
Expand Down Expand Up @@ -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;
Expand All @@ -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)) {
Expand Down

0 comments on commit c3dedcb

Please sign in to comment.