Created
          July 24, 2023 07:56 
        
      - 
      
- 
        Save M0nteCarl0/526bf8ac4bee78f1bf93c692e73e6bba to your computer and use it in GitHub Desktop. 
    Folder scaner for ELF files
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | package main | |
| import ( | |
| "fmt" | |
| "os" | |
| "path/filepath" | |
| ) | |
| func main() { | |
| folderPath := "path/to/folder" | |
| err := filepath.Walk(folderPath, func(path string, info os.FileInfo, err error) error { | |
| if err != nil { | |
| return err | |
| } | |
| if !info.IsDir() && isELFFile(path) { | |
| fmt.Println(path) | |
| } | |
| return nil | |
| }) | |
| if err != nil { | |
| fmt.Println("Failed to scan folder:", err) | |
| return | |
| } | |
| } | |
| func isELFFile(path string) bool { | |
| file, err := os.Open(path) | |
| if err != nil { | |
| return false | |
| } | |
| defer file.Close() | |
| // Read the first 4 bytes to check the ELF magic number | |
| magic := make([]byte, 4) | |
| _, err = file.Read(magic) | |
| if err != nil { | |
| return false | |
| } | |
| return string(magic) == "\x7fELF" | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment