Skip to content

Commit

Permalink
Added functions to get system firmware version.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rinnegatamante committed Jul 19, 2020
1 parent cbee569 commit 163e808
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ LIBS = -lcurl -lssl -lcrypto -lvorbisfile -lvorbis -logg -lsndfile -lvita2d -lSc
-ljpeg -lfreetype -lc -lScePower_stub -lSceCommonDialog_stub -lpng16 -lz -lSceCamera_stub \
-lspeexdsp -lmpg123 -lSceAudio_stub -lSceGxm_stub -lSceDisplay_stub -lSceShellSvc_stub \
-lopusfile -lopus -lSceHttp_stub -lSceAudioIn_stub -lluajit -ldl -ltaihen_stub -lSceSysmodule_stub \
-lSceVideodec_stub -lSceShutterSound_stub -lSceSsl_stub
-lSceVideodec_stub -lSceShutterSound_stub -lSceSsl_stub -lSceVshBridge_stub

CFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.c))
CPPFILES := $(foreach dir,$(SOURCES), $(wildcard $(dir)/*.cpp))
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ Here are some PSVITA homebrews made using Lua Player Plus Vita:
* [Video Bubbles Creator](http://wololo.net/talk/viewtopic.php?f=116&t=48581)
* [VitaGraphs](https://vitadb.rinnegatamante.it/#/info/363)
* [SwitchView UI](https://vitadb.rinnegatamante.it/#/info/338)
* [RandomHentai](https://vitadb.rinnegatamante.it/#/info/526)

##### Emulators
* [MicroCHIP](http://wololo.net/talk/viewtopic.php?f=116&t=48620)
Expand Down
43 changes: 43 additions & 0 deletions doc/luaSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,49 @@ class System{
*/
void exit(void);

/**
* Get unspoofed system firmware version.
* \ingroup System
*
* @par Usage example:
* @code
* fw = System.getFirmware()
* @endcode
*
* @return The unspoofed system firmware version.
*
* @note This function is available only in unsafe mode.
*/
string getFirmware(void);

/**
* Get spoofed system firmware version.
* \ingroup System
*
* @par Usage example:
* @code
* fw = System.getSpoofedFirmware()
* @endcode
*
* @return The spoofed system firmware version.
*/
string getSpoofedFirmware(void);

/**
* Get factory system firmware version.
* \ingroup System
*
* @par Usage example:
* @code
* fw = System.getFactoryFirmware()
* @endcode
*
* @return The factory system firmware version.
*
* @note This function is available only in unsafe mode.
*/
string getFactoryFirmware(void);

/**
* Sleep the application for a certain time.
* \ingroup System
Expand Down
66 changes: 66 additions & 0 deletions source/luaSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,26 @@ static int zipThread(unsigned int args, void* arg){
return 0;
}

// Taken from modoru, thanks to TheFloW
void firmware_string(char string[8], unsigned int version) {
char a = (version >> 24) & 0xf;
char b = (version >> 20) & 0xf;
char c = (version >> 16) & 0xf;
char d = (version >> 12) & 0xf;

memset(string, 0, 8);
string[0] = '0' + a;
string[1] = '.';
string[2] = '0' + b;
string[3] = '0' + c;
string[4] = '\0';

if (d) {
string[4] = '0' + d;
string[5] = '\0';
}
}

static void pushDateToTable(lua_State *L, SceDateTime date) {
lua_pushstring(L, "year");
lua_pushinteger(L, date.year);
Expand Down Expand Up @@ -1099,6 +1119,49 @@ static int lua_totalspace(lua_State *L){
return 1;
}

static int lua_firmware(lua_State *L){
int argc = lua_gettop(L);
#ifndef SKIP_ERROR_HANDLING
if (argc != 1) return luaL_error(L, "wrong number of arguments");
if (!unsafe_mode) return luaL_error(L, "this function requires unsafe mode");
#endif
char fw_str[8];
SceKernelFwInfo info;
info.size = sizeof(SceKernelFwInfo);
_vshSblGetSystemSwVersion(&info);
firmware_string(fw_str, info.version);
lua_pushstring(L, fw_str);
return 1;
}

static int lua_firmware2(lua_State *L){
int argc = lua_gettop(L);
#ifndef SKIP_ERROR_HANDLING
if (argc != 1) return luaL_error(L, "wrong number of arguments");
#endif
char fw_str[8];
SceKernelFwInfo info;
info.size = sizeof(SceKernelFwInfo);
sceKernelGetSystemSwVersion(&info);
firmware_string(fw_str, info.version);
lua_pushstring(L, fw_str);
return 1;
}

static int lua_firmware3(lua_State *L){
int argc = lua_gettop(L);
#ifndef SKIP_ERROR_HANDLING
if (argc != 1) return luaL_error(L, "wrong number of arguments");
if (!unsafe_mode) return luaL_error(L, "this function requires unsafe mode");
#endif
char fw_str[8];
int ver;
_vshSblAimgrGetSMI(&ver);
firmware_string(fw_str, ver);
lua_pushstring(L, fw_str);
return 1;
}

//Register our System Functions
static const luaL_Reg System_functions[] = {
{"openFile", lua_openfile},
Expand Down Expand Up @@ -1165,6 +1228,9 @@ static const luaL_Reg System_functions[] = {
{"getPsId", lua_getpsid},
{"getFreeSpace", lua_freespace},
{"getTotalSpace", lua_totalspace},
{"getFirmware", lua_firmware},
{"getSpoofedFirmware", lua_firmware2},
{"getFactoryFirmware", lua_firmware3},
{0, 0}
};

Expand Down

0 comments on commit 163e808

Please sign in to comment.