Skip to content

Commit b96a758

Browse files
authored
Merge pull request #1539 from j-t-1/mac
Small readability improvements
2 parents 89d32df + 5c21f4a commit b96a758

File tree

1 file changed

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

1 file changed

+11
-14
lines changed

volatility3/framework/automagic/mac.py

Lines changed: 11 additions & 14 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: 0x{idlepml4_ptr:0x}",
104+
f"Skipping invalid idlepml4_ptr: {idlepml4_ptr:#x}",
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: 0x{tmp_dtb:0x}",
115+
f"Skipping non-page aligned DTB: {tmp_dtb:#x}",
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: 0x{dtb:0x}")
139+
vollog.debug(f"DTB was found at: {dtb:#x}")
140140
return new_layer
141141
vollog.debug("No suitable mac banner could be matched")
142142
return None
@@ -182,33 +182,30 @@ 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".")[0:2])
185+
banner_major, banner_minor = (int(x) for x in banner[22:].split(b".")[:2])
186186

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

191189
major_string = context.layers[layer_name].read(
192-
version_major_phys_offset + tmp_aslr_shift, 4
190+
version_major_phys_offset + aslr_shift, 4
193191
)
194192
major = struct.unpack("<I", major_string)[0]
195193

196194
if major != banner_major:
197195
continue
198196

199197
minor_string = context.layers[layer_name].read(
200-
version_minor_phys_offset + tmp_aslr_shift, 4
198+
version_minor_phys_offset + aslr_shift, 4
201199
)
202200
minor = struct.unpack("<I", minor_string)[0]
203201

204202
if minor != banner_minor:
205203
continue
206204

207-
if tmp_aslr_shift & 0xFFF != 0:
205+
if aslr_shift & 0xFFF != 0:
208206
continue
209207

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

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

@@ -219,9 +216,9 @@ def virtual_to_physical_address(cls, addr: int) -> int:
219216
"""Converts a virtual mac address to a physical one (does not account
220217
of ASLR)"""
221218
if addr > 0xFFFFFF8000000000:
222-
addr = addr - 0xFFFFFF8000000000
219+
addr -= 0xFFFFFF8000000000
223220
else:
224-
addr = addr - 0xFF8000000000
221+
addr -= 0xFF8000000000
225222

226223
return addr
227224

0 commit comments

Comments
 (0)