[CRIU] [PATCH 2/3] Issue #360: Anonymize image files

Harshavardhan Unnibhavi hvubfoss at gmail.com
Sat Jun 22 12:37:31 MSK 2019


This commit changes the pycriu.images.load() function to return magic type of the loaded image file. The reason was to use this type information to call appropriate methods to handle anonymisation.

Signed-off-by: Harshavardhan Unnibhavi <hvubfoss at gmail.com>
---
 lib/py/cli.py           | 17 ++++++++++++++++-
 lib/py/images/images.py |  5 ++++-
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/lib/py/cli.py b/lib/py/cli.py
index d3242f08..17622fd2 100755
--- a/lib/py/cli.py
+++ b/lib/py/cli.py
@@ -273,8 +273,23 @@ def explore_rss(opts):
 
 
 def anonymize(opts):
-	pass
+	try:
+		os.stat(opts['out'])
+	except:
+		os.mkdir(opts['out'])
+	
+	img_files = os.listdir(opts['in'])
+
+	for i in img_files:
+		temp = {'in':os.path.join(opts['in'], i)}
 
+		try:
+			m, img = pycriu.images.load(inf(temp), anon_info = True)
+		except pycriu.images.MagicException as exc:
+			print("Unknown magic %#x.\n"\
+					"Found a raw image, continuing ..."% exc.magic, file=sys.stderr)
+			continue
+		
 
 explorers = { 'ps': explore_ps, 'fds': explore_fds, 'mems': explore_mems, 'rss': explore_rss }
 
diff --git a/lib/py/images/images.py b/lib/py/images/images.py
index 7a9b9da6..a411ffc4 100644
--- a/lib/py/images/images.py
+++ b/lib/py/images/images.py
@@ -528,7 +528,7 @@ def __rhandler(f):
 
 	return m, handler
 
-def load(f, pretty = False, no_payload = False):
+def load(f, pretty = False, no_payload = False, anon_info = False):
 	"""
 	Convert criu image from binary format to dict(json).
 	Takes a file-like object to read criu image from.
@@ -541,6 +541,9 @@ def load(f, pretty = False, no_payload = False):
 	image['magic'] = m
 	image['entries'] = handler.load(f, pretty, no_payload)
 
+	if anon_info:
+		return m, image
+
 	return image
 
 def info(f):
-- 
2.17.1



More information about the CRIU mailing list