Skip to content

Instantly share code, notes, and snippets.

@p-sam
Created January 18, 2019 10:49
Show Gist options
  • Save p-sam/93c17f99bb3df72c6a5d9749e795f3cc to your computer and use it in GitHub Desktop.
Save p-sam/93c17f99bb3df72c6a5d9749e795f3cc to your computer and use it in GitHub Desktop.
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <switch.h>
#include "web_wifi.h"
#define PRINT_RC(str, rc) printf("[!] %s: [0x%x] %04d-%04d\n", str, rc, R_MODULE(rc), R_DESCRIPTION(rc))
void userAppInit() {
consoleInit(NULL);
socketInitializeDefault();
nxlinkStdio();
}
void userAppExit() {
consoleExit(NULL);
socketExit();
}
void showWebWifi() {
printf("* showWebWifi\n");
Result rc = 0;
WebWifiConfig config;
printf("sizeof(config): %lx\n", sizeof(config));
printf("sizeof(config.arg): %lx\n", sizeof(config.arg));
webWifiCreate(&config, "http://google.fr");
rc = webWifiShow(&config);
PRINT_RC("webWifiShow", rc);
}
int main(int argc, char *argv[]) {
printf(
"START\n"
"======\n"
"Press B to show a webpage using wifiwebauth\n"
"======\n"
"Press + to exit\n"
);
while (appletMainLoop()) {
hidScanInput();
u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
if (kDown & KEY_PLUS) {
break;
}
if (kDown & KEY_B) {
showWebWifi();
}
consoleUpdate(NULL);
}
return 0;
}
#include "web_wifi.h"
#include <string.h>
#include <malloc.h>
static void _webWifiUrlCreate(WebWifiPageArgUrl* argUrl, const char* url) {
strncpy(argUrl->url, url, sizeof(argUrl->url)-1);
}
void webWifiCreate(WebWifiConfig* config, const char* url) {
memset(config, 0, sizeof(WebWifiConfig));
_webWifiUrlCreate(&config->arg.url1, url);
_webWifiUrlCreate(&config->arg.url2, url);
}
Result webWifiShow(WebWifiConfig* config) {
Result rc = 0;
AppletHolder holder;
AppletStorage storage;
memset(&storage, 0, sizeof(AppletStorage));
rc = appletCreateLibraryApplet(&holder, AppletId_wifiWebAuth, LibAppletMode_AllForeground);
if (R_FAILED(rc)) return rc;
LibAppletArgs commonargs;
libappletArgsCreate(&commonargs, 0);
rc = libappletArgsPush(&commonargs, &holder);
if (R_SUCCEEDED(rc)) rc = libappletPushInData(&holder, &config->arg, sizeof(config->arg));
if (R_SUCCEEDED(rc)) rc = appletHolderStart(&holder);
if (R_SUCCEEDED(rc)) {
while(appletHolderWaitInteractiveOut(&holder)) {
//TODO: Handle Interactive data here.
}
}
if (R_SUCCEEDED(rc)) {
appletHolderJoin(&holder);
LibAppletExitReason reason = appletHolderGetExitReason(&holder);
if (reason == LibAppletExitReason_Abnormal || reason == LibAppletExitReason_Unexpected) {
//TODO: Official sw asserts here - return a proper error here.
return -1;
}
}
appletHolderClose(&holder);
return rc;
}
#pragma once
#include <switch.h>
typedef struct {
u8 unk1[0x4];
char url[0xFC];
} WebWifiPageArgUrl;
typedef struct {
WebWifiPageArgUrl url1;
WebWifiPageArgUrl url2;
u8 unkgap1 [0x300];
u8 unk2[0x18];
} WebWifiPageArg;
typedef struct {
WebWifiPageArg arg;
} WebWifiConfig;
void webWifiCreate(WebWifiConfig* config, const char* url);
Result webWifiShow(WebWifiConfig* config);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment