-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2d1935d
commit b279457
Showing
6 changed files
with
141 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# SPDX-FileCopyrightText: AISEC Pentesting Team | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
from abc import ABC, abstractmethod | ||
from dataclasses import dataclass | ||
from typing import Any, Literal, NotRequired, TypeAlias, TypedDict | ||
|
||
from gallia.services.uds.core.service import UDSRequest, UDSResponse | ||
|
||
|
||
@dataclass | ||
class Field: | ||
name: str | ||
raw_data: bytes | ||
dissected_data: str | ||
|
||
|
||
class BaseDissector(ABC): | ||
PROTO: str = "" | ||
|
||
def __init_subclass__( | ||
cls, | ||
/, | ||
proto: str, | ||
**kwargs: Any, | ||
) -> None: | ||
super().__init_subclass__(**kwargs) | ||
cls.PROTO = proto | ||
|
||
@abstractmethod | ||
def dissect(self, data: bytes, iotype: str | None = None) -> list[Field]: ... | ||
|
||
|
||
class UDSDissector(BaseDissector, proto="uds"): | ||
def dissect(self, data: bytes, iotype: str | None = None) -> list[Field]: | ||
if data[0] & 0b01000000: | ||
dissected_data = repr(UDSResponse.parse_dynamic(data)) | ||
name = "uds response" | ||
else: | ||
dissected_data = repr(UDSRequest.parse_dynamic(data)) | ||
name = "uds request" | ||
|
||
return [Field(name=name, raw_data=data, dissected_data=dissected_data)] | ||
|
||
|
||
# TODO: Can the PROTO attribute be used? | ||
registry: dict[str, BaseDissector] = {"uds": UDSDissector()} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters