Skip to content

Commit 57ffd5b

Browse files
committed
Linux: Boottime API: Refactor TimespecVol3::negate() to return a new object instead of modifying the original. It also normalizes its values, aligning with the behavior of the other addition and subtraction operators
1 parent c4274c9 commit 57ffd5b

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

volatility3/framework/symbols/linux/__init__.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,7 @@ def __sub__(self, timespec) -> "TimespecVol3":
909909
tv_sec=self.tv_sec - timespec.tv_sec,
910910
tv_nsec=self.tv_nsec - timespec.tv_nsec,
911911
)
912+
912913
result.normalize()
913914

914915
return result
@@ -925,6 +926,13 @@ def normalize(self):
925926
self.tv_sec -= 1
926927

927928
def negate(self):
928-
"""Negates the sign of both tv_sec and tv_nsec"""
929-
self.tv_sec = -self.tv_sec
930-
self.tv_nsec = -self.tv_nsec
929+
"""Returns a new TimespecVol3 object with the values of the current object negated"""
930+
931+
result = TimespecVol3(
932+
tv_sec=-self.tv_sec,
933+
tv_nsec=-self.tv_nsec,
934+
)
935+
936+
result.normalize()
937+
938+
return result

volatility3/framework/symbols/linux/extensions/__init__.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -502,10 +502,7 @@ def _get_boottime_raw(self) -> "linux.TimespecVol3":
502502

503503
boottime += timekeeper.total_sleep_time
504504

505-
boottime.negate()
506-
boottime.normalize()
507-
508-
return boottime
505+
return boottime.negate()
509506

510507
elif vmlinux.has_symbol("wall_to_monotonic"):
511508
# kernels < 3.4 - Tested on Debian7 3.2.0-4 (3.2.57-3+deb7u2)
@@ -523,10 +520,7 @@ def _get_boottime_raw(self) -> "linux.TimespecVol3":
523520
# kernels < 2.6.32 total_sleep_time is an unsigned long as seconds
524521
boottime.tv_sec += total_sleep_time
525522

526-
boottime.negate()
527-
boottime.normalize()
528-
529-
return boottime
523+
return boottime.negate()
530524

531525
raise exceptions.VolatilityException("Unsupported")
532526

0 commit comments

Comments
 (0)