47 lines
1.5 KiB
Diff
47 lines
1.5 KiB
Diff
From 0827581dc9f64cfa96601fa36ae1fdc6d8e14dac Mon Sep 17 00:00:00 2001
|
|
From: xuezhixin <xuezhixin@uniontech.com>
|
|
Date: Mon, 13 Nov 2023 10:19:04 +0800
|
|
Subject: [PATCH] =?UTF-8?q?ABI=E5=A2=9E=E5=8A=A0ELF=E6=96=87=E4=BB=B6?=
|
|
=?UTF-8?q?=E6=A3=80=E6=B5=8B?=
|
|
MIME-Version: 1.0
|
|
Content-Type: text/plain; charset=UTF-8
|
|
Content-Transfer-Encoding: 8bit
|
|
|
|
---
|
|
sysmig_agent/Abisystmcompchk.py | 22 ++++++++++++++++++++++
|
|
1 file changed, 22 insertions(+)
|
|
|
|
diff --git a/sysmig_agent/Abisystmcompchk.py b/sysmig_agent/Abisystmcompchk.py
|
|
index e442cb5..541e9a8 100644
|
|
--- a/sysmig_agent/Abisystmcompchk.py
|
|
+++ b/sysmig_agent/Abisystmcompchk.py
|
|
@@ -180,3 +180,25 @@ def logger_init():
|
|
logger.addHandler(fh)
|
|
|
|
return logger
|
|
+
|
|
+
|
|
+# Check whether it is an ELF file
|
|
+def is_ELFfile(filepath, logger):
|
|
+ if not os.path.exists(filepath):
|
|
+ logger.info('file not exit:' + filepath)
|
|
+ return False
|
|
+ try:
|
|
+ FileStates = os.stat(filepath)
|
|
+ FileMode = FileStates[stat.ST_MODE]
|
|
+ if not stat.S_ISREG(FileMode) or stat.S_ISLNK(FileMode):
|
|
+ return False
|
|
+ with open(filepath, 'rb') as f:
|
|
+ header = (bytearray(f.read(4)[1:4])).decode(encoding="utf-8")
|
|
+ # logger.info("header is {}".format(header))
|
|
+ if header in ["ELF"]:
|
|
+ return True
|
|
+ except UnicodeDecodeError as e:
|
|
+ # logger.info("is_ELFfile UnicodeDecodeError {}".format(filepath))
|
|
+ # logger.info(str(e))
|
|
+ pass
|
|
+ return False
|
|
--
|
|
2.20.1
|
|
|