Browse Source

Update some headers and remove unused fields

Tulir Asokan 2 năm trước cách đây
mục cha
commit
9e37a04f97

+ 8 - 1
mauigpapi/http/base.py

@@ -1,5 +1,5 @@
 # mautrix-instagram - A Matrix-Instagram puppeting bridge.
 # mautrix-instagram - A Matrix-Instagram puppeting bridge.
-# Copyright (C) 2022 Tulir Asokan
+# Copyright (C) 2023 Tulir Asokan
 #
 #
 # This program is free software: you can redistribute it and/or modify
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU Affero General Public License as published by
 # it under the terms of the GNU Affero General Public License as published by
@@ -103,6 +103,7 @@ class BaseAndroidAPI:
             "x-device-id": self.state.device.uuid,
             "x-device-id": self.state.device.uuid,
             "x-ig-app-locale": self.state.device.language,
             "x-ig-app-locale": self.state.device.language,
             "x-ig-device-locale": self.state.device.language,
             "x-ig-device-locale": self.state.device.language,
+            "x-ig-mapped-locale": self.state.device.language,
             "x-pigeon-session-id": self.state.pigeon_session_id,
             "x-pigeon-session-id": self.state.pigeon_session_id,
             "x-pigeon-rawclienttime": str(round(time.time(), 3)),
             "x-pigeon-rawclienttime": str(round(time.time(), 3)),
             "x-ig-connection-speed": f"{random.randint(1000, 3700)}kbps",
             "x-ig-connection-speed": f"{random.randint(1000, 3700)}kbps",
@@ -124,6 +125,7 @@ class BaseAndroidAPI:
             "x-ig-device-id": self.state.device.uuid,
             "x-ig-device-id": self.state.device.uuid,
             "x-ig-android-id": self.state.device.id,
             "x-ig-android-id": self.state.device.id,
             "x-ig-connection-type": self.state.device.connection_type,
             "x-ig-connection-type": self.state.device.connection_type,
+            "x-fb-connection-type": self.state.device.connection_type,
             "x-ig-capabilities": self.state.application.CAPABILITIES,
             "x-ig-capabilities": self.state.application.CAPABILITIES,
             "x-ig-app-id": self.state.application.FACEBOOK_ANALYTICS_APPLICATION_ID,
             "x-ig-app-id": self.state.application.FACEBOOK_ANALYTICS_APPLICATION_ID,
             "user-agent": self.state.user_agent,
             "user-agent": self.state.user_agent,
@@ -135,8 +137,13 @@ class BaseAndroidAPI:
             "ig-u-shbts": self.state.session.shbts,
             "ig-u-shbts": self.state.session.shbts,
             "ig-u-ds-user-id": self.state.session.ds_user_id,
             "ig-u-ds-user-id": self.state.session.ds_user_id,
             "ig-u-rur": self.state.session.rur,
             "ig-u-rur": self.state.session.rur,
+            "ig-intended-user-id": self.state.session.ds_user_id or "0",
+            "ig-client-endpoint": "unknown",
             "x-fb-http-engine": "Liger",
             "x-fb-http-engine": "Liger",
             "x-fb-client-ip": "True",
             "x-fb-client-ip": "True",
+            "x-fb-rmd": "cached=0;state=NO_MATCH",
+            "x-fb-server-cluster": "True",
+            "x-tigon-is-retry": "False",
             "accept-encoding": "gzip",
             "accept-encoding": "gzip",
         }
         }
         return {k: v for k, v in headers.items() if v is not None}
         return {k: v for k, v in headers.items() if v is not None}

+ 21 - 4
mauigpapi/http/thread.py

@@ -1,5 +1,5 @@
 # mautrix-instagram - A Matrix-Instagram puppeting bridge.
 # mautrix-instagram - A Matrix-Instagram puppeting bridge.
-# Copyright (C) 2022 Tulir Asokan
+# Copyright (C) 2023 Tulir Asokan
 #
 #
 # This program is free software: you can redistribute it and/or modify
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU Affero General Public License as published by
 # it under the terms of the GNU Affero General Public License as published by
@@ -40,6 +40,7 @@ class ThreadAPI(BaseAndroidAPI):
         message_limit: int = 10,
         message_limit: int = 10,
         limit: int = 20,
         limit: int = 20,
         pending: bool = False,
         pending: bool = False,
+        spam: bool = False,
         direction: str = "older",
         direction: str = "older",
     ) -> DMInboxResponse:
     ) -> DMInboxResponse:
         query = {
         query = {
@@ -50,8 +51,20 @@ class ThreadAPI(BaseAndroidAPI):
             "thread_message_limit": message_limit,
             "thread_message_limit": message_limit,
             "persistentBadging": "true",
             "persistentBadging": "true",
             "limit": limit,
             "limit": limit,
+            "push_disabled": "true",
+            "is_prefetching": "false",
+        }
+        inbox_type = "inbox"
+        if pending:
+            inbox_type = "pending_inbox"
+            if spam:
+                inbox_type = "spam_inbox"
+        elif not cursor:
+            query["fetch_reason"] = "initial_snapshot"  # can also be manual_refresh
+        headers = {
+            # MainFeedFragment:feed_timeline for limit=0 cold start fetch
+            "ig-client-endpoint": "DirectInboxFragment:direct_inbox",
         }
         }
-        inbox_type = "pending_inbox" if pending else "inbox"
         return await self.std_http_get(
         return await self.std_http_get(
             f"/api/v1/direct_v2/{inbox_type}/", query=query, response_type=DMInboxResponse
             f"/api/v1/direct_v2/{inbox_type}/", query=query, response_type=DMInboxResponse
         )
         )
@@ -80,7 +93,7 @@ class ThreadAPI(BaseAndroidAPI):
             has_more = True
             has_more = True
         while has_more:
         while has_more:
             try:
             try:
-                resp = await self.get_inbox(message_limit=10, cursor=cursor, seq_id=seq_id)
+                resp = await self.get_inbox(cursor=cursor, seq_id=seq_id)
             except IGRateLimitError:
             except IGRateLimitError:
                 self.log.warning(
                 self.log.warning(
                     "Fetching more threads failed due to rate limit. Waiting for "
                     "Fetching more threads failed due to rate limit. Waiting for "
@@ -106,7 +119,7 @@ class ThreadAPI(BaseAndroidAPI):
         self,
         self,
         thread_id: str,
         thread_id: str,
         cursor: str | None = None,
         cursor: str | None = None,
-        limit: int = 10,
+        limit: int = 20,
         direction: str = "older",
         direction: str = "older",
         seq_id: int | None = None,
         seq_id: int | None = None,
     ) -> DMThreadResponse:
     ) -> DMThreadResponse:
@@ -117,6 +130,10 @@ class ThreadAPI(BaseAndroidAPI):
             "seq_id": seq_id,
             "seq_id": seq_id,
             "limit": limit,
             "limit": limit,
         }
         }
+        headers = {
+            "ig-client-endpoint": "DirectThreadFragment:direct_thread",
+            "x-ig-nav-chain": "MainFeedFragment:feed_timeline:1:cold_start::,DirectInboxFragment:direct_inbox:4:on_launch_direct_inbox::",
+        }
         return await self.std_http_get(
         return await self.std_http_get(
             f"/api/v1/direct_v2/threads/{thread_id}/", query=query, response_type=DMThreadResponse
             f"/api/v1/direct_v2/threads/{thread_id}/", query=query, response_type=DMThreadResponse
         )
         )

+ 1 - 17
mauigpapi/state/application.py

@@ -1,5 +1,5 @@
 # mautrix-instagram - A Matrix-Instagram puppeting bridge.
 # mautrix-instagram - A Matrix-Instagram puppeting bridge.
-# Copyright (C) 2020 Tulir Asokan
+# Copyright (C) 2023 Tulir Asokan
 #
 #
 # This program is free software: you can redistribute it and/or modify
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU Affero General Public License as published by
 # it under the terms of the GNU Affero General Public License as published by
@@ -13,35 +13,19 @@
 #
 #
 # You should have received a copy of the GNU Affero General Public License
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
-import json
-import pkgutil
-
 from attr import dataclass
 from attr import dataclass
 
 
 from mautrix.types import SerializableAttrs
 from mautrix.types import SerializableAttrs
 
 
-default_capabilities = json.loads(
-    pkgutil.get_data("mauigpapi.state", "samples/supported-capabilities.json")
-)
-
 
 
 @dataclass
 @dataclass
 class AndroidApplication(SerializableAttrs):
 class AndroidApplication(SerializableAttrs):
     APP_VERSION: str = "256.0.0.18.105"
     APP_VERSION: str = "256.0.0.18.105"
     APP_VERSION_CODE: str = "407842973"
     APP_VERSION_CODE: str = "407842973"
-    BREADCRUMB_KEY: str = "iN4$aGr0m"
     FACEBOOK_ANALYTICS_APPLICATION_ID: str = "567067343352427"
     FACEBOOK_ANALYTICS_APPLICATION_ID: str = "567067343352427"
-    FACEBOOK_OTA_FIELDS: str = (
-        "update%7Bdownload_uri%2Cdownload_uri_delta_base%2Cversion_code_delta_base"
-        "%2Cdownload_uri_delta%2Cfallback_to_full_update%2Cfile_size_delta%2Cversion_code"
-        "%2Cpublished_date%2Cfile_size%2Cota_bundle_type%2Cresources_checksum"
-        "%2Cresources_sha256_checksum%2Callowed_networks%2Crelease_id%7D "
-    )
-    FACEBOOK_ORCA_APPLICATION_ID: str = "124024574287414"
 
 
     BLOKS_VERSION_ID: str = "0928297a84f74885ff39fc1628f8a40da3ef1c467555d555bfd9f8fe1aaacafe"
     BLOKS_VERSION_ID: str = "0928297a84f74885ff39fc1628f8a40da3ef1c467555d555bfd9f8fe1aaacafe"
     CAPABILITIES: str = "3brTv10="
     CAPABILITIES: str = "3brTv10="
-    SUPPORTED_CAPABILITIES: str = default_capabilities
 
 
     EXPERIMENTS: str = ",".join(
     EXPERIMENTS: str = ",".join(
         (
         (

+ 8 - 8
mauigpapi/state/device.py

@@ -1,5 +1,5 @@
 # mautrix-instagram - A Matrix-Instagram puppeting bridge.
 # mautrix-instagram - A Matrix-Instagram puppeting bridge.
-# Copyright (C) 2020 Tulir Asokan
+# Copyright (C) 2023 Tulir Asokan
 #
 #
 # This program is free software: you can redistribute it and/or modify
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU Affero General Public License as published by
 # it under the terms of the GNU Affero General Public License as published by
@@ -15,8 +15,6 @@
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 from typing import Optional, Union
 from typing import Optional, Union
 from uuid import UUID
 from uuid import UUID
-import json
-import pkgutil
 import random
 import random
 import string
 import string
 import time
 import time
@@ -26,8 +24,7 @@ import attr
 
 
 from mautrix.types import SerializableAttrs
 from mautrix.types import SerializableAttrs
 
 
-builds = json.loads(pkgutil.get_data("mauigpapi.state", "samples/builds.json"))
-descriptors = json.loads(pkgutil.get_data("mauigpapi.state", "samples/devices.json"))
+# descriptors = json.loads(pkgutil.get_data("mauigpapi.state", "devices.json"))
 
 
 
 
 @dataclass
 @dataclass
@@ -38,7 +35,6 @@ class AndroidDevice(SerializableAttrs):
     phone_id: Optional[str] = attr.ib(default=None, metadata={"json": "phoneId"})
     phone_id: Optional[str] = attr.ib(default=None, metadata={"json": "phoneId"})
     # Google Play advertising ID
     # Google Play advertising ID
     adid: Optional[str] = None
     adid: Optional[str] = None
-    build: Optional[str] = None
 
 
     language: str = "en_US"
     language: str = "en_US"
     radio_type: str = "wifi-none"
     radio_type: str = "wifi-none"
@@ -75,6 +71,10 @@ class AndroidDevice(SerializableAttrs):
         self.phone_id = str(UUID(int=rand.getrandbits(128), version=4))
         self.phone_id = str(UUID(int=rand.getrandbits(128), version=4))
         self.adid = str(UUID(int=rand.getrandbits(128), version=4))
         self.adid = str(UUID(int=rand.getrandbits(128), version=4))
         self.id = f"android-{''.join(rand.choices(string.hexdigits, k=16))}"
         self.id = f"android-{''.join(rand.choices(string.hexdigits, k=16))}"
-        self.descriptor = rand.choice(descriptors)
+        self.descriptor = rand.choice(
+            [
+                "33/13; 420dpi; 1080x2219; Google/google; Pixel 6; oriole; oriole",
+                "33/13; 560dpi; 1440x2934; Google/google; Pixel 6 Pro; raven; raven",
+            ]
+        )
         self.uuid = str(UUID(int=rand.getrandbits(128), version=4))
         self.uuid = str(UUID(int=rand.getrandbits(128), version=4))
-        self.build = rand.choice(builds)

+ 0 - 0
mauigpapi/state/samples/devices.json → mauigpapi/state/devices.json


+ 0 - 18
mauigpapi/state/samples/builds.json

@@ -1,18 +0,0 @@
-[
-  "NMF26X",
-  "MMB29M",
-  "MRA58K",
-  "NRD90M",
-  "MRA58K",
-  "OPM1.171019.011",
-  "IMM76L",
-  "JZO54K",
-  "JDQ39",
-  "JLS36I",
-  "KTU84P",
-  "LRX22C",
-  "LMY48M",
-  "MMB29V",
-  "NRD91N",
-  "N2G48C"
-]

+ 0 - 26
mauigpapi/state/samples/supported-capabilities.json

@@ -1,26 +0,0 @@
-[
-  {
-    "name": "SUPPORTED_SDK_VERSIONS",
-    "value": "13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0,21.0,22.0,23.0,24.0,25.0,26.0,27.0,28.0,29.0,30.0,31.0,32.0,33.0,34.0,35.0,36.0,37.0,38.0,39.0,40.0,41.0,42.0,43.0,44.0,45.0,46.0,47.0,48.0,49.0,50.0,51.0,52.0,53.0,54.0,55.0,56.0,57.0,58.0,59.0,60.0,61.0,62.0,63.0,64.0,65.0,66.0"
-  },
-  {
-    "name": "FACE_TRACKER_VERSION",
-    "value": 12
-  },
-  {
-    "name": "segmentation",
-    "value": "segmentation_enabled"
-  },
-  {
-    "name": "COMPRESSION",
-    "value": "ETC2_COMPRESSION"
-  },
-  {
-    "name": "world_tracker",
-    "value": "world_tracker_enabled"
-  },
-  {
-    "name": "gyroscope",
-    "value": "gyroscope_enabled"
-  }
-]

+ 1 - 2
mautrix_instagram/commands/auth.py

@@ -1,5 +1,5 @@
 # mautrix-instagram - A Matrix-Instagram puppeting bridge.
 # mautrix-instagram - A Matrix-Instagram puppeting bridge.
-# Copyright (C) 2022 Tulir Asokan
+# Copyright (C) 2023 Tulir Asokan
 #
 #
 # This program is free software: you can redistribute it and/or modify
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU Affero General Public License as published by
 # it under the terms of the GNU Affero General Public License as published by
@@ -46,7 +46,6 @@ async def get_login_state(user: u.User, seed: str) -> tuple[AndroidAPI, AndroidS
         seed = hmac.new(seed.encode("utf-8"), user.mxid.encode("utf-8"), hashlib.sha256).digest()
         seed = hmac.new(seed.encode("utf-8"), user.mxid.encode("utf-8"), hashlib.sha256).digest()
         state.device.generate(seed)
         state.device.generate(seed)
         api = AndroidAPI(state, log=user.api_log, proxy_handler=user.proxy_handler)
         api = AndroidAPI(state, log=user.api_log, proxy_handler=user.proxy_handler)
-        await api.qe_sync_login_experiments()
         user.command_status = {
         user.command_status = {
             "action": "Login",
             "action": "Login",
             "state": state,
             "state": state,

+ 1 - 1
setup.py

@@ -69,7 +69,7 @@ setuptools.setup(
             "example-config.yaml",
             "example-config.yaml",
         ],
         ],
         "mauigpapi.state": [
         "mauigpapi.state": [
-            "samples/*.json",
+            "devices.json",
         ],
         ],
     },
     },
     data_files=[
     data_files=[