From e92af9d6d11491cc095b008cec9f59c00f40d905 Mon Sep 17 00:00:00 2001 From: Starry-OvO Date: Wed, 15 Mar 2023 23:24:49 +0800 Subject: [PATCH 1/9] docs: update examples --- docs/tutorial/many_utils.md | 116 ++++++++++++++---------------------- 1 file changed, 44 insertions(+), 72 deletions(-) diff --git a/docs/tutorial/many_utils.md b/docs/tutorial/many_utils.md index 29df2c39..4c6186e8 100644 --- a/docs/tutorial/many_utils.md +++ b/docs/tutorial/many_utils.md @@ -1,6 +1,6 @@ # 实用工具 -## 签到水经验 +## 签到 ```python import asyncio @@ -9,57 +9,22 @@ from typing import List import aiotieba as tb -class WaterTask(object): - __slots__ = ['fname', 'tid', 'times'] +class NeedRetry(RuntimeError): + pass - def __init__(self, fname: str, tid: int, times: int = 6) -> None: - self.fname = fname - self.tid = tid - self.times = times +def handle_exce(err: tb.exception.TiebaServerError) -> None: + if isinstance(err, tb.exception.TiebaServerError): + if err.code in [160002, 340006]: + # 已经签过或吧被屏蔽 + return -async def water(BDUSS_key: str, tasks: List[WaterTask]) -> None: - """ - 水帖 - - Args: - BDUSS_key (str): 用于创建客户端 - tasks (List[WaterTask]): 水帖任务列表 - """ - - async with tb.Client(BDUSS_key) as client: - for task in tasks: - for i in range(task.times): - await client.add_post(task.fname, task.tid, str(i)) - await asyncio.sleep(120) - - -async def agree(BDUSS_key: str, tids: List[int], *, times: int = 3): - """ - 点赞楼层刷经验 - - Args: - BDUSS_key (str): 用于创建客户端 - tids (list[int]): tid列表 对每个tid的最后一楼执行点赞操作 - times (int, optional): 点赞轮数 每轮包含一次点赞和一次取消赞. Defaults to 3. - """ - - async with tb.Client(BDUSS_key) as client: - for tid in tids: - posts = await client.get_posts(tid, 0xFFFF, rn=0, sort=1) - tid = posts[-1].tid - pid = posts[-1].pid - - for _ in range(times): - await client.agree(tid, pid) - await asyncio.sleep(6) - await client.unagree(tid, pid) - await asyncio.sleep(6) + raise NeedRetry() async def sign(BDUSS_key: str, *, retry_times: int = 0) -> None: """ - 签到 + 各种签到 Args: BDUSS_key (str): 用于创建客户端 @@ -67,48 +32,56 @@ async def sign(BDUSS_key: str, *, retry_times: int = 0) -> None: """ async with tb.Client(BDUSS_key) as client: + # 成长等级签到 + for _ in range(retry_times): + await asyncio.sleep(1.0) + if await client.sign_growth(): + break + # 分享任务 + for _ in range(retry_times): + await asyncio.sleep(1.0) + if await client.sign_growth_share(): + break + # 虚拟形象点赞 + for _ in range(retry_times): + await asyncio.sleep(1.0) + if await client.agree_vimage(6050811555): + break + # 互关任务 + for _ in range(retry_times): + await asyncio.sleep(1.0) + success = False + success = await client.unfollow_user('tb.1.2fc1394a.ukuFqA26BTuAeXqYr1Nmwg') + if not success: + continue + success = await client.follow_user('tb.1.2fc1394a.ukuFqA26BTuAeXqYr1Nmwg') + if not success: + continue + if success: + break + # 签到 retry_list: List[str] = [] for pn in range(1, 9999): forums = await client.get_self_follow_forums(pn) retry_list += [forum.fname for forum in forums] if not forums.has_more: break - for _ in range(retry_times + 1): new_retry_list: List[str] = [] for fname in retry_list: - if not await client.sign_forum(fname): + try: + await client.sign_forum(fname) + except NeedRetry: new_retry_list.append(fname) + await asyncio.sleep(1.0) if not new_retry_list: break retry_list = new_retry_list - # 用户成长等级签到 - for _ in range(retry_times): - if await client.sign_growth(): - break - async def main() -> None: - agree_tids = [2986143112, 3611123694, 7689322018, 7966279046] - - await asyncio.gather( - # 大号每天在lol半价吧和v吧水6帖 在个人吧水1帖以保证吧主不掉 - water( - "default", - [ - WaterTask("lol半价", 2986143112), - WaterTask("v", 3611123694), - WaterTask("starry", 6154402005, 1), - ], - ), - # 大小号每天签到 大号每次签到重试3轮 确保连签不断 小号只重试1轮 - sign("default", retry_times=3), - sign("backup", retry_times=1), - # 大小号每天点赞刷经验 - agree("default", agree_tids, max_times=1), - agree("backup", agree_tids, max_times=1), - ) + await sign("default", retry_times=3) + await sign("backup", retry_times=3) asyncio.run(main()) @@ -237,5 +210,4 @@ async def main() -> None: asyncio.run(main()) - ``` From 2c6c3501e8944cfb8edced973c27bca5781453f1 Mon Sep 17 00:00:00 2001 From: Starry-OvO Date: Wed, 15 Mar 2023 23:29:15 +0800 Subject: [PATCH 2/9] docs: update examples --- docs/tutorial/many_utils.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/tutorial/many_utils.md b/docs/tutorial/many_utils.md index 4c6186e8..9a81c06f 100644 --- a/docs/tutorial/many_utils.md +++ b/docs/tutorial/many_utils.md @@ -32,6 +32,8 @@ async def sign(BDUSS_key: str, *, retry_times: int = 0) -> None: """ async with tb.Client(BDUSS_key) as client: + tb.exception.exc_handlers[client.sign_forum] = handle_exce + # 成长等级签到 for _ in range(retry_times): await asyncio.sleep(1.0) From 15e8dee3e3907cdbfc1d082569fb4c0915e77cc8 Mon Sep 17 00:00:00 2001 From: Starry-OvO Date: Sat, 18 Mar 2023 07:55:30 +0800 Subject: [PATCH 3/9] chore: bump client version to 12.38.0.3 --- aiotieba/const.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aiotieba/const.py b/aiotieba/const.py index 181ed50f..9d84f988 100644 --- a/aiotieba/const.py +++ b/aiotieba/const.py @@ -1,4 +1,4 @@ -MAIN_VERSION = "12.37.0.1" +MAIN_VERSION = "12.38.0.3" POST_VERSION = "9.1.0.0" APP_SECURE_SCHEME = "https" From 7fa45b678a7282a43bd667f160f08d9d090fe592 Mon Sep 17 00:00:00 2001 From: Starry-OvO Date: Sat, 18 Mar 2023 08:03:24 +0800 Subject: [PATCH 4/9] fix: remove invalid fields --- aiotieba/api/get_posts/_classdef.py | 28 ---------------------------- tests/test_get_posts.py | 2 -- 2 files changed, 30 deletions(-) diff --git a/aiotieba/api/get_posts/_classdef.py b/aiotieba/api/get_posts/_classdef.py index a6ac2b8d..0e30422f 100644 --- a/aiotieba/api/get_posts/_classdef.py +++ b/aiotieba/api/get_posts/_classdef.py @@ -1559,7 +1559,6 @@ class UserInfo_pt(object): level (int): 等级 glevel (int): 贴吧成长等级 - fan_num (int): 粉丝数 ip (str): ip归属地 is_bawu (bool): 是否吧务 @@ -1580,7 +1579,6 @@ class UserInfo_pt(object): '_nick_name_new', '_level', '_glevel', - '_fan_num', '_ip', '_is_bawu', '_is_vip', @@ -1599,7 +1597,6 @@ def _init(self, data_proto: TypeMessage) -> "UserInfo_pt": self._nick_name_new = data_proto.name_show self._level = data_proto.level_id self._glevel = data_proto.user_growth.level_id - self._fan_num = data_proto.fans_num self._ip = data_proto.ip_address self._is_bawu = bool(data_proto.is_bawu) self._is_vip = bool(data_proto.new_tshow_icon) @@ -1615,7 +1612,6 @@ def _init_null(self) -> "UserInfo_pt": self._nick_name_new = '' self._level = 0 self._glevel = 0 - self._fan_num = 0 self._ip = '' self._is_bawu = False self._is_vip = False @@ -1636,7 +1632,6 @@ def __repr__(self) -> str: 'show_name': self.show_name, 'level': self._level, 'glevel': self._glevel, - 'fan_num': self._fan_num, 'ip': self._ip, 'priv_like': self._priv_like, 'priv_reply': self._priv_reply, @@ -1714,14 +1709,6 @@ def glevel(self) -> int: return self._glevel - @property - def fan_num(self) -> int: - """ - 粉丝数 - """ - - return self._fan_num - @property def ip(self) -> str: """ @@ -1979,7 +1966,6 @@ class Thread_p(object): agree (int): 点赞数 disagree (int): 点踩数 create_time (int): 创建时间 - last_time (int): 最后回复时间 """ __slots__ = [ @@ -2001,7 +1987,6 @@ class Thread_p(object): '_agree', '_disagree', '_create_time', - '_last_time', ] def _init(self, data_proto: TypeMessage) -> "Thread_p": @@ -2018,7 +2003,6 @@ def _init(self, data_proto: TypeMessage) -> "Thread_p": self._agree = data_proto.agree.agree_num self._disagree = data_proto.agree.disagree_num self._create_time = data_proto.create_time - self._last_time = data_proto.last_time_int if not self._is_share: self._contents = Contents_pt()._init(data_proto.origin_thread_info.content) @@ -2054,7 +2038,6 @@ def _init_null(self) -> "Thread_p": self._agree = 0 self._disagree = 0 self._create_time = 0 - self._last_time = 0 return self def __repr__(self) -> str: @@ -2236,17 +2219,6 @@ def create_time(self) -> int: return self._create_time - @property - def last_time(self) -> int: - """ - 最后回复时间 - - Note: - 10位时间戳 以秒为单位 - """ - - return self._last_time - class Posts(Containers[Post]): """ diff --git a/tests/test_get_posts.py b/tests/test_get_posts.py index 81c09f80..bd29272b 100644 --- a/tests/test_get_posts.py +++ b/tests/test_get_posts.py @@ -25,7 +25,6 @@ async def test_Posts(client: tb.Client): assert user.show_name == user.nick_name_new assert user.level > 0 assert user.glevel > 0 - # assert user.fan_num > 0 assert user.ip != '' assert user.priv_like != 0 assert user.priv_reply != 0 @@ -50,7 +49,6 @@ async def test_Posts(client: tb.Client): assert thread.reply_num > 0 assert thread.share_num > 0 assert thread.create_time > 0 - # assert thread.last_time > 0 ##### Post ##### assert len(posts) >= 2 From 79502d33385ffe99759e1c29377ed10669be21dc Mon Sep 17 00:00:00 2001 From: Starry-OvO Date: Sat, 18 Mar 2023 08:16:56 +0800 Subject: [PATCH 5/9] fix: support floor agree --- aiotieba/__version__.py | 2 +- aiotieba/api/agree/_api.py | 9 +++++++-- aiotieba/client.py | 20 ++++++++++++-------- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/aiotieba/__version__.py b/aiotieba/__version__.py index ff041687..5d76f77a 100644 --- a/aiotieba/__version__.py +++ b/aiotieba/__version__.py @@ -1 +1 @@ -__version__ = "3.3.1" +__version__ = "3.3.2a0" diff --git a/aiotieba/api/agree/_api.py b/aiotieba/api/agree/_api.py index b453eaf7..0237f2ac 100644 --- a/aiotieba/api/agree/_api.py +++ b/aiotieba/api/agree/_api.py @@ -15,13 +15,18 @@ def parse_body(body: bytes) -> None: raise TiebaServerError(code, res_json['error_msg']) -async def request(http_core: HttpCore, tid: int, pid: int, is_disagree: bool, is_undo: bool) -> bool: +async def request(http_core: HttpCore, tid: int, pid: int, is_floor: bool, is_disagree: bool, is_undo: bool) -> bool: + if pid: + obj_type = '2' if is_floor else '1' + else: + obj_type = '3' + data = [ ('BDUSS', http_core.account._BDUSS), ('_client_version', MAIN_VERSION), ('agree_type', '5' if is_disagree else '2'), ('cuid', http_core.account.cuid_galaxy2), - ('obj_type', '1' if pid else '3'), + ('obj_type', obj_type), ('op_type', str(int(is_undo))), ('post_id', pid), ('tbs', http_core.account._tbs), diff --git a/aiotieba/client.py b/aiotieba/client.py index da5857de..16e41a36 100644 --- a/aiotieba/client.py +++ b/aiotieba/client.py @@ -1694,13 +1694,14 @@ async def get_dislike_forums(self, pn: int = 1, /, *, rn: int = 20) -> get_disli return await get_dislike_forums.request_http(self._http_core, pn, rn) @handle_exception(bool, no_format=True) - async def agree(self, tid: int, pid: int = 0) -> bool: + async def agree(self, tid: int, pid: int = 0, is_floor: bool = False) -> bool: """ 点赞主题帖或回复 Args: tid (int): 待点赞的主题帖或回复所在的主题帖的tid pid (int, optional): 待点赞的回复pid. Defaults to 0. + is_floor (bool, optional): pid是否指向楼中楼. Defaults to False. Returns: bool: True成功 False失败 @@ -1712,16 +1713,17 @@ async def agree(self, tid: int, pid: int = 0) -> bool: await self.__init_tbs() - return await agree.request(self._http_core, tid, pid, is_disagree=False, is_undo=False) + return await agree.request(self._http_core, tid, pid, is_floor, is_disagree=False, is_undo=False) @handle_exception(bool, no_format=True) - async def unagree(self, tid: int, pid: int = 0) -> bool: + async def unagree(self, tid: int, pid: int = 0, is_floor: bool = False) -> bool: """ 取消点赞主题帖或回复 Args: tid (int): 待取消点赞的主题帖或回复所在的主题帖的tid pid (int, optional): 待取消点赞的回复pid. Defaults to 0. + is_floor (bool, optional): pid是否指向楼中楼. Defaults to False. Returns: bool: True成功 False失败 @@ -1729,16 +1731,17 @@ async def unagree(self, tid: int, pid: int = 0) -> bool: await self.__init_tbs() - return await agree.request(self._http_core, tid, pid, is_disagree=False, is_undo=True) + return await agree.request(self._http_core, tid, pid, is_floor, is_disagree=False, is_undo=True) @handle_exception(bool, no_format=True) - async def disagree(self, tid: int, pid: int = 0) -> bool: + async def disagree(self, tid: int, pid: int = 0, is_floor: bool = False) -> bool: """ 点踩主题帖或回复 Args: tid (int): 待点踩的主题帖或回复所在的主题帖的tid pid (int, optional): 待点踩的回复pid. Defaults to 0. + is_floor (bool, optional): pid是否指向楼中楼. Defaults to False. Returns: bool: True成功 False失败 @@ -1746,16 +1749,17 @@ async def disagree(self, tid: int, pid: int = 0) -> bool: await self.__init_tbs() - return await agree.request(self._http_core, tid, pid, is_disagree=True, is_undo=False) + return await agree.request(self._http_core, tid, pid, is_floor, is_disagree=True, is_undo=False) @handle_exception(bool, no_format=True) - async def undisagree(self, tid: int, pid: int = 0) -> bool: + async def undisagree(self, tid: int, pid: int = 0, is_floor: bool = False) -> bool: """ 取消点踩主题帖或回复 Args: tid (int): 待取消点踩的主题帖或回复所在的主题帖的tid pid (int, optional): 待取消点踩的回复pid. Defaults to 0. + is_floor (bool, optional): pid是否指向楼中楼. Defaults to False. Returns: bool: True成功 False失败 @@ -1763,7 +1767,7 @@ async def undisagree(self, tid: int, pid: int = 0) -> bool: await self.__init_tbs() - return await agree.request(self._http_core, tid, pid, is_disagree=True, is_undo=True) + return await agree.request(self._http_core, tid, pid, is_floor, is_disagree=True, is_undo=True) @handle_exception(bool, no_format=True) async def agree_vimage(self, _id: Union[str, int]) -> bool: From 01992aa29dbb0e90317422fa699869e9b00e673c Mon Sep 17 00:00:00 2001 From: Starry-OvO Date: Fri, 24 Mar 2023 22:05:58 +0800 Subject: [PATCH 6/9] chore: update versions --- aiotieba/const.py | 2 +- tests/requirements.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/aiotieba/const.py b/aiotieba/const.py index 9d84f988..a2f21ce8 100644 --- a/aiotieba/const.py +++ b/aiotieba/const.py @@ -1,4 +1,4 @@ -MAIN_VERSION = "12.38.0.3" +MAIN_VERSION = "12.38.1.0" POST_VERSION = "9.1.0.0" APP_SECURE_SCHEME = "https" diff --git a/tests/requirements.txt b/tests/requirements.txt index 957ae938..435e11c3 100644 --- a/tests/requirements.txt +++ b/tests/requirements.txt @@ -2,4 +2,4 @@ # Test Suite pytest==7.2.2 -pytest-asyncio==0.20.3 +pytest-asyncio==0.21.0 From bc79a9ec58cc44520c5faf8ca840e3943173e8aa Mon Sep 17 00:00:00 2001 From: Starry-OvO Date: Tue, 28 Mar 2023 21:47:42 +0800 Subject: [PATCH 7/9] feat: pin to MbedTLS 3.4.0 --- 3rdparty/mbedtls/include/mbedtls/build_info.h | 8 +- 3rdparty/mbedtls/library/alignment.h | 116 +++++++++--------- 3rdparty/mbedtls/library/md5.c | 2 - 3rdparty/mbedtls/library/platform_util.c | 58 ++++++++- 4 files changed, 117 insertions(+), 67 deletions(-) diff --git a/3rdparty/mbedtls/include/mbedtls/build_info.h b/3rdparty/mbedtls/include/mbedtls/build_info.h index 99d6cbc9..a1df1196 100644 --- a/3rdparty/mbedtls/include/mbedtls/build_info.h +++ b/3rdparty/mbedtls/include/mbedtls/build_info.h @@ -37,7 +37,7 @@ * Major, Minor, Patchlevel */ #define MBEDTLS_VERSION_MAJOR 3 -#define MBEDTLS_VERSION_MINOR 3 +#define MBEDTLS_VERSION_MINOR 4 #define MBEDTLS_VERSION_PATCH 0 /** @@ -45,9 +45,9 @@ * MMNNPP00 * Major version | Minor version | Patch version */ -#define MBEDTLS_VERSION_NUMBER 0x03030000 -#define MBEDTLS_VERSION_STRING "3.3.0" -#define MBEDTLS_VERSION_STRING_FULL "mbed TLS 3.3.0" +#define MBEDTLS_VERSION_NUMBER 0x03040000 +#define MBEDTLS_VERSION_STRING "3.4.0" +#define MBEDTLS_VERSION_STRING_FULL "mbed TLS 3.4.0" #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE) #define _CRT_SECURE_NO_DEPRECATE 1 diff --git a/3rdparty/mbedtls/library/alignment.h b/3rdparty/mbedtls/library/alignment.h index aa09ff85..a518a8a3 100644 --- a/3rdparty/mbedtls/library/alignment.h +++ b/3rdparty/mbedtls/library/alignment.h @@ -130,7 +130,7 @@ inline void mbedtls_put_unaligned_uint64(void *p, uint64_t x) * byte from x, where byte 0 is the least significant byte. */ #define MBEDTLS_BYTE_0(x) ((uint8_t) ((x) & 0xff)) -#define MBEDTLS_BYTE_1(x) ((uint8_t) (((x) >> 8) & 0xff)) +#define MBEDTLS_BYTE_1(x) ((uint8_t) (((x) >> 8) & 0xff)) #define MBEDTLS_BYTE_2(x) ((uint8_t) (((x) >> 16) & 0xff)) #define MBEDTLS_BYTE_3(x) ((uint8_t) (((x) >> 24) & 0xff)) #define MBEDTLS_BYTE_4(x) ((uint8_t) (((x) >> 32) & 0xff)) @@ -155,13 +155,13 @@ inline void mbedtls_put_unaligned_uint64(void *p, uint64_t x) * Detect Clang built-in byteswap routines */ #if defined(__clang__) && defined(__has_builtin) -#if __has_builtin(__builtin_bswap16) +#if __has_builtin(__builtin_bswap16) && !defined(MBEDTLS_BSWAP16) #define MBEDTLS_BSWAP16 __builtin_bswap16 #endif /* __has_builtin(__builtin_bswap16) */ -#if __has_builtin(__builtin_bswap32) +#if __has_builtin(__builtin_bswap32) && !defined(MBEDTLS_BSWAP32) #define MBEDTLS_BSWAP32 __builtin_bswap32 #endif /* __has_builtin(__builtin_bswap32) */ -#if __has_builtin(__builtin_bswap64) +#if __has_builtin(__builtin_bswap64) && !defined(MBEDTLS_BSWAP64) #define MBEDTLS_BSWAP64 __builtin_bswap64 #endif /* __has_builtin(__builtin_bswap64) */ #endif /* defined(__clang__) && defined(__has_builtin) */ @@ -170,13 +170,19 @@ inline void mbedtls_put_unaligned_uint64(void *p, uint64_t x) * Detect MSVC built-in byteswap routines */ #if defined(_MSC_VER) +#if !defined(MBEDTLS_BSWAP16) #define MBEDTLS_BSWAP16 _byteswap_ushort +#endif +#if !defined(MBEDTLS_BSWAP32) #define MBEDTLS_BSWAP32 _byteswap_ulong +#endif +#if !defined(MBEDTLS_BSWAP64) #define MBEDTLS_BSWAP64 _byteswap_uint64 +#endif #endif /* defined(_MSC_VER) */ /* Detect armcc built-in byteswap routine */ -#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 410000) +#if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 410000) && !defined(MBEDTLS_BSWAP32) #define MBEDTLS_BSWAP32 __rev #endif @@ -211,14 +217,14 @@ static inline uint32_t mbedtls_bswap32(uint32_t x) static inline uint64_t mbedtls_bswap64(uint64_t x) { return - (x & 0x00000000000000ff) << 56 | - (x & 0x000000000000ff00) << 40 | - (x & 0x0000000000ff0000) << 24 | - (x & 0x00000000ff000000) << 8 | - (x & 0x000000ff00000000) >> 8 | - (x & 0x0000ff0000000000) >> 24 | - (x & 0x00ff000000000000) >> 40 | - (x & 0xff00000000000000) >> 56; + (x & 0x00000000000000ffULL) << 56 | + (x & 0x000000000000ff00ULL) << 40 | + (x & 0x0000000000ff0000ULL) << 24 | + (x & 0x00000000ff000000ULL) << 8 | + (x & 0x000000ff00000000ULL) >> 8 | + (x & 0x0000ff0000000000ULL) >> 24 | + (x & 0x00ff000000000000ULL) >> 40 | + (x & 0xff00000000000000ULL) >> 56; } #define MBEDTLS_BSWAP64 mbedtls_bswap64 #endif /* !defined(MBEDTLS_BSWAP64) */ @@ -239,8 +245,8 @@ static const uint16_t mbedtls_byte_order_detector = { 0x100 }; * byte of the four bytes to build the 32 bits unsigned * integer from. */ -#define MBEDTLS_GET_UINT32_BE(data, offset) \ - ((MBEDTLS_IS_BIG_ENDIAN) \ +#define MBEDTLS_GET_UINT32_BE(data, offset) \ + ((MBEDTLS_IS_BIG_ENDIAN) \ ? mbedtls_get_unaligned_uint32((data) + (offset)) \ : MBEDTLS_BSWAP32(mbedtls_get_unaligned_uint32((data) + (offset))) \ ) @@ -254,11 +260,11 @@ static const uint16_t mbedtls_byte_order_detector = { 0x100 }; * \param offset Offset from \p data where to put the most significant * byte of the 32 bits unsigned integer \p n. */ -#define MBEDTLS_PUT_UINT32_BE(n, data, offset) \ +#define MBEDTLS_PUT_UINT32_BE(n, data, offset) \ { \ - if (MBEDTLS_IS_BIG_ENDIAN) \ + if (MBEDTLS_IS_BIG_ENDIAN) \ { \ - mbedtls_put_unaligned_uint32((data) + (offset), (uint32_t) (n)); \ + mbedtls_put_unaligned_uint32((data) + (offset), (uint32_t) (n)); \ } \ else \ { \ @@ -275,8 +281,8 @@ static const uint16_t mbedtls_byte_order_detector = { 0x100 }; * byte of the four bytes to build the 32 bits unsigned * integer from. */ -#define MBEDTLS_GET_UINT32_LE(data, offset) \ - ((MBEDTLS_IS_BIG_ENDIAN) \ +#define MBEDTLS_GET_UINT32_LE(data, offset) \ + ((MBEDTLS_IS_BIG_ENDIAN) \ ? MBEDTLS_BSWAP32(mbedtls_get_unaligned_uint32((data) + (offset))) \ : mbedtls_get_unaligned_uint32((data) + (offset)) \ ) @@ -291,15 +297,15 @@ static const uint16_t mbedtls_byte_order_detector = { 0x100 }; * \param offset Offset from \p data where to put the least significant * byte of the 32 bits unsigned integer \p n. */ -#define MBEDTLS_PUT_UINT32_LE(n, data, offset) \ +#define MBEDTLS_PUT_UINT32_LE(n, data, offset) \ { \ - if (MBEDTLS_IS_BIG_ENDIAN) \ + if (MBEDTLS_IS_BIG_ENDIAN) \ { \ mbedtls_put_unaligned_uint32((data) + (offset), MBEDTLS_BSWAP32((uint32_t) (n))); \ } \ else \ { \ - mbedtls_put_unaligned_uint32((data) + (offset), ((uint32_t) (n))); \ + mbedtls_put_unaligned_uint32((data) + (offset), ((uint32_t) (n))); \ } \ } @@ -312,8 +318,8 @@ static const uint16_t mbedtls_byte_order_detector = { 0x100 }; * byte of the two bytes to build the 16 bits unsigned * integer from. */ -#define MBEDTLS_GET_UINT16_LE(data, offset) \ - ((MBEDTLS_IS_BIG_ENDIAN) \ +#define MBEDTLS_GET_UINT16_LE(data, offset) \ + ((MBEDTLS_IS_BIG_ENDIAN) \ ? MBEDTLS_BSWAP16(mbedtls_get_unaligned_uint16((data) + (offset))) \ : mbedtls_get_unaligned_uint16((data) + (offset)) \ ) @@ -327,15 +333,15 @@ static const uint16_t mbedtls_byte_order_detector = { 0x100 }; * \param offset Offset from \p data where to put the least significant * byte of the 16 bits unsigned integer \p n. */ -#define MBEDTLS_PUT_UINT16_LE(n, data, offset) \ +#define MBEDTLS_PUT_UINT16_LE(n, data, offset) \ { \ - if (MBEDTLS_IS_BIG_ENDIAN) \ + if (MBEDTLS_IS_BIG_ENDIAN) \ { \ mbedtls_put_unaligned_uint16((data) + (offset), MBEDTLS_BSWAP16((uint16_t) (n))); \ } \ else \ { \ - mbedtls_put_unaligned_uint16((data) + (offset), (uint16_t) (n)); \ + mbedtls_put_unaligned_uint16((data) + (offset), (uint16_t) (n)); \ } \ } @@ -348,8 +354,8 @@ static const uint16_t mbedtls_byte_order_detector = { 0x100 }; * byte of the two bytes to build the 16 bits unsigned * integer from. */ -#define MBEDTLS_GET_UINT16_BE(data, offset) \ - ((MBEDTLS_IS_BIG_ENDIAN) \ +#define MBEDTLS_GET_UINT16_BE(data, offset) \ + ((MBEDTLS_IS_BIG_ENDIAN) \ ? mbedtls_get_unaligned_uint16((data) + (offset)) \ : MBEDTLS_BSWAP16(mbedtls_get_unaligned_uint16((data) + (offset))) \ ) @@ -363,11 +369,11 @@ static const uint16_t mbedtls_byte_order_detector = { 0x100 }; * \param offset Offset from \p data where to put the most significant * byte of the 16 bits unsigned integer \p n. */ -#define MBEDTLS_PUT_UINT16_BE(n, data, offset) \ +#define MBEDTLS_PUT_UINT16_BE(n, data, offset) \ { \ - if (MBEDTLS_IS_BIG_ENDIAN) \ + if (MBEDTLS_IS_BIG_ENDIAN) \ { \ - mbedtls_put_unaligned_uint16((data) + (offset), (uint16_t) (n)); \ + mbedtls_put_unaligned_uint16((data) + (offset), (uint16_t) (n)); \ } \ else \ { \ @@ -384,11 +390,11 @@ static const uint16_t mbedtls_byte_order_detector = { 0x100 }; * byte of the three bytes to build the 24 bits unsigned * integer from. */ -#define MBEDTLS_GET_UINT24_BE(data, offset) \ - ( \ - ((uint32_t) (data)[(offset)] << 16) \ - | ((uint32_t) (data)[(offset) + 1] << 8) \ - | ((uint32_t) (data)[(offset) + 2]) \ +#define MBEDTLS_GET_UINT24_BE(data, offset) \ + ( \ + ((uint32_t) (data)[(offset)] << 16) \ + | ((uint32_t) (data)[(offset) + 1] << 8) \ + | ((uint32_t) (data)[(offset) + 2]) \ ) /** @@ -401,8 +407,8 @@ static const uint16_t mbedtls_byte_order_detector = { 0x100 }; * byte of the 24 bits unsigned integer \p n. */ #define MBEDTLS_PUT_UINT24_BE(n, data, offset) \ - { \ - (data)[(offset)] = MBEDTLS_BYTE_2(n); \ + { \ + (data)[(offset)] = MBEDTLS_BYTE_2(n); \ (data)[(offset) + 1] = MBEDTLS_BYTE_1(n); \ (data)[(offset) + 2] = MBEDTLS_BYTE_0(n); \ } @@ -416,9 +422,9 @@ static const uint16_t mbedtls_byte_order_detector = { 0x100 }; * byte of the three bytes to build the 24 bits unsigned * integer from. */ -#define MBEDTLS_GET_UINT24_LE(data, offset) \ - ( \ - ((uint32_t) (data)[(offset)]) \ +#define MBEDTLS_GET_UINT24_LE(data, offset) \ + ( \ + ((uint32_t) (data)[(offset)]) \ | ((uint32_t) (data)[(offset) + 1] << 8) \ | ((uint32_t) (data)[(offset) + 2] << 16) \ ) @@ -433,8 +439,8 @@ static const uint16_t mbedtls_byte_order_detector = { 0x100 }; * byte of the 24 bits unsigned integer \p n. */ #define MBEDTLS_PUT_UINT24_LE(n, data, offset) \ - { \ - (data)[(offset)] = MBEDTLS_BYTE_0(n); \ + { \ + (data)[(offset)] = MBEDTLS_BYTE_0(n); \ (data)[(offset) + 1] = MBEDTLS_BYTE_1(n); \ (data)[(offset) + 2] = MBEDTLS_BYTE_2(n); \ } @@ -448,8 +454,8 @@ static const uint16_t mbedtls_byte_order_detector = { 0x100 }; * byte of the eight bytes to build the 64 bits unsigned * integer from. */ -#define MBEDTLS_GET_UINT64_BE(data, offset) \ - ((MBEDTLS_IS_BIG_ENDIAN) \ +#define MBEDTLS_GET_UINT64_BE(data, offset) \ + ((MBEDTLS_IS_BIG_ENDIAN) \ ? mbedtls_get_unaligned_uint64((data) + (offset)) \ : MBEDTLS_BSWAP64(mbedtls_get_unaligned_uint64((data) + (offset))) \ ) @@ -463,11 +469,11 @@ static const uint16_t mbedtls_byte_order_detector = { 0x100 }; * \param offset Offset from \p data where to put the most significant * byte of the 64 bits unsigned integer \p n. */ -#define MBEDTLS_PUT_UINT64_BE(n, data, offset) \ +#define MBEDTLS_PUT_UINT64_BE(n, data, offset) \ { \ - if (MBEDTLS_IS_BIG_ENDIAN) \ + if (MBEDTLS_IS_BIG_ENDIAN) \ { \ - mbedtls_put_unaligned_uint64((data) + (offset), (uint64_t) (n)); \ + mbedtls_put_unaligned_uint64((data) + (offset), (uint64_t) (n)); \ } \ else \ { \ @@ -484,8 +490,8 @@ static const uint16_t mbedtls_byte_order_detector = { 0x100 }; * byte of the eight bytes to build the 64 bits unsigned * integer from. */ -#define MBEDTLS_GET_UINT64_LE(data, offset) \ - ((MBEDTLS_IS_BIG_ENDIAN) \ +#define MBEDTLS_GET_UINT64_LE(data, offset) \ + ((MBEDTLS_IS_BIG_ENDIAN) \ ? MBEDTLS_BSWAP64(mbedtls_get_unaligned_uint64((data) + (offset))) \ : mbedtls_get_unaligned_uint64((data) + (offset)) \ ) @@ -499,15 +505,15 @@ static const uint16_t mbedtls_byte_order_detector = { 0x100 }; * \param offset Offset from \p data where to put the least significant * byte of the 64 bits unsigned integer \p n. */ -#define MBEDTLS_PUT_UINT64_LE(n, data, offset) \ +#define MBEDTLS_PUT_UINT64_LE(n, data, offset) \ { \ - if (MBEDTLS_IS_BIG_ENDIAN) \ + if (MBEDTLS_IS_BIG_ENDIAN) \ { \ mbedtls_put_unaligned_uint64((data) + (offset), MBEDTLS_BSWAP64((uint64_t) (n))); \ } \ else \ { \ - mbedtls_put_unaligned_uint64((data) + (offset), (uint64_t) (n)); \ + mbedtls_put_unaligned_uint64((data) + (offset), (uint64_t) (n)); \ } \ } diff --git a/3rdparty/mbedtls/library/md5.c b/3rdparty/mbedtls/library/md5.c index fe17a004..d250edad 100644 --- a/3rdparty/mbedtls/library/md5.c +++ b/3rdparty/mbedtls/library/md5.c @@ -313,8 +313,6 @@ int mbedtls_md5_finish(mbedtls_md5_context *ctx, return 0; } - - /* * output = MD5( input buffer ) */ diff --git a/3rdparty/mbedtls/library/platform_util.c b/3rdparty/mbedtls/library/platform_util.c index bbb8e15e..c6db1a9a 100644 --- a/3rdparty/mbedtls/library/platform_util.c +++ b/3rdparty/mbedtls/library/platform_util.c @@ -20,23 +20,49 @@ /* * Ensure gmtime_r is available even with -std=c99; must be defined before - * mbedtls_config.h, which pulls in glibc's features.h. Harmless on other platforms. + * mbedtls_config.h, which pulls in glibc's features.h. Harmless on other platforms + * except OpenBSD, where it stops us accessing explicit_bzero. */ -#if !defined(_POSIX_C_SOURCE) +#if !defined(_POSIX_C_SOURCE) && !defined(__OpenBSD__) #define _POSIX_C_SOURCE 200112L #endif +#if !defined(_GNU_SOURCE) +/* Clang requires this to get support for explicit_bzero */ +#define _GNU_SOURCE +#endif + #include "common.h" #include "mbedtls/platform_util.h" #include "mbedtls/platform.h" #include + +#ifndef __STDC_WANT_LIB_EXT1__ +#define __STDC_WANT_LIB_EXT1__ 1 /* Ask for the C11 gmtime_s() and memset_s() if available */ +#endif #include +#if defined(_WIN32) +#include +#endif + +// Detect platforms known to support explicit_bzero() +#if defined(__GLIBC__) && (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 25) +#define MBEDTLS_PLATFORM_HAS_EXPLICIT_BZERO 1 +#elif (defined(__FreeBSD__) && (__FreeBSD_version >= 1100037)) || defined(__OpenBSD__) +#define MBEDTLS_PLATFORM_HAS_EXPLICIT_BZERO 1 +#endif + #if !defined(MBEDTLS_PLATFORM_ZEROIZE_ALT) /* - * This implementation should never be optimized out by the compiler + * Where possible, we try to detect the presence of a platform-provided + * secure memset, such as explicit_bzero(), that is safe against being optimized + * out, and use that. + * + * For other platforms, we provide an implementation that aims not to be + * optimized out by the compiler. * * This implementation for mbedtls_platform_zeroize() was inspired from Colin * Percival's blog article at: @@ -51,24 +77,44 @@ * (refer to http://www.daemonology.net/blog/2014-09-05-erratum.html for * details), optimizations of the following form are still possible: * - * if( memset_func != memset ) - * memset_func( buf, 0, len ); + * if (memset_func != memset) + * memset_func(buf, 0, len); * * Note that it is extremely difficult to guarantee that - * mbedtls_platform_zeroize() will not be optimized out by aggressive compilers + * the memset() call will not be optimized out by aggressive compilers * in a portable way. For this reason, Mbed TLS also provides the configuration * option MBEDTLS_PLATFORM_ZEROIZE_ALT, which allows users to configure * mbedtls_platform_zeroize() to use a suitable implementation for their * platform and needs. */ +#if !defined(MBEDTLS_PLATFORM_HAS_EXPLICIT_BZERO) && !defined(__STDC_LIB_EXT1__) \ + && !defined(_WIN32) static void *(*const volatile memset_func)(void *, int, size_t) = memset; +#endif void mbedtls_platform_zeroize(void *buf, size_t len) { MBEDTLS_INTERNAL_VALIDATE(len == 0 || buf != NULL); if (len > 0) { +#if defined(MBEDTLS_PLATFORM_HAS_EXPLICIT_BZERO) + explicit_bzero(buf, len); +#if defined(HAVE_MEMORY_SANITIZER) + /* You'd think that Msan would recognize explicit_bzero() as + * equivalent to bzero(), but it actually doesn't on several + * platforms, including Linux (Ubuntu 20.04). + * https://github.com/google/sanitizers/issues/1507 + * https://github.com/openssh/openssh-portable/commit/74433a19bb6f4cef607680fa4d1d7d81ca3826aa + */ + __msan_unpoison(buf, len); +#endif +#elif defined(__STDC_LIB_EXT1__) + memset_s(buf, len, 0, len); +#elif defined(_WIN32) + SecureZeroMemory(buf, len); +#else memset_func(buf, 0, len); +#endif } } #endif /* MBEDTLS_PLATFORM_ZEROIZE_ALT */ From 3c962b34bc1c15b7fec8c51d3c34952201e9cf1e Mon Sep 17 00:00:00 2001 From: Starry-OvO Date: Thu, 30 Mar 2023 19:07:48 +0800 Subject: [PATCH 8/9] chore: bump client version to 12.38.2.0 --- aiotieba/const.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aiotieba/const.py b/aiotieba/const.py index a2f21ce8..671127a3 100644 --- a/aiotieba/const.py +++ b/aiotieba/const.py @@ -1,4 +1,4 @@ -MAIN_VERSION = "12.38.1.0" +MAIN_VERSION = "12.38.2.0" POST_VERSION = "9.1.0.0" APP_SECURE_SCHEME = "https" From fd5e602d9885b604f1a02fdd1dcc9f296eb618ed Mon Sep 17 00:00:00 2001 From: Starry-OvO Date: Fri, 31 Mar 2023 09:51:25 +0800 Subject: [PATCH 9/9] chore: bump version to 3.3.2 --- aiotieba/__version__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aiotieba/__version__.py b/aiotieba/__version__.py index 5d76f77a..3e2d550b 100644 --- a/aiotieba/__version__.py +++ b/aiotieba/__version__.py @@ -1 +1 @@ -__version__ = "3.3.2a0" +__version__ = "3.3.2"