Bfdgrep.c looks through binaries for filenames which exist on the local system.
c4d7a70b3b9d5600018271aea48c7ea0d07dd88eec8756fd97a27b7d51cfb26f
/* BFDGREP: binary filename/directory grep. **********************************
* bfgrep.c/bfgrep, binary filename/directory grep. (from which exist) *
* for obtaining existing filename(s) or directory(s) used by a binary *
* executable. argument 1 will be treated as a (binary) file, if none is *
* provided or the provided argument isn't accessable it will revert to *
* standard input. *
* *
* EXAMPLES: *
* # bfdgrep [filename] [...] *
* # cat <filename> | bfdgrep *
* *
* DISPLAY: *
* /path/file(location found:access): /path/file found. *
* *
* COMMENTS: *
* this program will only display with full valid paths (files and dirs). *
* also, this program will not display information that is not used in a *
* function. for example, something mentioned in a printf() statement *
* would not get displayed. *
* *
* by: vade79 -> v9[v9@realhalo.org] -> realhalo.org. (88l!271w!3208b) *
*****************************************************************************/
#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#define MAX_PATHNAME 4096 /* maximum path storage. (max) */
#define INPUT "/dev/stdin" /* revert to this (input) if no file. */
char id[]="$Id: bfdgrep.c,v 3.0 2001/03/24 01:11:36 EST vade79 Exp $";
char *file;
int main(int argc,char **argv) {
int i=0;
if(argc>1){
for(i=1;i<argc;i++){
parse_file(argv[i]);
}
}
else
parse_file(INPUT);
}
int parse_file(char *fn){
int i=0;
int chr=0;
long loc=0x0;
char string[MAX_PATHNAME];
char mode[5];
struct stat mod;
FILE *fd;
if(!(fd=fopen(fn,"r")))
printf("%s: failed opening file for reading.\n",fn);
else{
while((chr=fgetc(fd))!=EOF){
if(isprint(chr)){
string[i++]=chr;
if(i>sizeof(string)){
bzero(string,sizeof(string));
i=0;
}
}
else if(chr==0x0){
if(strlen(string)>1&&!stat(string,&mod))
if(string[0]==0x2f){
bzero(mode,sizeof(mode));
if(!access(string,F_OK)){
sprintf(mode,"+");
if(!access(string,R_OK))
strcat(mode,"r");
if(!access(string,W_OK))
strcat(mode,"w");
if(!access(string,X_OK))
strcat(mode,"x");
}
else
sprintf(mode,"-");
fprintf(stderr,"%s(0x%lx:%s): %s\n",strcmp(fn,INPUT)?fn:"input",
(loc-strlen(string)),mode,string);
}
bzero(string,sizeof(string));
i=0;
}
else{
bzero(string,sizeof(string));
i=0;
}
loc++;
}
fclose(fd);
}
}