Skip to content

Commit

Permalink
add MagicGate test Feature
Browse files Browse the repository at this point in the history
Check if your card supports updates and see the resulting kelf header without writing data to the card!
  • Loading branch information
israpps committed Feb 21, 2023
1 parent c75a0c1 commit 9c5a464
Show file tree
Hide file tree
Showing 8 changed files with 205 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ BIN2S = $(PS2SDK)/bin/bin2s
#-------------------------- App Content ---------------------------#
EXT_LIBS = modules/ds34usb/ee/libds34usb.a modules/ds34bt/ee/libds34bt.a

APP_CORE = main.o libcdvd_add.o modelname.o system.o pad.o graphics.o render.o \
APP_CORE = main.o sioprintf.o libcdvd_add.o modelname.o system.o pad.o graphics.o render.o \
calc_3d.o gsKit3d_sup.o atlas.o fntsys.o md5.o \
libsecr.o baexec-system_paths.o # sound.o

Expand Down
108 changes: 92 additions & 16 deletions bin/INSTALL/KELFBinder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ local SYSUPDATE_ICON_SYS_RES = "INSTALL/ASSETS/"..SYSUPDATE_ICON_SYS
DVDPLAYERUPDATE = "INSTALL/KELF/DVDPLAYER.XLF"
SYSUPDATE_MAIN = "INSTALL/KELF/SYSTEM.XLF"
PSX_SYSUPDATE = "INSTALL/KELF/XSYSTEM.XLF"
KERNEL_PATCH_100 = "INSTALL/KELF/OSDSYS.KERNEL"
KERNEL_PATCH_101 = "INSTALL/KELF/OSD110.KERNEL"
TEST_KELF = "INSTALL/KELF/BENCHMARK.XLF"

temporaryVar = System.openFile(SYSUPDATE_MAIN, FREAD)
SYSUPDATE_SIZE = System.sizeFile(temporaryVar)
System.closeFile(temporaryVar)
KERNEL_PATCH_100 = "INSTALL/KELF/OSDSYS.KERNEL"
KERNEL_PATCH_101 = "INSTALL/KELF/OSD110.KERNEL"


Screen.clear() Graphics.drawRect(280, 222, 80, 4, Color.new(255, 255, 255)) Screen.flip()
local circle = Graphics.loadImageEmbedded(5)
Expand Down Expand Up @@ -110,11 +112,6 @@ else
Screen.clear(Color.new(128, 128, 0)) Screen.flip() while true do end
end

-- Sound.setVolume(100)
-- Sound.setADPCMVolume(1, 100)
-- SND_NOTI = Sound.loadADPCM("common/NOTIF.ADP")
-- Sound.playADPCM(1, SND_OK)

function ORBMAN(Q)
R = R+RINCREMENT
if R > 200 and RINCREMENT > 0 then RINCREMENT = -0.00018 end
Expand Down Expand Up @@ -369,27 +366,29 @@ function Installmodepicker()
local PROMTPS = {
LNG_IMPP0,
LNG_IMPP1,
LNG_IMPP2
LNG_IMPP2,
LNG_IMPP3
}
while true do
Screen.clear()
Graphics.drawScaleImage(BG, 0.0, 0.0, 640.0, 448.0)
ORBMAN(0x80)
if T == 1 then
Font.ftPrint(font, 321, 150, 0, 630, 16, LNG_IMPMP1, Color.new(0, 0xde, 0xff, 0x80 - A))
else
Font.ftPrint(font, 321, 150, 0, 630, 16, LNG_IMPMP1, Color.new(0, 0xde, 0xff, 0x80 - A)) else
Font.ftPrint(font, 320, 150, 0, 630, 16, LNG_IMPMP1, Color.new(200, 200, 200, 0x80 - A))
end
if T == 2 then
Font.ftPrint(font, 321, 190, 0, 630, 16, LNG_IMPMP2, Color.new(0, 0xde, 0xff, 0x80 - A))
else
Font.ftPrint(font, 321, 190, 0, 630, 16, LNG_IMPMP2, Color.new(0, 0xde, 0xff, 0x80 - A)) else
Font.ftPrint(font, 320, 190, 0, 630, 16, LNG_IMPMP2, Color.new(200, 200, 200, 0x80 - A))
end
if T == 3 then
Font.ftPrint(font, 321, 230, 0, 630, 16, LNG_IMPMP3, Color.new(0, 0xde, 0xff, 0x80 - A))
else
Font.ftPrint(font, 321, 230, 0, 630, 16, LNG_IMPMP3, Color.new(0, 0xde, 0xff, 0x80 - A)) else
Font.ftPrint(font, 320, 230, 0, 630, 16, LNG_IMPMP3, Color.new(200, 200, 200, 0x80 - A))
end
if T == 4 then
Font.ftPrint(font, 321, 270, 0, 630, 16, LNG_IMPMP4, Color.new(0, 0xde, 0xff, 0x80 - A)) else
Font.ftPrint(font, 320, 270, 0, 630, 16, LNG_IMPMP4, Color.new(200, 200, 200, 0x80 - A))
end

Font.ftPrint(font, 80, 350, 0, 600, 32, PROMTPS[T], Color.new(128, 128, 128, 0x80 - A))
promptkeys(1, LNG_CT0, 1, LNG_CT1, 0, 0, A)
Expand Down Expand Up @@ -417,8 +416,8 @@ function Installmodepicker()
end
if D > 0 then D = D + 1 end
if D > 10 then D = 0 end
if T < 1 then T = 3 end
if T > 3 then T = 1 end
if T < 1 then T = 4 end
if T > 4 then T = 1 end

end
return T
Expand Down Expand Up @@ -1004,6 +1003,76 @@ function secrerr(RET)
OrbIntro(1)
end

function MagicGateTest(port, slot)
local A = 0x80
local Q = 0x7f
local QIN = 1
local PADV = 0
while A > 0 do
Screen.clear()
Graphics.drawScaleImage(BG, 0.0, 0.0, 640.0, 448.0, Color.new(0x80, 0x80, 0x80, A))
Font.ftPrint(font, 320, 40, 8, 630, 64, string.format(LNG_PLS_WAIT, RET), Color.new(0x80, 0x80, 0x80, 0x80 - A))
A = A - 1
Screen.flip()
end
local RET
local HEADER
local MESSAGE = ""
local LOL = 0
if System.doesFileExist(TEST_KELF) then
RET, HEADER = Secrman.Testdownloadfile(port, slot, TEST_KELF) else
RET, HEADER = Secrman.Testdownloadfile(port, slot, KERNEL_PATCH_100)
end
for b in HEADER:gmatch('.') do
MESSAGE = MESSAGE..string.format(('%02X '):format(b:byte()))
LOL = LOL+1
if LOL == 16 then MESSAGE = MESSAGE.."\n" end
end
A = 0x80
while true do
Screen.clear()
if RET == 1 then
Graphics.drawScaleImage(BGSCS, 0.0, 0.0, 640.0, 448.0, Color.new(0x80, 0x80, 0x80, 0x80 - Q))
ORBMANex(GREENCURSOR, 0x80 - Q - 1, 180, 180, 80 + Q)
else
Graphics.drawScaleImage(BGERR, 0.0, 0.0, 640.0, 448.0, Color.new(0x80, 0x80, 0x80, 0x80 - Q))
ORBMANex(REDCURSOR, 0x80 - Q - 1, 180, 180, 80 + Q)
end
if Q < 0x20 then
PADV = Pads.get()
if A > 0 then A = A - 1 end
promptkeys(1, LNG_CONTINUE, 0, 0, 0, 0, A)
if RET ~= 1 then
Font.ftPrint(font, 320, 40, 8, 630, 64, string.format(LNG_TESTTERR, RET), Color.new(0x80, 0x80, 0x80, 0x80 - A))
else
Font.ftPrint(font, 320, 40, 8, 630, 64, LNG_TESTSUCC, Color.new(0x80, 0x80, 0x80, 0x80 - A))
Font.ftPrint(font, 120, 280, 8, 630, 64, LNG_KELF_HEAD, Color.new(0x80, 0x80, 0x80, 0x80 - A))
Font.ftPrint(font, 120, 300, 0, 630, 32, MESSAGE, Color.new(0x80, 0x80, 0x80, 0x80 - A))
end
if RET == (-5) then
Font.ftPrint(font, 320, 60, 8, 630, 64, LNG_EIO, Color.new(0x80, 0x80, 0x80, 0x80 - A))
elseif RET == (-22) then
Font.ftPrint(font, 320, 60, 8, 630, 64, LNG_SECRMANERR, Color.new(0x80, 0x80, 0x80, 0x80 - A))
elseif RET == (-12) then
Font.ftPrint(font, 320, 60, 8, 630, 64, LNG_ENOMEM, Color.new(0x80, 0x80, 0x80, 0x80 - A))
elseif RET == (-201) then
Font.ftPrint(font, 320, 60, 8, 630, 64, LNG_SOURCE_KELF_GONE, Color.new(0x80, 0x80, 0x80, 0x80 - A))
elseif RET ~= 1 then -- only write unknown error if retcode is not a success
Font.ftPrint(font, 320, 60, 8, 630, 64, LNG_EUNKNOWN, Color.new(0x80, 0, 0, 0x80 - A))
end

if Pads.check(PADV, PAD_CROSS) and A == 0 then
QIN = -2
Q = 1
end
end
if Q > 0 and Q < 0x80 then Q = Q - QIN end
if Q > 0x7f then break end
Screen.flip()
end
OrbIntro(1)
end

function WarnOfShittyFMCBInst()
local A = 0x80
local AIN = -1
Expand Down Expand Up @@ -1446,6 +1515,13 @@ while true do
performExpertINST(port, 0, UPDT)
else WaitWithORBS(20) end
end
elseif TTT == 4 then -- MAGICGATE TEST
local port = MemcardPickup()
if port ~= -1 then
FadeWIthORBS()
MagicGateTest(port, 0)
WaitWithORBS(50)
end
end
elseif TT == 2 then -- DVDPLAYER
local port = MemcardPickup()
Expand Down
13 changes: 10 additions & 3 deletions bin/lang/spanish.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
LNG_CRDTS1 = "Basado en Enceladus por Daniel Santos"
LNG_CRDTS2 = "SECRMAN y SECRSIF tomados de FreeMcBoot 1.9"
LNG_CRDTS3 = "GFX por Berion"
LNG_CRDTS4 = "obteneme gratis en github.com/israpps/KelfBinder"
LNG_CRDTS4 = "obteneme gratis en https://github.com/israpps/KELFBinder"
LNG_CRDTS5 = "Gracias a:"
LNG_MM1 = "Bienvenido a KELFBinder"
LNG_MM2 = "Administrar actualizaciones de sistema"
Expand All @@ -18,10 +18,12 @@
LNG_IMPP0 = "Realiza una Instalación compatible con\n Esta consola y modelos similares"
LNG_IMPP1 = "Los modos de instalación clásicos de FreeMcBoot"
LNG_IMPP2 = "Elige manualmente las actualizaciones a instalar"
LNG_IMPP3 = "Prueba si tu tarjeta soporta actualizaciones\nSin escribir información en ella"
LNG_IMPMP0 = "Elige modo de Instalación"
LNG_IMPMP1 = "Instalación normal"
LNG_IMPMP2 = "Instalación avanzada"
LNG_IMPMP3 = "Instalación Experta"
LNG_IMPMP4 = "Prueba MagicGate"
LNG_INSTPMPT = "ENLAZANDO KELF\n\n%s\n"
LNG_INSTPMPT1 = "Instalación Finalizada!"
LNG_MEMCARD0 = "Selecciona una Memory card"
Expand All @@ -45,14 +47,18 @@
LNG_REGS3 = "China - SCPH-XXX09"
LNG_EIO = "ERROR I/O"
LNG_SECRMANERR = "SECRDOWNLOADFILE Falló! - Posible error Magicgate"
LNG_ENOMEM = "MEMORY ALLOCATION ERROR!"
LNG_ENOMEM = "ERROR RESERVANDO MEMORIA!"
LNG_SOURCE_KELF_GONE = "no se puede acceder al KELF"
LNG_EUNKNOWN = "error desconocido!"
LNG_INSTERR = "Installacáon Fallida! (%d)"
LNG_INSTERR = "Installación Fallida! (%d)"
LNG_TESTTERR = "Prueba Fallida! (%d)"
LNG_TESTSUCC = "Prueba completada!"
LNG_INSTALLING = "Instalando actualizaciones de sistema..."
LNG_INSTFINISH = "Instalación concluida!"
LNG_WANNAQUIT = "Cerrar Programa?"
LNG_YES = "Si"
LNG_NO = "No"
LNG_PLS_WAIT = "Por favor espera..."
LNG_RWLE = "Correr wLaunchELF"
LNG_SYSTEMINFO = "Información de Sistema"
LNG_SUPATH = "ruta de actualización = [%s]"
Expand Down Expand Up @@ -88,4 +94,5 @@
LNG_UNFORMATTED_CARD = "sin formatear"
LNG_EXTRA_INSTALL_ENABLE = "Se instalarán archivos extra"
LNG_EXTRA_INSTALL_DISABLE = "No se instalarán archivos extra"
LNG_KELF_HEAD = "cabecera KELF:"
-- TRADUCCION POR El_isra
9 changes: 7 additions & 2 deletions etc/boot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Screen.clear() Graphics.drawRect(318, 222, 4, 4, Color.new(255, 255, 255)) Scree
LNG_CRDTS1 = "Based on Enceladus by Daniel Santos"
LNG_CRDTS2 = "SECRMAN and SECRSIF taken from Free McBoot 1.9 series installer"
LNG_CRDTS3 = "GFX by Berion"
LNG_CRDTS4 = "Get me free at https://www.github.com/israpps/KelfBinder"
LNG_CRDTS4 = "Get me free at https://github.com/israpps/KELFBinder"
LNG_CRDTS5 = "Thanks to:"
LNG_MM1 = "Welcome to KELFBinder"
LNG_MM2 = "Manage System Updates"
Expand All @@ -19,9 +19,11 @@ Screen.clear() Graphics.drawRect(318, 222, 4, 4, Color.new(255, 255, 255)) Scree
LNG_IMPP0 = "Perform an installation compatible with this console\nand similar units"
LNG_IMPP1 = "Free McBoot's classic installation modes"
LNG_IMPP2 = "Choose manually which updates will be installed"
LNG_IMPP3 = "Test if your card supports updates\nWithout writing data to the card"
LNG_IMPMP1 = "Normal Install"
LNG_IMPMP2 = "Advanced Install"
LNG_IMPMP3 = "Expert Install"
LNG_IMPMP4 = "MagicGate Test"
LNG_INSTPMPT = "BINDING KELF\n\n%s\n"
LNG_INSTPMPT1 = "Installation finished!"
LNG_MEMCARD0 = "Choose a Memory Card"
Expand Down Expand Up @@ -49,11 +51,14 @@ Screen.clear() Graphics.drawRect(318, 222, 4, 4, Color.new(255, 255, 255)) Scree
LNG_SOURCE_KELF_GONE = "input KELF can't be opened"
LNG_EUNKNOWN = "Unknown error!"
LNG_INSTERR = "Installation failed! (%d)"
LNG_TESTTERR = "Test failed! (%d)"
LNG_TESTSUCC = "Test succeeded!"
LNG_INSTALLING = "Installing System Updates..."
LNG_INSTFINISH = "Installation finished!"
LNG_WANNAQUIT = "Exit application?"
LNG_YES = "Yes"
LNG_NO = "No"
LNG_PLS_WAIT = "Please Wait..."
LNG_RWLE = "Run wLaunchELF"
LNG_SYSTEMINFO = "SYSTEM INFORMATION"
LNG_SUPATH = "System Update Path = [%s]"
Expand Down Expand Up @@ -89,7 +94,7 @@ Screen.clear() Graphics.drawRect(318, 222, 4, 4, Color.new(255, 255, 255)) Scree
LNG_UNFORMATTED_CARD = "unformatted"
LNG_EXTRA_INSTALL_ENABLE = "Extra files will be installed"
LNG_EXTRA_INSTALL_DISABLE = "Extra files will not be installed"

LNG_KELF_HEAD = "KELF Header:"

BETANUM = "014"
IS_NOT_PUBLIC_READY = false
Expand Down
12 changes: 10 additions & 2 deletions src/include/dbgprintf.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
#ifndef DPRINTF_H
#define DPRINTF_H

#ifdef __cplusplus
extern "C" {
#endif
void sio_printf(const char *fmt, ...);
#ifdef __cplusplus
}
#endif

#ifdef SIO_PRINTF
#include <SIOCookie.h>
#define DPRINTF_INIT() ee_sio_start(38400, 0, 0, 0, 0)
#define DPRINTF(x...) printf(x)
#define DPRINTF(x...) sio_printf(x)
//#define DFLUSH() fflush(stdout)
#endif

Expand All @@ -20,7 +28,7 @@
#ifndef DPRINTF
#include <SIOCookie.h>
#define DPRINTF_INIT() ee_sio_start(38400, 0, 0, 0, 0)
#define DPRINTF(x...) printf(x)
#define DPRINTF(x...) sio_printf(x)
//#define DFLUSH() fflush(stdout)
#endif

Expand Down
2 changes: 1 addition & 1 deletion src/luagraphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ static int lua_loadHWCimg(lua_State *L) {
if (argc != 1 && argc != 2) return luaL_error(L, "wrong number of arguments");
lua_gc(L, LUA_GCCOLLECT, 0);
int numeroausar = luaL_checkinteger(L, 1);
DPRINTF("%s: resource ID %d requested!\n",__func__, numeroausar);
DPRINTF("Embedd res: resource ID %d requested!\n",__func__, numeroausar);
GSTEXTURE* image = NULL;
bool delayed = true;
image = luaP_loadHWCpng(numeroausar, delayed);
Expand Down
73 changes: 73 additions & 0 deletions src/luasecrman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,83 @@ static int lua_secrdownloadfile(lua_State *L)
return 1;
}

static int lua_secrdownloadfileTest(lua_State *L)
{
unsigned char header[32+1];
int argc = lua_gettop(L);
#ifndef SKIP_ERROR_HANDLING
if (argc != 3)
return luaL_error(L, "wrong number of arguments");
#endif
int port = luaL_checkinteger(L, 1);
int slot = luaL_checkinteger(L, 2);
const char *file_tbo = luaL_checkstring(L, 3);
DPRINTF("--------------------\n%s: Starting with %d argumments:\n"
"[Port]: %d\n"
"[Slot]: %d\n"
"[input KELF]: %s\n",
__func__, argc,
port, slot, file_tbo);
void *buf;
int result = 0;
int fd = open(file_tbo, O_RDONLY);
DPRINTF("%s: input fd is %d\n", __func__, fd);
if (fd < 0) {
lua_pushinteger(L, -201);
return 1;
}
int size = lseek(fd, 0, SEEK_END);
DPRINTF("%s: KELF size is %d\n", __func__, size);
if (size < 0) {
close(fd);
lua_pushinteger(L, -201);
return -EIO;
}
lseek(fd, 0, SEEK_SET);
if ((buf = memalign(64, size)) != NULL) {
if ((read(fd, buf, size)) != size) {
close(fd);
result = -EIO;
} else {
close(fd);
if ((result = SignKELF(buf, size, port, slot)) < 0) {
free(buf);
DPRINTF("%s: SignKELF failed with value %d\n", __func__, result);
} else {
DPRINTF("%s: SignKELF returns %d\n", __func__, result);
}
}
} else {
DPRINTF("%s: memory allocation of %d bytesfailed\n", __func__, size);
result = -ENOMEM;
close(fd);
}
if (buf != NULL)
{
memset(header, 0x00, 32);
memcpy(header, buf, 32);
DPRINTF("%s: finished!\nKELF Header = {", __func__);
int x=0;
for (x = 0; x < 32; x++)
{
if(!(x % 16))
DPRINTF("\n");
DPRINTF("%02x ", header[x]);
}
DPRINTF("\n}\n");

free(buf);
}
lua_pushinteger(L, result);
lua_pushlstring(L, (const char *)header, 32);
return 2;
}

static const luaL_Reg Secrman_functions[] = {
{"init", lua_initsecrman},
{"deinit", lua_deinitsecrman},
{"downloadfile", lua_secrdownloadfile},
{"Testdownloadfile", lua_secrdownloadfileTest},
//{"signKELFfile", lua_signKELFfile},
{0, 0}};

Expand Down
Loading

0 comments on commit 9c5a464

Please sign in to comment.