Rewrite argv munger.
This commit is contained in:
parent
1b622ff5ac
commit
8abc78aa84
@ -150,9 +150,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
int busybox_main(int argc, char **argv)
|
int busybox_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int col = 0;
|
int col = 0, len, i;
|
||||||
int ps_index;
|
|
||||||
char *index, *index2;
|
|
||||||
|
|
||||||
argc--;
|
argc--;
|
||||||
|
|
||||||
@ -185,25 +183,16 @@ int busybox_main(int argc, char **argv)
|
|||||||
/* Flag that we've been here already */
|
/* Flag that we've been here already */
|
||||||
been_there_done_that = 1;
|
been_there_done_that = 1;
|
||||||
|
|
||||||
/* We do not want the word "busybox" to show up in ps, so we move
|
/* Move the command line down a notch */
|
||||||
* everything in argv around to fake ps into showing what we want it to
|
len = argv[argc] + strlen(argv[argc]) - argv[1];
|
||||||
* show. Since we are only shrinking the string, we don't need to move
|
memmove(argv[0], argv[1], len);
|
||||||
* __environ or any of that tedious stuff... */
|
memset(argv[0] + len, 0, argv[1] - argv[0]);
|
||||||
ps_index = 0;
|
|
||||||
index=*argv;
|
/* Fix up the argv pointers */
|
||||||
index2=argv[argc];
|
len = argv[1] - argv[0];
|
||||||
index2+=strlen(argv[argc]);
|
memmove(argv, argv+1, sizeof(char *) * (argc + 1));
|
||||||
while(ps_index < argc) {
|
for (i = 0; i < argc; i++)
|
||||||
argv[ps_index]=index;
|
argv[i] -= len;
|
||||||
memmove(index, argv[ps_index+1], strlen(argv[ps_index+1])+1);
|
|
||||||
index+=(strlen(index));
|
|
||||||
*index='\0';
|
|
||||||
index++;
|
|
||||||
ps_index++;
|
|
||||||
}
|
|
||||||
while(index<=index2)
|
|
||||||
*index++='\0';
|
|
||||||
argv[ps_index]=NULL;
|
|
||||||
|
|
||||||
return (main(argc, argv));
|
return (main(argc, argv));
|
||||||
}
|
}
|
||||||
|
33
busybox.c
33
busybox.c
@ -150,9 +150,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
int busybox_main(int argc, char **argv)
|
int busybox_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int col = 0;
|
int col = 0, len, i;
|
||||||
int ps_index;
|
|
||||||
char *index, *index2;
|
|
||||||
|
|
||||||
argc--;
|
argc--;
|
||||||
|
|
||||||
@ -185,25 +183,16 @@ int busybox_main(int argc, char **argv)
|
|||||||
/* Flag that we've been here already */
|
/* Flag that we've been here already */
|
||||||
been_there_done_that = 1;
|
been_there_done_that = 1;
|
||||||
|
|
||||||
/* We do not want the word "busybox" to show up in ps, so we move
|
/* Move the command line down a notch */
|
||||||
* everything in argv around to fake ps into showing what we want it to
|
len = argv[argc] + strlen(argv[argc]) - argv[1];
|
||||||
* show. Since we are only shrinking the string, we don't need to move
|
memmove(argv[0], argv[1], len);
|
||||||
* __environ or any of that tedious stuff... */
|
memset(argv[0] + len, 0, argv[1] - argv[0]);
|
||||||
ps_index = 0;
|
|
||||||
index=*argv;
|
/* Fix up the argv pointers */
|
||||||
index2=argv[argc];
|
len = argv[1] - argv[0];
|
||||||
index2+=strlen(argv[argc]);
|
memmove(argv, argv+1, sizeof(char *) * (argc + 1));
|
||||||
while(ps_index < argc) {
|
for (i = 0; i < argc; i++)
|
||||||
argv[ps_index]=index;
|
argv[i] -= len;
|
||||||
memmove(index, argv[ps_index+1], strlen(argv[ps_index+1])+1);
|
|
||||||
index+=(strlen(index));
|
|
||||||
*index='\0';
|
|
||||||
index++;
|
|
||||||
ps_index++;
|
|
||||||
}
|
|
||||||
while(index<=index2)
|
|
||||||
*index++='\0';
|
|
||||||
argv[ps_index]=NULL;
|
|
||||||
|
|
||||||
return (main(argc, argv));
|
return (main(argc, argv));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user