Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d86da70eeb | ||
|
|
aa0b4b63a9 | ||
|
|
5f479e46b4 | ||
|
|
1e55d5a9d8 | ||
|
|
077a95b5e7 | ||
|
|
4f1399cf66 | ||
|
|
9590b30e66 | ||
|
|
34f3ee4c3e | ||
|
|
7d655543f5 | ||
|
|
5de3ed0d5e | ||
|
|
74c3287cc0 | ||
|
|
3a7f8072a0 | ||
|
|
5fa91580eb | ||
|
|
d8fbb55438 | ||
|
|
99eb4fed74 | ||
|
|
6b78b841df | ||
|
|
dae852db69 |
2
.github/workflows/pytest.yml
vendored
2
.github/workflows/pytest.yml
vendored
@@ -8,7 +8,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
python-version: [3.8, 3.9]
|
||||
python-version: ["3.8", "3.10"]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
@@ -375,6 +375,12 @@ To have your client's traffic proxied through Hippolyzer the general flow is:
|
||||
* The proxy needs to use content sniffing to figure out which requests are login requests,
|
||||
so make sure your request would pass `MITMProxyEventManager._is_login_request()`
|
||||
|
||||
#### Do I have to do all that?
|
||||
|
||||
You might be able to automate some of it on Linux by using
|
||||
[LinHippoAutoProxy](https://github.com/SaladDais/LinHippoAutoProxy). If you're on Windows or MacOS the
|
||||
above is your only option.
|
||||
|
||||
### Should I use this library to make an SL client in Python?
|
||||
|
||||
No. If you just want to write a client in Python, you should instead look at using
|
||||
|
||||
@@ -11,7 +11,7 @@ import enum
|
||||
import os.path
|
||||
from typing import *
|
||||
|
||||
from PySide2 import QtCore, QtGui, QtWidgets
|
||||
from PySide6 import QtCore, QtGui, QtWidgets
|
||||
|
||||
from hippolyzer.lib.base.datatypes import Vector3
|
||||
from hippolyzer.lib.base.message.message import Block, Message
|
||||
|
||||
@@ -20,13 +20,13 @@ bulk upload, like changing priority or removing a joint.
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import os
|
||||
import pathlib
|
||||
from abc import abstractmethod
|
||||
from typing import *
|
||||
|
||||
from hippolyzer.lib.base import serialization as se
|
||||
from hippolyzer.lib.base.datatypes import UUID
|
||||
from hippolyzer.lib.base.helpers import get_mtime
|
||||
from hippolyzer.lib.base.llanim import Animation
|
||||
from hippolyzer.lib.base.message.message import Block, Message
|
||||
from hippolyzer.lib.proxy import addon_ctx
|
||||
@@ -39,13 +39,6 @@ from hippolyzer.lib.proxy.region import ProxiedRegion
|
||||
from hippolyzer.lib.proxy.sessions import Session, SessionManager
|
||||
|
||||
|
||||
def _get_mtime(path: str):
|
||||
try:
|
||||
return os.stat(path).st_mtime
|
||||
except:
|
||||
return None
|
||||
|
||||
|
||||
class LocalAnimAddon(BaseAddon):
|
||||
# name -> path, only for anims actually from files
|
||||
local_anim_paths: Dict[str, str] = SessionProperty(dict)
|
||||
@@ -176,7 +169,7 @@ class LocalAnimAddon(BaseAddon):
|
||||
anim_data = None
|
||||
if anim_path:
|
||||
old_mtime = cls.local_anim_mtimes.get(anim_name)
|
||||
mtime = _get_mtime(anim_path)
|
||||
mtime = get_mtime(anim_path)
|
||||
if only_if_changed and old_mtime == mtime:
|
||||
return
|
||||
|
||||
|
||||
@@ -16,18 +16,23 @@ import local_mesh
|
||||
AddonManager.hot_reload(local_mesh, require_addons_loaded=True)
|
||||
|
||||
|
||||
def _reorient_coord(coord, orientation):
|
||||
def _reorient_coord(coord, orientation, normals=False):
|
||||
coords = []
|
||||
for axis in orientation:
|
||||
axis_idx = abs(axis) - 1
|
||||
coords.append(coord[axis_idx] if axis >= 0 else 1.0 - coord[axis_idx])
|
||||
if normals:
|
||||
# Normals have a static domain from -1.0 to 1.0, just negate.
|
||||
new_coord = coord[axis_idx] if axis >= 0 else -coord[axis_idx]
|
||||
else:
|
||||
new_coord = coord[axis_idx] if axis >= 0 else 1.0 - coord[axis_idx]
|
||||
coords.append(new_coord)
|
||||
if coord.__class__ in (list, tuple):
|
||||
return coord.__class__(coords)
|
||||
return coord.__class__(*coords)
|
||||
|
||||
|
||||
def _reorient_coord_list(coord_list, orientation):
|
||||
return [_reorient_coord(x, orientation) for x in coord_list]
|
||||
def _reorient_coord_list(coord_list, orientation, normals=False):
|
||||
return [_reorient_coord(x, orientation, normals) for x in coord_list]
|
||||
|
||||
|
||||
def reorient_mesh(orientation):
|
||||
@@ -42,7 +47,7 @@ def reorient_mesh(orientation):
|
||||
# flipping the axes around.
|
||||
material["Position"] = _reorient_coord_list(material["Position"], orientation)
|
||||
# Are you even supposed to do this to the normals?
|
||||
material["Normal"] = _reorient_coord_list(material["Normal"], orientation)
|
||||
material["Normal"] = _reorient_coord_list(material["Normal"], orientation, normals=True)
|
||||
return mesh
|
||||
return _reorienter
|
||||
|
||||
|
||||
@@ -206,7 +206,7 @@ class MessageMirrorAddon(BaseAddon):
|
||||
return
|
||||
caps_source = target_region
|
||||
|
||||
new_base_url = caps_source.caps.get(cap_data.cap_name)
|
||||
new_base_url = caps_source.cap_urls.get(cap_data.cap_name)
|
||||
if not new_base_url:
|
||||
print("No equiv cap?")
|
||||
return
|
||||
|
||||
49
addon_examples/mock_proxy_cap.py
Normal file
49
addon_examples/mock_proxy_cap.py
Normal file
@@ -0,0 +1,49 @@
|
||||
"""
|
||||
Example of proxy-provided caps
|
||||
|
||||
Useful for mocking out a cap that isn't actually implemented by the server
|
||||
while developing the viewer-side pieces of it.
|
||||
|
||||
Implements a cap that accepts an `obj_id` UUID query parameter and returns
|
||||
the name of the object.
|
||||
"""
|
||||
import asyncio
|
||||
import asgiref.wsgi
|
||||
|
||||
from flask import Flask, Response, request
|
||||
|
||||
from hippolyzer.lib.base.datatypes import UUID
|
||||
from hippolyzer.lib.proxy import addon_ctx
|
||||
from hippolyzer.lib.proxy.webapp_cap_addon import WebAppCapAddon
|
||||
|
||||
app = Flask("GetObjectNameCapApp")
|
||||
|
||||
|
||||
@app.route('/')
|
||||
async def get_object_name():
|
||||
# Should always have the current region, the cap handler is bound to one.
|
||||
# Just need to pull it from the `addon_ctx` module's global.
|
||||
obj_mgr = addon_ctx.region.get().objects
|
||||
obj_id = UUID(request.args['obj_id'])
|
||||
obj = obj_mgr.lookup_fullid(obj_id)
|
||||
if not obj:
|
||||
return Response(f"Couldn't find {obj_id!r}", status=404, mimetype="text/plain")
|
||||
|
||||
try:
|
||||
await asyncio.wait_for(obj_mgr.request_object_properties(obj)[0], 1.0)
|
||||
except asyncio.TimeoutError:
|
||||
return Response(f"Timed out requesting {obj_id!r}'s properties", status=500, mimetype="text/plain")
|
||||
|
||||
return Response(obj.Name, mimetype="text/plain")
|
||||
|
||||
|
||||
class MockProxyCapExampleAddon(WebAppCapAddon):
|
||||
# A cap URL with this name will be tied to each region when
|
||||
# the sim is first connected to. The URL will be returned to the
|
||||
# viewer in the Seed if the viewer requests it by name.
|
||||
CAP_NAME = "GetObjectNameExample"
|
||||
# Any asgi app should be fine.
|
||||
APP = asgiref.wsgi.WsgiToAsgi(app)
|
||||
|
||||
|
||||
addons = [MockProxyCapExampleAddon()]
|
||||
@@ -9,7 +9,7 @@ import asyncio
|
||||
import struct
|
||||
from typing import *
|
||||
|
||||
from PySide2.QtGui import QImage
|
||||
from PySide6.QtGui import QImage
|
||||
|
||||
from hippolyzer.lib.base.datatypes import UUID, Vector3, Quaternion
|
||||
from hippolyzer.lib.base.helpers import to_chunks
|
||||
@@ -42,7 +42,7 @@ class PixelArtistAddon(BaseAddon):
|
||||
return
|
||||
img = QImage()
|
||||
with open(filename, "rb") as f:
|
||||
img.loadFromData(f.read(), aformat=None)
|
||||
img.loadFromData(f.read(), format=None)
|
||||
img = img.convertToFormat(QImage.Format_RGBA8888)
|
||||
height = img.height()
|
||||
width = img.width()
|
||||
|
||||
@@ -3,7 +3,7 @@ Example of how to request a Transfer
|
||||
"""
|
||||
from typing import *
|
||||
|
||||
from hippolyzer.lib.base.legacy_inv import InventoryModel, InventoryItem
|
||||
from hippolyzer.lib.base.inventory import InventoryModel, InventoryItem
|
||||
from hippolyzer.lib.base.message.message import Block, Message
|
||||
from hippolyzer.lib.base.templates import (
|
||||
AssetType,
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
Example of how to request an Xfer
|
||||
"""
|
||||
from hippolyzer.lib.base.datatypes import UUID
|
||||
from hippolyzer.lib.base.legacy_inv import InventoryModel
|
||||
from hippolyzer.lib.base.inventory import InventoryModel
|
||||
from hippolyzer.lib.base.templates import XferFilePath, AssetType, InventoryType, WearableType
|
||||
from hippolyzer.lib.base.message.message import Block, Message
|
||||
from hippolyzer.lib.proxy.addon_utils import BaseAddon, show_message
|
||||
|
||||
@@ -2,7 +2,7 @@ import enum
|
||||
import logging
|
||||
import typing
|
||||
|
||||
from PySide2 import QtCore, QtGui
|
||||
from PySide6 import QtCore, QtGui
|
||||
|
||||
from hippolyzer.lib.proxy.region import ProxiedRegion
|
||||
from hippolyzer.lib.proxy.message_logger import FilteringMessageLogger
|
||||
|
||||
@@ -7,6 +7,7 @@ import sys
|
||||
import time
|
||||
from typing import Optional
|
||||
|
||||
import mitmproxy.ctx
|
||||
import mitmproxy.exceptions
|
||||
|
||||
from hippolyzer.lib.base import llsd
|
||||
@@ -131,6 +132,9 @@ def start_proxy(session_manager: SessionManager, extra_addons: Optional[list] =
|
||||
daemon=True,
|
||||
)
|
||||
http_proc.start()
|
||||
# These need to be set for mitmproxy's ASGIApp serving code to work.
|
||||
mitmproxy.ctx.master = None
|
||||
mitmproxy.ctx.log = logging.getLogger("mitmproxy log")
|
||||
|
||||
server = SLSOCKS5Server(session_manager)
|
||||
coro = asyncio.start_server(server.handle_connection, proxy_host, udp_proxy_port)
|
||||
|
||||
@@ -18,7 +18,7 @@ from typing import *
|
||||
|
||||
import multidict
|
||||
from qasync import QEventLoop, asyncSlot
|
||||
from PySide2 import QtCore, QtWidgets, QtGui
|
||||
from PySide6 import QtCore, QtWidgets, QtGui
|
||||
|
||||
from hippolyzer.apps.model import MessageLogModel, MessageLogHeader, RegionListModel
|
||||
from hippolyzer.apps.proxy import start_proxy
|
||||
@@ -35,6 +35,7 @@ from hippolyzer.lib.base.message.message_formatting import (
|
||||
)
|
||||
from hippolyzer.lib.base.message.msgtypes import MsgType
|
||||
from hippolyzer.lib.base.message.template_dict import DEFAULT_TEMPLATE_DICT
|
||||
from hippolyzer.lib.base.settings import SettingDescriptor
|
||||
from hippolyzer.lib.base.ui_helpers import loadUi
|
||||
import hippolyzer.lib.base.serialization as se
|
||||
from hippolyzer.lib.base.network.transport import Direction, SocketUDPTransport
|
||||
@@ -163,6 +164,8 @@ class GUIInteractionManager(BaseInteractionManager, QtCore.QObject):
|
||||
|
||||
|
||||
class GUIProxySettings(ProxySettings):
|
||||
FIRST_RUN: bool = SettingDescriptor(True)
|
||||
|
||||
"""Persistent settings backed by QSettings"""
|
||||
def __init__(self, settings: QtCore.QSettings):
|
||||
super().__init__()
|
||||
@@ -265,7 +268,7 @@ class MessageLogWindow(QtWidgets.QMainWindow):
|
||||
self.lineEditFilter.editingFinished.connect(self.setFilter)
|
||||
self.btnMessageBuilder.clicked.connect(self._sendToMessageBuilder)
|
||||
self.btnCopyRepr.clicked.connect(self._copyRepr)
|
||||
self.actionInstallHTTPSCerts.triggered.connect(self._installHTTPSCerts)
|
||||
self.actionInstallHTTPSCerts.triggered.connect(self.installHTTPSCerts)
|
||||
self.actionManageAddons.triggered.connect(self._manageAddons)
|
||||
self.actionManageFilters.triggered.connect(self._manageFilters)
|
||||
self.actionOpenMessageBuilder.triggered.connect(self._openMessageBuilder)
|
||||
@@ -300,7 +303,7 @@ class MessageLogWindow(QtWidgets.QMainWindow):
|
||||
|
||||
def _populateFilterMenu(self):
|
||||
def _addFilterAction(text, filter_str):
|
||||
filter_action = QtWidgets.QAction(text, self)
|
||||
filter_action = QtGui.QAction(text, self)
|
||||
filter_action.triggered.connect(lambda: self.setFilter(filter_str))
|
||||
self._filterMenu.addAction(filter_action)
|
||||
|
||||
@@ -311,6 +314,9 @@ class MessageLogWindow(QtWidgets.QMainWindow):
|
||||
for preset_name, preset_filter in filters.items():
|
||||
_addFilterAction(preset_name, preset_filter)
|
||||
|
||||
def getFilterDict(self):
|
||||
return self.settings.FILTERS
|
||||
|
||||
def setFilterDict(self, val: dict):
|
||||
self.settings.FILTERS = val
|
||||
self._populateFilterMenu()
|
||||
@@ -441,10 +447,10 @@ class MessageLogWindow(QtWidgets.QMainWindow):
|
||||
with open(log_file, "wb") as f:
|
||||
f.write(export_log_entries(self.model))
|
||||
|
||||
def _installHTTPSCerts(self):
|
||||
def installHTTPSCerts(self):
|
||||
msg = QtWidgets.QMessageBox()
|
||||
msg.setText("This will install the proxy's HTTPS certificate in the config dir"
|
||||
" of any installed viewers, continue?")
|
||||
msg.setText("Would you like to install the proxy's HTTPS certificate in the config dir"
|
||||
" of any installed viewers so that HTTPS connections will work?")
|
||||
yes_btn = msg.addButton("Yes", QtWidgets.QMessageBox.NoRole)
|
||||
msg.addButton("No", QtWidgets.QMessageBox.NoRole)
|
||||
msg.exec()
|
||||
@@ -565,7 +571,7 @@ class MessageBuilderWindow(QtWidgets.QMainWindow):
|
||||
else:
|
||||
self.comboUntrusted.addItem(message_name)
|
||||
|
||||
cap_names = sorted(set(itertools.chain(*[r.caps.keys() for r in self.regionModel.regions])))
|
||||
cap_names = sorted(set(itertools.chain(*[r.cap_urls.keys() for r in self.regionModel.regions])))
|
||||
for cap_name in cap_names:
|
||||
if cap_name.endswith("ProxyWrapper"):
|
||||
continue
|
||||
@@ -596,7 +602,7 @@ class MessageBuilderWindow(QtWidgets.QMainWindow):
|
||||
break
|
||||
self.textRequest.setPlainText(
|
||||
f"""{method} [[{cap_name}]]{path}{params} HTTP/1.1
|
||||
# {region.caps.get(cap_name, "<unknown URI>")}
|
||||
# {region.cap_urls.get(cap_name, "<unknown URI>")}
|
||||
{headers}
|
||||
{body}"""
|
||||
)
|
||||
@@ -697,7 +703,7 @@ class MessageBuilderWindow(QtWidgets.QMainWindow):
|
||||
else:
|
||||
self._sendHTTPRequest(
|
||||
"POST",
|
||||
region.caps["UntrustedSimulatorMessage"],
|
||||
region.cap_urls["UntrustedSimulatorMessage"],
|
||||
{"Content-Type": "application/llsd+xml", "Accept": "application/llsd+xml"},
|
||||
self.llsdSerializer.serialize(msg),
|
||||
)
|
||||
@@ -741,7 +747,7 @@ class MessageBuilderWindow(QtWidgets.QMainWindow):
|
||||
cap_name = match.group(1)
|
||||
cap_url = session.global_caps.get(cap_name)
|
||||
if not cap_url:
|
||||
cap_url = region.caps.get(cap_name)
|
||||
cap_url = region.cap_urls.get(cap_name)
|
||||
if not cap_url:
|
||||
raise ValueError("Don't have a Cap for %s" % cap_name)
|
||||
uri = cap_url + match.group(2)
|
||||
@@ -915,6 +921,10 @@ def gui_main():
|
||||
http_host = None
|
||||
if window.sessionManager.settings.REMOTELY_ACCESSIBLE:
|
||||
http_host = "0.0.0.0"
|
||||
if settings.FIRST_RUN:
|
||||
settings.FIRST_RUN = False
|
||||
# Automatically offer to install the HTTPS certs on first run.
|
||||
window.installHTTPSCerts()
|
||||
start_proxy(
|
||||
session_manager=window.sessionManager,
|
||||
extra_addon_paths=window.getAddonList(),
|
||||
|
||||
@@ -2,6 +2,8 @@ from __future__ import annotations
|
||||
|
||||
import codecs
|
||||
import functools
|
||||
import os
|
||||
|
||||
import pkg_resources
|
||||
import re
|
||||
import weakref
|
||||
@@ -145,3 +147,10 @@ def to_chunks(chunkable: Sequence[_T], chunk_size: int) -> Generator[_T, None, N
|
||||
while chunkable:
|
||||
yield chunkable[:chunk_size]
|
||||
chunkable = chunkable[chunk_size:]
|
||||
|
||||
|
||||
def get_mtime(path):
|
||||
try:
|
||||
return os.stat(path).st_mtime
|
||||
except:
|
||||
return None
|
||||
|
||||
@@ -9,6 +9,7 @@ import dataclasses
|
||||
import datetime as dt
|
||||
import itertools
|
||||
import logging
|
||||
import struct
|
||||
import weakref
|
||||
from io import StringIO
|
||||
from typing import *
|
||||
@@ -33,6 +34,17 @@ LOG = logging.getLogger(__name__)
|
||||
_T = TypeVar("_T")
|
||||
|
||||
|
||||
class SchemaFlagField(SchemaHexInt):
|
||||
"""Like a hex int, but must be serialized as bytes in LLSD due to being a U32"""
|
||||
@classmethod
|
||||
def from_llsd(cls, val: Any) -> int:
|
||||
return struct.unpack("!I", val)[0]
|
||||
|
||||
@classmethod
|
||||
def to_llsd(cls, val: int) -> Any:
|
||||
return struct.pack("!I", val)
|
||||
|
||||
|
||||
def _yield_schema_tokens(reader: StringIO):
|
||||
in_bracket = False
|
||||
# empty str == EOF in Python
|
||||
@@ -76,7 +88,7 @@ class InventoryBase(SchemaBase):
|
||||
if schema_name != cls.SCHEMA_NAME:
|
||||
raise ValueError(f"Expected schema name {schema_name!r} to be {cls.SCHEMA_NAME!r}")
|
||||
|
||||
fields = cls._fields_dict()
|
||||
fields = cls._get_fields_dict()
|
||||
obj_dict = {}
|
||||
for key, val in tok_iter:
|
||||
if key in fields:
|
||||
@@ -100,7 +112,7 @@ class InventoryBase(SchemaBase):
|
||||
def to_writer(self, writer: StringIO):
|
||||
writer.write(f"\t{self.SCHEMA_NAME}\t0\n")
|
||||
writer.write("\t{\n")
|
||||
for field_name, field in self._fields_dict().items():
|
||||
for field_name, field in self._get_fields_dict().items():
|
||||
spec = field.metadata.get("spec")
|
||||
# Not meant to be serialized
|
||||
if not spec:
|
||||
@@ -147,12 +159,38 @@ class InventoryModel(InventoryBase):
|
||||
model.reparent_nodes()
|
||||
return model
|
||||
|
||||
@classmethod
|
||||
def from_llsd(cls, llsd_val: List[Dict]) -> InventoryModel:
|
||||
model = cls()
|
||||
for obj_dict in llsd_val:
|
||||
if InventoryCategory.ID_ATTR in obj_dict:
|
||||
if (obj := InventoryCategory.from_llsd(obj_dict)) is not None:
|
||||
model.add_container(obj)
|
||||
elif InventoryObject.ID_ATTR in obj_dict:
|
||||
if (obj := InventoryObject.from_llsd(obj_dict)) is not None:
|
||||
model.add_container(obj)
|
||||
elif InventoryItem.ID_ATTR in obj_dict:
|
||||
if (obj := InventoryItem.from_llsd(obj_dict)) is not None:
|
||||
model.add_item(obj)
|
||||
else:
|
||||
LOG.warning(f"Unknown object type {obj_dict!r}")
|
||||
model.reparent_nodes()
|
||||
return model
|
||||
|
||||
def to_writer(self, writer: StringIO):
|
||||
for container in self.containers.values():
|
||||
container.to_writer(writer)
|
||||
for item in self.items.values():
|
||||
item.to_writer(writer)
|
||||
|
||||
def to_llsd(self):
|
||||
vals = []
|
||||
for container in self.containers.values():
|
||||
vals.append(container.to_llsd())
|
||||
for item in self.items.values():
|
||||
vals.append(item.to_llsd())
|
||||
return vals
|
||||
|
||||
def add_container(self, container: InventoryContainerBase):
|
||||
self.containers[container.node_id] = container
|
||||
container.model = weakref.proxy(self)
|
||||
@@ -246,7 +284,7 @@ class InventoryCategory(InventoryContainerBase):
|
||||
SCHEMA_NAME: ClassVar[str] = "inv_object"
|
||||
|
||||
cat_id: UUID = schema_field(SchemaUUID)
|
||||
pref_type: str = schema_field(SchemaStr)
|
||||
pref_type: str = schema_field(SchemaStr, llsd_name="preferred_type")
|
||||
owner_id: UUID = schema_field(SchemaUUID)
|
||||
version: int = schema_field(SchemaInt)
|
||||
|
||||
@@ -259,10 +297,10 @@ class InventoryItem(InventoryNodeBase):
|
||||
item_id: UUID = schema_field(SchemaUUID)
|
||||
type: str = schema_field(SchemaStr)
|
||||
inv_type: str = schema_field(SchemaStr)
|
||||
flags: int = schema_field(SchemaHexInt)
|
||||
flags: int = schema_field(SchemaFlagField)
|
||||
name: str = schema_field(SchemaMultilineStr)
|
||||
desc: str = schema_field(SchemaMultilineStr)
|
||||
creation_date: dt.datetime = schema_field(SchemaDate)
|
||||
creation_date: dt.datetime = schema_field(SchemaDate, llsd_name="created_at")
|
||||
permissions: InventoryPermissions = schema_field(InventoryPermissions)
|
||||
sale_info: InventorySaleInfo = schema_field(InventorySaleInfo)
|
||||
asset_id: Optional[UUID] = schema_field(SchemaUUID, default=None)
|
||||
@@ -1,7 +1,6 @@
|
||||
import os
|
||||
import tempfile
|
||||
from io import BytesIO
|
||||
from typing import *
|
||||
|
||||
import defusedxml.ElementTree
|
||||
from glymur import jp2box, Jp2k
|
||||
@@ -10,12 +9,6 @@ from glymur import jp2box, Jp2k
|
||||
jp2box.ET = defusedxml.ElementTree
|
||||
|
||||
|
||||
SL_DEFAULT_ENCODE = {
|
||||
"cratios": (1920.0, 480.0, 120.0, 30.0, 10.0),
|
||||
"irreversible": True,
|
||||
}
|
||||
|
||||
|
||||
class BufferedJp2k(Jp2k):
|
||||
"""
|
||||
For manipulating JP2K from within a binary buffer.
|
||||
@@ -24,12 +17,7 @@ class BufferedJp2k(Jp2k):
|
||||
based on filename, so this is the least brittle approach.
|
||||
"""
|
||||
|
||||
def __init__(self, contents: bytes, encode_kwargs: Optional[Dict] = None):
|
||||
if encode_kwargs is None:
|
||||
self.encode_kwargs = SL_DEFAULT_ENCODE.copy()
|
||||
else:
|
||||
self.encode_kwargs = encode_kwargs
|
||||
|
||||
def __init__(self, contents: bytes):
|
||||
stream = BytesIO(contents)
|
||||
self.temp_file = tempfile.NamedTemporaryFile(delete=False)
|
||||
stream.seek(0)
|
||||
@@ -44,11 +32,12 @@ class BufferedJp2k(Jp2k):
|
||||
os.remove(self.temp_file.name)
|
||||
self.temp_file = None
|
||||
|
||||
def _write(self, img_array, verbose=False, **kwargs):
|
||||
# Glymur normally only lets you control encode params when a write happens within
|
||||
# the constructor. Keep around the encode params from the constructor and pass
|
||||
# them to successive write calls.
|
||||
return super()._write(img_array, verbose=False, **self.encode_kwargs, **kwargs)
|
||||
def _populate_cparams(self, img_array):
|
||||
if self._cratios is None:
|
||||
self._cratios = (1920.0, 480.0, 120.0, 30.0, 10.0)
|
||||
if self._irreversible is None:
|
||||
self.irreversible = True
|
||||
return super()._populate_cparams(img_array)
|
||||
|
||||
def __bytes__(self):
|
||||
with open(self.temp_file.name, "rb") as f:
|
||||
|
||||
@@ -31,6 +31,14 @@ class SchemaFieldSerializer(abc.ABC, Generic[_T]):
|
||||
def serialize(cls, val: _T) -> str:
|
||||
pass
|
||||
|
||||
@classmethod
|
||||
def from_llsd(cls, val: Any) -> _T:
|
||||
return val
|
||||
|
||||
@classmethod
|
||||
def to_llsd(cls, val: _T) -> Any:
|
||||
return val
|
||||
|
||||
|
||||
class SchemaDate(SchemaFieldSerializer[dt.datetime]):
|
||||
@classmethod
|
||||
@@ -41,6 +49,14 @@ class SchemaDate(SchemaFieldSerializer[dt.datetime]):
|
||||
def serialize(cls, val: dt.datetime) -> str:
|
||||
return str(calendar.timegm(val.utctimetuple()))
|
||||
|
||||
@classmethod
|
||||
def from_llsd(cls, val: Any) -> dt.datetime:
|
||||
return dt.datetime.utcfromtimestamp(val)
|
||||
|
||||
@classmethod
|
||||
def to_llsd(cls, val: dt.datetime):
|
||||
return calendar.timegm(val.utctimetuple())
|
||||
|
||||
|
||||
class SchemaHexInt(SchemaFieldSerializer[int]):
|
||||
@classmethod
|
||||
@@ -95,10 +111,11 @@ class SchemaUUID(SchemaFieldSerializer[UUID]):
|
||||
|
||||
|
||||
def schema_field(spec: Type[Union[SchemaBase, SchemaFieldSerializer]], *, default=dataclasses.MISSING, init=True,
|
||||
repr=True, hash=None, compare=True) -> dataclasses.Field: # noqa
|
||||
repr=True, hash=None, compare=True, llsd_name=None) -> dataclasses.Field: # noqa
|
||||
"""Describe a field in the inventory schema and the shape of its value"""
|
||||
return dataclasses.field(
|
||||
metadata={"spec": spec}, default=default, init=init, repr=repr, hash=hash, compare=compare
|
||||
metadata={"spec": spec, "llsd_name": llsd_name}, default=default,
|
||||
init=init, repr=repr, hash=hash, compare=compare,
|
||||
)
|
||||
|
||||
|
||||
@@ -121,8 +138,14 @@ def parse_schema_line(line: str):
|
||||
@dataclasses.dataclass
|
||||
class SchemaBase(abc.ABC):
|
||||
@classmethod
|
||||
def _fields_dict(cls):
|
||||
return {f.name: f for f in dataclasses.fields(cls)}
|
||||
def _get_fields_dict(cls, llsd=False):
|
||||
fields_dict = {}
|
||||
for field in dataclasses.fields(cls):
|
||||
field_name = field.name
|
||||
if llsd:
|
||||
field_name = field.metadata.get("llsd_name") or field_name
|
||||
fields_dict[field_name] = field
|
||||
return fields_dict
|
||||
|
||||
@classmethod
|
||||
def from_str(cls, text: str):
|
||||
@@ -137,6 +160,30 @@ class SchemaBase(abc.ABC):
|
||||
def from_bytes(cls, data: bytes):
|
||||
return cls.from_str(data.decode("utf8"))
|
||||
|
||||
@classmethod
|
||||
def from_llsd(cls, inv_dict: Dict):
|
||||
fields = cls._get_fields_dict(llsd=True)
|
||||
obj_dict = {}
|
||||
for key, val in inv_dict.items():
|
||||
if key in fields:
|
||||
field: dataclasses.Field = fields[key]
|
||||
key = field.name
|
||||
spec = field.metadata.get("spec")
|
||||
# Not a real key, an internal var on our dataclass
|
||||
if not spec:
|
||||
LOG.warning(f"Internal key {key!r}")
|
||||
continue
|
||||
# some kind of nested structure like sale_info
|
||||
if issubclass(spec, SchemaBase):
|
||||
obj_dict[key] = spec.from_llsd(val)
|
||||
elif issubclass(spec, SchemaFieldSerializer):
|
||||
obj_dict[key] = spec.from_llsd(val)
|
||||
else:
|
||||
raise ValueError(f"Unsupported spec for {key!r}, {spec!r}")
|
||||
else:
|
||||
LOG.warning(f"Unknown key {key!r}")
|
||||
return cls._obj_from_dict(obj_dict)
|
||||
|
||||
def to_bytes(self) -> bytes:
|
||||
return self.to_str().encode("utf8")
|
||||
|
||||
@@ -146,6 +193,28 @@ class SchemaBase(abc.ABC):
|
||||
writer.seek(0)
|
||||
return writer.read()
|
||||
|
||||
def to_llsd(self):
|
||||
obj_dict = {}
|
||||
for field_name, field in self._get_fields_dict(llsd=True).items():
|
||||
spec = field.metadata.get("spec")
|
||||
# Not meant to be serialized
|
||||
if not spec:
|
||||
continue
|
||||
|
||||
val = getattr(self, field.name)
|
||||
if val is None:
|
||||
continue
|
||||
|
||||
# Some kind of nested structure like sale_info
|
||||
if isinstance(val, SchemaBase):
|
||||
val = val.to_llsd()
|
||||
elif issubclass(spec, SchemaFieldSerializer):
|
||||
val = spec.to_llsd(val)
|
||||
else:
|
||||
raise ValueError(f"Bad inventory spec {spec!r}")
|
||||
obj_dict[field_name] = val
|
||||
return obj_dict
|
||||
|
||||
@abc.abstractmethod
|
||||
def to_writer(self, writer: StringIO):
|
||||
pass
|
||||
|
||||
@@ -270,8 +270,8 @@ LOD_SEGMENT_SERIALIZER = SegmentSerializer({
|
||||
# Each position represents a single vert.
|
||||
"Position": se.Collection(None, se.Vector3U16(0.0, 1.0)),
|
||||
"TexCoord0": se.Collection(None, se.Vector2U16(0.0, 1.0)),
|
||||
# Normals have a static domain between -1 and 1
|
||||
"Normal": se.Collection(None, se.Vector3U16(0.0, 1.0)),
|
||||
# Normals have a static domain between -1 and 1, so just use that.
|
||||
"Normal": se.Collection(None, se.Vector3U16(-1.0, 1.0)),
|
||||
"Weights": se.Collection(None, VertexWeights)
|
||||
})
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from PySide2.QtCore import QMetaObject
|
||||
from PySide2.QtUiTools import QUiLoader
|
||||
from PySide6.QtCore import QMetaObject
|
||||
from PySide6.QtUiTools import QUiLoader
|
||||
|
||||
|
||||
class UiLoader(QUiLoader):
|
||||
|
||||
@@ -13,7 +13,7 @@ from xml.etree.ElementTree import parse as parse_etree
|
||||
|
||||
from hippolyzer.lib.base.datatypes import UUID
|
||||
from hippolyzer.lib.base.helpers import get_resource_filename
|
||||
from hippolyzer.lib.base.legacy_inv import InventorySaleInfo, InventoryPermissions
|
||||
from hippolyzer.lib.base.inventory import InventorySaleInfo, InventoryPermissions
|
||||
from hippolyzer.lib.base.legacy_schema import SchemaBase, parse_schema_line, SchemaParsingError
|
||||
from hippolyzer.lib.base.templates import WearableType
|
||||
|
||||
|
||||
@@ -181,6 +181,9 @@ class BaseAddon(abc.ABC):
|
||||
def handle_region_changed(self, session: Session, region: ProxiedRegion):
|
||||
pass
|
||||
|
||||
def handle_region_registered(self, session: Session, region: ProxiedRegion):
|
||||
pass
|
||||
|
||||
def handle_circuit_created(self, session: Session, region: ProxiedRegion):
|
||||
pass
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ from types import ModuleType
|
||||
from typing import *
|
||||
|
||||
from hippolyzer.lib.base.datatypes import UUID
|
||||
from hippolyzer.lib.base.helpers import get_mtime
|
||||
from hippolyzer.lib.base.message.message import Message
|
||||
from hippolyzer.lib.base.network.transport import UDPPacket
|
||||
from hippolyzer.lib.proxy import addon_ctx
|
||||
@@ -31,13 +32,6 @@ if TYPE_CHECKING:
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _get_mtime(path):
|
||||
try:
|
||||
return os.stat(path).st_mtime
|
||||
except:
|
||||
return None
|
||||
|
||||
|
||||
class BaseInteractionManager:
|
||||
@abc.abstractmethod
|
||||
async def open_dir(self, caption: str = '', directory: str = '', filter_str: str = '') -> Optional[str]:
|
||||
@@ -187,7 +181,7 @@ class AddonManager:
|
||||
def _check_hotreloads(cls):
|
||||
"""Mark addons that rely on changed files for reloading"""
|
||||
for filename, importers in cls.HOTRELOAD_IMPORTERS.items():
|
||||
mtime = _get_mtime(filename)
|
||||
mtime = get_mtime(filename)
|
||||
if not mtime or mtime == cls.FILE_MTIMES.get(filename, None):
|
||||
continue
|
||||
|
||||
@@ -216,7 +210,7 @@ class AddonManager:
|
||||
# Mark the caller as having imported (and being dependent on) `module`
|
||||
stack = inspect.stack()[1]
|
||||
cls.HOTRELOAD_IMPORTERS[imported_file].add(stack.filename)
|
||||
cls.FILE_MTIMES[imported_file] = _get_mtime(imported_file)
|
||||
cls.FILE_MTIMES[imported_file] = get_mtime(imported_file)
|
||||
|
||||
importing_spec = next((s for s in cls.BASE_ADDON_SPECS if s.origin == stack.filename), None)
|
||||
imported_spec = next((s for s in cls.BASE_ADDON_SPECS if s.origin == imported_file), None)
|
||||
@@ -264,7 +258,7 @@ class AddonManager:
|
||||
for spec in cls.BASE_ADDON_SPECS[:]:
|
||||
had_mod = spec.name in cls.FRESH_ADDON_MODULES
|
||||
try:
|
||||
mtime = _get_mtime(spec.origin)
|
||||
mtime = get_mtime(spec.origin)
|
||||
mtime_changed = mtime != cls.FILE_MTIMES.get(spec.origin, None)
|
||||
if not mtime_changed and had_mod:
|
||||
continue
|
||||
@@ -527,6 +521,11 @@ class AddonManager:
|
||||
with addon_ctx.push(session, region):
|
||||
return cls._call_all_addon_hooks("handle_region_changed", session, region)
|
||||
|
||||
@classmethod
|
||||
def handle_region_registered(cls, session: Session, region: ProxiedRegion):
|
||||
with addon_ctx.push(session, region):
|
||||
return cls._call_all_addon_hooks("handle_region_registered", session, region)
|
||||
|
||||
@classmethod
|
||||
def handle_circuit_created(cls, session: Session, region: ProxiedRegion):
|
||||
with addon_ctx.push(session, region):
|
||||
|
||||
@@ -24,6 +24,10 @@ class CapType(enum.Enum):
|
||||
WRAPPER = enum.auto()
|
||||
PROXY_ONLY = enum.auto()
|
||||
|
||||
@property
|
||||
def fake(self) -> bool:
|
||||
return self == CapType.PROXY_ONLY or self == CapType.WRAPPER
|
||||
|
||||
|
||||
class SerializedCapData(typing.NamedTuple):
|
||||
cap_name: typing.Optional[str] = None
|
||||
|
||||
@@ -20,7 +20,7 @@ class ProxyCapsClient(CapsClient):
|
||||
def _get_caps(self) -> Optional[CAPS_DICT]:
|
||||
if not self._region:
|
||||
return None
|
||||
return self._region.caps
|
||||
return self._region.cap_urls
|
||||
|
||||
def _request_fixups(self, cap_or_url: str, headers: Dict, proxy: Optional[bool], ssl: Any):
|
||||
# We want to proxy this through Hippolyzer
|
||||
|
||||
@@ -83,16 +83,19 @@ class MITMProxyEventManager:
|
||||
finally:
|
||||
# If someone has taken this request out of the regular callback flow,
|
||||
# they'll manually send a callback at some later time.
|
||||
if not flow.taken:
|
||||
self.to_proxy_queue.put(("callback", flow.id, flow.get_state()))
|
||||
if not flow.taken and not flow.resumed:
|
||||
# Addon hasn't taken ownership of this flow, send it back to mitmproxy
|
||||
# ourselves.
|
||||
flow.resume()
|
||||
|
||||
def _handle_request(self, flow: HippoHTTPFlow):
|
||||
url = flow.request.url
|
||||
cap_data = self.session_manager.resolve_cap(url)
|
||||
flow.cap_data = cap_data
|
||||
# Don't do anything special with the proxy's own requests,
|
||||
# we only pass it through for logging purposes.
|
||||
if flow.request_injected:
|
||||
# Don't do anything special with the proxy's own requests unless the requested
|
||||
# URL can only be handled by the proxy. Ideally we only pass the request through
|
||||
# for logging purposes.
|
||||
if flow.request_injected and (not cap_data or not cap_data.type.fake):
|
||||
return
|
||||
|
||||
# The local asset repo gets first bite at the apple
|
||||
@@ -104,7 +107,7 @@ class MITMProxyEventManager:
|
||||
AddonManager.handle_http_request(flow)
|
||||
if cap_data and cap_data.cap_name.endswith("ProxyWrapper"):
|
||||
orig_cap_name = cap_data.cap_name.rsplit("ProxyWrapper", 1)[0]
|
||||
orig_cap_url = cap_data.region().caps[orig_cap_name]
|
||||
orig_cap_url = cap_data.region().cap_urls[orig_cap_name]
|
||||
split_orig_url = urllib.parse.urlsplit(orig_cap_url)
|
||||
orig_cap_host = split_orig_url[1]
|
||||
|
||||
@@ -135,7 +138,7 @@ class MITMProxyEventManager:
|
||||
)
|
||||
elif cap_data and cap_data.asset_server_cap:
|
||||
# Both the wrapper request and the actual asset server request went through
|
||||
# the proxy
|
||||
# the proxy. Don't bother trying the redirect strategy anymore.
|
||||
self._asset_server_proxied = True
|
||||
logging.warning("noproxy not used, switching to URI rewrite strategy")
|
||||
elif cap_data and cap_data.cap_name == "EventQueueGet":
|
||||
@@ -159,6 +162,17 @@ class MITMProxyEventManager:
|
||||
"Connection": "close",
|
||||
},
|
||||
)
|
||||
elif cap_data and cap_data.cap_name == "Seed":
|
||||
# Drop any proxy-only caps from the seed request we send to the server,
|
||||
# add those cap names as metadata so we know to send their urls in the response
|
||||
parsed_seed: List[str] = llsd.parse_xml(flow.request.content)
|
||||
flow.metadata['needed_proxy_caps'] = []
|
||||
for known_cap_name, (known_cap_type, known_cap_url) in cap_data.region().caps.items():
|
||||
if known_cap_type == CapType.PROXY_ONLY and known_cap_name in parsed_seed:
|
||||
parsed_seed.remove(known_cap_name)
|
||||
flow.metadata['needed_proxy_caps'].append(known_cap_name)
|
||||
if flow.metadata['needed_proxy_caps']:
|
||||
flow.request.content = llsd.format_xml(parsed_seed)
|
||||
elif not cap_data:
|
||||
if self._is_login_request(flow):
|
||||
# Not strictly a Cap, but makes it easier to filter on.
|
||||
@@ -198,10 +212,14 @@ class MITMProxyEventManager:
|
||||
def _handle_response(self, flow: HippoHTTPFlow):
|
||||
message_logger = self.session_manager.message_logger
|
||||
if message_logger:
|
||||
message_logger.log_http_response(flow)
|
||||
try:
|
||||
message_logger.log_http_response(flow)
|
||||
except:
|
||||
logging.exception("Failed while logging HTTP flow")
|
||||
|
||||
# Don't handle responses for requests injected by the proxy
|
||||
if flow.request_injected:
|
||||
# Don't process responses for requests or responses injected by the proxy.
|
||||
# We already processed it, it came from us!
|
||||
if flow.request_injected or flow.response_injected:
|
||||
return
|
||||
|
||||
status = flow.response.status_code
|
||||
@@ -262,7 +280,10 @@ class MITMProxyEventManager:
|
||||
for cap_name in wrappable_caps:
|
||||
if cap_name in parsed:
|
||||
parsed[cap_name] = region.register_wrapper_cap(cap_name)
|
||||
flow.response.content = llsd.format_pretty_xml(parsed)
|
||||
# Send the client the URLs for any proxy-only caps it requested
|
||||
for cap_name in flow.metadata['needed_proxy_caps']:
|
||||
parsed[cap_name] = region.cap_urls[cap_name]
|
||||
flow.response.content = llsd.format_xml(parsed)
|
||||
elif cap_data.cap_name == "EventQueueGet":
|
||||
parsed_eq_resp = llsd.parse_xml(flow.response.content)
|
||||
if parsed_eq_resp:
|
||||
@@ -281,7 +302,7 @@ class MITMProxyEventManager:
|
||||
# HACK: see note in above request handler for EventQueueGet
|
||||
req_ack_id = llsd.parse_xml(flow.request.content)["ack"]
|
||||
eq_manager.cache_last_poll_response(req_ack_id, parsed_eq_resp)
|
||||
flow.response.content = llsd.format_pretty_xml(parsed_eq_resp)
|
||||
flow.response.content = llsd.format_xml(parsed_eq_resp)
|
||||
elif cap_data.cap_name in self.UPLOAD_CREATING_CAPS:
|
||||
if not region:
|
||||
return
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import copy
|
||||
import multiprocessing
|
||||
import weakref
|
||||
from typing import *
|
||||
from typing import Optional
|
||||
|
||||
@@ -20,12 +22,14 @@ class HippoHTTPFlow:
|
||||
Hides the nastiness of writing to flow.metadata so we can pass
|
||||
state back and forth between the two proxies
|
||||
"""
|
||||
__slots__ = ("flow",)
|
||||
__slots__ = ("flow", "callback_queue", "resumed", "taken")
|
||||
|
||||
def __init__(self, flow: HTTPFlow):
|
||||
def __init__(self, flow: HTTPFlow, callback_queue: Optional[multiprocessing.Queue] = None):
|
||||
self.flow: HTTPFlow = flow
|
||||
self.resumed = False
|
||||
self.taken = False
|
||||
self.callback_queue = weakref.ref(callback_queue) if callback_queue else None
|
||||
meta = self.flow.metadata
|
||||
meta.setdefault("taken", False)
|
||||
meta.setdefault("can_stream", True)
|
||||
meta.setdefault("response_injected", False)
|
||||
meta.setdefault("request_injected", False)
|
||||
@@ -91,12 +95,21 @@ class HippoHTTPFlow:
|
||||
|
||||
def take(self) -> HippoHTTPFlow:
|
||||
"""Don't automatically pass this flow back to mitmproxy"""
|
||||
self.metadata["taken"] = True
|
||||
# TODO: Having to explicitly take / release Flows to use them in an async
|
||||
# context is kind of janky. The HTTP callback handling code should probably
|
||||
# be made totally async, including the addon hooks. Would coroutine per-callback
|
||||
# be expensive?
|
||||
assert not self.taken and not self.resumed
|
||||
self.taken = True
|
||||
return self
|
||||
|
||||
@property
|
||||
def taken(self) -> bool:
|
||||
return self.metadata["taken"]
|
||||
def resume(self):
|
||||
"""Release the HTTP flow back to the normal processing flow"""
|
||||
assert self.callback_queue
|
||||
assert not self.resumed
|
||||
self.taken = False
|
||||
self.resumed = True
|
||||
self.callback_queue().put(("callback", self.flow.id, self.get_state()))
|
||||
|
||||
@property
|
||||
def is_replay(self) -> bool:
|
||||
@@ -120,11 +133,14 @@ class HippoHTTPFlow:
|
||||
flow: Optional[HTTPFlow] = HTTPFlow.from_state(flow_state)
|
||||
assert flow is not None
|
||||
cap_data_ser = flow.metadata.get("cap_data_ser")
|
||||
callback_queue = None
|
||||
if session_manager:
|
||||
callback_queue = session_manager.flow_context.to_proxy_queue
|
||||
if cap_data_ser is not None:
|
||||
flow.metadata["cap_data"] = CapData.deserialize(cap_data_ser, session_manager)
|
||||
else:
|
||||
flow.metadata["cap_data"] = None
|
||||
return cls(flow)
|
||||
return cls(flow, callback_queue)
|
||||
|
||||
def copy(self) -> HippoHTTPFlow:
|
||||
# HACK: flow.copy() expects the flow to be fully JSON serializable, but
|
||||
|
||||
@@ -136,9 +136,6 @@ class IPCInterceptionAddon:
|
||||
if event_type == "callback":
|
||||
orig_flow = self.intercepted_flows.pop(flow_id)
|
||||
orig_flow.set_state(flow_state)
|
||||
# Remove the taken flag from the flow if present, the flow by definition
|
||||
# isn't take()n anymore once it's been passed back to the proxy.
|
||||
orig_flow.metadata.pop("taken", None)
|
||||
elif event_type == "replay":
|
||||
flow: HTTPFlow = HTTPFlow.from_state(flow_state)
|
||||
# mitmproxy won't replay intercepted flows, this is an old flow so
|
||||
@@ -189,7 +186,10 @@ class IPCInterceptionAddon:
|
||||
flow.response.headers["Content-Encoding"] = "identity"
|
||||
|
||||
def response(self, flow: HTTPFlow):
|
||||
if flow.metadata["response_injected"]:
|
||||
cap_data: typing.Optional[SerializedCapData] = flow.metadata.get("cap_data")
|
||||
if flow.metadata["response_injected"] and cap_data and cap_data.asset_server_cap:
|
||||
# Don't bother intercepting asset server requests where we injected a response.
|
||||
# We don't want to log them and they don't need any more processing by user hooks.
|
||||
return
|
||||
self._queue_flow_interception("response", flow)
|
||||
|
||||
|
||||
@@ -51,10 +51,11 @@ class ProxiedRegion(BaseClientRegion):
|
||||
self.cache_id: Optional[UUID] = None
|
||||
self.circuit: Optional[ProxiedCircuit] = None
|
||||
self.circuit_addr = circuit_addr
|
||||
self._caps = CapsMultiDict()
|
||||
self.caps = CapsMultiDict()
|
||||
# Reverse lookup for URL -> cap data
|
||||
self._caps_url_lookup: Dict[str, Tuple[CapType, str]] = {}
|
||||
if seed_cap:
|
||||
self._caps["Seed"] = (CapType.NORMAL, seed_cap)
|
||||
self.caps["Seed"] = (CapType.NORMAL, seed_cap)
|
||||
self.session: Callable[[], Session] = weakref.ref(session)
|
||||
self.message_handler: MessageHandler[Message, str] = MessageHandler()
|
||||
self.http_message_handler: MessageHandler[HippoHTTPFlow, str] = MessageHandler()
|
||||
@@ -77,8 +78,8 @@ class ProxiedRegion(BaseClientRegion):
|
||||
self._name = val
|
||||
|
||||
@property
|
||||
def caps(self):
|
||||
return multidict.MultiDict((x, y[1]) for x, y in self._caps.items())
|
||||
def cap_urls(self) -> multidict.MultiDict[str, str]:
|
||||
return multidict.MultiDict((x, y[1]) for x, y in self.caps.items())
|
||||
|
||||
@property
|
||||
def global_pos(self) -> Vector3:
|
||||
@@ -95,12 +96,12 @@ class ProxiedRegion(BaseClientRegion):
|
||||
def update_caps(self, caps: Mapping[str, str]):
|
||||
for cap_name, cap_url in caps.items():
|
||||
if isinstance(cap_url, str) and cap_url.startswith('http'):
|
||||
self._caps.add(cap_name, (CapType.NORMAL, cap_url))
|
||||
self.caps.add(cap_name, (CapType.NORMAL, cap_url))
|
||||
self._recalc_caps()
|
||||
|
||||
def _recalc_caps(self):
|
||||
self._caps_url_lookup.clear()
|
||||
for name, cap_info in self._caps.items():
|
||||
for name, cap_info in self.caps.items():
|
||||
cap_type, cap_url = cap_info
|
||||
self._caps_url_lookup[cap_url] = (cap_type, name)
|
||||
|
||||
@@ -111,15 +112,15 @@ class ProxiedRegion(BaseClientRegion):
|
||||
caps like ViewerAsset may be the same globally and wouldn't let us infer
|
||||
which session / region the request was related to without a wrapper
|
||||
"""
|
||||
parsed = list(urllib.parse.urlsplit(self._caps[name][1]))
|
||||
seed_id = self._caps["Seed"][1].split("/")[-1].encode("utf8")
|
||||
parsed = list(urllib.parse.urlsplit(self.caps[name][1]))
|
||||
seed_id = self.caps["Seed"][1].split("/")[-1].encode("utf8")
|
||||
# Give it a unique domain tied to the current Seed URI
|
||||
parsed[1] = f"{name.lower()}-{hashlib.sha256(seed_id).hexdigest()[:16]}.hippo-proxy.localhost"
|
||||
# Force the URL to HTTP, we're going to handle the request ourselves so it doesn't need
|
||||
# to be secure. This should save on expensive TLS context setup for each req.
|
||||
parsed[0] = "http"
|
||||
wrapper_url = urllib.parse.urlunsplit(parsed)
|
||||
self._caps.add(name + "ProxyWrapper", (CapType.WRAPPER, wrapper_url))
|
||||
self.caps.add(name + "ProxyWrapper", (CapType.WRAPPER, wrapper_url))
|
||||
self._recalc_caps()
|
||||
return wrapper_url
|
||||
|
||||
@@ -127,14 +128,14 @@ class ProxiedRegion(BaseClientRegion):
|
||||
"""
|
||||
Register a cap to be completely handled by the proxy
|
||||
"""
|
||||
cap_url = f"https://caps.hippo-proxy.localhost/cap/{uuid.uuid4()!s}"
|
||||
self._caps.add(name, (CapType.PROXY_ONLY, cap_url))
|
||||
cap_url = f"http://{uuid.uuid4()!s}.caps.hippo-proxy.localhost"
|
||||
self.caps.add(name, (CapType.PROXY_ONLY, cap_url))
|
||||
self._recalc_caps()
|
||||
return cap_url
|
||||
|
||||
def register_temporary_cap(self, name: str, cap_url: str):
|
||||
"""Register a Cap that only has meaning the first time it's used"""
|
||||
self._caps.add(name, (CapType.TEMPORARY, cap_url))
|
||||
self.caps.add(name, (CapType.TEMPORARY, cap_url))
|
||||
self._recalc_caps()
|
||||
|
||||
def resolve_cap(self, url: str, consume=True) -> Optional[Tuple[str, str, CapType]]:
|
||||
@@ -143,9 +144,9 @@ class ProxiedRegion(BaseClientRegion):
|
||||
cap_type, name = self._caps_url_lookup[cap_url]
|
||||
if cap_type == CapType.TEMPORARY and consume:
|
||||
# Resolving a temporary cap pops it out of the dict
|
||||
temporary_caps = self._caps.popall(name)
|
||||
temporary_caps = self.caps.popall(name)
|
||||
temporary_caps.remove((cap_type, cap_url))
|
||||
self._caps.extend((name, x) for x in temporary_caps)
|
||||
self.caps.extend((name, x) for x in temporary_caps)
|
||||
self._recalc_caps()
|
||||
return name, cap_url, cap_type
|
||||
return None
|
||||
|
||||
@@ -99,12 +99,12 @@ class Session(BaseClientSession):
|
||||
|
||||
for region in self.regions:
|
||||
if region.circuit_addr == circuit_addr:
|
||||
if seed_url and region.caps.get("Seed") != seed_url:
|
||||
if seed_url and region.cap_urls.get("Seed") != seed_url:
|
||||
region.update_caps({"Seed": seed_url})
|
||||
if handle:
|
||||
region.handle = handle
|
||||
return region
|
||||
if seed_url and region.caps.get("Seed") == seed_url:
|
||||
if seed_url and region.cap_urls.get("Seed") == seed_url:
|
||||
return region
|
||||
|
||||
if not circuit_addr:
|
||||
@@ -113,6 +113,7 @@ class Session(BaseClientSession):
|
||||
logging.info("Registering region for %r" % (circuit_addr,))
|
||||
region = ProxiedRegion(circuit_addr, seed_url, self, handle=handle)
|
||||
self.regions.append(region)
|
||||
AddonManager.handle_region_registered(self, region)
|
||||
return region
|
||||
|
||||
def region_by_circuit_addr(self, circuit_addr) -> Optional[ProxiedRegion]:
|
||||
|
||||
46
hippolyzer/lib/proxy/webapp_cap_addon.py
Normal file
46
hippolyzer/lib/proxy/webapp_cap_addon.py
Normal file
@@ -0,0 +1,46 @@
|
||||
import abc
|
||||
|
||||
from mitmproxy.addons import asgiapp
|
||||
from mitmproxy.controller import DummyReply
|
||||
|
||||
from hippolyzer.lib.proxy.addon_utils import BaseAddon
|
||||
from hippolyzer.lib.proxy.http_flow import HippoHTTPFlow
|
||||
from hippolyzer.lib.proxy.region import ProxiedRegion
|
||||
from hippolyzer.lib.proxy.sessions import Session, SessionManager
|
||||
|
||||
|
||||
async def serve(app, flow: HippoHTTPFlow):
|
||||
"""Serve a request based on a Hippolyzer HTTP flow using a provided app"""
|
||||
# Shove this on mitmproxy's flow object so asgiapp doesn't explode when it tries
|
||||
# to commit the flow reply. Our take / commit semantics are different than mitmproxy
|
||||
# proper, so we ignore what mitmproxy sets here anyhow.
|
||||
flow.flow.reply = DummyReply()
|
||||
flow.flow.reply.take()
|
||||
await asgiapp.serve(app, flow.flow)
|
||||
flow.flow.reply = None
|
||||
# Send the modified flow object back to mitmproxy
|
||||
flow.resume()
|
||||
|
||||
|
||||
class WebAppCapAddon(BaseAddon, abc.ABC):
|
||||
"""
|
||||
Addon that provides a cap via an ASGI webapp
|
||||
|
||||
Handles all registration of the cap URL and routing of the request.
|
||||
"""
|
||||
CAP_NAME: str
|
||||
APP: any
|
||||
|
||||
def handle_region_registered(self, session: Session, region: ProxiedRegion):
|
||||
# Register a fake URL for our cap. This will add the cap URL to the Seed
|
||||
# response that gets sent back to the client if that cap name was requested.
|
||||
if self.CAP_NAME not in region.cap_urls:
|
||||
region.register_proxy_cap(self.CAP_NAME)
|
||||
|
||||
def handle_http_request(self, session_manager: SessionManager, flow: HippoHTTPFlow):
|
||||
if flow.cap_data.cap_name != self.CAP_NAME:
|
||||
return
|
||||
# This request may take a while to generate a response for, take it out of the normal
|
||||
# HTTP handling flow and handle it in a async task.
|
||||
# TODO: Make all HTTP handling hooks async so this isn't necessary
|
||||
self._schedule_task(serve(self.APP, flow.take()))
|
||||
@@ -1,65 +1,66 @@
|
||||
aiohttp==3.7.4.post0
|
||||
aiohttp==3.8.1
|
||||
aiosignal==1.2.0
|
||||
appdirs==1.4.4
|
||||
Arpeggio==1.10.2
|
||||
asgiref==3.4.1
|
||||
async-timeout==3.0.1
|
||||
async-timeout==4.0.1
|
||||
attrs==21.2.0
|
||||
blinker==1.4
|
||||
Brotli==1.0.9
|
||||
certifi==2021.5.30
|
||||
cffi==1.14.6
|
||||
chardet==4.0.0
|
||||
charset-normalizer==2.0.3
|
||||
click==8.0.1
|
||||
cryptography==3.4.7
|
||||
certifi==2021.10.8
|
||||
cffi==1.15.0
|
||||
charset-normalizer==2.0.9
|
||||
click==8.0.3
|
||||
cryptography==3.4.8
|
||||
defusedxml==0.7.1
|
||||
Flask==2.0.1
|
||||
Glymur==0.9.3
|
||||
Flask==2.0.2
|
||||
frozenlist==1.2.0
|
||||
Glymur==0.9.6
|
||||
h11==0.12.0
|
||||
h2==4.0.0
|
||||
h2==4.1.0
|
||||
hpack==4.0.0
|
||||
hyperframe==6.0.1
|
||||
idna==2.10
|
||||
itsdangerous==2.0.1
|
||||
jedi==0.18.0
|
||||
Jinja2==3.0.1
|
||||
jedi==0.18.1
|
||||
Jinja2==3.0.3
|
||||
kaitaistruct==0.9
|
||||
lazy-object-proxy==1.6.0
|
||||
ldap3==2.9
|
||||
ldap3==2.9.1
|
||||
llbase==1.2.11
|
||||
lxml==4.6.3
|
||||
lxml==4.6.4
|
||||
MarkupSafe==2.0.1
|
||||
mitmproxy==7.0.2
|
||||
msgpack==1.0.2
|
||||
multidict==5.1.0
|
||||
numpy==1.21.0
|
||||
parso==0.8.2
|
||||
mitmproxy==7.0.4
|
||||
msgpack==1.0.3
|
||||
multidict==5.2.0
|
||||
numpy==1.21.4
|
||||
parso==0.8.3
|
||||
passlib==1.7.4
|
||||
prompt-toolkit==3.0.19
|
||||
protobuf==3.17.3
|
||||
ptpython==3.0.19
|
||||
prompt-toolkit==3.0.23
|
||||
protobuf==3.18.1
|
||||
ptpython==3.0.20
|
||||
publicsuffix2==2.20191221
|
||||
pyasn1==0.4.8
|
||||
pycparser==2.20
|
||||
Pygments==2.9.0
|
||||
pycparser==2.21
|
||||
Pygments==2.10.0
|
||||
pyOpenSSL==20.0.1
|
||||
pyparsing==2.4.7
|
||||
pyperclip==1.8.2
|
||||
PySide2==5.15.2
|
||||
qasync==0.17.0
|
||||
PySide6==6.2.2
|
||||
qasync==0.22.0
|
||||
recordclass==0.14.3
|
||||
requests==2.26.0
|
||||
ruamel.yaml==0.17.10
|
||||
ruamel.yaml==0.17.16
|
||||
ruamel.yaml.clib==0.2.6
|
||||
shiboken2==5.15.2
|
||||
shiboken6==6.2.2
|
||||
six==1.16.0
|
||||
sortedcontainers==2.4.0
|
||||
tornado==6.1
|
||||
typing-extensions==3.10.0.0
|
||||
urllib3==1.26.6
|
||||
typing-extensions==4.0.1
|
||||
urllib3==1.26.7
|
||||
urwid==2.1.2
|
||||
wcwidth==0.2.5
|
||||
Werkzeug==2.0.1
|
||||
Werkzeug==2.0.2
|
||||
wsproto==1.0.0
|
||||
yarl==1.6.3
|
||||
yarl==1.7.2
|
||||
zstandard==0.15.2
|
||||
|
||||
7
setup.py
7
setup.py
@@ -25,7 +25,7 @@ from setuptools import setup, find_packages
|
||||
|
||||
here = path.abspath(path.dirname(__file__))
|
||||
|
||||
version = '0.7.1'
|
||||
version = '0.8.0'
|
||||
|
||||
with open(path.join(here, 'README.md')) as readme_fh:
|
||||
readme = readme_fh.read()
|
||||
@@ -44,6 +44,7 @@ setup(
|
||||
"Programming Language :: Python :: 3 :: Only",
|
||||
"Programming Language :: Python :: 3.8",
|
||||
"Programming Language :: Python :: 3.9",
|
||||
"Programming Language :: Python :: 3.10",
|
||||
"Programming Language :: Python :: Implementation :: CPython",
|
||||
"Topic :: System :: Networking :: Monitoring",
|
||||
"Topic :: Software Development :: Libraries :: Python Modules",
|
||||
@@ -92,10 +93,10 @@ setup(
|
||||
# For REPLs
|
||||
'ptpython<4.0',
|
||||
# JP2 codec
|
||||
'Glymur<1.0',
|
||||
'Glymur<0.9.7',
|
||||
'numpy<2.0',
|
||||
# These could be in extras_require if you don't want a GUI.
|
||||
'pyside2<6.0',
|
||||
'pyside6',
|
||||
'qasync',
|
||||
],
|
||||
tests_require=[
|
||||
|
||||
@@ -9,20 +9,21 @@ from cx_Freeze import setup, Executable
|
||||
|
||||
# We don't need any of these and they make the archive huge.
|
||||
TO_DELETE = [
|
||||
"lib/PySide2/Qt3DRender.pyd",
|
||||
"lib/PySide2/Qt53DRender.dll",
|
||||
"lib/PySide2/Qt5Charts.dll",
|
||||
"lib/PySide2/Qt5Location.dll",
|
||||
"lib/PySide2/Qt5Pdf.dll",
|
||||
"lib/PySide2/Qt5Quick.dll",
|
||||
"lib/PySide2/Qt5WebEngineCore.dll",
|
||||
"lib/PySide2/QtCharts.pyd",
|
||||
"lib/PySide2/QtMultimedia.pyd",
|
||||
"lib/PySide2/QtOpenGLFunctions.pyd",
|
||||
"lib/PySide2/QtOpenGLFunctions.pyi",
|
||||
"lib/PySide2/d3dcompiler_47.dll",
|
||||
"lib/PySide2/opengl32sw.dll",
|
||||
"lib/PySide2/translations",
|
||||
"lib/PySide6/Qt6DRender.pyd",
|
||||
"lib/PySide6/Qt63DRender.dll",
|
||||
"lib/PySide6/Qt6Charts.dll",
|
||||
"lib/PySide6/Qt6Location.dll",
|
||||
"lib/PySide6/Qt6Pdf.dll",
|
||||
"lib/PySide6/Qt6Quick.dll",
|
||||
"lib/PySide6/Qt6WebEngineCore.dll",
|
||||
"lib/PySide6/QtCharts.pyd",
|
||||
"lib/PySide6/QtMultimedia.pyd",
|
||||
"lib/PySide6/QtOpenGLFunctions.pyd",
|
||||
"lib/PySide6/QtOpenGLFunctions.pyi",
|
||||
"lib/PySide6/d3dcompiler_47.dll",
|
||||
"lib/PySide6/opengl32sw.dll",
|
||||
"lib/PySide6/lupdate.exe",
|
||||
"lib/PySide6/translations",
|
||||
"lib/aiohttp/_find_header.c",
|
||||
"lib/aiohttp/_frozenlist.c",
|
||||
"lib/aiohttp/_helpers.c",
|
||||
@@ -112,7 +113,7 @@ executables = [
|
||||
|
||||
setup(
|
||||
name="hippolyzer_gui",
|
||||
version="0.7.1",
|
||||
version="0.8.0",
|
||||
description="Hippolyzer GUI",
|
||||
options=options,
|
||||
executables=executables,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import unittest
|
||||
|
||||
from hippolyzer.lib.base.datatypes import *
|
||||
from hippolyzer.lib.base.legacy_inv import InventoryModel
|
||||
from hippolyzer.lib.base.inventory import InventoryModel
|
||||
from hippolyzer.lib.base.wearables import Wearable, VISUAL_PARAMS
|
||||
|
||||
SIMPLE_INV = """\tinv_object\t0
|
||||
@@ -61,6 +61,51 @@ class TestLegacyInv(unittest.TestCase):
|
||||
self.assertEqual(item.sale_info.sale_type, "not")
|
||||
self.assertEqual(item.model, model)
|
||||
|
||||
def test_llsd_serialization(self):
|
||||
model = InventoryModel.from_str(SIMPLE_INV)
|
||||
self.assertEqual(
|
||||
model.to_llsd(),
|
||||
[
|
||||
{
|
||||
'name': 'Contents',
|
||||
'obj_id': UUID('f4d91477-def1-487a-b4f3-6fa201c17376'),
|
||||
'parent_id': UUID('00000000-0000-0000-0000-000000000000'),
|
||||
'type': 'category'
|
||||
},
|
||||
{
|
||||
'asset_id': UUID('00000000-0000-0000-0000-000000000000'),
|
||||
'created_at': 1587367239,
|
||||
'desc': '2020-04-20 04:20:39 lsl2 script',
|
||||
'flags': b'\x00\x00\x00\x00',
|
||||
'inv_type': 'script',
|
||||
'item_id': UUID('dd163122-946b-44df-99f6-a6030e2b9597'),
|
||||
'name': 'New Script',
|
||||
'parent_id': UUID('f4d91477-def1-487a-b4f3-6fa201c17376'),
|
||||
'permissions': {
|
||||
'base_mask': 2147483647,
|
||||
'creator_id': UUID('a2e76fcd-9360-4f6d-a924-000000000003'),
|
||||
'everyone_mask': 0,
|
||||
'group_id': UUID('00000000-0000-0000-0000-000000000000'),
|
||||
'group_mask': 0,
|
||||
'last_owner_id': UUID('a2e76fcd-9360-4f6d-a924-000000000003'),
|
||||
'next_owner_mask': 581632,
|
||||
'owner_id': UUID('a2e76fcd-9360-4f6d-a924-000000000003'),
|
||||
'owner_mask': 2147483647
|
||||
},
|
||||
'sale_info': {
|
||||
'sale_price': 10,
|
||||
'sale_type': 'not'
|
||||
},
|
||||
'type': 'lsltext'
|
||||
}
|
||||
]
|
||||
)
|
||||
|
||||
def test_llsd_legacy_equality(self):
|
||||
model = InventoryModel.from_str(SIMPLE_INV)
|
||||
new_model = InventoryModel.from_llsd(model.to_llsd())
|
||||
self.assertEqual(model, new_model)
|
||||
|
||||
|
||||
GIRL_NEXT_DOOR_SHAPE = """LLWearable version 22
|
||||
Girl Next Door - C2 - med - Adam n Eve
|
||||
|
||||
@@ -12,7 +12,6 @@ from hippolyzer.lib.base.datatypes import UUID
|
||||
from hippolyzer.lib.base.message.message import Block, Message
|
||||
from hippolyzer.lib.base.message.udpdeserializer import UDPMessageDeserializer
|
||||
from hippolyzer.lib.base.objects import Object
|
||||
import hippolyzer.lib.base.serialization as se
|
||||
from hippolyzer.lib.proxy.addon_utils import BaseAddon
|
||||
from hippolyzer.lib.proxy.addons import AddonManager
|
||||
from hippolyzer.lib.proxy.message_logger import FilteringMessageLogger, LLUDPMessageLogEntry
|
||||
@@ -262,11 +261,6 @@ class LLUDPIntegrationTests(BaseProxyTest):
|
||||
# Don't have a serializer, onto the next field
|
||||
continue
|
||||
deser = serializer.deserialize(block, orig_val)
|
||||
# For now we consider returning UNSERIALIZABLE to be acceptable.
|
||||
# We should probably consider raising instead of returning that.
|
||||
if deser is se.UNSERIALIZABLE:
|
||||
continue
|
||||
|
||||
new_val = serializer.serialize(block, deser)
|
||||
if orig_val != new_val:
|
||||
raise AssertionError(f"{block.name}.{var_name} didn't reserialize correctly,"
|
||||
|
||||
Reference in New Issue
Block a user