Example #1
0
int nvram_cmd(int argc, CmdArg* argv) {
	char* var = NULL;
	char* value = NULL;
	char* action = NULL;
	if(argc < 2) {
		puts("usage: nvram <action> [options]\n");
		puts("  list              \t\tdisplay list of nvram variables\n");
		puts("  remove <var>      \t\tdeletes entry from nvram variables\n");
		puts("  get <var>         \t\tshow contents of nvram variable\n");
		puts("  set <var> <value> \t\tset contents of nvram variable\n\n");
		return 0;
	}

	action = argv[1].string;
	if(argc == 2) {
		if(!strcmp(action, "list")) {
			nvram_display_list();
			return 0;
		}

	} else if(argc == 3) {
		if(!strcmp(action, "get")) {
			var = argv[2].string;
			return nvram_get_var(var);

		} else if(!strcmp(action, "remove")) {
			var = argv[2].string;
			return nvram_remove_var(var);
		}

	} else if(argc == 4) {
		if(!strcmp(action, "set")) {
			var = argv[2].string;
			value = argv[3].string;
			return nvram_set_var(var, value);
		}
	}

	return 0;
}
Example #2
0
int main(int argc, CmdArg* argv) {
	int i = 0;
	char result[0x10];
	if(!gGpHasInit || gCmdCount == 0) {
		if(gp_init()) {
			puts("Unable to initialize greenpois0n!!\n");
			return -1;
		}
		puts("=========================\n");
		puts("iFaith Thanks & Credits:\n");
		puts("=========================\n");
		puts("* AKi_nG\n");
		puts("* bile\n");
		puts("* Chronic Dev-Team\n");
		puts("* CPICH\n");
		puts("* cj\n");
		puts("* demize\n");
		puts("* geohot\n");
		puts("* GreySyntax\n");
		puts("* iFish12\n");
		puts("* msftguy\n");
		puts("* MuscleNerd\n");
		puts("* Neal\n");
		puts("* planetbeing\n");
		puts("* pod2g\n");
		puts("* posixninja\n");
		puts("* qwertyoruiop\n");
		puts("* sbingner\n");
		puts("* ThePirate\n");
		puts("* vonswanko\n");
		puts("=========================\n");
		cmd_detect();
		fs_mount("nand0a", "hfs", "/boot");		
		//puts("HFS+ filesystem mounted.\n")
		//puts("=========================\n");		
		return 0;
	}

	for(i = 1; i < argc; i++) {
		if(!strcmp(argv[i].string, "$_")) {
			NvramVar* retval = nvram_find_var("?");
			argv[i].string = retval->string;
			continue;
		}
		if(argv[i].string[0] == '$') {
			NvramVar* var = nvram_find_var(&(argv[i].string[1]));
			if(var == NULL) {
				printf("Unable to find nvram var for %s\n", &(argv[i].string[1]));
			} else {
				argv[i].string = var->string;
			}
		}
	}

	if(argc > 1) {
		int i = 0;
		char* command = argv[1].string;
		for(i = 0; i < gCmdCount; i++) {
			if(!strcmp(gCmdCommands[i]->name, command)) {
				int ret = gCmdCommands[i]->handler(argc-1, &argv[1]);
				snprintf(result, 0xF, "0x%x", ret);
				nvram_set_var("cmd-results", result);
				return ret;
			}
		}

		printf("Command %s not found.\n\n", command);
		return -1;
	}

	return 0;
}