Skip to content

Commit 7f77cbd

Browse files
committed
Extract kernel config when present
1 parent feef875 commit 7f77cbd

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

reolinkfw/__init__.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import asyncio
2+
import gzip
23
import hashlib
34
import io
45
import lzma
@@ -57,6 +58,7 @@
5758

5859
RE_BANNER = re.compile(b"\x00(Linux version .+? \(.+?@.+?\) \(.+?\) .+?)\n\x00")
5960
RE_COMPLINK = re.compile(b"\x00([^\x00]+?-linux-.+? \(.+?\) [0-9].+?)\n\x00+(.+?)\n\x00")
61+
RE_IKCFG = re.compile(b"IKCFG_ST(.+?)IKCFG_ED", re.DOTALL)
6062
RE_KERNEL_COMP = re.compile(
6163
b"(?P<lz4>" + FileType.LZ4_LEGACY_FRAME.value + b')'
6264
b"|(?P<xz>\xFD\x37\x7A\x58\x5A\x00\x00.(?!XZ))"
@@ -242,6 +244,11 @@ def get_linux_banner(self) -> Optional[str]:
242244
match = RE_BANNER.search(self.kernel)
243245
return match.group(1).decode() if match is not None else None
244246

247+
def get_kernel_config(self) -> Optional[bytes]:
248+
if (match := RE_IKCFG.search(self.kernel)) is not None:
249+
return gzip.decompress(match.group(1))
250+
return None
251+
245252
def get_fs_info(self) -> list[dict[str, str]]:
246253
result = []
247254
for section in self._fs_sections:
@@ -328,6 +335,9 @@ def extract(self, dest: Optional[Path] = None, force: bool = False) -> None:
328335
f.write(self.uboot)
329336
with open(dest / "kernel", mode) as f:
330337
f.write(self.kernel)
338+
if (kcfg := self.get_kernel_config()) is not None:
339+
with open(dest / ".config", mode) as f:
340+
f.write(kcfg)
331341

332342

333343
async def download(url: StrOrURL) -> Union[bytes, int]:

0 commit comments

Comments
 (0)