Skip to content

Commit

Permalink
Yeet.
Browse files Browse the repository at this point in the history
  • Loading branch information
viferga committed Sep 2, 2024
1 parent bafcadf commit dc15eeb
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions brew-pkg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,32 @@ def elf_file?(file_path)
# Check if the file exists
return false unless File.exist?(file_path)

File.open(file_path, "rb") do |file|
# Read the first 4 bytes
header = file.read(4)
stdout, status = Open3.capture2("file -bL --mime-encoding \"#{file_path}\"")
ohai "Debug file is elf #{stdout}"

# Check for ELF format
return header == "\x7FELF"
end
return true

# File.open(file_path, "rb") do |file|
# # Read the first 4 bytes
# header = file.read(4)

# ohai "Debug file is elf #{header[0].to_i} == \x7FELF"
# ohai "Debug file is elf #{header[1].to_i} == \x7FELF"
# ohai "Debug file is elf #{header[2].to_i} == \x7FELF"
# ohai "Debug file is elf #{header[3].to_i} == \x7FELF"

# # Check for ELF format
# return header == "\x7FELF"
# end
end

def patchelf(root_dir, prefix_path, binary)

# Get the full binary path and check if it's a valid ELF
binary_path = File.join(root_dir, prefix_path, binary)

# TODO: Elf check does not work
ohai "Debug file exists #{binary_path}: #{File.exist?(binary_path)}"
ohai "Debug file is elf #{elf_file?(binary_path)}"
# return unless elf_file?(binary_path)
return unless File.exist?(binary_path)
# Check if file exists and it is an executable
return unless elf_file?(binary_path)

# Get the list of linked libraries with otool
stdout, status = Open3.capture2("otool -L #{binary_path}")
Expand Down

0 comments on commit dc15eeb

Please sign in to comment.