module Helpers::Void
Public Instance Methods
add_line(file, line)
click to toggle source
# File lib/getch/helpers.rb, line 123 def add_line(file, line) raise "No file #{file} found !" unless File.exist? file File.write(file, "#{line}\n", mode: 'a') end
chroot(cmd)
click to toggle source
Used only when need password
# File lib/getch/helpers.rb, line 136 def chroot(cmd) if !system("chroot", Getch::MOUNTPOINT, "/bin/bash", "-c", cmd) raise "[-] Error with: #{cmd}" end end
command(args)
click to toggle source
# File lib/getch/helpers.rb, line 96 def command(args) print " => Exec: #{args}..." cmd = "chroot #{Getch::MOUNTPOINT} /bin/bash -c \"#{args}\"" _, stderr, status = Open3.capture3(cmd) if status.success? then puts "\s[OK]" return end raise "\n[-] Fail cmd #{args} - #{stderr}." end
command_output(args)
click to toggle source
# File lib/getch/helpers.rb, line 107 def command_output(args) print " => Exec: #{args}..." cmd = "chroot #{Getch::MOUNTPOINT} /bin/bash -c \"#{args}\"" Open3.popen2e(cmd) do |stdin, stdout_err, wait_thr| puts while line = stdout_err.gets puts line end exit_status = wait_thr.value unless exit_status.success? raise "\n[-] Fail cmd #{args} - #{stdout_err}." end end end
grub_cmdline(*args)
click to toggle source
# File lib/getch/helpers.rb, line 158 def grub_cmdline(*args) conf = "#{Getch::MOUNTPOINT}/etc/default/grub" list = args.join(" ") secs = "GRUB_CMDLINE_LINUX=\"#{list} init_on_alloc=1 init_on_free=1" secs += " slab_nomerge pti=on slub_debug=ZF vsyscall=none\"" raise "No default/grub found" unless File.exist? conf unless search(conf, "GRUB_CMDLINE_LINUX=") File.write(conf, "#{secs}\n", mode: 'a') end end
line_fstab(dev, rest)
click to toggle source
# File lib/getch/helpers.rb, line 150 def line_fstab(dev, rest) conf = "#{Getch::MOUNTPOINT}/etc/fstab" device = s_uuid(dev) raise "No partuuid for #{dev} #{device}" if !device raise "Bad partuuid for #{dev} #{device}" if device.kind_of? Array add_line(conf, "PARTUUID=#{device} #{rest}") end
s_uuid(dev)
click to toggle source
# File lib/getch/helpers.rb, line 142 def s_uuid(dev) device = dev.delete_prefix("/dev/") Dir.glob("/dev/disk/by-partuuid/*").each { |f| link = File.readlink(f) return f.delete_prefix("/dev/disk/by-partuuid/") if link.match(/#{device}$/) } end
search(file, text)
click to toggle source
# File lib/getch/helpers.rb, line 128 def search(file, text) File.open(file).each { |line| return true if line.match(/#{text}/) } return false end