Compare commits

..

No commits in common. "master" and "v2.2.0" have entirely different histories.

6 changed files with 115 additions and 22 deletions

View File

@ -122,7 +122,7 @@ static int internalfs_mkdir(lua_State* L) {
FRESULT res = fvx_rmkdir(path); FRESULT res = fvx_rmkdir(path);
if (res != FR_OK) { if (res != FR_OK) {
return luaL_error(L, "could not mkdir %s (%d)", path, res); return luaL_error(L, "could not mkdir (%d)", path, res);
} }
return 0; return 0;
@ -145,7 +145,6 @@ static int internalfs_list_dir(lua_State* L) {
for (int i = 1; true; i++) { for (int i = 1; true; i++) {
res = fvx_readdir(&dir, &fno); res = fvx_readdir(&dir, &fno);
if (res != FR_OK) { if (res != FR_OK) {
fvx_closedir(&dir);
lua_pop(L, 1); // remove final table from stack lua_pop(L, 1); // remove final table from stack
return luaL_error(L, "could not readdir %s (%d)", path, res); return luaL_error(L, "could not readdir %s (%d)", path, res);
} }
@ -153,7 +152,6 @@ static int internalfs_list_dir(lua_State* L) {
CreateStatTable(L, &fno); CreateStatTable(L, &fno);
lua_seti(L, -2, i); // add nested table to final table lua_seti(L, -2, i); // add nested table to final table
} }
fvx_closedir(&dir);
return 1; return 1;
} }
@ -467,7 +465,7 @@ static int internalfs_make_dummy_file(lua_State* L) {
CheckWritePermissionsLuaError(L, path); CheckWritePermissionsLuaError(L, path);
if (!(FileCreateDummy(path, NULL, size))) { if (!(FileCreateDummy(path, NULL, size))) {
return luaL_error(L, "FileCreateDummy failed on %s", path); return luaL_error(L, "FileCreateDummy failed on %s");
} }
return 0; return 0;

View File

@ -35,7 +35,7 @@ static inline void CheckLuaArgCount(lua_State* L, int argcount, const char* cmd)
static inline bool CheckLuaArgCountPlusExtra(lua_State* L, int argcount, const char* cmd) { static inline bool CheckLuaArgCountPlusExtra(lua_State* L, int argcount, const char* cmd) {
int args = lua_gettop(L); int args = lua_gettop(L);
if (args != argcount && args != argcount + 1) { if (args != argcount && args != argcount + 1) {
luaL_error(L, "bad number of arguments passed to '%s' (expected %d or %d, got %d)", cmd, argcount, argcount + 1, args); luaL_error(L, "bad number of arguments passed to '%s' (expected %d, got %d or %d)", cmd, argcount, args);
} }
return args == argcount + 1; return args == argcount + 1;
} }

View File

@ -35,7 +35,7 @@ function file.new(filename, mode)
end end
debugf("opening", filename, mode) debugf("opening", filename, mode)
of = setmetatable({_filename=filename, _mode=mode, _seek=0, _open=true, _readable=false, _writable=false, _append_only=false}, file) of = setmetatable({_filename=filename, _mode=mode, _seek=0, _open=true, _readable=false, _writable=false, _append_only=false}, file)
if string.find(mode, "w", 1, true) then if string.find(mode, "w") then
debugf("opening", filename, "for writing") debugf("opening", filename, "for writing")
-- preemptively allow writing instead of having that prompt at file:write -- preemptively allow writing instead of having that prompt at file:write
allowed = fs.allow(filename) allowed = fs.allow(filename)
@ -48,7 +48,7 @@ function file.new(filename, mode)
of._size = 0 of._size = 0
of._readable = false of._readable = false
of._writable = true of._writable = true
elseif string.find(mode, "r+", 1, true) then elseif string.find(mode, "r+") then
debugf("opening", filename, "for updating") debugf("opening", filename, "for updating")
allowed = fs.allow(filename) allowed = fs.allow(filename)
debugf("allowed:", allowed) debugf("allowed:", allowed)
@ -64,7 +64,7 @@ function file.new(filename, mode)
of._stat = {} of._stat = {}
of._size = 0 of._size = 0
end end
elseif string.find(mode, "a", 1, true) then elseif string.find(mode, "a") then
debugf("opening", filename, "for appending") debugf("opening", filename, "for appending")
allowed = fs.allow(filename) allowed = fs.allow(filename)
debugf("allowed:", allowed) debugf("allowed:", allowed)
@ -82,7 +82,7 @@ function file.new(filename, mode)
of._stat = {} of._stat = {}
of._size = 0 of._size = 0
end end
if string.find(mode, "+", 1, true) then if string.find(mode, "+") then
debugf("append update mode") debugf("append update mode")
of._readable = true of._readable = true
else else

View File

@ -409,6 +409,100 @@ else
end end
goto Hax_Options_Install_Boot9Strap goto Hax_Options_Install_Boot9Strap
###################Hax Uninstall##################
@Hax_Options_Un-install_Hax
set PREVIEW_MODE "GODMODE9 ALL-IN-ONE MEGASCRIPT\nby annson24\n \nHax Options\n>Hax Un-install"
if not ask "!!WARNING!!\nThis will completely remove CFW and\nrevert your system to stock.\n \nProceed anyway?"
goto MainMenu_Hax_Options
end
if not chk -u $[HAX] "ntrboot"
if not ask "!!WARNING!!\nntrboot not detected!\nYou should at least have ntrboot or a hardmod\nwith you before proceeding in case of brick.\n \nProceed anyway?"
goto MainMenu_Restore_Options
end
end
if chk -u $[ONTYPE] "N3DS"
goto Unhax_Old
end
if not sha S:/sector0x96.bin 82F2730D2C2DA3F30165F987FDCCAC5CBAB24B4E5F65C981CD7BE6F438E6D9D3
if not find 0:/boot9strap/secret_sector.bin SECRET
if not find $[GM9IN]/boot9strap/secret_sector.bin SECRET
echo "Sector 0x96 is not genuine.\nYou must have the secret_sector.bin file in the\nboot9strap folder first then try again.\n \nAborting."
goto Hax_Options_Install_Boot9Strap
end
end
if not allow -a S:
echo "Permissions denied. Aborting."
goto MainMenu_Hax_Options
end
cp -n -w S:/sector0x96.bin $[SECRET].bak
cp -n -w $[SECRET] S:/sector0x96.bin
end
if not find 1:/title/00040138/20000002/content/????????.app NATIVE_NCCH
echo "NATIVE_FIRM not found.\nIs this a N3DS?"
goto MainMenu_Hax_Options
end
imgmount $[NATIVE_NCCH]
verify G:/exefs/.firm
set NATIVE_FIRM $[GM9OUT]/NATIVE_FIRM.firm
cp -w G:/exefs/.firm $[NATIVE_FIRM]
imgumount
if allow -a S:
allow -a 1:
rm -o -s 1:/boot.firm
rm -o -s 1:/rw/luma
cp -n $[NATIVE_FIRM] S:/firm0.bin
cp -n $[NATIVE_FIRM] S:/firm1.bin
shaget S:/nand.bin@57FFE00:200 PRE_STAGE2_HASH
if not sha S:/nand.bin@B800000:200 $[PRE_STAGE2_HASH]
fget S:/nand.bin@57FFE00:1 PRE_STAGE2
fill S:/nand.bin@B7FFE00:89C00 $[PRE_STAGE2]
end
echo "CFW uninstalled successfully"
else
echo "Permissions denied. Aborting."
end
goto MainMenu_Hax_Options
@Unhax_Old
if not find 1:/title/00040138/00000002/content/????????.app NATIVE_NCCH
echo "NATIVE_FIRM not found.\nIs this an O3DS?"
goto MainMenu_Hax_Options
end
imgmount $[NATIVE_NCCH]
verify G:/exefs/.firm
set NATIVE_FIRM $[GM9OUT]/NATIVE_FIRM.firm
cp -w G:/exefs/.firm $[NATIVE_FIRM]
imgumount
if allow -a S:
allow -a 1:
rm -o -s 1:/boot.firm
rm -o -s 1:/rw/luma
cp -n $[NATIVE_FIRM] S:/firm0.bin
cp -n $[NATIVE_FIRM] S:/firm1.bin
shaget S:/nand.bin@57FFE00:200 PRE_STAGE2_HASH
if not sha S:/nand.bin@B800000:200 $[PRE_STAGE2_HASH]
fget S:/nand.bin@57FFE00:1 PRE_STAGE2
fill S:/nand.bin@B7FFE00:89C00 $[PRE_STAGE2]
end
echo "CFW uninstalled successfully"
else
echo "Permissions denied. Aborting."
end
goto MainMenu_Hax_Options
################FBI to H&S Options################ ################FBI to H&S Options################
@MainMenu_FBI_to_H&S_Options @MainMenu_FBI_to_H&S_Options

View File

@ -60,7 +60,7 @@ mount | fs.img_mount |  
umount | fs.img_umount |   umount | fs.img_umount |  
find | fs.find |   find | fs.find |  
findnot | fs.find_not |   findnot | fs.find_not |  
fget | fs.read_file |   fget | fs.write_file |  
fset | fs.write_file |   fset | fs.write_file |  
sha | fs.hash_file OR fs.verify_with_sha_file | hash_file simply returns a hash, verify_with_sha_file compares it with a corresponding .sha file sha | fs.hash_file OR fs.verify_with_sha_file | hash_file simply returns a hash, verify_with_sha_file compares it with a corresponding .sha file
shaget | fs.hash_file |   shaget | fs.hash_file |  
@ -111,9 +111,9 @@ EMUID0 | sys.emu_id0 |  
EMUBASE | sys.emu_base |   EMUBASE | sys.emu_base |  
SERIAL | sys.serial |   SERIAL | sys.serial |  
REGION | sys.region |   REGION | sys.region |  
SDSIZE | fs.stat_fs("0:/").total | int instead of string (use ui.format_bytes to format it) SDSIZE | fs.stat_fs("0:/").total | int instead of string (use util.format_bytes to format it)
SDFREE | fs.stat_fs("0:/").free | int instead of string (use ui.format_bytes to format it) SDFREE | fs.stat_fs("0:/").free | int instead of string (use util.format_bytes to format it)
NANDSIZE | NANDSIZE | int instead of string (use ui.format_bytes to format it) NANDSIZE | NANDSIZE | int instead of string (use util.format_bytes to format it)
GM9OUT | GM9OUT |   GM9OUT | GM9OUT |  
CURRDIR | CURRDIR | nil instead of “(null)" if it cant be found CURRDIR | CURRDIR | nil instead of “(null)" if it cant be found
ONTYPE | CONSOLE_TYPE | “O3DS" or “N3DS" ONTYPE | CONSOLE_TYPE | “O3DS" or “N3DS"
@ -251,7 +251,7 @@ Ask the user to input text.
#### ui.ask_selection #### ui.ask_selection
* `int ui.ask_selection(string prompt, table options)` * `int ui.ask_selection(string prompt, array options)`
Ask the user to choose an option from a list. A maximum of 256 options are allowed. Ask the user to choose an option from a list. A maximum of 256 options are allowed.
@ -437,7 +437,7 @@ Create a directory. This creates intermediate directories as required, so `fs.mk
#### fs.stat #### fs.stat
* `table fs.stat(string path)` * `array fs.stat(string path)`
Get information about a file or directory. The result is a stat table with these keys: Get information about a file or directory. The result is a stat table with these keys:
@ -453,7 +453,7 @@ Get information about a file or directory. The result is a stat table with these
#### fs.list_dir #### fs.list_dir
* `table fs.list_dir(string path)` * `array fs.list_dir(string path)`
Get the contents of a directory. The result is a list of stat tables with these keys: Get the contents of a directory. The result is a list of stat tables with these keys:
* `name` (string) * `name` (string)
@ -474,7 +474,7 @@ Get the contents of a directory. The result is a list of stat tables with these
#### fs.stat_fs #### fs.stat_fs
* `table fs.stat_fs(string path)` * `array fs.stat_fs(string path)`
Get information about a filesystem. Get information about a filesystem.
@ -490,7 +490,7 @@ Get information about a filesystem.
#### fs.dir_info #### fs.dir_info
* `table fs.dir_info(string path)` * `array fs.dir_info(string path)`
Get information about a directory. Get information about a directory.
@ -570,7 +570,7 @@ Pattern can use `?` for search values, for example `nand_??.bin` will check to s
#### fs.find_all #### fs.find_all
* `table fs.find_all(string dir, string pattern[, table opts {bool recursive}])` * `string fs.find_all(string dir, string pattern[, table opts {bool recursive}])`
Search for all files that match a pattern. Search for all files that match a pattern.
* **Arguments** * **Arguments**
@ -578,7 +578,6 @@ Search for all files that match a pattern.
* `pattern` - Filename pattern * `pattern` - Filename pattern
* `opts` (optional) - Option flags * `opts` (optional) - Option flags
* `recursive` - Remove directories recursively * `recursive` - Remove directories recursively
* **Returns:** table of found files
* **Throws** * **Throws**
* `"could not open directory"` - failed to open directory * `"could not open directory"` - failed to open directory
@ -680,6 +679,8 @@ Calculate the hash of a file and compare it with a corresponding `.sha` file.
> [!IMPORTANT] > [!IMPORTANT]
> This currently assumes SHA-256. In the future this may automatically use SHA-1 when appropriate, based on the `.sha` file size. > This currently assumes SHA-256. In the future this may automatically use SHA-1 when appropriate, based on the `.sha` file size.
TODO: add errors for fs.read_file here
* **Argumens** * **Argumens**
* `path` - File to hash * `path` - File to hash
* **Returns:** `true` if successful, `false` if failed, `nil` if `.sha` file could not be read * **Returns:** `true` if successful, `false` if failed, `nil` if `.sha` file could not be read

View File

@ -61,7 +61,7 @@ fs.copy("M:/otp.mem", "9:/otp_copied_by_lua.mem", {overwrite=true})
-- SCRIPT - the executed script, such as "0:/gm9/luascripts/HelloScript.lua" -- SCRIPT - the executed script, such as "0:/gm9/luascripts/HelloScript.lua"
-- CURRDIR - the directory of the executed script, such as "0:/gm9/luascripts" -- CURRDIR - the directory of the executed script, such as "0:/gm9/luascripts"
-- GM9OUT - the standard output path "0:/gm9/out" -- GM9OUT - the standard output path "0:/gm9/out"
-- HAX - the hax the system is currently running from, which can be "ntrboot", "sighax", or an empty string -- HAX - the hax the system is currently running from, whihc can be "ntrboot", "sighax", or an empty string
-- NANDSIZE - total size of SysNAND in bytes -- NANDSIZE - total size of SysNAND in bytes
-- CONSOLE_TYPE - the string "O3DS" or "N3DS" -- CONSOLE_TYPE - the string "O3DS" or "N3DS"
-- IS_DEVKIT - true if the console is a developer unit -- IS_DEVKIT - true if the console is a developer unit
@ -82,7 +82,7 @@ end
ui.echo("Your GodMode9 version is "..GM9VER.. ui.echo("Your GodMode9 version is "..GM9VER..
"\nYour region is "..sys.region.. "\nYour region is "..sys.region..
"\nYour serial number is "..sys.serial.. "\nYour serial number is "..sys.serial..
"\nYour std out path is "..GM9OUT.. "\nYour std out oath is "..GM9OUT..
"\nCurrent dir is "..CURRDIR.. "\nCurrent dir is "..CURRDIR..
"\nCurrent hax is "..HAX.. "\nCurrent hax is "..HAX..
"\nYour system is a "..retail_or_devkit.. "\nYour system is a "..retail_or_devkit..