Skip to content

Commit

Permalink
Fix circular require
Browse files Browse the repository at this point in the history
  • Loading branch information
david942j committed Oct 25, 2018
1 parent b06d893 commit 707aeb7
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 15 deletions.
4 changes: 2 additions & 2 deletions lib/one_gadget/emulators/x86.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def process(cmd)
false
end

# Support instruction set.
# @return [Array<Instruction>] The support instructions.
# Supported instruction set.
# @return [Array<Instruction>] The supported instructions.
def instructions
[
Instruction.new('add', 2),
Expand Down
3 changes: 1 addition & 2 deletions lib/one_gadget/fetchers/amd64.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def candidates

true
end
cands + jmp_case_candidates # + sigaction_case_candidates
cands + jmp_case_candidates
end

# find gadgets in form:
Expand All @@ -30,7 +30,6 @@ def candidates
# ...
# call execve
def jmp_case_candidates
bin_sh_hex = str_offset('/bin/sh').to_s(16)
`#{objdump_cmd}|egrep 'rdi.*# #{bin_sh_hex}' -A 3`.split('--').map do |cand|
cand = cand.lines.map(&:strip).reject(&:empty?)
jmp_at = cand.index { |c| c.include?('jmp') }
Expand Down
2 changes: 1 addition & 1 deletion lib/one_gadget/gadget.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def builds(build_id, remote: true)
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::Helper.ask_update(msg: 'The desired one-gadget can be found in lastest version!')
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
Expand Down
9 changes: 0 additions & 9 deletions lib/one_gadget/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
require 'elftools'

require 'one_gadget/error'
require 'one_gadget/logger'

module OneGadget
# Define some helpful methods here.
Expand Down Expand Up @@ -184,14 +183,6 @@ def url_request(url)
nil
end

# Show the message of ask user to update gem.
# @return [void]
def ask_update(msg: '')
name = 'one_gadget'
cmd = colorize("gem update #{name} && gem cleanup #{name}")
OneGadget::Logger.info(msg + "\n" + "Update with: $ #{cmd}" + "\n")
end

# Fetch the file archiecture of +file+.
# @param [String] file The target ELF filename.
# @return [Symbol]
Expand Down
8 changes: 8 additions & 0 deletions lib/one_gadget/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ def not_found(build_id)
[]
end

# Show the message of ask user to update gem.
# @return [void]
def ask_update(msg: '')
name = 'one_gadget'
cmd = OneGadget::Helper.colorize("gem update #{name} && gem cleanup #{name}")
OneGadget::Logger.info(msg + "\n" + "Update with: $ #{cmd}" + "\n")
end

%i[info warn error].each do |sym|
define_method(sym) do |msg|
@logger.__send__(sym, msg)
Expand Down
2 changes: 1 addition & 1 deletion lib/one_gadget/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def check!

# show update message
msg = format('A newer version of OneGadget is available (%s --> %s).', OneGadget::VERSION, latest)
OneGadget::Helper.ask_update(msg: msg)
OneGadget::Logger.ask_update(msg: msg)
end

private
Expand Down

0 comments on commit 707aeb7

Please sign in to comment.