Skip to content

Commit 85f7862

Browse files
!feat(scan-sessions): Invert scanning approach: --fast to --thorough
With the assumption that it does not matter how a session is entered, it is only interesting to know from where one can reach a session. Thus, the better default is to use a fast approach that only scans from each session once in order to find available session transitions. To replicate the old scanning behaviour, --thorough can be specified to scan multiple times from the same session. In order to avoid infinite loops, --depth now has a default value of 4.
1 parent 1f5ae75 commit 85f7862

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

src/gallia/commands/scan/uds/sessions.py

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020

2121
class SessionsScannerConfig(UDSScannerConfig):
22-
depth: AutoInt | None = Field(None, description="Specify max scanning depth.")
22+
depth: AutoInt = Field(4, description="Specify max scanning depth.")
2323
sleep: AutoInt = Field(
2424
0,
2525
description="Sleep this amount of seconds after changing to DefaultSession",
@@ -34,9 +34,9 @@ class SessionsScannerConfig(UDSScannerConfig):
3434
description="Reset the ECU before each iteration with the optionally given reset level",
3535
const=0x01,
3636
)
37-
fast: bool = Field(
37+
thorough: bool = Field(
3838
False,
39-
description="Only search for new sessions once in a particular session, i.e. ignore different stacks",
39+
description="Perform a session scan for each 'stack' of a session instead of only once per session",
4040
)
4141

4242

@@ -127,22 +127,21 @@ async def main(self) -> None:
127127
positive_results: list[dict[str, Any]] = []
128128
negative_results: list[dict[str, Any]] = []
129129
activated_sessions: set[int] = set()
130-
search_sessions: list[int] = []
130+
searched_sessions: list[int] = []
131131

132132
sessions = list(range(1, 0x80))
133-
depth = 0
133+
current_depth = 0
134134

135-
while (self.config.depth is None or depth < self.config.depth) and len(found[depth]) > 0:
136-
depth += 1
135+
while current_depth < self.config.depth and len(found[current_depth]) > 0:
136+
current_depth += 1
137137

138-
found[depth] = []
139-
logger.notice(f"Enumerating at depth: {depth}")
138+
found[current_depth] = []
139+
logger.notice(f"Enumerating at depth: {current_depth}")
140140

141-
for stack in found[depth - 1]:
142-
if self.config.fast and stack[-1] in search_sessions:
141+
for stack in found[current_depth - 1]:
142+
if (not self.config.thorough) and stack[-1] in searched_sessions:
143143
continue
144-
145-
search_sessions.append(stack[-1])
144+
searched_sessions.append(stack[-1])
146145

147146
if stack:
148147
logger.info(f"Starting from session: {g_repr(stack[-1])}")
@@ -203,10 +202,10 @@ async def main(self) -> None:
203202
# Presumably we did not successfully leave the session, so no need to recover the stack
204203
continue
205204

206-
# Do not track a session in "found" if it is already present on the stack
205+
# Do not track a session in "found" if it is already present on the stack unless 'thorough'
207206
# This avoids looping through sessions, e.g. 0x01->0x02->0x01->0x02->...
208-
if session not in stack:
209-
found[depth].append(stack + [session])
207+
if self.config.thorough or session not in stack:
208+
found[current_depth].append(stack + [session])
210209

211210
activated_sessions.add(session)
212211
positive_results.append({"session": session, "stack": stack, "error": None})

0 commit comments

Comments
 (0)