From 67e09d3b0f6e86c8f4fadfdef14ce73ea01b49d0 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Wed, 2 Apr 2025 17:02:59 +0200 Subject: [PATCH] Optimized get_resume_offset() --- main.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 702b81a..0a7ca2b 100755 --- a/main.py +++ b/main.py @@ -70,10 +70,14 @@ def get_swap_uuid(): def get_resume_offset(): print("[+] Calculating resume_offset...") out = run(f"filefrag -v {SWAPFILE}", capture=True) - match = re.search(r"^\s*0:\s+(\d+)", out, re.MULTILINE) - if match: - return match.group(1) - raise RuntimeError("Couldn't find resume offset.") + for line in out.splitlines(): + match = re.search(r"^\s*\d+:\s+\d+\.\.\s*\d+:\s+(\d+)", line) + if match: + offset = match.group(1) + if offset != "0": + print(f"[✓] Found resume_offset: {offset}") + return offset + raise RuntimeError("Couldn't find valid resume offset.") def update_grub(uuid, offset): print("[+] Updating GRUB_CMDLINE_LINUX_DEFAULT...")