├── README.md ├── .gitignore ├── source └── main.c └── Makefile /README.md: -------------------------------------------------------------------------------- 1 | # switch-90dns-setter 2 | 3 | Applies 90dns to all wifi networks 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | build/ 3 | 4 | *.elf 5 | 6 | *.nacp 7 | 8 | *.nro 9 | 10 | *.nso 11 | 12 | *.pfs0 13 | mydata/ 14 | -------------------------------------------------------------------------------- /source/main.c: -------------------------------------------------------------------------------- 1 | // Include the most common headers from the C standard library 2 | #include 3 | #include 4 | #include 5 | 6 | // Include the main libnx system header, for Switch development 7 | #include 8 | 9 | const char *regions[] = { 10 | "Japan", 11 | "America", 12 | "Europe", 13 | "Australia/New Zealand", 14 | "Hong Kong/Taiwan/Korea", 15 | "China", 16 | }; 17 | 18 | void rebootSystem(){ 19 | spsmInitialize(); 20 | spsmShutdown(true); 21 | spsmExit(); 22 | printf("Something went wrong while rebooting!"); 23 | } 24 | 25 | int main(int argc, char* argv[]) 26 | { 27 | consoleInit(NULL); 28 | 29 | padConfigureInput(1, HidNpadStyleSet_NpadStandard); 30 | 31 | PadState pad; 32 | padInitializeDefault(&pad); 33 | 34 | bool disableX = false; 35 | Result res = 0; 36 | SetRegion region; 37 | u32 europeDns = 0xdb8daca3; // 163.172.141.219 38 | u32 americaDns = 0x4d79f6cf; // 207.246.121.77 39 | 40 | u32 primaryDns = 0; 41 | u32 secondaryDns = 0; 42 | 43 | printf("90dns Setter tool\n\n"); 44 | 45 | res = setInitialize(); 46 | if (res){ 47 | printf("Failed to initialise set! Err %x\n", res); 48 | disableX = true; 49 | } 50 | else { 51 | res = setsysInitialize(); 52 | if (res){ 53 | printf("Failed to initialise setsys! Err %x\n", res); 54 | disableX = true; 55 | } 56 | else { 57 | res = setGetRegionCode(®ion); 58 | if (res){ 59 | printf("Failed to get region! Err %x\n", res); 60 | disableX = true; 61 | } 62 | else { 63 | if (region <= SetRegion_CHN){ 64 | printf("Detected %s as region\n", regions[region]); 65 | if (region == SetRegion_USA){ 66 | printf("American dns will be used as primary\n"); 67 | primaryDns = americaDns; 68 | secondaryDns = europeDns; 69 | } 70 | else { 71 | printf("Europe dns will be used as primary\n"); 72 | primaryDns = europeDns; 73 | secondaryDns = americaDns; 74 | } 75 | } 76 | else { 77 | printf("Unknown region? Europe dns will be used as primary\n"); 78 | primaryDns = europeDns; 79 | secondaryDns = americaDns; 80 | } 81 | 82 | } 83 | } 84 | } 85 | 86 | printf("\nPress + To exit\nPress Y to reboot the system\n"); 87 | if (!disableX) 88 | printf("Press X to apply 90dns to all wifi networks\n"); 89 | 90 | while (appletMainLoop()) 91 | { 92 | // Scan the gamepad. This should be done once for each frame 93 | padUpdate(&pad); 94 | 95 | // padGetButtonsDown returns the set of buttons that have been 96 | // newly pressed in this frame compared to the previous one 97 | u64 kDown = padGetButtonsDown(&pad); 98 | 99 | if (kDown & HidNpadButton_Plus) 100 | break; // break in order to return to hbmenu 101 | 102 | if (kDown & HidNpadButton_Y){ 103 | rebootSystem(); 104 | } 105 | 106 | if (kDown & HidNpadButton_X && !disableX){ 107 | consoleInit(NULL); 108 | 109 | SetSysNetworkSettings* wifiSettings = malloc(sizeof(SetSysNetworkSettings) * 0x200); 110 | 111 | if (wifiSettings != NULL){ 112 | s32 entryCount = 0; 113 | res = setsysGetNetworkSettings(&entryCount, wifiSettings, 0x200); 114 | if (res){ 115 | printf("Getting wifi networks failed! Err %x\n", res); 116 | } 117 | else { 118 | printf("Wifi networks found: %d\n", entryCount); 119 | for (int i = 0; i < entryCount; i++){ 120 | wifiSettings[i].primary_dns = primaryDns; 121 | wifiSettings[i].secondary_dns = secondaryDns; 122 | wifiSettings[i].auto_settings &= ~SetSysAutoSettings_AutoDns; 123 | } 124 | 125 | if (entryCount){ 126 | res = setsysSetNetworkSettings(wifiSettings, entryCount); 127 | if (res){ 128 | printf("Setting wifi networks failed! Err %x\n", res); 129 | } 130 | else { 131 | printf("Done!\nTo apply the changes, reboot the system\n"); 132 | } 133 | } 134 | } 135 | } 136 | else { 137 | printf("Memory allocation failed!\n"); 138 | } 139 | 140 | disableX = true; 141 | printf("\nPress + To exit\nPress Y to reboot the system\n"); 142 | free(wifiSettings); 143 | } 144 | 145 | // Update the console, sending a new frame to the display 146 | consoleUpdate(NULL); 147 | } 148 | 149 | // Deinitialize and clean up resources used by the console (important!) 150 | consoleExit(NULL); 151 | setExit(); 152 | setsysExit(); 153 | return 0; 154 | } 155 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | .SUFFIXES: 3 | #--------------------------------------------------------------------------------- 4 | 5 | ifeq ($(strip $(DEVKITPRO)),) 6 | $(error "Please set DEVKITPRO in your environment. export DEVKITPRO=/devkitpro") 7 | endif 8 | 9 | TOPDIR ?= $(CURDIR) 10 | include $(DEVKITPRO)/libnx/switch_rules 11 | 12 | #--------------------------------------------------------------------------------- 13 | # TARGET is the name of the output 14 | # BUILD is the directory where object files & intermediate files will be placed 15 | # SOURCES is a list of directories containing source code 16 | # DATA is a list of directories containing data files 17 | # INCLUDES is a list of directories containing header files 18 | # ROMFS is the directory containing data to be added to RomFS, relative to the Makefile (Optional) 19 | # 20 | # NO_ICON: if set to anything, do not use icon. 21 | # NO_NACP: if set to anything, no .nacp file is generated. 22 | # APP_TITLE is the name of the app stored in the .nacp file (Optional) 23 | # APP_AUTHOR is the author of the app stored in the .nacp file (Optional) 24 | # APP_VERSION is the version of the app stored in the .nacp file (Optional) 25 | # APP_TITLEID is the titleID of the app stored in the .nacp file (Optional) 26 | # ICON is the filename of the icon (.jpg), relative to the project folder. 27 | # If not set, it attempts to use one of the following (in this order): 28 | # - .jpg 29 | # - icon.jpg 30 | # - /default_icon.jpg 31 | # 32 | # CONFIG_JSON is the filename of the NPDM config file (.json), relative to the project folder. 33 | # If not set, it attempts to use one of the following (in this order): 34 | # - .json 35 | # - config.json 36 | # If a JSON file is provided or autodetected, an ExeFS PFS0 (.nsp) is built instead 37 | # of a homebrew executable (.nro). This is intended to be used for sysmodules. 38 | # NACP building is skipped as well. 39 | #--------------------------------------------------------------------------------- 40 | TARGET := $(notdir $(CURDIR)) 41 | APP_TITLE := 90dns setter 42 | APP_AUTHOR := Such Meme, Many Skill 43 | BUILD := build 44 | SOURCES := source 45 | DATA := data 46 | INCLUDES := include 47 | #ROMFS := romfs 48 | 49 | #--------------------------------------------------------------------------------- 50 | # options for code generation 51 | #--------------------------------------------------------------------------------- 52 | ARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE 53 | 54 | CFLAGS := -g -Wall -O2 -ffunction-sections \ 55 | $(ARCH) $(DEFINES) 56 | 57 | CFLAGS += $(INCLUDE) -D__SWITCH__ 58 | 59 | CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions 60 | 61 | ASFLAGS := -g $(ARCH) 62 | LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) 63 | 64 | LIBS := -lnx 65 | 66 | #--------------------------------------------------------------------------------- 67 | # list of directories containing libraries, this must be the top level containing 68 | # include and lib 69 | #--------------------------------------------------------------------------------- 70 | LIBDIRS := $(PORTLIBS) $(LIBNX) 71 | 72 | 73 | #--------------------------------------------------------------------------------- 74 | # no real need to edit anything past this point unless you need to add additional 75 | # rules for different file extensions 76 | #--------------------------------------------------------------------------------- 77 | ifneq ($(BUILD),$(notdir $(CURDIR))) 78 | #--------------------------------------------------------------------------------- 79 | 80 | export OUTPUT := $(CURDIR)/$(TARGET) 81 | export TOPDIR := $(CURDIR) 82 | 83 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 84 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) 85 | 86 | export DEPSDIR := $(CURDIR)/$(BUILD) 87 | 88 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 89 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 90 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 91 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) 92 | 93 | #--------------------------------------------------------------------------------- 94 | # use CXX for linking C++ projects, CC for standard C 95 | #--------------------------------------------------------------------------------- 96 | ifeq ($(strip $(CPPFILES)),) 97 | #--------------------------------------------------------------------------------- 98 | export LD := $(CC) 99 | #--------------------------------------------------------------------------------- 100 | else 101 | #--------------------------------------------------------------------------------- 102 | export LD := $(CXX) 103 | #--------------------------------------------------------------------------------- 104 | endif 105 | #--------------------------------------------------------------------------------- 106 | 107 | export OFILES_BIN := $(addsuffix .o,$(BINFILES)) 108 | export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) 109 | export OFILES := $(OFILES_BIN) $(OFILES_SRC) 110 | export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES))) 111 | 112 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ 113 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 114 | -I$(CURDIR)/$(BUILD) 115 | 116 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) 117 | 118 | ifeq ($(strip $(CONFIG_JSON)),) 119 | jsons := $(wildcard *.json) 120 | ifneq (,$(findstring $(TARGET).json,$(jsons))) 121 | export APP_JSON := $(TOPDIR)/$(TARGET).json 122 | else 123 | ifneq (,$(findstring config.json,$(jsons))) 124 | export APP_JSON := $(TOPDIR)/config.json 125 | endif 126 | endif 127 | else 128 | export APP_JSON := $(TOPDIR)/$(CONFIG_JSON) 129 | endif 130 | 131 | ifeq ($(strip $(ICON)),) 132 | icons := $(wildcard *.jpg) 133 | ifneq (,$(findstring $(TARGET).jpg,$(icons))) 134 | export APP_ICON := $(TOPDIR)/$(TARGET).jpg 135 | else 136 | ifneq (,$(findstring icon.jpg,$(icons))) 137 | export APP_ICON := $(TOPDIR)/icon.jpg 138 | endif 139 | endif 140 | else 141 | export APP_ICON := $(TOPDIR)/$(ICON) 142 | endif 143 | 144 | ifeq ($(strip $(NO_ICON)),) 145 | export NROFLAGS += --icon=$(APP_ICON) 146 | endif 147 | 148 | ifeq ($(strip $(NO_NACP)),) 149 | export NROFLAGS += --nacp=$(CURDIR)/$(TARGET).nacp 150 | endif 151 | 152 | ifneq ($(APP_TITLEID),) 153 | export NACPFLAGS += --titleid=$(APP_TITLEID) 154 | endif 155 | 156 | ifneq ($(ROMFS),) 157 | export NROFLAGS += --romfsdir=$(CURDIR)/$(ROMFS) 158 | endif 159 | 160 | .PHONY: $(BUILD) clean all 161 | 162 | #--------------------------------------------------------------------------------- 163 | all: $(BUILD) 164 | 165 | $(BUILD): 166 | @[ -d $@ ] || mkdir -p $@ 167 | @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 168 | 169 | #--------------------------------------------------------------------------------- 170 | clean: 171 | @echo clean ... 172 | ifeq ($(strip $(APP_JSON)),) 173 | @rm -fr $(BUILD) $(TARGET).nro $(TARGET).nacp $(TARGET).elf 174 | else 175 | @rm -fr $(BUILD) $(TARGET).nsp $(TARGET).nso $(TARGET).npdm $(TARGET).elf 176 | endif 177 | 178 | 179 | #--------------------------------------------------------------------------------- 180 | else 181 | .PHONY: all 182 | 183 | DEPENDS := $(OFILES:.o=.d) 184 | 185 | #--------------------------------------------------------------------------------- 186 | # main targets 187 | #--------------------------------------------------------------------------------- 188 | ifeq ($(strip $(APP_JSON)),) 189 | 190 | all : $(OUTPUT).nro 191 | 192 | ifeq ($(strip $(NO_NACP)),) 193 | $(OUTPUT).nro : $(OUTPUT).elf $(OUTPUT).nacp 194 | else 195 | $(OUTPUT).nro : $(OUTPUT).elf 196 | endif 197 | 198 | else 199 | 200 | all : $(OUTPUT).nsp 201 | 202 | $(OUTPUT).nsp : $(OUTPUT).nso $(OUTPUT).npdm 203 | 204 | $(OUTPUT).nso : $(OUTPUT).elf 205 | 206 | endif 207 | 208 | $(OUTPUT).elf : $(OFILES) 209 | 210 | $(OFILES_SRC) : $(HFILES_BIN) 211 | 212 | #--------------------------------------------------------------------------------- 213 | # you need a rule like this for each extension you use as binary data 214 | #--------------------------------------------------------------------------------- 215 | %.bin.o %_bin.h : %.bin 216 | #--------------------------------------------------------------------------------- 217 | @echo $(notdir $<) 218 | @$(bin2o) 219 | 220 | -include $(DEPENDS) 221 | 222 | #--------------------------------------------------------------------------------------- 223 | endif 224 | #--------------------------------------------------------------------------------------- 225 | --------------------------------------------------------------------------------