twrpRepacker: Fix ramdisk_format in Unpack_Image function

Compatible with new versions of magiskboot:

HEADER_VER      [3]
KERNEL_SZ       [23247306]
RAMDISK_SZ      [54275594]
OS_VERSION      [13.0.0]
OS_PATCH_LEVEL  [2023-09]
PAGESIZE        [4096]
CMDLINE         []
KERNEL_FMT      [gzip]
RAMDISK_FMT     [gzip]
unexpected ASN.1 DER tag: expected SEQUENCE, got APPLICATION [1] (primitive)
VBMETA

Change-Id: I50df42a34363e85de3eaa4e93d3c35c73a99f44c
diff --git a/twrpRepacker.cpp b/twrpRepacker.cpp
index c5816c1..d6f8ed7 100755
--- a/twrpRepacker.cpp
+++ b/twrpRepacker.cpp
@@ -101,12 +101,17 @@
 		gui_msg(Msg(msg::kError, "unpack_error=Error unpacking image."));
 		return std::string();
 	}
-	size_t pos = magisk_unpack_output.find(txt_to_find) + txt_to_find.size();
-	std::string ramdisk_format = magisk_unpack_output.substr(pos, magisk_unpack_output.size() - 1);
-	ramdisk_format.erase(std::remove(ramdisk_format.begin(), ramdisk_format.end(), '['), ramdisk_format.end());
-	ramdisk_format.erase(std::remove(ramdisk_format.begin(), ramdisk_format.end(), ']'), ramdisk_format.end());
-	ramdisk_format.erase(std::remove(ramdisk_format.begin(), ramdisk_format.end(), ' '), ramdisk_format.end());
-	ramdisk_format.erase(std::remove(ramdisk_format.begin(), ramdisk_format.end(), '\n'), ramdisk_format.end());
+	std::string ramdisk_format;
+	auto pos = magisk_unpack_output.find(txt_to_find);
+	if (pos != std::string::npos) {
+		auto start = magisk_unpack_output.find('[', pos + txt_to_find.size());
+			if (start != std::string::npos) {
+				auto end = magisk_unpack_output.find(']', start);
+				if (end != std::string::npos) {
+					ramdisk_format = std::move(magisk_unpack_output.substr(start + 1, end - start - 1));
+				}
+		}
+	}
 	return ramdisk_format;
 }