Skip to content

Commit 20c55ae

Browse files
committed
elf: even better handling of kernel images
1 parent 3525980 commit 20c55ae

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

pwnlib/elf/elf.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,20 +1153,17 @@ def _populate_kernel_version(self):
11531153

11541154
banner = self.string(self.symbols.linux_banner)
11551155

1156-
# convert banner into a utf-8 string since re.search does not accept bytes anymore
1157-
banner = banner.decode('utf-8', 'surrogateescape')
1158-
11591156
# 'Linux version 3.18.31-gd0846ecc
1160-
regex = r'Linux version (\S+)'
1157+
regex = br'Linux version (\S+)'
11611158
match = re.search(regex, banner)
11621159

11631160
if match:
1164-
version = match.group(1)
1161+
version = match.group(1).decode('utf-8', 'surrogateescape')
11651162

11661163
if '-' in version:
11671164
version, self.build = version.split('-', 1)
11681165

1169-
self.version = list(map(int, version.rstrip('+').split('.')))
1166+
self.version = tuple(map(int, version.rstrip('+').split('.')))
11701167

11711168
self.config['version'] = self.version
11721169

0 commit comments

Comments
 (0)