Module: OneGadget::Gadget::ClassMethods
- Included in:
- OneGadget::Gadget
- Defined in:
- lib/one_gadget/gadget.rb
Overview
Define class methods here.
Constant Summary collapse
- BUILDS_PATH =
Path to the pre-build files.
File.join(__dir__, 'builds').freeze
- BUILDS =
Record.
Hash.new { |h, k| h[k] = [] }
Instance Method Summary collapse
-
#add(build_id, offset, **options) ⇒ void
Add a gadget, for scripts in builds/ to use.
-
#builds(build_id, remote: true) ⇒ Array<Gadget::Gadget>?
Get gadgets from pre-defined corpus.
-
#builds_info(build_id) ⇒ String?
Returns the comments in builds/libc-*-<build_id>*.rb.
Instance Method Details
#add(build_id, offset, **options) ⇒ void
This method returns an undefined value.
Add a gadget, for scripts in builds/ to use.
199 200 201 |
# File 'lib/one_gadget/gadget.rb', line 199 def add(build_id, offset, **) BUILDS[build_id] << OneGadget::Gadget::Gadget.new(offset, **) end |
#builds(build_id, remote: true) ⇒ Array<Gadget::Gadget>?
Get gadgets from pre-defined corpus.
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/one_gadget/gadget.rb', line 148 def builds(build_id, remote: true) ret = find_build(build_id) return ret unless ret.nil? return build_not_found unless remote # fetch remote builds table = OneGadget::Helper.remote_builds.find { |c| c.include?(build_id) } return build_not_found if table.nil? # remote doesn't have this one either. # builds found in remote! Ask update gem and download remote gadgets. OneGadget::Logger.ask_update(msg: 'The desired one-gadget can be found in lastest version!') tmp_file = OneGadget::Helper.download_build(table) require tmp_file.path tmp_file.unlink BUILDS[build_id] end |
#builds_info(build_id) ⇒ String?
Returns the comments in builds/libc-*-<build_id>*.rb
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/one_gadget/gadget.rb', line 177 def builds_info(build_id) raise Error::ArgumentError, "Invalid BuildID #{build_id.inspect}" if build_id =~ /[^0-9a-f]/ files = Dir.glob(File.join(BUILDS_PATH, "*-#{build_id}*.rb")) return OneGadget::Logger.not_found(build_id) && nil if files.empty? if files.size > 1 OneGadget::Logger.warn("Multiple BuildIDs match /^#{build_id}/\n") show = files.map do |f| File.basename(f, '.rb').reverse.split('-', 2).join(' ').reverse end OneGadget::Logger.warn("Candidates are:\n#{show * "\n"}\n") return nil end OneGadget::Helper.comments_of_file(files.first) end |