findfile.cna 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # author REDMED-X
  2. beacon_command_register(
  3. "findfile", "Search for matching files based on a word, extention or keyword.",
  4. "INFO:\nSearch for matching files based on a word, extention or keyword in the file content. Wildcards are supported . Keyword matching only works for text based files.\n\n" .
  5. "ARGUMENTS:\n[<path to directory>]: specify a path to the directory from which to start searching (recursive searching supported).\n[<search pattern>]: specify a single word or extention to search for (support wildcards).\n[<keyword>]: leave empty OR specify a keyword to search for in text based files (support wildcards).\n\n" .
  6. "USAGE:\nfindfile <path to directory> <search pattern> <(optional) keyword> \n\n" .
  7. "EXAMPLES:\nfindfile C:\\Users\\RTO\\Documents *.xlsx\nfindfile C:\\Users\\RTO *login*.* username\nfindfile C:\\Users\\RTO *.txt *pass*\n\n");
  8. alias findfile {
  9. $bid = $1;
  10. $lpDirectory = $2;
  11. $lpSearchPattern = $3;
  12. $keyword = $4;
  13. if ($lpDirectory eq "") {
  14. berror($bid, "Please specify a path to a directory.\n");
  15. return;
  16. }
  17. if ($lpSearchPattern eq "") {
  18. berror($bid, "Please specify a pattern/word to search for.\n");
  19. return;
  20. }
  21. # Read in the right BOF file
  22. $handle = openf(script_resource("findfile.o"));
  23. $data = readb($handle, -1);
  24. closef($handle);
  25. # Pack our arguments
  26. $arg_data = bof_pack($bid, "zzz", $lpDirectory, $lpSearchPattern, $keyword);
  27. blog($bid, "Tasked to search for matching files..");
  28. beacon_inline_execute($bid, $data, "go", $arg_data);
  29. }