Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*-------------------------------------------------------------
- title_lister.c -- displays contents of Wii NAND flash FS
- Copyright (C) 2008 bushing
- This software is provided 'as-is', without any express or implied
- warranty. In no event will the authors be held liable for any
- damages arising from the use of this software.
- Permission is granted to anyone to use this software for any
- purpose, including commercial applications, and to alter it and
- redistribute it freely, subject to the following restrictions:
- 1.The origin of this software must not be misrepresented; you
- must not claim that you wrote the original software. If you use
- this software in a product, an acknowledgment in the product
- documentation would be appreciated but is not required.
- 2.Altered source versions must be plainly marked as such, and
- must not be misrepresented as being the original software.
- 3.This notice may not be removed or altered from any source
- distribution.
- -------------------------------------------------------------*/
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <malloc.h>
- #include <ogcsys.h>
- #include <gccore.h>
- #include <ogc/ipc.h>
- #include <stdarg.h>
- #include <ctype.h>
- #include <unistd.h>
- #include <assert.h>
- #include <network.h>
- char ascii(char s) {
- if(s < 0x20) return '.';
- if(s > 0x7E) return '.';
- return s;
- }
- static void *xfb = NULL;
- static GXRModeObj *rmode = NULL;
- typedef void (*Loader_Entry)(void);
- Loader_Entry loader = (Loader_Entry)0x80001800;
- void checkAndReload(void) {
- PAD_ScanPads();
- int buttonsDown = PAD_ButtonsHeld(0);
- if( (buttonsDown & PAD_TRIGGER_Z) && (buttonsDown & PAD_BUTTON_START)) {
- loader();
- }
- }
- void waita(void) {
- while(1) {
- VIDEO_WaitVSync();
- PAD_ScanPads();
- int buttonsDown = PAD_ButtonsDown(0);
- if(buttonsDown & PAD_BUTTON_A)
- return;
- if( (buttonsDown & PAD_TRIGGER_Z) && (buttonsDown & PAD_BUTTON_START)) {
- loader();
- }
- }
- }
- void printvers(void) {
- printf("IOS Version: %08x\n", *((u32*)0xC0003140));
- }
- s32 __STM_Init();
- void console_setup(void) {
- VIDEO_Init();
- PAD_Init();
- switch(VIDEO_GetCurrentTvMode()) {
- case VI_NTSC:
- rmode = &TVNtsc480IntDf;
- break;
- case VI_PAL:
- rmode = &TVPal528IntDf;
- break;
- case VI_MPAL:
- rmode = &TVMpal480IntDf;
- break;
- default:
- rmode = &TVNtsc480IntDf;
- break;
- }
- xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
- console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
- VIDEO_Configure(rmode);
- VIDEO_SetNextFramebuffer(xfb);
- VIDEO_SetBlack(FALSE);
- VIDEO_Flush();
- VIDEO_WaitVSync();
- if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();
- }
- char * display_tmd_info(const tmd *t) {
- static char desc[256];
- u32 kind = t->title_id >> 32;
- u32 title_l = t->title_id & 0xFFFFFFFF;
- char title_ascii[5];
- u32 i;
- memcpy(title_ascii, &title_l, 4);
- for (i=0; i<4; i++) title_ascii[i]=ascii(title_ascii[i]);
- title_ascii[4]='\0';
- switch (kind) {
- case 1: // IOS, MIOS, BC, System Menu
- snprintf(desc, sizeof(desc), "Title=1-%x (", title_l);
- switch(title_l) {
- case 2: strlcat(desc, "System Menu) ", sizeof(desc)); break;
- case 0x100: strlcat(desc, "BC) ", sizeof(desc)); break;
- case 0x101: strlcat(desc, "MIOS) ", sizeof(desc)); break;
- default: sprintf(desc + strlen(desc), "IOS%d) ", title_l); break;
- }
- break;
- case 0x10000: // TMD installed by running a disc
- snprintf(desc, sizeof(desc), "Title=10000-%08x (savedata for '%s')",
- title_l, title_ascii); break;
- case 0x10001: // Normal channels / VC
- snprintf(desc, sizeof(desc), "Title=10001-%08x (downloaded channel '%s')",
- title_l, title_ascii); break;
- case 0x10002: // "System channels" -- News, Weather, etc.
- snprintf(desc, sizeof(desc), "Title=10002-%08x (system channel '%s')",
- title_l, title_ascii); break;
- case 0x10004: // "Hidden channels" -- WiiFit channel
- snprintf(desc, sizeof(desc), "Title=10004-%08x (game channel '%s')",
- title_l, title_ascii); break;
- case 0x10008: // "Hidden channels" -- EULA, rgnsel
- snprintf(desc, sizeof(desc), "Title=10008-%08x (hidden? channel '%s')",
- title_l, title_ascii); break;
- default:
- printf("Unknown title type %x %08x\n", kind, title_l);
- break;
- }
- if (t->title_version)
- snprintf(desc, sizeof(desc), "%s vers: %d.%d (%d)", desc, t->title_version >> 8, t->title_version & 0xFF,
- t->title_version);
- if (t->sys_version) snprintf(desc, sizeof(desc), "%s FW: IOS%llu ", desc, t->sys_version & 0xff);
- return desc;
- }
- /* code to establish a socket; originally from bzs@bu-cs.bu.edu
- */
- int establish(unsigned short portnum) {
- int s;
- struct sockaddr_in sa;
- memset(&sa, 0, sizeof(struct sockaddr_in)); /* clear our address */
- sa.sin_family= AF_INET; /* this is our host address */
- sa.sin_port= htons(portnum); /* this is our port number */
- sa.sin_addr.s_addr = net_gethostip();
- sa.sin_len = 8;
- if ((s= net_socket(AF_INET, SOCK_STREAM, 0)) < 0) /* create socket */
- return(-1);
- if (net_bind(s,(struct sockaddr *)&sa,8) < 0) {
- net_close(s);
- return(-1); /* bind address to socket */
- }
- net_listen(s, 3); /* max # of queued connects */
- return(s);
- }
- // wait for a connection to occur on a socket created with establish()
- int get_connection(int s)
- {
- int t; /* socket of connection */
- struct sockaddr_in sa;
- sa.sin_len = 8;
- sa.sin_family = AF_INET;
- u32 buflen = 8;
- t = net_accept(s,(struct sockaddr *)&sa, &buflen);
- printf("Incoming connection from %d.%d.%d.%d\n",
- (sa.sin_addr.s_addr >> 24) & 0xFF,
- (sa.sin_addr.s_addr >> 16) & 0xFF,
- (sa.sin_addr.s_addr >> 8) & 0xFF,
- (sa.sin_addr.s_addr) & 0xFF);
- return t;
- }
- int read_data(int s, /* connected socket */
- char *buf, /* pointer to the buffer */
- int n /* number of characters (bytes) we want */
- )
- { int bcount; /* counts bytes read */
- int br; /* bytes read this pass */
- bcount= 0;
- br= 0;
- while (bcount < n) { /* loop until full buffer */
- if ((br= net_read(s,buf,n-bcount)) > 0) {
- bcount += br; /* increment byte counter */
- buf += br; /* move buffer ptr for next read */
- }
- else if (br < 0) /* signal an error to the caller */
- return br;
- }
- // debug_printf("read_data(%d, %p, %d): \n", s, buf, n);
- return bcount;
- }
- int write_data(int s, char *buf, int n)
- {
- int bcount;
- int br;
- bcount = 0;
- br = 0;
- while(bcount < n) {
- if ((br = net_write(s,buf,n-bcount)) > 0) {
- bcount += br;
- buf += br;
- }
- else if (br < 0)
- return br;
- }
- // debug_printf("write_data(%d, %p, %d): \n", s, buf, n);
- // hexdump(buf, bcount);
- return (bcount);
- }
- int socket_printf(const s32 socket, const char *format, ...) {
- char *buf;
- int retval;
- va_list ap;
- va_start(ap, format);
- retval = vasprintf(&buf, format, ap);
- va_end(ap);
- write_data(socket, buf, retval);
- free(buf);
- return retval;
- }
- int main(int argc, char **argv) {
- console_setup();
- // printvers();
- __STM_Init();
- SYS_SetResetCallback(loader);
- printf("Initializing network, please wait.\n");
- net_init();
- s32 ret;
- u32 count;
- printf("Opening listening socket on port 8080:\n");
- s32 listener = establish(8080);
- printf("Listener socket = %d\n", listener);
- s32 client_socket = get_connection(listener);
- if (client_socket >= 0) {
- socket_printf(client_socket, "Hello, World!\n");
- ret = ES_GetNumTitles(&count);
- if (ret) {
- socket_printf(client_socket, "ES_GetNumTitles=%d, count=%08x\n", ret, count);
- return ret;
- }
- socket_printf(client_socket, "Found %d titles:\n", count);
- static u64 title_list[256] ATTRIBUTE_ALIGN(32);
- ret = ES_GetTitles(title_list, count);
- if (ret) {
- socket_printf(client_socket, "ES_GetTitles=%d\n", ret);
- return ret;
- }
- int i;
- for(i=0; i<0xe0; i++) socket_printf(client_socket, "%02hhx", buffer[i]);
- socket_printf(client_socket, "\n");
- for (i=0; i < count; i++) {
- u32 tmd_size;
- ret = ES_GetStoredTMDSize(title_list[i], &tmd_size);
- static u8 tmd_buf[MAX_SIGNED_TMD_SIZE] ATTRIBUTE_ALIGN(32);
- signed_blob *s_tmd = (signed_blob *)tmd_buf;
- ret = ES_GetStoredTMD(title_list[i], s_tmd, tmd_size);
- socket_printf(client_socket, "%d: %s\n", i+1, display_tmd_info(SIGNATURE_PAYLOAD(s_tmd)));
- }
- net_close(client_socket);
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment