├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── config.json ├── resources ├── audio.wav ├── banner.png ├── icon.png ├── logo.bcma.lz └── rominfo.rsf └── source ├── cia.c ├── cia.h ├── common.hpp ├── config.cpp ├── config.hpp ├── download.cpp ├── download.hpp ├── extract.cpp ├── extract.hpp ├── file.c ├── file.h ├── json.hpp ├── main.cpp ├── menu.cpp ├── menu.hpp ├── stringutils.cpp └── stringutils.hpp /.gitignore: -------------------------------------------------------------------------------- 1 | *.smdh 2 | *.bin 3 | *.bnr 4 | *.icn 5 | *.icon 6 | *.3dsx 7 | *.elf 8 | *.bat 9 | *.lnk 10 | *.cia 11 | *.lst 12 | *.map 13 | build/* 14 | out/* -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 LiquidFenrir 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | .SUFFIXES: 3 | #--------------------------------------------------------------------------------- 4 | 5 | ifeq ($(strip $(DEVKITARM)),) 6 | $(error "Please set DEVKITARM in your environment. export DEVKITARM=devkitARM") 7 | endif 8 | 9 | TOPDIR ?= $(CURDIR) 10 | include $(DEVKITARM)/3ds_rules 11 | 12 | APP_TITLE := MultiUpdater 13 | APP_DESCRIPTION := Updater for FIRM payloads, CIAs, and other files. 14 | APP_AUTHOR := LiquidFenrir 15 | 16 | TARGET := MultiUpdater 17 | OUTDIR := out 18 | BUILD := build 19 | SOURCES := source 20 | INCLUDES := include 21 | RESOURCES := $(CURDIR)/resources 22 | 23 | ICON := $(RESOURCES)/icon.png 24 | ICON_FLAGS := visible,nosavebackups 25 | 26 | BANNER_AUDIO := $(RESOURCES)/audio.wav 27 | BANNER_IMAGE := $(RESOURCES)/banner.png 28 | 29 | RSF_PATH := $(RESOURCES)/rominfo.rsf 30 | PRODUCT_CODE := CTR-P-ULTI 31 | UNIQUE_ID := 0xd5c49 32 | 33 | LOGO := $(RESOURCES)/logo.bcma.lz 34 | 35 | VERSION := $(shell git describe --tags) 36 | VERSION_MAJOR := $(shell echo $(VERSION) | cut -c2- | cut -f1 -d- | cut -f1 -d.) 37 | VERSION_MINOR := $(shell echo $(VERSION) | cut -c2- | cut -f1 -d- | cut -f2 -d.) 38 | VERSION_BUILD := $(shell echo $(VERSION) | cut -c2- | cut -f1 -d- | cut -f3 -d.) 39 | 40 | ifeq ($(strip $(VERSION_BUILD)),) 41 | VERSION_BUILD := 0 42 | endif 43 | 44 | #--------------------------------------------------------------------------------- 45 | # options for code generation 46 | #--------------------------------------------------------------------------------- 47 | ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft 48 | 49 | CFLAGS := -g -O2 -Wall -Wextra -mword-relocations \ 50 | -fomit-frame-pointer -ffunction-sections \ 51 | $(ARCH) 52 | 53 | CFLAGS += $(INCLUDE) -DARM11 -D_3DS -D_GNU_SOURCE -DAPP_TITLE="\"$(APP_TITLE)\"" -DAPP_AUTHOR="\"$(APP_AUTHOR)\"" -DVERSION_STRING="\"$(VERSION)\"" 54 | 55 | CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11 56 | 57 | ASFLAGS := -g $(ARCH) 58 | LDFLAGS = -specs=3dsx.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) 59 | 60 | LIBS := -lcurl -lmbedtls -lmbedx509 -lmbedcrypto -larchive -lbz2 -llzma -lz -lctru -lm 61 | 62 | #--------------------------------------------------------------------------------- 63 | # list of directories containing libraries, this must be the top level containing 64 | # include and lib 65 | #--------------------------------------------------------------------------------- 66 | LIBDIRS := $(CTRULIB) $(PORTLIBS) $(PORTLIBS_PATH) 67 | 68 | 69 | #--------------------------------------------------------------------------------- 70 | # no real need to edit anything past this point unless you need to add additional 71 | # rules for different file extensions 72 | #--------------------------------------------------------------------------------- 73 | ifneq ($(BUILD),$(notdir $(CURDIR))) 74 | #--------------------------------------------------------------------------------- 75 | 76 | export OUTPUT := $(CURDIR)/$(OUTDIR)/$(TARGET) 77 | export TOPDIR := $(CURDIR) 78 | 79 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 80 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) 81 | 82 | export DEPSDIR := $(CURDIR)/$(BUILD) 83 | 84 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 85 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 86 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 87 | PICAFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.v.pica))) 88 | SHLISTFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.shlist))) 89 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) 90 | 91 | #--------------------------------------------------------------------------------- 92 | # use CXX for linking C++ projects, CC for standard C 93 | #--------------------------------------------------------------------------------- 94 | ifeq ($(strip $(CPPFILES)),) 95 | #--------------------------------------------------------------------------------- 96 | export LD := $(CC) 97 | #--------------------------------------------------------------------------------- 98 | else 99 | #--------------------------------------------------------------------------------- 100 | export LD := $(CXX) 101 | #--------------------------------------------------------------------------------- 102 | endif 103 | #--------------------------------------------------------------------------------- 104 | 105 | export OFILES := $(addsuffix .o,$(BINFILES)) \ 106 | $(PICAFILES:.v.pica=.shbin.o) $(SHLISTFILES:.shlist=.shbin.o) \ 107 | $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) 108 | 109 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ 110 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 111 | -I$(CURDIR)/$(BUILD) 112 | 113 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) 114 | 115 | ifeq ($(strip $(ICON)),) 116 | icons := $(wildcard *.png) 117 | ifneq (,$(findstring $(TARGET).png,$(icons))) 118 | export APP_ICON := $(TOPDIR)/$(TARGET).png 119 | else 120 | ifneq (,$(findstring icon.png,$(icons))) 121 | export APP_ICON := $(TOPDIR)/icon.png 122 | endif 123 | endif 124 | else 125 | export APP_ICON := $(ICON) 126 | endif 127 | 128 | ifeq ($(strip $(NO_SMDH)),) 129 | export _3DSXFLAGS += --smdh=$(OUTPUT).smdh 130 | endif 131 | 132 | ifneq ($(ROMFS),) 133 | export _3DSXFLAGS += --romfs=$(CURDIR)/$(ROMFS) 134 | endif 135 | 136 | .PHONY: $(BUILD) clean all release 137 | 138 | #--------------------------------------------------------------------------------- 139 | 3dsx: $(BUILD) 140 | 141 | cia : $(OUTPUT).cia 142 | 143 | all: 3dsx cia 144 | 145 | release: clean all $(OUTPUT)-$(VERSION).zip 146 | 147 | $(BUILD): 148 | @mkdir -p $(OUTDIR) 149 | @[ -d "$@" ] || mkdir -p "$@" 150 | @$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 151 | @rm -f "$(OUTPUT).smdh" 152 | 153 | #--------------------------------------------------------------------------------- 154 | clean: 155 | @echo clean ... 156 | @rm -fr "$(BUILD)" "$(OUTDIR)" 157 | 158 | #--------------------------------------------------------------------------------- 159 | %.zip: 160 | @7z a -bso0 "$@" "$(OUTPUT).cia" "$(OUTPUT).3dsx" 161 | @7z rn -bso0 "$@" "$(TARGET).3dsx" "3ds/$(TARGET)/$(TARGET).3dsx" 162 | 163 | #--------------------------------------------------------------------------------- 164 | 165 | MAKEROM ?= makerom 166 | 167 | %.cia: $(OUTPUT).elf $(BUILD)/banner.bnr $(BUILD)/icon.icn 168 | $(MAKEROM) -f cia -o "$@" -elf "$(OUTPUT).elf" -rsf "$(RSF_PATH)" -logo "$(LOGO)" -target t -exefslogo -banner "$(BUILD)/banner.bnr" -icon "$(BUILD)/icon.icn" -DAPP_TITLE="$(APP_TITLE)" -DAPP_PRODUCT_CODE="$(PRODUCT_CODE)" -DAPP_UNIQUE_ID="$(UNIQUE_ID)" -major $(VERSION_MAJOR) -minor $(VERSION_MINOR) -micro $(VERSION_BUILD) 169 | 170 | # Banner 171 | 172 | BANNERTOOL ?= bannertool 173 | 174 | ifeq ($(suffix $(BANNER_IMAGE)),.cgfx) 175 | BANNER_IMAGE_ARG := -ci 176 | else 177 | BANNER_IMAGE_ARG := -i 178 | endif 179 | 180 | ifeq ($(suffix $(BANNER_AUDIO)),.cwav) 181 | BANNER_AUDIO_ARG := -ca 182 | else 183 | BANNER_AUDIO_ARG := -a 184 | endif 185 | 186 | $(BUILD)/banner.bnr : $(BANNER_IMAGE) $(BANNER_AUDIO) 187 | $(BANNERTOOL) makebanner $(BANNER_IMAGE_ARG) "$(BANNER_IMAGE)" $(BANNER_AUDIO_ARG) "$(BANNER_AUDIO)" -o "$@" 188 | 189 | $(BUILD)/icon.icn : $(ICON) 190 | $(BANNERTOOL) makesmdh -s "$(APP_TITLE)" -l "$(APP_DESCRIPTION)" -p "$(APP_AUTHOR)" -i "$(ICON)" -f "$(ICON_FLAGS)" -o "$@" 191 | 192 | 193 | #--------------------------------------------------------------------------------- 194 | else 195 | 196 | DEPENDS := $(OFILES:.o=.d) 197 | 198 | #--------------------------------------------------------------------------------- 199 | # main targets 200 | #--------------------------------------------------------------------------------- 201 | ifeq ($(strip $(NO_SMDH)),) 202 | $(OUTPUT).3dsx : $(OUTPUT).elf $(OUTPUT).smdh 203 | else 204 | $(OUTPUT).3dsx : $(OUTPUT).elf 205 | endif 206 | 207 | $(OUTPUT).elf : $(OFILES) 208 | 209 | #--------------------------------------------------------------------------------- 210 | # you need a rule like this for each extension you use as binary data 211 | #--------------------------------------------------------------------------------- 212 | %.bin.o : %.bin 213 | #--------------------------------------------------------------------------------- 214 | @echo $(notdir $<) 215 | @$(bin2o) 216 | 217 | #--------------------------------------------------------------------------------- 218 | # rules for assembling GPU shaders 219 | #--------------------------------------------------------------------------------- 220 | define shader-as 221 | $(eval CURBIN := $(patsubst %.shbin.o,%.shbin,$(notdir $@))) 222 | picasso -o $(CURBIN) $1 223 | bin2s $(CURBIN) | $(AS) -o $@ 224 | echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(CURBIN) | tr . _)`.h 225 | echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(CURBIN) | tr . _)`.h 226 | echo "extern const u32" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(CURBIN) | tr . _)`.h 227 | endef 228 | 229 | %.shbin.o : %.v.pica %.g.pica 230 | @echo $(notdir $^) 231 | @$(call shader-as,$^) 232 | 233 | %.shbin.o : %.v.pica 234 | @echo $(notdir $<) 235 | @$(call shader-as,$<) 236 | 237 | %.shbin.o : %.shlist 238 | @echo $(notdir $<) 239 | @$(call shader-as,$(foreach file,$(shell cat $<),$(dir $<)/$(file))) 240 | 241 | -include $(DEPENDS) 242 | 243 | #--------------------------------------------------------------------------------------- 244 | endif 245 | #--------------------------------------------------------------------------------------- 246 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Archived project 2 | This will not be worked on anymore. 3 | 4 | # MultiUpdater 5 | MultiUpdater is an updater for FIRM payloads, CIA applications, and other files on the SD card. 6 | 7 | # Configuration 8 | The configuration file is named `config.json` and should be placed in `/3ds/MultiUpdater/`. 9 | An example config can be found in the repo. 10 | 11 | # Dependencies / Requirements 12 | This project requires ctrulib, zlib, bzip2, xz, libarchive, curl and mbedtls. 13 | zlib, bzip2, xz, libarchive, curl and mbedtls can be installed with [3ds_portlibs](https://github.com/devkitPro/3ds_portlibs). 14 | 15 | # Compilation 16 | Just run `make` in terminal. Bannertool and makerom **must** be in your PATH or CIA compilation will fail. 17 | 18 | # License 19 | MultiUpdater is licensed under the MIT license, a copy of which can be found in the [LICENSE file](../blob/master/LICENSE). 20 | 21 | # Credits 22 | All of the ctrulib contributors, for ctrulib which this depends upon 23 | Angelsl for libctrfgh, from which the example curl code has been taken 24 | \#Cakey on freenode for help 25 | -------------------------------------------------------------------------------- /config.json: -------------------------------------------------------------------------------- 1 | { 2 | "config": { 3 | "self_updater": false, 4 | "delete_archives": true, 5 | "delete_cias": false 6 | }, 7 | "entries": [ 8 | { 9 | "name": "Anemone3DS", 10 | "url": "https://github.com/astronautlevel2/Anemone3DS", 11 | "inrelease": "Anemone3DS\\.cia", 12 | "path": "/cias/Anemone3DS.cia" 13 | }, 14 | { 15 | "name": "3DSident", 16 | "url": "https://github.com/joel16/3DSident", 17 | "inrelease": "3DSident-GUI\\.cia", 18 | "path": "/cias/3DSident-GUI.cia" 19 | }, 20 | { 21 | "name": "Checkpoint", 22 | "url": "https://github.com/BernardoGiordano/Checkpoint", 23 | "inrelease": "Checkpoint\\.cia", 24 | "path": "/cias/Checkpoint.cia" 25 | }, 26 | { 27 | "name": "GodMode9 (latest release)", 28 | "url": "https://github.com/d0k3/GodMode9", 29 | "inrelease": "GodMode9.*\\.zip", 30 | "inarchive": "GodMode9\\.firm", 31 | "path": "/luma/payloads/GodMode9.firm" 32 | }, 33 | { 34 | "name": "Luma3DS (latest commit)", 35 | "url": "https://astronautlevel2.github.io/Luma3DS/latest.zip", 36 | "inarchive": "out/boot\\.firm", 37 | "path": "/boot.firm" 38 | }, 39 | { 40 | "name": "Luma3DS (latest release)", 41 | "url": "https://github.com/AuroraWright/Luma3DS", 42 | "inrelease": "Luma3DS.*\\.7z", 43 | "inarchive": "boot\\.firm", 44 | "path": "/boot.firm" 45 | }, 46 | { 47 | "name": "CTRNAND Luma3DS (latest release)", 48 | "url": "https://github.com/AuroraWright/Luma3DS", 49 | "inrelease": "Luma3DS.*\\.7z", 50 | "inarchive": "boot\\.firm", 51 | "path": "ctrnand:/boot.firm" 52 | } 53 | ] 54 | } 55 | -------------------------------------------------------------------------------- /resources/audio.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFenrir/MultiUpdater/7d0ce6df21de24924c851f9e4049e2c17b08d9a4/resources/audio.wav -------------------------------------------------------------------------------- /resources/banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFenrir/MultiUpdater/7d0ce6df21de24924c851f9e4049e2c17b08d9a4/resources/banner.png -------------------------------------------------------------------------------- /resources/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFenrir/MultiUpdater/7d0ce6df21de24924c851f9e4049e2c17b08d9a4/resources/icon.png -------------------------------------------------------------------------------- /resources/logo.bcma.lz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/LiquidFenrir/MultiUpdater/7d0ce6df21de24924c851f9e4049e2c17b08d9a4/resources/logo.bcma.lz -------------------------------------------------------------------------------- /resources/rominfo.rsf: -------------------------------------------------------------------------------- 1 | BasicInfo: 2 | Title : $(APP_TITLE) 3 | ProductCode : $(APP_PRODUCT_CODE) 4 | Logo : Homebrew 5 | 6 | TitleInfo: 7 | Category : Application 8 | UniqueId : $(APP_UNIQUE_ID) 9 | 10 | Option: 11 | UseOnSD : true # true if App is to be installed to SD 12 | FreeProductCode : true # Removes limitations on ProductCode 13 | MediaFootPadding : false # If true CCI files are created with padding 14 | EnableCrypt : false # Enables encryption for NCCH and CIA 15 | EnableCompress : true # Compresses where applicable (currently only exefs:/.code) 16 | 17 | AccessControlInfo: 18 | CoreVersion : 2 19 | 20 | # Exheader Format Version 21 | DescVersion : 2 22 | 23 | # Minimum Required Kernel Version (below is for 4.5.0) 24 | ReleaseKernelMajor : "02" 25 | ReleaseKernelMinor : "46" 26 | 27 | # ExtData 28 | UseExtSaveData : false # enables ExtData 29 | #ExtSaveDataId : 0x300 # only set this when the ID is different to the UniqueId 30 | 31 | # FS:USER Archive Access Permissions 32 | # Uncomment as required 33 | FileSystemAccess: 34 | - CategorySystemApplication 35 | - CategoryHardwareCheck 36 | - CategoryFileSystemTool 37 | - Debug 38 | - TwlCardBackup 39 | - TwlNandData 40 | - Boss 41 | - DirectSdmc 42 | - Core 43 | - CtrNandRo 44 | - CtrNandRw 45 | - CtrNandRoWrite 46 | - CategorySystemSettings 47 | - CardBoard 48 | - ExportImportIvs 49 | - DirectSdmcWrite 50 | - SwitchCleanup 51 | - SaveDataMove 52 | - Shop 53 | - Shell 54 | - CategoryHomeMenu 55 | - SeedDB 56 | IoAccessControl: 57 | - FsMountNand 58 | - FsMountNandRoWrite 59 | - FsMountTwln 60 | - FsMountWnand 61 | - FsMountCardSpi 62 | - UseSdif3 63 | - CreateSeed 64 | - UseCardSpi 65 | 66 | # Process Settings 67 | MemoryType : Application # Application/System/Base 68 | SystemMode : 64MB # 64MB(Default)/96MB/80MB/72MB/32MB 69 | IdealProcessor : 0 70 | AffinityMask : 1 71 | Priority : 16 72 | MaxCpu : 0x9E # Default 73 | HandleTableSize : 0x200 74 | DisableDebug : false 75 | EnableForceDebug : false 76 | CanWriteSharedPage : true 77 | CanUsePrivilegedPriority : false 78 | CanUseNonAlphabetAndNumber : true 79 | PermitMainFunctionArgument : true 80 | CanShareDeviceMemory : true 81 | RunnableOnSleep : false 82 | SpecialMemoryArrange : true 83 | 84 | # New3DS Exclusive Process Settings 85 | SystemModeExt : Legacy # Legacy(Default)/124MB/178MB Legacy:Use Old3DS SystemMode 86 | CpuSpeed : 804MHz # 268MHz(Default)/804MHz 87 | EnableL2Cache : true # false(default)/true 88 | CanAccessCore2 : false 89 | 90 | # Virtual Address Mappings 91 | IORegisterMapping: 92 | - 1ff00000-1ff7ffff # DSP memory 93 | MemoryMapping: 94 | - 1f000000-1f5fffff:r # VRAM 95 | 96 | # Accessible SVCs, : 97 | SystemCallAccess: 98 | ControlMemory: 1 99 | QueryMemory: 2 100 | ExitProcess: 3 101 | GetProcessAffinityMask: 4 102 | SetProcessAffinityMask: 5 103 | GetProcessIdealProcessor: 6 104 | SetProcessIdealProcessor: 7 105 | CreateThread: 8 106 | ExitThread: 9 107 | SleepThread: 10 108 | GetThreadPriority: 11 109 | SetThreadPriority: 12 110 | GetThreadAffinityMask: 13 111 | SetThreadAffinityMask: 14 112 | GetThreadIdealProcessor: 15 113 | SetThreadIdealProcessor: 16 114 | GetCurrentProcessorNumber: 17 115 | Run: 18 116 | CreateMutex: 19 117 | ReleaseMutex: 20 118 | CreateSemaphore: 21 119 | ReleaseSemaphore: 22 120 | CreateEvent: 23 121 | SignalEvent: 24 122 | ClearEvent: 25 123 | CreateTimer: 26 124 | SetTimer: 27 125 | CancelTimer: 28 126 | ClearTimer: 29 127 | CreateMemoryBlock: 30 128 | MapMemoryBlock: 31 129 | UnmapMemoryBlock: 32 130 | CreateAddressArbiter: 33 131 | ArbitrateAddress: 34 132 | CloseHandle: 35 133 | WaitSynchronization1: 36 134 | WaitSynchronizationN: 37 135 | SignalAndWait: 38 136 | DuplicateHandle: 39 137 | GetSystemTick: 40 138 | GetHandleInfo: 41 139 | GetSystemInfo: 42 140 | GetProcessInfo: 43 141 | GetThreadInfo: 44 142 | ConnectToPort: 45 143 | SendSyncRequest1: 46 144 | SendSyncRequest2: 47 145 | SendSyncRequest3: 48 146 | SendSyncRequest4: 49 147 | SendSyncRequest: 50 148 | OpenProcess: 51 149 | OpenThread: 52 150 | GetProcessId: 53 151 | GetProcessIdOfThread: 54 152 | GetThreadId: 55 153 | GetResourceLimit: 56 154 | GetResourceLimitLimitValues: 57 155 | GetResourceLimitCurrentValues: 58 156 | GetThreadContext: 59 157 | Break: 60 158 | OutputDebugString: 61 159 | ControlPerformanceCounter: 62 160 | CreatePort: 71 161 | CreateSessionToPort: 72 162 | CreateSession: 73 163 | AcceptSession: 74 164 | ReplyAndReceive1: 75 165 | ReplyAndReceive2: 76 166 | ReplyAndReceive3: 77 167 | ReplyAndReceive4: 78 168 | ReplyAndReceive: 79 169 | BindInterrupt: 80 170 | UnbindInterrupt: 81 171 | InvalidateProcessDataCache: 82 172 | StoreProcessDataCache: 83 173 | FlushProcessDataCache: 84 174 | StartInterProcessDma: 85 175 | StopDma: 86 176 | GetDmaState: 87 177 | RestartDma: 88 178 | DebugActiveProcess: 96 179 | BreakDebugProcess: 97 180 | TerminateDebugProcess: 98 181 | GetProcessDebugEvent: 99 182 | ContinueDebugEvent: 100 183 | GetProcessList: 101 184 | GetThreadList: 102 185 | GetDebugThreadContext: 103 186 | SetDebugThreadContext: 104 187 | QueryDebugProcessMemory: 105 188 | ReadProcessMemory: 106 189 | WriteProcessMemory: 107 190 | SetHardwareBreakPoint: 108 191 | GetDebugThreadParam: 109 192 | ControlProcessMemory: 112 193 | MapProcessMemory: 113 194 | UnmapProcessMemory: 114 195 | CreateCodeSet: 115 196 | CreateProcess: 117 197 | TerminateProcess: 118 198 | SetProcessResourceLimits: 119 199 | CreateResourceLimit: 120 200 | SetResourceLimitValues: 121 201 | AddCodeSegment: 122 202 | Backdoor: 123 203 | KernelSetState: 124 204 | QueryProcessMemory: 125 205 | 206 | # Service List 207 | # Maximum 34 services (32 if firmware is prior to 9.6.0) 208 | ServiceAccessControl: 209 | - APT:U 210 | - ac:u 211 | - am:net 212 | - boss:U 213 | - cam:u 214 | - cecd:u 215 | - cfg:nor 216 | - cfg:u 217 | - csnd:SND 218 | - dsp::DSP 219 | - frd:u 220 | - fs:USER 221 | - gsp::Gpu 222 | - gsp::Lcd 223 | - hid:USER 224 | - http:C 225 | - ir:rst 226 | - ir:u 227 | - ir:USER 228 | - mic:u 229 | - ndm:u 230 | - news:s 231 | - nwm::EXT 232 | - nwm::UDS 233 | - ptm:sysm 234 | - ptm:u 235 | - pxi:dev 236 | - soc:U 237 | - ssl:C 238 | - y2r:u 239 | 240 | 241 | SystemControlInfo: 242 | SaveDataSize: 0KB # Change if the app uses savedata 243 | RemasterVersion: 2 244 | StackSize: 0x40000 245 | 246 | # Modules that run services listed above should be included below 247 | # Maximum 48 dependencies 248 | # : 249 | Dependency: 250 | ac: 0x0004013000002402 251 | #act: 0x0004013000003802 252 | am: 0x0004013000001502 253 | boss: 0x0004013000003402 254 | camera: 0x0004013000001602 255 | cecd: 0x0004013000002602 256 | cfg: 0x0004013000001702 257 | codec: 0x0004013000001802 258 | csnd: 0x0004013000002702 259 | dlp: 0x0004013000002802 260 | dsp: 0x0004013000001a02 261 | friends: 0x0004013000003202 262 | gpio: 0x0004013000001b02 263 | gsp: 0x0004013000001c02 264 | hid: 0x0004013000001d02 265 | http: 0x0004013000002902 266 | i2c: 0x0004013000001e02 267 | ir: 0x0004013000003302 268 | mcu: 0x0004013000001f02 269 | mic: 0x0004013000002002 270 | ndm: 0x0004013000002b02 271 | news: 0x0004013000003502 272 | #nfc: 0x0004013000004002 273 | nim: 0x0004013000002c02 274 | nwm: 0x0004013000002d02 275 | pdn: 0x0004013000002102 276 | ps: 0x0004013000003102 277 | ptm: 0x0004013000002202 278 | #qtm: 0x0004013020004202 279 | ro: 0x0004013000003702 280 | socket: 0x0004013000002e02 281 | spi: 0x0004013000002302 282 | ssl: 0x0004013000002f02 283 | -------------------------------------------------------------------------------- /source/cia.c: -------------------------------------------------------------------------------- 1 | #include "cia.h" 2 | 3 | Result deletePrevious(u64 titleid, FS_MediaType media) 4 | { 5 | Result ret = 0; 6 | 7 | u32 titles_amount = 0; 8 | ret = AM_GetTitleCount(media, &titles_amount); 9 | if (R_FAILED(ret)) { 10 | printf("Error in:\nAM_GetTitleCount\n"); 11 | return ret; 12 | } 13 | 14 | u32 read_titles = 0; 15 | u64 * titleIDs = malloc(titles_amount * sizeof(u64)); 16 | ret = AM_GetTitleList(&read_titles, media, titles_amount, titleIDs); 17 | if (R_FAILED(ret)) { 18 | free(titleIDs); 19 | printf("Error in:\nAM_GetTitleList\n"); 20 | return ret; 21 | } 22 | 23 | for (u32 i = 0; i < read_titles; i++) { 24 | if (titleIDs[i] == titleid) { 25 | ret = AM_DeleteAppTitle(media, titleid); 26 | break; 27 | } 28 | } 29 | 30 | free(titleIDs); 31 | if (R_FAILED(ret)) { 32 | printf("Error in:\nAM_DeleteAppTitle\n"); 33 | return ret; 34 | } 35 | 36 | return 0; 37 | } 38 | 39 | Result installCia(const char * ciaPath) 40 | { 41 | u64 size = 0; 42 | u32 bytes; 43 | Handle ciaHandle; 44 | Handle fileHandle; 45 | AM_TitleEntry info; 46 | Result ret = 0; 47 | 48 | FS_MediaType media = MEDIATYPE_SD; 49 | 50 | ret = openFile(&fileHandle, ciaPath, false); 51 | if (R_FAILED(ret)) { 52 | printf("Error in:\nopenFile\n"); 53 | return ret; 54 | } 55 | 56 | ret = AM_GetCiaFileInfo(media, &info, fileHandle); 57 | if (R_FAILED(ret)) { 58 | printf("Error in:\nAM_GetCiaFileInfo\n"); 59 | return ret; 60 | } 61 | 62 | ret = deletePrevious(info.titleID, media); 63 | if (R_FAILED(ret)) 64 | return ret; 65 | 66 | ret = FSFILE_GetSize(fileHandle, &size); 67 | if (R_FAILED(ret)) { 68 | printf("Error in:\nFSFILE_GetSize\n"); 69 | return ret; 70 | } 71 | ret = AM_StartCiaInstall(media, &ciaHandle); 72 | if (R_FAILED(ret)) { 73 | printf("Error in:\nAM_StartCiaInstall\n"); 74 | return ret; 75 | } 76 | 77 | u32 toRead = 0x1000; 78 | u8 * cia_buffer = malloc(toRead); 79 | for (u64 startSize = size; size != 0; size -= toRead) { 80 | if (size < toRead) toRead = size; 81 | FSFILE_Read(fileHandle, &bytes, startSize-size, cia_buffer, toRead); 82 | FSFILE_Write(ciaHandle, &bytes, startSize-size, cia_buffer, toRead, 0); 83 | } 84 | free(cia_buffer); 85 | 86 | ret = AM_FinishCiaInstall(ciaHandle); 87 | if (R_FAILED(ret)) { 88 | printf("Error in:\nAM_FinishCiaInstall\n"); 89 | return ret; 90 | } 91 | ret = FSFILE_Close(fileHandle); 92 | if (R_FAILED(ret)) { 93 | printf("Error in:\nFSFILE_Close\n"); 94 | return ret; 95 | } 96 | 97 | return 0; 98 | } 99 | -------------------------------------------------------------------------------- /source/cia.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "common.hpp" 4 | 5 | Result installCia(const char * ciaPath); 6 | -------------------------------------------------------------------------------- /source/common.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include <3ds.h> 4 | 5 | #ifdef __cplusplus 6 | extern "C" { 7 | #endif 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "file.h" 15 | 16 | #ifdef __cplusplus 17 | } 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include "stringutils.hpp" 27 | #include "json.hpp" 28 | 29 | using json = nlohmann::json; 30 | 31 | #endif 32 | 33 | extern char * arg0; 34 | 35 | #define WORKING_DIR "/3ds/" APP_TITLE 36 | 37 | #define HBL_FILE_NAME APP_TITLE ".3dsx" 38 | #define HBL_FILE_PATH WORKING_DIR "/" HBL_FILE_NAME 39 | 40 | #define CONFIG_FILE_NAME "config.json" 41 | #define CONFIG_FILE_PATH WORKING_DIR "/" CONFIG_FILE_NAME 42 | 43 | #define CONFIG_FILE_URL "https://raw.githubusercontent.com/LiquidFenrir/MultiUpdater/rewrite/config.json" 44 | -------------------------------------------------------------------------------- /source/config.cpp: -------------------------------------------------------------------------------- 1 | #include "config.hpp" 2 | 3 | #include "extract.hpp" 4 | #include "download.hpp" 5 | 6 | extern "C" { 7 | #include "cia.h" 8 | } 9 | 10 | Entry::Entry(json jsonEntry) 11 | { 12 | state = STATE_NONE; 13 | if (jsonEntry["inarchive"].is_string()) 14 | m_inArchive = jsonEntry["inarchive"]; 15 | if (jsonEntry["inrelease"].is_string()) 16 | m_inRelease = jsonEntry["inrelease"]; 17 | if (jsonEntry["path"].is_string()) 18 | m_path = jsonEntry["path"]; 19 | if (jsonEntry["url"].is_string()) 20 | m_url = jsonEntry["url"]; 21 | if (jsonEntry["name"].is_string()) 22 | name = jsonEntry["name"]; 23 | } 24 | 25 | void Entry::update(bool deleteArchive, bool deleteCia) 26 | { 27 | printf("\x1b[40;34mUpdating %s...\x1b[0m\n", name.c_str()); 28 | std::string downloadPath; 29 | 30 | //if the file to download isnt an archive, direcly download where wanted 31 | if (m_inArchive.empty()) { 32 | downloadPath = m_path; 33 | } 34 | //otherwise, download to an archive in the working dir, then extract where wanted 35 | else { 36 | std::stringstream downloadPathStream; 37 | downloadPathStream << WORKING_DIR << "/" << name.c_str() << ".archive"; 38 | downloadPath = downloadPathStream.str(); 39 | } 40 | 41 | Result ret = 0; 42 | 43 | //if the entry doesnt want anything from a release, expect it to be a normal file 44 | if (m_inRelease.empty()) 45 | ret = downloadToFile(m_url, downloadPath); 46 | else 47 | ret = downloadFromRelease(m_url, m_inRelease, downloadPath); 48 | 49 | if (ret != 0) { 50 | printf("\x1b[40;31mDownload failed!"); 51 | goto failure; 52 | } 53 | else 54 | printf("\x1b[40;32mDownload successful!"); 55 | 56 | if (!(m_inArchive.empty())) { 57 | printf("\n\x1b[40;34mExtracting file from the archive...\x1b[0m\n"); 58 | ret = extractArchive(downloadPath, m_inArchive, m_path); 59 | 60 | if (deleteArchive) 61 | deleteFile(downloadPath.c_str()); 62 | 63 | if (ret != 0) { 64 | printf("\x1b[40;31mExtraction failed!"); 65 | goto failure; 66 | } 67 | else 68 | printf("\x1b[40;32mExtraction successful!"); 69 | } 70 | 71 | if (matchPattern(".*(\\.cia)$", m_path)) { 72 | printf("\n\x1b[40;34mInstalling CIA...\x1b[0m\n"); 73 | ret = installCia(m_path.c_str()); 74 | if (deleteCia) 75 | deleteFile(m_path.c_str()); 76 | 77 | if (ret != 0) { 78 | printf("\x1b[40;31mInstall failed!"); 79 | goto failure; 80 | } 81 | else 82 | printf("\x1b[40;32mInstall successful!"); 83 | } 84 | 85 | printf("\n\x1b[40;32mUpdate complete!\x1b[0m\n"); 86 | state = STATE_SUCCESS; 87 | return; 88 | 89 | failure: 90 | printf("\n\x1b[40;31mUpdate failed!\n"); 91 | printf("\x1b[40;33mError code: %.8lx\x1b[0m\n", ret); 92 | state = STATE_FAILED; 93 | return; 94 | } 95 | 96 | Config::Config() 97 | { 98 | m_selfUpdater = true; 99 | m_deleteCIA = false; 100 | m_deleteArchive = true; 101 | 102 | Handle configHandle; 103 | char* configString = nullptr; 104 | Result ret = openFile(&configHandle, CONFIG_FILE_PATH, false); 105 | 106 | if (R_FAILED(ret)) { 107 | json configDownloadJson; 108 | configDownloadJson["name"] = "Download the latest example config!"; 109 | configDownloadJson["url"] = CONFIG_FILE_URL; 110 | configDownloadJson["path"] = CONFIG_FILE_PATH; 111 | 112 | Entry configDownloadEntry(configDownloadJson); 113 | entries.push_back(configDownloadEntry); 114 | } 115 | else { 116 | u64 configSize = 0; 117 | FSFILE_GetSize(configHandle, &configSize); 118 | configString = (char*)calloc(configSize+1, sizeof(char)); 119 | u32 bytesRead = 0; 120 | FSFILE_Read(configHandle, &bytesRead, 0, configString, (u32)configSize); 121 | 122 | json parsedConfig = json::parse(configString); 123 | 124 | if (parsedConfig["config"].is_object()) { 125 | if (parsedConfig["config"]["self_updater"].is_boolean()) 126 | m_selfUpdater = parsedConfig["config"]["self_updater"]; 127 | if (parsedConfig["config"]["delete_cias"].is_boolean()) 128 | m_deleteCIA = parsedConfig["config"]["delete_cias"]; 129 | if (parsedConfig["config"]["delete_archives"].is_boolean()) 130 | m_deleteArchive = parsedConfig["config"]["delete_archives"]; 131 | } 132 | 133 | if (m_selfUpdater) { 134 | json selfUpdaterJson; 135 | selfUpdaterJson["url"] = "https://github.com/LiquidFenrir/MultiUpdater"; 136 | selfUpdaterJson["inrelease"] = "MultiUpdater.*\\.zip"; 137 | 138 | if (envIsHomebrew()) { 139 | selfUpdaterJson["name"] = "MultiUpdater (3dsx)"; 140 | selfUpdaterJson["inarchive"] = (char*)HBL_FILE_PATH+1; 141 | if (arg0 == NULL || arg0[0] == '3') //bug, or 3dslink 142 | selfUpdaterJson["path"] = HBL_FILE_PATH; 143 | else 144 | selfUpdaterJson["path"] = arg0; 145 | } 146 | else { 147 | selfUpdaterJson["name"] = "MultiUpdater"; 148 | selfUpdaterJson["inarchive"] = "MultiUpdater.cia"; 149 | selfUpdaterJson["path"] = "/cias/MultiUpdater.cia"; 150 | } 151 | 152 | Entry selfUpdateEntry(selfUpdaterJson); 153 | entries.push_back(selfUpdateEntry); 154 | } 155 | 156 | if (parsedConfig["entries"].is_array()) { 157 | for (auto jsonEntry : parsedConfig["entries"]) { 158 | if (jsonEntry.is_object()) { 159 | Entry configEntry(jsonEntry); 160 | entries.push_back(configEntry); 161 | } 162 | } 163 | } 164 | } 165 | 166 | free(configString); 167 | FSFILE_Close(configHandle); 168 | } 169 | -------------------------------------------------------------------------------- /source/config.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "common.hpp" 4 | 5 | enum EntryState { 6 | STATE_NONE = 0, 7 | STATE_FAILED = BIT(0), 8 | STATE_SUCCESS = BIT(1), 9 | STATE_MARKED = BIT(2), 10 | }; 11 | 12 | class Entry 13 | { 14 | public: 15 | 16 | std::string name; 17 | int state; 18 | 19 | Entry(json jsonEntry); 20 | 21 | void update(bool deleteArchive, bool deleteCia); 22 | 23 | private: 24 | 25 | std::string m_url; 26 | std::string m_path; 27 | std::string m_inRelease; 28 | std::string m_inArchive; 29 | }; 30 | 31 | class Config 32 | { 33 | public: 34 | 35 | bool m_selfUpdater; 36 | bool m_deleteCIA; 37 | bool m_deleteArchive; 38 | 39 | std::vector entries; 40 | 41 | Config(); 42 | 43 | }; -------------------------------------------------------------------------------- /source/download.cpp: -------------------------------------------------------------------------------- 1 | #include "download.hpp" 2 | 3 | #define USER_AGENT APP_TITLE "-" VERSION_STRING 4 | 5 | static char* result_buf = NULL; 6 | static size_t result_sz = 0; 7 | static size_t result_written = 0; 8 | 9 | // following function is from 10 | // https://github.com/angelsl/libctrfgh/blob/master/curl_test/src/main.c 11 | static size_t handle_data(char* ptr, size_t size, size_t nmemb, void* userdata) 12 | { 13 | (void) userdata; 14 | const size_t bsz = size*nmemb; 15 | 16 | if (result_sz == 0 || !result_buf) 17 | { 18 | result_sz = 0x1000; 19 | result_buf = (char*)malloc(result_sz); 20 | } 21 | 22 | bool need_realloc = false; 23 | while (result_written + bsz > result_sz) 24 | { 25 | result_sz <<= 1; 26 | need_realloc = true; 27 | } 28 | 29 | if (need_realloc) 30 | { 31 | char *new_buf = (char*)realloc(result_buf, result_sz); 32 | if (!new_buf) 33 | { 34 | return 0; 35 | } 36 | result_buf = new_buf; 37 | } 38 | 39 | if (!result_buf) 40 | { 41 | return 0; 42 | } 43 | 44 | memcpy(result_buf + result_written, ptr, bsz); 45 | result_written += bsz; 46 | return bsz; 47 | } 48 | 49 | static Result setupContext(CURL *hnd, const char * url) 50 | { 51 | curl_easy_setopt(hnd, CURLOPT_BUFFERSIZE, 102400L); 52 | curl_easy_setopt(hnd, CURLOPT_URL, url); 53 | curl_easy_setopt(hnd, CURLOPT_NOPROGRESS, 1L); 54 | curl_easy_setopt(hnd, CURLOPT_USERAGENT, USER_AGENT); 55 | curl_easy_setopt(hnd, CURLOPT_FOLLOWLOCATION, 1L); 56 | curl_easy_setopt(hnd, CURLOPT_MAXREDIRS, 50L); 57 | curl_easy_setopt(hnd, CURLOPT_HTTP_VERSION, (long)CURL_HTTP_VERSION_2TLS); 58 | curl_easy_setopt(hnd, CURLOPT_WRITEFUNCTION, handle_data); 59 | curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYPEER, 0L); 60 | curl_easy_setopt(hnd, CURLOPT_VERBOSE, 1L); 61 | curl_easy_setopt(hnd, CURLOPT_STDERR, stdout); 62 | 63 | return 0; 64 | } 65 | 66 | Result downloadToFile(std::string url, std::string path) 67 | { 68 | Result ret = 0; 69 | printf("Downloading from:\n%s\nto:\n%s\n", url.c_str(), path.c_str()); 70 | 71 | void *socubuf = memalign(0x1000, 0x100000); 72 | if (!socubuf) 73 | { 74 | return -1; 75 | } 76 | 77 | ret = socInit((u32*)socubuf, 0x100000); 78 | if (R_FAILED(ret)) 79 | { 80 | free(socubuf); 81 | return ret; 82 | } 83 | 84 | CURL *hnd = curl_easy_init(); 85 | ret = setupContext(hnd, url.c_str()); 86 | if (ret != 0) { 87 | socExit(); 88 | free(result_buf); 89 | free(socubuf); 90 | result_buf = NULL; 91 | result_sz = 0; 92 | result_written = 0; 93 | return ret; 94 | } 95 | 96 | Handle fileHandle; 97 | u64 offset = 0; 98 | u32 bytesWritten = 0; 99 | 100 | ret = openFile(&fileHandle, path.c_str(), true); 101 | if (R_FAILED(ret)) { 102 | printf("Error: couldn't open file to write.\n"); 103 | socExit(); 104 | free(result_buf); 105 | free(socubuf); 106 | result_buf = NULL; 107 | result_sz = 0; 108 | result_written = 0; 109 | return DL_ERROR_WRITEFILE; 110 | } 111 | 112 | u64 startTime = osGetTime(); 113 | 114 | CURLcode cres = curl_easy_perform(hnd); 115 | curl_easy_cleanup(hnd); 116 | 117 | if (cres != CURLE_OK) { 118 | printf("Error in:\ncurl\n"); 119 | socExit(); 120 | free(result_buf); 121 | free(socubuf); 122 | result_buf = NULL; 123 | result_sz = 0; 124 | result_written = 0; 125 | return -1; 126 | } 127 | 128 | FSFILE_Write(fileHandle, &bytesWritten, offset, result_buf, result_written, 0); 129 | 130 | u64 endTime = osGetTime(); 131 | u64 totalTime = endTime - startTime; 132 | printf("Download took %llu milliseconds.\n", totalTime); 133 | 134 | socExit(); 135 | free(result_buf); 136 | free(socubuf); 137 | result_buf = NULL; 138 | result_sz = 0; 139 | result_written = 0; 140 | FSFILE_Close(fileHandle); 141 | return 0; 142 | } 143 | 144 | Result downloadFromRelease(std::string url, std::string asset, std::string path) 145 | { 146 | Result ret = 0; 147 | void *socubuf = memalign(0x1000, 0x100000); 148 | if (!socubuf) 149 | { 150 | return -1; 151 | } 152 | 153 | ret = socInit((u32*)socubuf, 0x100000); 154 | if (R_FAILED(ret)) 155 | { 156 | free(socubuf); 157 | return ret; 158 | } 159 | 160 | std::regex parseUrl("github\\.com\\/(.+)\\/(.+)"); 161 | std::smatch result; 162 | regex_search(url, result, parseUrl); 163 | 164 | std::string repoOwner = result[1].str(), repoName = result[2].str(); 165 | 166 | std::stringstream apiurlStream; 167 | apiurlStream << "https://api.github.com/repos/" << repoOwner << "/" << repoName << "/releases/latest"; 168 | std::string apiurl = apiurlStream.str(); 169 | 170 | printf("Downloading latest release from repo:\n%s\nby:\n%s\n", repoName.c_str(), repoOwner.c_str()); 171 | printf("Crafted API url:\n%s\n", apiurl.c_str()); 172 | 173 | CURL *hnd = curl_easy_init(); 174 | ret = setupContext(hnd, apiurl.c_str()); 175 | if (ret != 0) { 176 | socExit(); 177 | free(result_buf); 178 | free(socubuf); 179 | result_buf = NULL; 180 | result_sz = 0; 181 | result_written = 0; 182 | return ret; 183 | } 184 | 185 | CURLcode cres = curl_easy_perform(hnd); 186 | curl_easy_cleanup(hnd); 187 | char* newbuf = (char*)realloc(result_buf, result_written + 1); 188 | result_buf = newbuf; 189 | result_buf[result_written] = 0; //nullbyte to end it as a proper C style string 190 | 191 | if (cres != CURLE_OK) { 192 | printf("Error in:\ncurl\n"); 193 | socExit(); 194 | free(result_buf); 195 | free(socubuf); 196 | result_buf = NULL; 197 | result_sz = 0; 198 | result_written = 0; 199 | return -1; 200 | } 201 | 202 | printf("Looking for asset with name matching:\n%s\n", asset.c_str()); 203 | std::string assetUrl; 204 | json parsedAPI = json::parse(result_buf); 205 | if (parsedAPI["assets"].is_array()) { 206 | for (auto jsonAsset : parsedAPI["assets"]) { 207 | if (jsonAsset.is_object() && jsonAsset["name"].is_string() && jsonAsset["browser_download_url"].is_string()) { 208 | std::string assetName = jsonAsset["name"]; 209 | if (matchPattern(asset, assetName)) { 210 | assetUrl = jsonAsset["browser_download_url"]; 211 | break; 212 | } 213 | } 214 | } 215 | } 216 | socExit(); 217 | free(result_buf); 218 | free(socubuf); 219 | result_buf = NULL; 220 | result_sz = 0; 221 | result_written = 0; 222 | 223 | if (assetUrl.empty()) 224 | ret = DL_ERROR_GIT; 225 | else 226 | ret = downloadToFile(assetUrl, path); 227 | 228 | return ret; 229 | } 230 | -------------------------------------------------------------------------------- /source/download.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "common.hpp" 4 | 5 | enum DownloadError { 6 | DL_ERROR_NONE = 0, 7 | DL_ERROR_WRITEFILE, 8 | DL_ERROR_ALLOC, 9 | DL_ERROR_STATUSCODE, 10 | DL_ERROR_GIT, 11 | }; 12 | 13 | Result downloadToFile(std::string url, std::string path); 14 | Result downloadFromRelease(std::string url, std::string asset, std::string path); 15 | -------------------------------------------------------------------------------- /source/extract.cpp: -------------------------------------------------------------------------------- 1 | #include "extract.hpp" 2 | 3 | #include 4 | #include 5 | 6 | Result extractArchive(std::string archivePath, std::string wantedFile, std::string outputPath) 7 | { 8 | int r; 9 | struct archive_entry *entry; 10 | 11 | struct archive *a = archive_read_new(); 12 | archive_read_support_format_all(a); 13 | archive_read_support_format_raw(a); 14 | 15 | r = archive_read_open_filename(a, archivePath.c_str(), 0x4000); 16 | if (r != ARCHIVE_OK) { 17 | return EXTRACT_ERROR_ARCHIVE; 18 | } 19 | 20 | Result ret = EXTRACT_ERROR_FIND; 21 | while (archive_read_next_header(a, &entry) == ARCHIVE_OK) { 22 | std::string entryName(archive_entry_pathname(entry)); 23 | if (matchPattern(wantedFile, entryName)) { 24 | ret = EXTRACT_ERROR_NONE; 25 | 26 | Handle fileHandle; 27 | Result res = openFile(&fileHandle, outputPath.c_str(), true); 28 | if (R_FAILED(res)) { 29 | ret = EXTRACT_ERROR_OPENFILE; 30 | break; 31 | } 32 | 33 | u64 fileSize = archive_entry_size(entry); 34 | u32 toRead = 0x4000; 35 | u8 * buf = (u8 *)malloc(toRead); 36 | if (buf == NULL) { 37 | ret = EXTRACT_ERROR_ALLOC; 38 | FSFILE_Close(fileHandle); 39 | break; 40 | } 41 | 42 | u32 bytesWritten = 0; 43 | u64 offset = 0; 44 | do { 45 | if (toRead > fileSize) toRead = fileSize; 46 | ssize_t size = archive_read_data(a, buf, toRead); 47 | if (size < 0) { 48 | ret = EXTRACT_ERROR_READFILE; 49 | break; 50 | } 51 | 52 | res = FSFILE_Write(fileHandle, &bytesWritten, offset, buf, toRead, 0); 53 | if (R_FAILED(res)) { 54 | ret = EXTRACT_ERROR_WRITEFILE; 55 | break; 56 | } 57 | 58 | offset += bytesWritten; 59 | fileSize -= bytesWritten; 60 | } while(fileSize); 61 | 62 | FSFILE_Close(fileHandle); 63 | free(buf); 64 | break; 65 | } 66 | } 67 | 68 | archive_read_free(a); 69 | 70 | return ret; 71 | } -------------------------------------------------------------------------------- /source/extract.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "common.hpp" 4 | 5 | enum ExtractError { 6 | EXTRACT_ERROR_NONE = 0, 7 | EXTRACT_ERROR_ARCHIVE, 8 | EXTRACT_ERROR_ALLOC, 9 | EXTRACT_ERROR_FIND, 10 | EXTRACT_ERROR_READFILE, 11 | EXTRACT_ERROR_OPENFILE, 12 | EXTRACT_ERROR_WRITEFILE, 13 | }; 14 | 15 | Result extractArchive(std::string archivePath, std::string wantedFile, std::string outputPath); 16 | -------------------------------------------------------------------------------- /source/file.c: -------------------------------------------------------------------------------- 1 | #include "file.h" 2 | 3 | FS_Path getPathInfo(const char * path, FS_ArchiveID * archive) 4 | { 5 | *archive = ARCHIVE_SDMC; 6 | FS_Path filePath = {0}; 7 | unsigned int prefixlen = 0; 8 | 9 | if (!strncmp(path, "ctrnand:/", 9)) { 10 | *archive = ARCHIVE_NAND_CTR_FS; 11 | prefixlen = 8; 12 | } 13 | else if (!strncmp(path, "twlp:/", 6)) { 14 | *archive = ARCHIVE_TWL_PHOTO; 15 | prefixlen = 5; 16 | } 17 | else if (!strncmp(path, "twln:/", 6)) { 18 | *archive = ARCHIVE_NAND_TWL_FS; 19 | prefixlen = 5; 20 | } 21 | else if (!strncmp(path, "sdmc:/", 6)) { 22 | prefixlen = 5; 23 | } 24 | else if (*path != '/') { 25 | //if the path is local (doesnt start with a slash), it needs to be appended to the working dir to be valid 26 | char * actualPath = NULL; 27 | asprintf(&actualPath, "%s%s", WORKING_DIR, path); 28 | filePath = fsMakePath(PATH_ASCII, actualPath); 29 | free(actualPath); 30 | } 31 | 32 | //if the filePath wasnt set above, set it 33 | if (filePath.size == 0) 34 | filePath = fsMakePath(PATH_ASCII, path+prefixlen); 35 | 36 | return filePath; 37 | } 38 | 39 | Result makeDirs(FS_ArchiveID archiveID, char * path) 40 | { 41 | Result ret = 0; 42 | FS_Archive archive; 43 | 44 | ret = FSUSER_OpenArchive(&archive, archiveID, fsMakePath(PATH_EMPTY, "")); 45 | 46 | for (char * slashpos = strchr(path+1, '/'); slashpos != NULL; slashpos = strchr(slashpos+1, '/')) { 47 | char bak = *(slashpos); 48 | *(slashpos) = '\0'; 49 | 50 | FS_Path dirpath = fsMakePath(PATH_ASCII, path); 51 | Handle dirHandle; 52 | 53 | ret = FSUSER_OpenDirectory(&dirHandle, archive, dirpath); 54 | if (R_SUCCEEDED(ret)) 55 | FSDIR_Close(dirHandle); 56 | else 57 | ret = FSUSER_CreateDirectory(archive, dirpath, FS_ATTRIBUTE_DIRECTORY); 58 | 59 | *(slashpos) = bak; 60 | } 61 | 62 | FSUSER_CloseArchive(archive); 63 | free(path); 64 | 65 | return ret; 66 | } 67 | 68 | Result openFile(Handle* fileHandle, const char * path, bool write) 69 | { 70 | FS_ArchiveID archive; 71 | FS_Path filePath = getPathInfo(path, &archive); 72 | u32 flags = (write ? (FS_OPEN_CREATE | FS_OPEN_WRITE) : FS_OPEN_READ); 73 | 74 | Result ret = 0; 75 | ret = makeDirs(archive, strdup(path)); 76 | ret = FSUSER_OpenFileDirectly(fileHandle, archive, fsMakePath(PATH_EMPTY, ""), filePath, flags, 0); 77 | if (write) 78 | ret = FSFILE_SetSize(*fileHandle, 0); //truncate the file to remove previous contents before writing 79 | 80 | return ret; 81 | } 82 | 83 | Result deleteFile(const char * path) 84 | { 85 | FS_ArchiveID archiveID; 86 | FS_Path filePath = getPathInfo(path, &archiveID); 87 | 88 | FS_Archive archive; 89 | Result ret = FSUSER_OpenArchive(&archive, archiveID, fsMakePath(PATH_EMPTY, "")); 90 | if (R_FAILED(ret)) return ret; 91 | ret = FSUSER_DeleteFile(archive, filePath); 92 | FSUSER_CloseArchive(archive); 93 | 94 | return ret; 95 | } 96 | -------------------------------------------------------------------------------- /source/file.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "common.hpp" 4 | 5 | Result openFile(Handle* fileHandle, const char * path, bool write); 6 | Result deleteFile(const char * path); 7 | -------------------------------------------------------------------------------- /source/main.cpp: -------------------------------------------------------------------------------- 1 | #include "common.hpp" 2 | #include "menu.hpp" 3 | #include "config.hpp" 4 | 5 | char * arg0 = NULL; 6 | 7 | int main(int argc, char ** argv) 8 | { 9 | if (argc > 0) 10 | arg0 = argv[0]; 11 | 12 | gfxInitDefault(); 13 | httpcInit(0); 14 | amInit(); 15 | 16 | PrintConsole topScreen, bottomScreen; 17 | consoleInit(GFX_TOP, &topScreen); 18 | consoleInit(GFX_BOTTOM, &bottomScreen); 19 | 20 | Config config; 21 | unsigned int selectedEntry = 0; 22 | 23 | while(aptMainLoop()) 24 | { 25 | consoleSelect(&topScreen); 26 | drawMenu(config, selectedEntry); 27 | consoleSelect(&bottomScreen); 28 | 29 | hidScanInput(); 30 | 31 | u32 kDown = hidKeysDown(); 32 | if (kDown & KEY_START) 33 | break; 34 | else if (kDown & KEY_DOWN) { 35 | selectedEntry++; 36 | if (selectedEntry >= config.entries.size()) 37 | selectedEntry = config.entries.size()-1; 38 | } 39 | else if (kDown & KEY_UP) { 40 | selectedEntry--; 41 | if (selectedEntry >= config.entries.size()) 42 | selectedEntry = 0; 43 | } 44 | else if (kDown & KEY_LEFT) { 45 | selectedEntry = 0; 46 | } 47 | else if (kDown & KEY_RIGHT) { 48 | selectedEntry = config.entries.size()-1; 49 | } 50 | else if (kDown & KEY_Y) { 51 | config.entries[selectedEntry].state ^= STATE_MARKED; //toggle selected 52 | } 53 | else if (kDown & (KEY_L | KEY_R)) { 54 | for (unsigned int i = 0; i < config.entries.size(); i++) { 55 | if (kDown & KEY_L) 56 | config.entries[i].state |= STATE_MARKED; //mark all 57 | else 58 | config.entries[i].state &= ~STATE_MARKED; //unmark all 59 | } 60 | } 61 | else if (kDown & KEY_A) { 62 | for (unsigned int i = 0; i < config.entries.size(); i++) { 63 | if ((config.entries[i].state & STATE_MARKED) || (i == selectedEntry)) { 64 | consoleSelect(&topScreen); 65 | drawMenu(config, i); 66 | consoleSelect(&bottomScreen); 67 | 68 | config.entries[i].update(config.m_deleteArchive, config.m_deleteCIA); 69 | 70 | gfxFlushBuffers(); 71 | gfxSwapBuffers(); 72 | gspWaitForVBlank(); 73 | } 74 | } 75 | } 76 | 77 | gfxFlushBuffers(); 78 | gfxSwapBuffers(); 79 | gspWaitForVBlank(); 80 | } 81 | 82 | amExit(); 83 | httpcExit(); 84 | gfxExit(); 85 | return 0; 86 | } -------------------------------------------------------------------------------- /source/menu.cpp: -------------------------------------------------------------------------------- 1 | #include "menu.hpp" 2 | 3 | static const unsigned int FRAMES_FOR_TEXT_SCROLL = 40; 4 | static const unsigned int MENU_WIDTH = 40; 5 | static const unsigned int MAX_ENTRIES_PER_SCREEN = 20; 6 | 7 | static const unsigned int MENU_Y_OFFSET = 5; 8 | static const unsigned int MENU_X_OFFSET = 5; 9 | static const char MENU_DELIMITER_CHAR = '='; 10 | 11 | static const unsigned int TITLE_Y_OFFSET = 3; 12 | static const unsigned int TITLE_X_OFFSET = 3; 13 | #define TITLE_STRING APP_TITLE " " VERSION_STRING " by " APP_AUTHOR 14 | 15 | static unsigned int framesCount = 0; 16 | static unsigned int verticalScroll = 0; 17 | static unsigned int horizontalScroll = 0; 18 | static unsigned int previousSelectedEntry = 0; 19 | static int horizontalScrollChange = 1; 20 | 21 | void drawMenu(Config config, unsigned int selectedEntry) 22 | { 23 | unsigned int i = 0; 24 | 25 | // Scroll the entry name if it's larger than the width of the menu 26 | //---------------------------------------------------------------- 27 | if (previousSelectedEntry != selectedEntry) { 28 | previousSelectedEntry = selectedEntry; 29 | framesCount = 0; 30 | horizontalScroll = 0; 31 | horizontalScrollChange = 1; 32 | } 33 | 34 | framesCount = (framesCount+1) % FRAMES_FOR_TEXT_SCROLL; 35 | 36 | if (framesCount == 0 && (config.entries[selectedEntry].name.size() > MENU_WIDTH)) 37 | horizontalScroll += horizontalScrollChange; 38 | 39 | if (horizontalScroll == (config.entries[selectedEntry].name.size() - MENU_WIDTH)) 40 | horizontalScrollChange = -1; 41 | 42 | if (horizontalScroll == 0) 43 | horizontalScrollChange = 1; 44 | //---------------------------------------------------------------- 45 | 46 | //Scroll the menu up or down if the selected entry is out of its bounds 47 | //---------------------------------------------------------------- 48 | for (i = 0; i < config.entries.size(); i++) { 49 | if (config.entries.size() <= MAX_ENTRIES_PER_SCREEN) break; 50 | 51 | if (verticalScroll > selectedEntry) 52 | verticalScroll--; 53 | 54 | if ((i < selectedEntry) && \ 55 | ((selectedEntry - verticalScroll) >= MAX_ENTRIES_PER_SCREEN) && \ 56 | (verticalScroll != (config.entries.size() - MAX_ENTRIES_PER_SCREEN))) 57 | verticalScroll++; 58 | } 59 | //---------------------------------------------------------------- 60 | 61 | printf("\x1b[0m\x1b[%u;%uH%s\n", TITLE_Y_OFFSET, TITLE_X_OFFSET, TITLE_STRING); 62 | 63 | for (i = MENU_X_OFFSET; i < MENU_WIDTH+MENU_X_OFFSET; i++) { 64 | printf("\x1b[%u;%uH%c\n", MENU_Y_OFFSET, i, MENU_DELIMITER_CHAR); 65 | printf("\x1b[%u;%uH%c\n", MENU_Y_OFFSET+MAX_ENTRIES_PER_SCREEN+1, i, MENU_DELIMITER_CHAR); 66 | } 67 | 68 | for (i = verticalScroll; i < (MAX_ENTRIES_PER_SCREEN + verticalScroll); i++) { 69 | if (i >= config.entries.size()) 70 | break; 71 | 72 | // Gets the color of the text depending on the state of the entry 73 | // black for selected, white for normal 74 | // red for failed, green for success, yellow for marked 75 | //---------------------------------------------------------------- 76 | unsigned int textColor = (i == selectedEntry) ? 30 : 37; 77 | unsigned int textColorArray[] = { 78 | textColor, // STATE_NONE 79 | 31, // STATE_FAILED 80 | 32, // STATE_SUCCESS 81 | 33, // STATE_MARKED 82 | }; 83 | 84 | textColor = textColorArray[__builtin_clz(0)-__builtin_clz(config.entries[i].state)]; 85 | //---------------------------------------------------------------- 86 | 87 | printf("\x1b[%u;%uH\x1b[%u;%um%*.*s\x1b[0m\n", 88 | MENU_Y_OFFSET+i-verticalScroll+1, 89 | MENU_X_OFFSET, 90 | (i == selectedEntry) ? 47 : 40, //background color, white for selected, black for normal 91 | textColor, 92 | -MENU_WIDTH, //adds padding on the right 93 | MENU_WIDTH, //maximum length of text (will truncate if over) 94 | config.entries[i].name.c_str() + ((i == selectedEntry) ? horizontalScroll : 0) 95 | ); 96 | } 97 | 98 | printf("\x1b[0m\x1b[%u;%uH%*s\n", TITLE_Y_OFFSET+MAX_ENTRIES_PER_SCREEN+MENU_Y_OFFSET, TITLE_X_OFFSET, MENU_WIDTH+TITLE_X_OFFSET+1, "Press START to quit."); 99 | } -------------------------------------------------------------------------------- /source/menu.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "common.hpp" 4 | #include "config.hpp" 5 | 6 | void drawMenu(Config config, unsigned int selectedEntry); 7 | -------------------------------------------------------------------------------- /source/stringutils.cpp: -------------------------------------------------------------------------------- 1 | #include "stringutils.hpp" 2 | 3 | bool matchPattern(std::string pattern, std::string tested) 4 | { 5 | std::regex patternRegex(pattern); 6 | return regex_match(tested, patternRegex); 7 | } 8 | -------------------------------------------------------------------------------- /source/stringutils.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "common.hpp" 4 | 5 | bool matchPattern(std::string pattern, std::string tested); 6 | --------------------------------------------------------------------------------