sspatch: full rework

Signed-off-by: AuxXxilium <info@auxxxilium.tech>
This commit is contained in:
AuxXxilium 2024-08-21 18:28:29 +02:00
parent d754721c74
commit eee0b91cfa
7 changed files with 23 additions and 184 deletions

View File

@ -1,143 +0,0 @@
#!/bin/sh
# Copyright (c) 2014 Synology Inc. All rights reserved.
SURVEILLANCE_INC_SCRP=/var/packages/SurveillanceStation/scripts/SurveillanceStationCommon
. ${SURVEILLANCE_INC_SCRP}
SS_BIN_DIR="${SS_TARGET_DIR}/bin"
SSCTL="${SS_BIN_DIR}/ssctl"
SS_DBG_LOG_ROTATE_CONF="/usr/local/etc/logrotate.d/SurveillanceStation"
UpdateSSDbgLogRotateConf()
{
cat > $SS_DBG_LOG_ROTATE_CONF <<EOF
/var/log/surveillance/surveillance.log /var/log/surveillance/ssnotification.log
/var/log/surveillance/localdisplay.log /var/log/surveillance/ssrotate.log
/var/log/surveillance/ssdevice.log {
size 10M
rotate 4
missingok
}
EOF
}
CheckPgsqlService()
{
if [ true == $(IsDSM7) ]; then
echo $(IsSystemdUnitActivated "pqsql")
else
${SYNO_SERVICE_TOOL} --is-enabled pgsql > /dev/null 2>&1
if [ $? -ne ${RET_SYNO_SERVICE_ENABLED} ]; then
echo false
else
echo true
fi
fi
}
Start()
{
SSDebugLog "Start Surveillance [$SURVEILLANCE_PKG_VERSION] begin."
local Ret
UpdateSSDbgLogRotateConf
if [ true == $(IsNonRecordingMode) -a true == $(IsServiceDataLinkAlive) ]; then
rm -f ${SS_NON_RECORDING_FILE}
fi
if [ false == $(IsNonRecordingMode) ]; then
CheckToCreateRecDB
Ret=$?
if [ 0 -ne ${Ret} ]; then
SSDebugLog "Failed to prepare share folder."
UpdateNonRecordingMode
fi
if [ ! -f ${SS_REC_DB} ]; then
SSDebugLog "Recording db not found."
UpdateNonRecordingMode
fi
fi
if [ ${USE_SQLITE} == false ]; then
if [ false == $(CheckPgsqlService) ]; then
SSDebugLog "PGSQL is not enabled"
exit 1;
fi
if [ false == $(HasSSPgsqlData) ]; then
SSDebugLog "PGSQL db have not been created yet."
exit 1
fi
else
if [ ! -f ${SS_SYSTEM_DB} ]; then
SSDebugLog "System db not found."
exit 1
fi
fi
${SSCTL} start
sh /var/packages/SurveillanceStation/target/scripts/license.sh > /dev/null 2>&1 & echo $!
SSDebugLog "Start Surveillance [$SURVEILLANCE_PKG_VERSION] end."
}
Stop()
{
SSDebugLog "Stop Surveillance [$SURVEILLANCE_PKG_VERSION] begin."
if [ ${USE_SQLITE} == false ]; then
if [ false == $(HasSSPgsqlData) ]; then
echo "Surveillance: DB is stopped before Surveillance stops"
fi
else
if [ ! -f ${SS_SYSTEM_DB} ]; then
echo "Surveillance System DB not found."
fi
fi
${SSCTL} stop
sudo pkill -9 -f /var/packages/SurveillanceStation/target/scripts/license.sh
SSDebugLog "Stop Surveillance [$SURVEILLANCE_PKG_VERSION] end"
}
Restart()
{
Stop
sleep 1
Start
}
TriggerSctrl()
{
${SSCTL} "$1" "$2" "$3"
}
main()
{
PackageInfoGet
case $1 in
"start")
Start
;;
"stop")
Stop
;;
"restart")
Restart
;;
"trigger-ssctl")
TriggerSctrl "$2" "$3" "$4"
;;
*)
echo "Usage: $0 start|stop|restart|share_folder"
;;
esac
}
main "$@"

View File

@ -1,7 +0,0 @@
#!/bin/bash
while true
do
sleep 3600
/var/packages/SurveillanceStation/target/bin/ssctl restart
done

BIN
sspatch/all/usr/bin/patchelf Executable file

Binary file not shown.

View File

@ -1,4 +1,10 @@
#!/usr/bin/env bash
#
# Copyright (C) 2023 AuxXxilium <https://github.com/AuxXxilium>
#
# This is free software, licensed under the MIT License.
# See /LICENSE for more information.
#
if [ -d /var/packages/SurveillanceStation ]; then
# Define the entries to be added
@ -30,8 +36,8 @@ if [ -d /var/packages/SurveillanceStation ]; then
PATHSCRIPTS="${SSPATH}/target/scripts"
SPATCHBIN="/usr/bin"
SO_FILE="${SSPATH}/target/lib/libssutils.so"
if [ ! -f "${SO_FILE}" ]; then
SO_FILE="${SSPATH}/target/lib/libssutils"
if [ ! -f "${SO_FILE}.so" ]; then
echo "SSPatch: libssutils.so does not exist"
exit 1
fi
@ -40,26 +46,14 @@ if [ -d /var/packages/SurveillanceStation ]; then
sleep 5
# Check Sha256sum
if [ "$(sha256sum "${SO_FILE}" | cut -d' ' -f1)" = "81b64d65f4a2a65626f9280ba43ea43f031a239af3152b859b79e1b5124cc6e3" ]; then
PATCH="8548ffffff41be43000000e93dffffff/8548ffffff41be7b000000e93dffffff"
cp -f "${SO_FILE}" "${SO_FILE}.bak"
cp -f "${SO_FILE}" "${SO_FILE}.tmp"
xxd -c $(xxd -p "${SO_FILE}.tmp" 2>/dev/null | wc -c) -p "${SO_FILE}.tmp" 2>/dev/null |
sed "s/${PATCH}/" |
xxd -r -p >"${SO_FILE}" 2>/dev/null
rm -f "${SO_FILE}.tmp"
echo "SSPatch: libssutils.so is patched"
elif [ "$(sha256sum "${SO_FILE}" | cut -d' ' -f1)" = "b0fafefe820aa8ecd577313dff2ae22cf41a6ddf44051f01670c3b92ee04224d" ]; then
PATCH="850b010000e8b684e5ff83f80141bc43/850b010000e8b684e5ff83f80141bc7b"
cp -f "${SO_FILE}" "${SO_FILE}.bak"
cp -f "${SO_FILE}" "${SO_FILE}.tmp"
xxd -c $(xxd -p "${SO_FILE}.tmp" 2>/dev/null | wc -c) -p "${SO_FILE}.tmp" 2>/dev/null |
sed "s/${PATCH}/" |
xxd -r -p >"${SO_FILE}" 2>/dev/null
rm -f "${SO_FILE}.tmp"
if [ "$(sha256sum "${SO_FILE}" | cut -d' ' -f1)" = "b0fafefe820aa8ecd577313dff2ae22cf41a6ddf44051f01670c3b92ee04224d" ]; then
mv -f "${SO_FILE}.so" "${SO_FILE}.org.so"
cp -f "/usr/lib/libssutils.mitm.so" "${SO_FILE}.mitm.so"
patchelf --add-needed /var/packages/SurveillanceStation/target/lib/libssutils.org.so /var/packages/SurveillanceStation/target/lib/libssutils.mitm.so
mv -f "${SO_FILE}.mitm.so" "${SO_FILE}.so"
echo "SSPatch: libssutils.so is patched"
else
if [ -f "${SO_FILE}.bak" ]; then
if [ -f "${SO_FILE}.org.so" ]; then
echo "SSPatch: libssutils.so is already patched"
exit 0
else
@ -70,16 +64,6 @@ if [ -d /var/packages/SurveillanceStation ]; then
chown SurveillanceStation:SurveillanceStation "${SO_FILE}"
chmod 0644 "${SO_FILE}"
rm -f "${PATHSCRIPTS}/S82surveillance.sh"
cp -f "${SPATCHBIN}/S82surveillance.sh" "${PATHSCRIPTS}/S82surveillance.sh"
chown SurveillanceStation:SurveillanceStation "${PATHSCRIPTS}/S82surveillance.sh"
chmod 0755 "${PATHSCRIPTS}/S82surveillance.sh"
rm -f "${PATHSCRIPTS}/license.sh"
cp -f "${SPATCHBIN}/license.sh" "${PATHSCRIPTS}/license.sh"
chown SurveillanceStation:SurveillanceStation "${PATHSCRIPTS}/license.sh"
chmod 0777 "${PATHSCRIPTS}/license.sh"
echo -e "SSPatch: Successfull!"
sleep 5

Binary file not shown.

View File

@ -6,9 +6,14 @@ if [ "${1}" = "late" ]; then
cp -vf "${0}" "/tmpRoot/usr/arc/addons/"
cp -vf /usr/bin/sspatch.sh /tmpRoot/usr/bin/sspatch.sh
cp -vf /usr/bin/license.sh /tmpRoot/usr/bin/license.sh
cp -vf /usr/bin/S82surveillance.sh /tmpRoot/usr/bin/S82surveillance.sh
cp -vf /usr/bin/patchelf /tmpRoot/usr/bin/patchelf
cp -vf /usr/lib/libssutils.mitm.so /tmpRoot/usr/lib/libssutils.mitm.so
SED_PATH='/tmpRoot/usr/bin/sed'
${SED_PATH} -i '/synopkg restart SurveillanceStation/d' /tmpRoot/etc/crontab
# Add line to crontab, execute each minute
echo "5 0 * * * root synopkg restart SurveillanceStation #arc sspatch addon" >>/tmpRoot/etc/crontab
mkdir -p "/tmpRoot/usr/lib/systemd/system"
DEST="/tmpRoot/usr/lib/systemd/system/sspatch.service"
cat << EOF > ${DEST}
@ -23,7 +28,7 @@ User=root
Type=simple
Restart=on-failure
RestartSec=5s
ExecStart=/usr/bin/sspatch.sh
ExecStart=-/usr/bin/sspatch.sh
[Install]
WantedBy=multi-user.target

View File

@ -1,6 +1,6 @@
version: 1
name: sspatch
description: "Dynamic License Patch for SS! (Not for DVA)"
description: "Dynamic 50 License Patch for SS 9.2.0-11289!"
system: false
beta: true
all: