PS Wiki

Живее всех живых

Инструменты пользователя

Инструменты сайта


nsw:dev:kefir_sh

Различия

Показаны различия между двумя версиями страницы.

Ссылка на это сравнение

Предыдущая версия справа и слеваПредыдущая версия
Следующая версия
Предыдущая версия
nsw:dev:kefir_sh [2022.04.01 15:55:47] adminnsw:dev:kefir_sh [2022.04.13 03:47:36] (текущий) – [kefir.cpp] admin
Строка 1: Строка 1:
 ====== Kefir refreSH ====== ====== Kefir refreSH ======
 +===== kefir.sh =====
 <file bash kefir.sh> <file bash kefir.sh>
 #!/bin/sh #!/bin/sh
 kver=123 kver=123
-echo "Kefir Version:" +if [ -n "$1" ]; then 
-read kver+  kver=$1 
 +else 
 +  echo "Please enter Kefir version: " 
 +  read kver 
 +fi
 user=Atmosphere-NX user=Atmosphere-NX
 repo=Atmosphere repo=Atmosphere
Строка 11: Строка 16:
   if ! [ -f ./$repo.zip ]; then   if ! [ -f ./$repo.zip ]; then
     git clone --recurse-submodules https://github.com/$user/$repo     git clone --recurse-submodules https://github.com/$user/$repo
-    zip -r ./$repo.zip ./$repo/*+#    zip -r ./$repo.zip ./$repo/*
   else   else
     unzip ./$repo.zip     unzip ./$repo.zip
Строка 36: Строка 41:
  
 #sed -i 's///g' ./stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.cpp #sed -i 's///g' ./stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.cpp
-#...+md5 for 1.3.0 release is fa0f38f14964ec619527832357ec617c 
 +# md5 for 1.3.1 release is 7d34d689829a6b5d95954b410519beec  
 +if ! [ $(md5sum ./stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.cpp | awk '{print $1}') = 7d34d689829a6b5d95954b410519beec ]; then 
 +  echo "WARNING: md5sum is not same, replace the file and press enter" 
 +  read 
 +fi 
 +rm ./stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.cpp 
 +cp ../setsys_mitm_service.kef ./stratosphere/ams_mitm/source/set_mitm/setsys_mitm_service.cpp
  
 #sed -i 's///g' ./stratosphere/loader/source/ldr_development_manager.cpp #sed -i 's///g' ./stratosphere/loader/source/ldr_development_manager.cpp
Строка 52: Строка 64:
 sed -i 's/if (g_exfat_supported)/if (0)/g' ./troposphere/daybreak/source/ui.cpp sed -i 's/if (g_exfat_supported)/if (0)/g' ./troposphere/daybreak/source/ui.cpp
  
-#sed -i 's///g' ./libraries/libvapours/include/vapours/ams/ams_api_version.h +#sed -i 's///g' ./stratosphere/fatal/source/fatal_task_error_report.cpp [unused] 
-if [ $(wc -c ./libraries/libvapours/include/vapours/ams/ams_api_version.h | awk '{print $1}') -le 1078 ]; then +#sed -i 's/\%u.\%u.\%u-\%s/\%u.\%u.\%u-\%s-KEF'$kver'/g' ./stratosphere/fatal/source/fatal_task_error_report.cpp 
-  echo "#define KEFIR_RELEASE_VERSION $kver" >> ./libraries/libvapours/include/vapours/ams/ams_api_version.h + 
-else +#sed -i 's///g' ./stratosphere/fatal/source/fatal_task_screen.cpp [unused] 
-  sed -i 's/KEFIR_RELEASE_VERSION [0-9][0-9][0-9]/KEFIR_RELEASE_VERSION '$kver'/g' ./libraries/libvapours/include/vapours/ams/ams_api_version.h +#sed -i 's/\%u.\%u.\%u-\%s/\%u.\%u.\%u-\%s-KEF'$kver'/g' ./stratosphere/fatal/source/fatal_task_screen.cpp 
-fi+ 
 +#sed -i 's///g' ./libraries/libvapours/include/vapours/ams/ams_api_version.h [unused] 
 +#if [ $(wc -c ./libraries/libvapours/include/vapours/ams/ams_api_version.h | awk '{print $1}') -le 1078 ]; then 
 + echo "#define KEFIR_RELEASE_VERSION $kver" >> ./libraries/libvapours/include/vapours/ams/ams_api_version.h 
 +#else 
 + sed -i 's/KEFIR_RELEASE_VERSION [0-9][0-9][0-9]/KEFIR_RELEASE_VERSION '$kver'/g' ./libraries/libvapours/include/vapours/ams/ams_api_version.h 
 +#fi 
 + 
 +#sed -i 's///g' ./libraries/config/common.mk 
 +sed -i 's/dirty/KEF'$kver'/g' ./libraries/config/common.mk
  
 make make
 +</file>
 +===== kefir.cpp =====
 +<file cpp setsys_mitm_service.kef>
 +/*
 + * Copyright (c) Atmosphère-NX
 + *
 + * This program is free software; you can redistribute it and/or modify it
 + * under the terms and conditions of the GNU General Public License,
 + * version 2, as published by the Free Software Foundation.
 + *
 + * This program is distributed in the hope 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 this program.  If not, see <http://www.gnu.org/licenses/>.
 + */
 +#include <stratosphere.hpp>
 +#include "setsys_mitm_service.hpp"
 +#include "settings_sd_kvs.hpp"
 +
 +namespace ams::mitm::settings {
 +
 +    using namespace ams::settings;
 +
 +    namespace {
 +
 +        constinit os::SdkMutex g_firmware_version_lock;
 +        constinit bool g_cached_firmware_version;
 +        constinit settings::FirmwareVersion g_firmware_version;
 +        constinit settings::FirmwareVersion g_ams_firmware_version;
 +
 +        int g_kfr_firmware_version = 0;
 +
 +        void CacheFirmwareVersion() {
 +            if (AMS_LIKELY(g_cached_firmware_version)) {
 +                return;
 +            }
 +
 +            std::scoped_lock lk(g_firmware_version_lock);
 +
 +            if (AMS_UNLIKELY(g_cached_firmware_version)) {
 +                return;
 +            }
 +
 +            /* Mount the SD card. */
 +            {
 +                if (R_SUCCEEDED(fs::MountSdCard("sdmc"))) {
 +                    ams::fs::FileHandle file;
 +                    if (R_SUCCEEDED(fs::OpenFile(std::addressof(file), "sdmc:/switch/kefir-updater/version", fs::OpenMode_Read))) {
 +                        ON_SCOPE_EXIT { ams::fs::CloseFile(file); };
 +
 +                        /* Get file size. */
 +                        s64 file_size;
 +                        R_ABORT_UNLESS(fs::GetFileSize(std::addressof(file_size), file));
 +
 +                        /* Allocate kver txt buffer. */
 +                        char *kef_txt = static_cast<char *>(std::malloc(file_size + 1));
 +                        ON_SCOPE_EXIT { std::free(kef_txt); };
 +
 +                        /* Read kver into buffer. */
 +                        R_ABORT_UNLESS(fs::ReadFile(file, 0, kef_txt, file_size));
 +                        kef_txt[file_size] = '\x00';
 +
 +                        g_kfr_firmware_version = strtol(kef_txt, NULL, 10);
 +                    }
 +                }
 +            }
 +
 +            /* Mount firmware version data archive. */
 +            {
 +                R_ABORT_UNLESS(ams::fs::MountSystemData("sysver", ncm::SystemDataId::SystemVersion));
 +                ON_SCOPE_EXIT { ams::fs::Unmount("sysver"); };
 +
 +                /* Firmware version file must exist. */
 +                ams::fs::FileHandle file;
 +                R_ABORT_UNLESS(ams::fs::OpenFile(std::addressof(file), "sysver:/file", fs::OpenMode_Read));
 +                ON_SCOPE_EXIT { ams::fs::CloseFile(file); };
 +
 +                /* Must be possible to read firmware version from file. */
 +                R_ABORT_UNLESS(ams::fs::ReadFile(file, 0, std::addressof(g_firmware_version), sizeof(g_firmware_version)));
 +
 +                g_ams_firmware_version = g_firmware_version;
 +            }
 +
 +            /* Modify the atmosphere firmware version to display a custom version string. */
 +            {
 +                const auto api_info = exosphere::GetApiInfo();
 +                const char emummc_char = emummc::IsActive() ? 'E' : 'S';
 +
 +                /* NOTE: We have carefully accounted for the size of the string we print. */
 +                /* No truncation occurs assuming two-digits for all version number components. */
 +                char display_version[sizeof(g_ams_firmware_version.display_version)];
 +
 +                if (g_kfr_firmware_version != 0)
 +                    util::SNPrintf(display_version, sizeof(display_version), "%s|KEF%d-%u.%u.%u|%c", g_ams_firmware_version.display_version, g_kfr_firmware_version, api_info.GetMajorVersion(), api_info.GetMinorVersion(), api_info.GetMicroVersion(), emummc_char);
 +                else
 +                    util::SNPrintf(display_version, sizeof(display_version), "%s|KEF-%u.%u.%u|%c", g_ams_firmware_version.display_version, api_info.GetMajorVersion(), api_info.GetMinorVersion(), api_info.GetMicroVersion(), emummc_char);
 +
 +                std::memcpy(g_ams_firmware_version.display_version, display_version, sizeof(display_version));
 +            }
 +
 +            g_cached_firmware_version = true;
 +        }
 +
 +        Result GetFirmwareVersionImpl(settings::FirmwareVersion *out, const sm::MitmProcessInfo &client_info) {
 +            /* Ensure that we have the firmware version cached. */
 +            CacheFirmwareVersion();
 +
 +            /* We want to give a special firmware version to the home menu title, and nothing else. */
 +            /* This means Qlaunch + Maintenance Menu, and nothing else. */
 +            if (client_info.program_id == ncm::SystemAppletId::Qlaunch || client_info.program_id == ncm::SystemAppletId::MaintenanceMenu) {
 +                *out = g_ams_firmware_version;
 +            } else {
 +                *out = g_firmware_version;
 +            }
 +
 +            R_SUCCEED();
 +        }
 +
 +    }
 +
 +    Result SetSysMitmService::GetFirmwareVersion(sf::Out<settings::FirmwareVersion> out) {
 +        R_TRY(GetFirmwareVersionImpl(out.GetPointer(), m_client_info));
 +
 +        /* GetFirmwareVersion sanitizes the revision fields. */
 +        out.GetPointer()->revision_major = 0;
 +        out.GetPointer()->revision_minor = 0;
 +        R_SUCCEED();
 +    }
 +
 +    Result SetSysMitmService::GetFirmwareVersion2(sf::Out<settings::FirmwareVersion> out) {
 +        R_RETURN(GetFirmwareVersionImpl(out.GetPointer(), m_client_info));
 +    }
 +
 +    Result SetSysMitmService::GetSettingsItemValueSize(sf::Out<u64> out_size, const settings::SettingsName &name, const settings::SettingsItemKey &key) {
 +        R_TRY_CATCH(settings::fwdbg::GetSdCardKeyValueStoreSettingsItemValueSize(out_size.GetPointer(), name.value, key.value)) {
 +            R_CATCH_RETHROW(sf::impl::ResultRequestContextChanged)
 +            R_CONVERT_ALL(sm::mitm::ResultShouldForwardToSession());
 +        } R_END_TRY_CATCH;
 +
 +        R_SUCCEED();
 +    }
 +
 +    Result SetSysMitmService::GetSettingsItemValue(sf::Out<u64> out_size, const sf::OutBuffer &out, const settings::SettingsName &name, const settings::SettingsItemKey &key) {
 +        R_TRY_CATCH(settings::fwdbg::GetSdCardKeyValueStoreSettingsItemValue(out_size.GetPointer(), out.GetPointer(), out.GetSize(), name.value, key.value)) {
 +            R_CATCH_RETHROW(sf::impl::ResultRequestContextChanged)
 +            R_CONVERT_ALL(sm::mitm::ResultShouldForwardToSession());
 +        } R_END_TRY_CATCH;
 +
 +        R_SUCCEED();
 +    }
 +
 +    Result SetSysMitmService::GetDebugModeFlag(sf::Out<bool> out) {
 +        /* If we're not processing for am, just return the real flag value. */
 +        R_UNLESS(m_client_info.program_id == ncm::SystemProgramId::Am, sm::mitm::ResultShouldForwardToSession());
 +
 +        /* Retrieve the user configuration. */
 +        u8 en = 0;
 +        settings::fwdbg::GetSettingsItemValue(std::addressof(en), sizeof(en), "atmosphere", "enable_am_debug_mode");
 +
 +        out.SetValue(en != 0);
 +        R_SUCCEED();
 +    }
 +
 +}
 </file> </file>
nsw/dev/kefir_sh.1648817747.txt.gz · Последнее изменение: 2022.04.01 15:55:47 — admin