Skip to content

Commit bedcaa2

Browse files
authored
Merge pull request #1541 from volatilityfoundation/revert-1539-mac
Revert "Small readability improvements"
2 parents b96a758 + 7913fb2 commit bedcaa2

File tree

1 file changed

+14
-11
lines changed
  • volatility3/framework/automagic

1 file changed

+14
-11
lines changed

volatility3/framework/automagic/mac.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def stack(
101101
except exceptions.InvalidAddressException:
102102
vollog.log(
103103
constants.LOGLEVEL_VVVV,
104-
f"Skipping invalid idlepml4_ptr: {idlepml4_ptr:#x}",
104+
f"Skipping invalid idlepml4_ptr: 0x{idlepml4_ptr:0x}",
105105
)
106106
continue
107107

@@ -112,7 +112,7 @@ def stack(
112112
if tmp_dtb % 4096:
113113
vollog.log(
114114
constants.LOGLEVEL_VVV,
115-
f"Skipping non-page aligned DTB: {tmp_dtb:#x}",
115+
f"Skipping non-page aligned DTB: 0x{tmp_dtb:0x}",
116116
)
117117
continue
118118

@@ -136,7 +136,7 @@ def stack(
136136
new_layer.config["kernel_virtual_offset"] = kaslr_shift
137137

138138
if new_layer and dtb:
139-
vollog.debug(f"DTB was found at: {dtb:#x}")
139+
vollog.debug(f"DTB was found at: 0x{dtb:0x}")
140140
return new_layer
141141
vollog.debug("No suitable mac banner could be matched")
142142
return None
@@ -182,30 +182,33 @@ def find_aslr(
182182
aslr_shift = 0
183183

184184
for offset, banner in offset_generator:
185-
banner_major, banner_minor = (int(x) for x in banner[22:].split(b".")[:2])
185+
banner_major, banner_minor = (int(x) for x in banner[22:].split(b".")[0:2])
186186

187-
aslr_shift = offset - cls.virtual_to_physical_address(version_json_address)
187+
tmp_aslr_shift = offset - cls.virtual_to_physical_address(
188+
version_json_address
189+
)
188190

189191
major_string = context.layers[layer_name].read(
190-
version_major_phys_offset + aslr_shift, 4
192+
version_major_phys_offset + tmp_aslr_shift, 4
191193
)
192194
major = struct.unpack("<I", major_string)[0]
193195

194196
if major != banner_major:
195197
continue
196198

197199
minor_string = context.layers[layer_name].read(
198-
version_minor_phys_offset + aslr_shift, 4
200+
version_minor_phys_offset + tmp_aslr_shift, 4
199201
)
200202
minor = struct.unpack("<I", minor_string)[0]
201203

202204
if minor != banner_minor:
203205
continue
204206

205-
if aslr_shift & 0xFFF != 0:
207+
if tmp_aslr_shift & 0xFFF != 0:
206208
continue
207209

208-
aslr_shift &= 0xFFFFFFFF
210+
aslr_shift = tmp_aslr_shift & 0xFFFFFFFF
211+
break
209212

210213
vollog.log(constants.LOGLEVEL_VVVV, f"Mac find_aslr returned: {aslr_shift:0x}")
211214

@@ -216,9 +219,9 @@ def virtual_to_physical_address(cls, addr: int) -> int:
216219
"""Converts a virtual mac address to a physical one (does not account
217220
of ASLR)"""
218221
if addr > 0xFFFFFF8000000000:
219-
addr -= 0xFFFFFF8000000000
222+
addr = addr - 0xFFFFFF8000000000
220223
else:
221-
addr -= 0xFF8000000000
224+
addr = addr - 0xFF8000000000
222225

223226
return addr
224227

0 commit comments

Comments
 (0)