From 6694d8c2d964e7a017658c84c224f0076ac135ba Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Sun, 31 Jan 2021 08:04:25 -0800 Subject: [PATCH] dns.mitm: edit default behavior/hosts filenames --- config_templates/system_settings.ini | 2 +- .../dns_mitm/dnsmitm_host_redirection.cpp | 24 +++++++++---------- .../source/set_mitm/settings_sd_kvs.cpp | 2 +- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/config_templates/system_settings.ini b/config_templates/system_settings.ini index 20424d152..f67210883 100644 --- a/config_templates/system_settings.ini +++ b/config_templates/system_settings.ini @@ -48,7 +48,7 @@ ; Controls whether dns.mitm uses the default redirections in addition to ; whatever is specified in the user's hosts file. ; 0 = Disabled (use hosts file contents), 1 = Enabled (use defaults and hosts file contents) -; add_defaults_to_dns_hosts = u8!0x0 +; add_defaults_to_dns_hosts = u8!0x1 [hbloader] ; Controls the size of the homebrew heap when running as applet. ; If set to zero, all available applet memory is used as heap. diff --git a/stratosphere/ams_mitm/source/dns_mitm/dnsmitm_host_redirection.cpp b/stratosphere/ams_mitm/source/dns_mitm/dnsmitm_host_redirection.cpp index 10e5a4391..a9ed4c95a 100644 --- a/stratosphere/ams_mitm/source/dns_mitm/dnsmitm_host_redirection.cpp +++ b/stratosphere/ams_mitm/source/dns_mitm/dnsmitm_host_redirection.cpp @@ -199,7 +199,7 @@ namespace ams::mitm::socket::resolver { Log(log_file, "Selecting hosts file...\n"); const bool is_emummc = emummc::IsActive(); const u32 emummc_id = emummc::GetActiveId(); - util::SNPrintf(g_specific_emummc_hosts_path, sizeof(g_specific_emummc_hosts_path), "/hosts/emummc_%04x", emummc_id); + util::SNPrintf(g_specific_emummc_hosts_path, sizeof(g_specific_emummc_hosts_path), "/hosts/emummc_%04x.txt", emummc_id); if (is_emummc) { if (mitm::fs::HasAtmosphereSdFile(g_specific_emummc_hosts_path)) { @@ -207,18 +207,18 @@ namespace ams::mitm::socket::resolver { } Log(log_file, "Skipping %s because it does not exist...\n", g_specific_emummc_hosts_path); - if (mitm::fs::HasAtmosphereSdFile("/hosts/emummc")) { - return "/hosts/emummc"; + if (mitm::fs::HasAtmosphereSdFile("/hosts/emummc.txt")) { + return "/hosts/emummc.txt"; } - Log(log_file, "Skipping %s because it does not exist...\n", "/hosts/emummc"); + Log(log_file, "Skipping %s because it does not exist...\n", "/hosts/emummc.txt"); } else { - if (mitm::fs::HasAtmosphereSdFile("/hosts/sysmmc")) { - return "/hosts/sysmmc"; + if (mitm::fs::HasAtmosphereSdFile("/hosts/sysmmc.txt")) { + return "/hosts/sysmmc.txt"; } - Log(log_file, "Skipping %s because it does not exist...\n", "/hosts/sysmmc"); + Log(log_file, "Skipping %s because it does not exist...\n", "/hosts/sysmmc.txt"); } - return "/hosts/default"; + return "/hosts/default.txt"; } } @@ -240,14 +240,14 @@ namespace ams::mitm::socket::resolver { Log(log_file, "DNS Mitm:\n"); /* If a default hosts file doesn't exist on the sd card, create one. */ - if (!mitm::fs::HasAtmosphereSdFile("/hosts/default")) { - Log(log_file, "Creating /hosts/default because it does not exist.\n"); + if (!mitm::fs::HasAtmosphereSdFile("/hosts/default.txt")) { + Log(log_file, "Creating /hosts/default.txt because it does not exist.\n"); mitm::fs::CreateAtmosphereSdDirectory("/hosts"); - R_ABORT_UNLESS(mitm::fs::CreateAtmosphereSdFile("/hosts/default", sizeof(DefaultHostsFile) - 1, ams::fs::CreateOption_None)); + R_ABORT_UNLESS(mitm::fs::CreateAtmosphereSdFile("/hosts/default.txt", sizeof(DefaultHostsFile) - 1, ams::fs::CreateOption_None)); ::FsFile default_file; - R_ABORT_UNLESS(mitm::fs::OpenAtmosphereSdFile(std::addressof(default_file), "/hosts/default", ams::fs::OpenMode_ReadWrite)); + R_ABORT_UNLESS(mitm::fs::OpenAtmosphereSdFile(std::addressof(default_file), "/hosts/default.txt", ams::fs::OpenMode_ReadWrite)); R_ABORT_UNLESS(::fsFileWrite(std::addressof(default_file), 0, DefaultHostsFile, sizeof(DefaultHostsFile) - 1, ::FsWriteOption_Flush)); ::fsFileClose(std::addressof(default_file)); } diff --git a/stratosphere/ams_mitm/source/set_mitm/settings_sd_kvs.cpp b/stratosphere/ams_mitm/source/set_mitm/settings_sd_kvs.cpp index 4733bde4a..790b42e36 100644 --- a/stratosphere/ams_mitm/source/set_mitm/settings_sd_kvs.cpp +++ b/stratosphere/ams_mitm/source/set_mitm/settings_sd_kvs.cpp @@ -356,7 +356,7 @@ namespace ams::settings::fwdbg { /* Controls whether dns.mitm uses the default redirections in addition to */ /* whatever is specified in the user's hosts file. */ /* 0 = Disabled (use hosts file contents), 1 = Enabled (use defaults and hosts file contents) */ - R_ABORT_UNLESS(ParseSettingsItemValue("atmosphere", "add_defaults_to_dns_hosts", "u8!0x0")); + R_ABORT_UNLESS(ParseSettingsItemValue("atmosphere", "add_defaults_to_dns_hosts", "u8!0x1")); /* Hbloader custom settings. */