Skip to content

Commit

Permalink
(pkgs) Fix GetCommand on msi / inno nullsoft exe
Browse files Browse the repository at this point in the history
- Try to use the old getCommand generator to get the command. If nothing is found, use the rules.
- msi are detected by the old system.
- This commit update the rule on nullsoft exe. Before this modification all exe were caught by the "nullsoft rule".
  • Loading branch information
botheis committed Dec 2, 2024
1 parent cc9c411 commit b296794
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 18 deletions.
1 change: 1 addition & 0 deletions services/contrib/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ nobase_dist_contrib_DATA = dyngroup/sql/clean-db.sql \
pkgs/sql/schema-006.sql \
pkgs/sql/schema-007.sql \
pkgs/sql/schema-008.sql \
pkgs/sql/schema-009.sql \
updates/sql/schema-001.sql \
urbackup/sql/schema-001.sql \
monit/pulse2 \
Expand Down
35 changes: 35 additions & 0 deletions services/contrib/pkgs/sql/schema-009.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
--
-- (c) 2024 Siveo, http://siveo.net/
--
-- $Id$
--
-- This file is part of Pulse 2, http://siveo.net
--
-- Pulse 2 is free software; you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation; either version 2 of the License, or
-- (at your option) any later version.
--
-- Pulse 2 is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with Pulse 2; if not, write to the Free Software
-- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
-- MA 02110-1301, USA.

-- ----------------------------------------------------------------------
-- Database version
-- ----------------------------------------------------------------------

-- be sure to use the right database
use pkgs;

START TRANSACTION;

UPDATE extensions SET `file`="", strings="Nullsoft" WHERE rule_name="Nullsoft Rule";
UPDATE version SET Number = 9;
COMMIT;

45 changes: 27 additions & 18 deletions services/mmc/plugins/pkgs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1078,21 +1078,35 @@ def getTemporaryFileSuggestedCommand1(tempdir, size_max=524288000):
"version": "0.1",
"commandcmd": [],
}
base_dir = os.path.join(tmp_input_dir, tempdir)
if not os.path.isdir(base_dir):
retresult["commandcmd"] = "No command found with rules."
return retresult

suggestedCommand = []
file_size = simplecommand("du -b %s" % os.path.join(tmp_input_dir, tempdir))
file_size = simplecommand("du -b %s" % os.path.join(base_dir))

file_size["result"] = [
line.decode("utf-8") for line in file_size["result"]
] # Convertit en UTF-8
file_size["result"] = [line.decode("utf-8") for line in file_size["result"]] # Convertit en UTF-8
sizebytefolder = file_size["result"][0].split("\t")[0]
sizebytefolder = int(sizebytefolder)

sizebytefolder = 0
rules = PkgsDatabase().list_all_extensions()
if not isinstance(tempdir, list) and sizebytefolder <= size_max:
if os.path.exists(tmp_input_dir):
for f in os.listdir(os.path.join(tmp_input_dir, tempdir)):
fileadd = os.path.join(tmp_input_dir, tempdir, f)
for f in os.listdir(base_dir):
fileadd = os.path.join(base_dir, f)
if os.path.isfile(fileadd):
rules = PkgsDatabase().list_all_extensions()
# Use the old system
try:
challenger = getCommand(fileadd)
_propose = challenger.getCommand()
if _propose != None:
retresult["commandcmd"] = _propose
return retresult
except Exception:
# In this case, use the rules
pass

filename = fileadd.split("/")[-1]
filebasename = ".".join(filename.split(".")[:-1])

Expand All @@ -1116,7 +1130,7 @@ def getTemporaryFileSuggestedCommand1(tempdir, size_max=524288000):
stringstring = 0
if rule["strings"]:
recherche = rule["strings"].replace('"', '"')
cmd = 'strings %s | grep "%s"' % (fileadd, rule["strings"])
cmd = 'strings %s | grep -i "%s"' % (fileadd, rule["strings"])
result = simplecommand(cmd)
if result["result"]:
stringstring = 1
Expand All @@ -1143,8 +1157,7 @@ def getTemporaryFileSuggestedCommand1(tempdir, size_max=524288000):
logging.getLogger().debug(
"command propose %s" % retelt["proposition"]
)
command = retelt["proposition"].replace("'", '"') % filename
suggestedCommand.append(command)
suggestedCommand.append(retelt["proposition"])
break
if suggestedCommand:
retresult["commandcmd"] = "\n".join(suggestedCommand)
Expand Down Expand Up @@ -2349,7 +2362,7 @@ def getCommand(self):
# if assemblyIdentity don't exists, try assemblyIdentity
identity = xmldoc.getElementsByTagName("assemblyIdentity")

if identity > 0:
if len(identity) > 0:
if identity[0].hasAttribute("name"):
installer = identity[0].getAttribute("name")
self.logger.debug("Installer: %s" % installer)
Expand All @@ -2370,9 +2383,7 @@ def getCommand(self):
return self.getNSISCommand()
elif installer == "7zS.sfx.exe":
self.logger.debug("7zS.sfx detected (Mozilla app inside ?)")
if not os.system(
"grep Mozilla '%s' > /dev/null" % self.file
): # return code is 0 if file match
if not os.system("grep Mozilla '%s' > /dev/null" % self.file): # return code is 0 if file match
self.logger.debug("Mozilla App detected")
return self.getMozillaCommand()
else:
Expand All @@ -2399,9 +2410,7 @@ def getCommand(self):
return self.getMSICommand()
else:
return self.logger.info("No Template Key for %s" % self.file)
elif "Debian binary package" in file_data[self.file] or self.file.endswith(
".deb"
):
elif "Debian binary package" in file_data[self.file] or self.file.endswith(".deb"):
self.logger.debug("Debian package detected")
return self.getDpkgCommand()
elif self.file.endswith(".reg"):
Expand Down

0 comments on commit b296794

Please sign in to comment.