[Android Q&A, Help & Troubleshooting] droidvoider:
Execution functions revamped, contexts on the fly now and the beginnings of an actual root shell

1. I will be testing to make sure we no longer need two execution loops. system_server and install_recovery will both be the install_recovery loop and we will simply set the context we want.

--works, I can patch /init for instance.. we have juice now I believe.

2.) I have multiple requests now for a root shell using what we already have!! I didn't realize that I already have root until a couple of people pointed that out to me, I just need the 'shell'

3) I am into selinux like flies on poop now. sorry google, I'm taking it down.. this must happen or none of my pretty little setenforce 0 commands will stick :p

//execute commands
void eXecCmd(char *command_line) {
security_context_t newcontext;
int isetcon;

extern char **environ;	/* array of environment variables */
char *arguments[248];	/* the command line argument	*/

pid_t childprocess;	/* execv doesn't return on success so we need to fork a proc */
int status=0;	/* status is updated to parent */

int waitoptions = 0;	/* opitions listed below */
//WNOHANG return immediately if no child has exited.
//WUNTRACED also return if a child has stopped (but not traced via ptrace(2)). Status for traced children which have stopped is provided even if this option is not specified.
//WCONTINUED also return if a stopped child has been resumed by delivery of SIGCONT.

int res=0;
int iSaySo=1;
/* loop through contexts until success or we run out */
while (iSaySo){
/* reset on each loop */
status=0;
waitoptions = 0;
res=0;
switch (iSaySo) /* contexts to try */
{
case 1: newcontext	=	"u:r:install_recovery:s0";
break;
case 2: newcontext	=	"u:r:system_server:s0";
break;
case 3: newcontext	=	"u:r:init:s0";
break;
case 4: newcontext	=	"u:r:kernel:s0";
break;
case 5: newcontext	=	"u:r:shell:s0";
break;
case 6: newcontext	=	"u:r:toolbox:s0";
break;
default: iSaySo=0; /* <TODO> <DEBUG> error should be reported one time, here */
}if (!iSaySo){break;}
//<TODO> <DEBUG> --- return not tested
if (setcon(newcontext)){}
isetcon = setexeccon(newcontext);	/* it's proper to set the exec context before making an exec call */
if ( isetcon ) {	/* i've never seen an error feel free to remove this line */
LOGV("[-] Toolbox: error setexeccon %s",newcontext);
}

if( (childprocess = fork()) == 0 )	/* Child proc block */
{
parse(command_line, arguments);	/* parse the line	*/
if( (res = execve(*arguments, arguments, environ)) < 0 )	/* -=-=->] Execute [<-=-=- */
{
if (iSaySo == 0 ) {
LOGV("[-] Toolbox %s [failure: %s]",	/* Report errors */
command_line, strerror(errno));
exitreason(childprocess, status);	/* on error, test for signal and coredump & report them */
exit(91);	/* must exit child on failure because the proc returns */
}
}
}
else if( childprocess > 0 )
{
waitpid(childprocess, &status, waitoptions);	/* parent, waitfor child */
if ( !status )LOGV("[+] Toolbox success: %s", command_line);break;	/* if status is 0 we had success */
} else {LOGV("[-] Toolbox failed to fork process");}
iSaySo++;
}
}
//parse into a command line
void parse(char *line, char **arguments)
{
while (*line != '\0') { /* if not the end of line ....... */
while (*line == ' ' || *line == '\t' || *line == '\n')
*line++ = '\0'; /* replace white spaces with 0 */
*arguments++ = line; /* save the argument position */
while (*line != '\0' && *line != ' ' &&
*line != '\t' && *line != '\n')
line++; /* skip the argument until ... */
}
*arguments = '\0'; /* mark the end of argument list */
}
//some testing for when there was an error.
void exitreason(pid_t childprocess, int status)
{
if( WIFSIGNALED(status) )
{
LOGV("[-] Toolbox child %d process was terminated by a signal.",childprocess);
if( WTERMSIG(status) )
{
LOGV("[-] Toolbox child %d signal %d that caused the child process to terminate.",childprocess,WTERMSIG(status));
}
if( WCOREDUMP(status) )
{
LOGV("[-] Toolbox child %d produced a core dump",childprocess);
}
}
if( WIFSTOPPED(status) )
{
LOGV("[-] Toolbox child %d process was stopped by delivery of a signal (see ptrace(2)).",childprocess);
if( WSTOPSIG(status) )
{
LOGV("[-] Toolbox child %d number of the signal which caused the child to stop.",childprocess);
}
}
}
//WIFEXITED(status) returns true if the child terminated normally, that is, by calling exit(3) or _exit(2), or by returning from main().
//WEXITSTATUS(status) returns the exit status of the child. This consists of the least significant 8 bits of the status argument that the child specified in a call to exit(3) or _exit(2) or as the argument for a return statement in main(). This macro should only be employed if WIFEXITED returned true.
//WIFSIGNALED(status) returns true if the child process was terminated by a signal.
//WTERMSIG(status) returns the number of the signal that caused the child process to terminate. This macro should only be employed if WIFSIGNALED returned true.
//WCOREDUMP(status) returns true if the child produced a core dump. This macro should only be employed if WIFSIGNALED returned true. This macro is not specified in POSIX.1-2001 and is not available on some UNIX implementations (e.g., AIX, SunOS). Only use this enclosed in #ifdef WCOREDUMP ... #endif.
//WIFSTOPPED(status) returns true if the child process was stopped by delivery of a signal; this is only possible if the call was done using WUNTRACED or when the child is being traced (see ptrace(2)).
//WSTOPSIG(status) returns the number of the signal which caused the child to stop. This macro should only be employed if WIFSTOPPED returned true.
//WIFCONTINUED(status) (since Linux 2.6.10) returns true if the child process was resumed by delivery of SIGCONT.

could contain errors, as always this worked once and needs testing.

Ideas:

If anyone who is not a coder wants to help out please disable all your packages and then try to take down selinux! Google never expected us to be able to do this, so what will happen if we do?

(I almost guarantee you that if you leave the packages disabled and reboot, it won't boot up.. AT&T logo, might get hot.. take great caution!!)

How to see packages???

adb shell
pm list packages -e <----- enabled pacakges
pm list packages -d <----- disabled packages

make sure you make two lists!! a cmd_list.txt to disable and then another one to enable those packages again. you will never get root if you have to flash flash flash