code
stringlengths
26
124k
docstring
stringlengths
23
125k
func_name
stringlengths
1
98
language
stringclasses
1 value
repo
stringlengths
5
53
path
stringlengths
7
151
url
stringlengths
50
211
license
stringclasses
7 values
def recurring_tasks if supports_recurring_tasks? raise_incompatible_adapter_error_from :recurring_tasks end end
Returns an array with the list of recurring tasks. Each task is represented as a hash with these attributes: { id: "periodic-job", job_class_name: "MyJob", arguments: [ 123, { arg: :value }] schedule: "every monday at 9 am", last_enqueued_at: Fri, 26 Jan 2024 20:31:09.652174000 UTC +00:00, }
recurring_tasks
ruby
rails/mission_control-jobs
lib/mission_control/jobs/adapter.rb
https://github.com/rails/mission_control-jobs/blob/master/lib/mission_control/jobs/adapter.rb
MIT
def find_recurring_task(recurring_task_id) if supports_recurring_tasks? raise_incompatible_adapter_error_from :find_recurring_task end end
Returns a recurring task represented by a hash as indicated above
find_recurring_task
ruby
rails/mission_control-jobs
lib/mission_control/jobs/adapter.rb
https://github.com/rails/mission_control-jobs/blob/master/lib/mission_control/jobs/adapter.rb
MIT
def workers if exposes_workers? raise_incompatible_adapter_error_from :workers end end
Returns an array with the list of workers. Each worker is represented as a hash with these attributes: { id: 123, name: "worker-name", hostname: "hey-default-101", last_heartbeat_at: Fri, 26 Jan 2024 20:31:09.652174000 UTC +00:00, configuration: { ... } raw_data: { ... } }
workers
ruby
rails/mission_control-jobs
lib/mission_control/jobs/adapter.rb
https://github.com/rails/mission_control-jobs/blob/master/lib/mission_control/jobs/adapter.rb
MIT
def find_worker(worker_id) if exposes_workers? raise_incompatible_adapter_error_from :find_worker end end
Returns a worker represented by a hash as indicated above
find_worker
ruby
rails/mission_control-jobs
lib/mission_control/jobs/adapter.rb
https://github.com/rails/mission_control-jobs/blob/master/lib/mission_control/jobs/adapter.rb
MIT
def queues raise_incompatible_adapter_error_from :queue_names end
Returns an array with the list of queues. Each queue is represented as a hash with these attributes: { name: "queue_name", size: 1, active: true }
queues
ruby
rails/mission_control-jobs
lib/mission_control/jobs/adapter.rb
https://github.com/rails/mission_control-jobs/blob/master/lib/mission_control/jobs/adapter.rb
MIT
def perform_enqueued_jobs worker = Resque::Worker.new("*") worker.work(0.0) end
UI tests just use Resque for now
perform_enqueued_jobs
ruby
rails/mission_control-jobs
test/application_system_test_case.rb
https://github.com/rails/mission_control-jobs/blob/master/test/application_system_test_case.rb
MIT
def queue_adapter raise NotImplementedError end
Returns the adapter to test. Template method to override in child classes. E.g: +:resque+, +:sidekiq+
queue_adapter
ruby
rails/mission_control-jobs
test/active_job/queue_adapters/adapter_testing.rb
https://github.com/rails/mission_control-jobs/blob/master/test/active_job/queue_adapters/adapter_testing.rb
MIT
def perform_enqueued_jobs raise NotImplementedError end
Perform the jobs in the queue. Template method to override in child classes.
perform_enqueued_jobs
ruby
rails/mission_control-jobs
test/active_job/queue_adapters/adapter_testing.rb
https://github.com/rails/mission_control-jobs/blob/master/test/active_job/queue_adapters/adapter_testing.rb
MIT
def configuration if ActiveRecord::Base.configurations.respond_to?(:configs_for) ActiveRecord::Base.configurations.configs_for(env_name: Rails.env).first else ActiveRecord::Base.configurations[Rails.env] end end
[] is deprecated and will be removed in 6.2
configuration
ruby
gocardless/statesman
lib/generators/statesman/generator_helpers.rb
https://github.com/gocardless/statesman/blob/master/lib/generators/statesman/generator_helpers.rb
MIT
def validate_not_from_terminal_state(from) unless from.nil? || successors.key?(from) raise InvalidTransitionError, "Cannot transition away from terminal state '#{from}'" end end
Check that the 'from' state is not terminal
validate_not_from_terminal_state
ruby
gocardless/statesman
lib/statesman/machine.rb
https://github.com/gocardless/statesman/blob/master/lib/statesman/machine.rb
MIT
def validate_not_to_initial_state(to) unless to.nil? || successors.values.flatten.include?(to) raise InvalidTransitionError, "Cannot transition to initial state '#{to}'" end end
Check that the 'to' state is not initial
validate_not_to_initial_state
ruby
gocardless/statesman
lib/statesman/machine.rb
https://github.com/gocardless/statesman/blob/master/lib/statesman/machine.rb
MIT
def validate_from_and_to_state(from, to) unless successors.fetch(from, []).include?(to) raise InvalidTransitionError, "Cannot transition from '#{from}' to '#{to}'" end end
Check that the transition is valid when 'from' and 'to' are given
validate_from_and_to_state
ruby
gocardless/statesman
lib/statesman/machine.rb
https://github.com/gocardless/statesman/blob/master/lib/statesman/machine.rb
MIT
def update_most_recents(most_recent_id = nil) update = build_arel_manager(::Arel::UpdateManager, transition_class) update.table(transition_table) update.where(most_recent_transitions(most_recent_id)) update.set(build_most_recents_update_all_values(most_recent_id)) # MySQL will v...
Sets the given transition most_recent = t while unsetting the most_recent of any previous transitions.
update_most_recents
ruby
gocardless/statesman
lib/statesman/adapters/active_record.rb
https://github.com/gocardless/statesman/blob/master/lib/statesman/adapters/active_record.rb
MIT
def build_most_recents_update_all_values(most_recent_id = nil) [ [ transition_table[:most_recent], Arel::Nodes::SqlLiteral.new(most_recent_value(most_recent_id)), ], ].tap do |values| # Only if we support the updated at timestamps should we add this ...
Generates update_all Arel values that will touch the updated timestamp (if valid for this model) and set most_recent to true only for the transition with a matching most_recent ID. This is quite nasty, but combines two updates (set all most_recent = f, set current most_recent = t) into one, which helps improve transit...
build_most_recents_update_all_values
ruby
gocardless/statesman
lib/statesman/adapters/active_record.rb
https://github.com/gocardless/statesman/blob/master/lib/statesman/adapters/active_record.rb
MIT
def not_most_recent_value(db_cast: true) if transition_class.columns_hash["most_recent"].null == false return db_cast ? db_false : false end db_cast ? db_null : nil end
Check whether the `most_recent` column allows null values. If it doesn't, set old records to `false`, otherwise, set them to `NULL`. Some conditioning here is required to support databases that don't support partial indexes. By doing the conditioning on the column, rather than Rails' opinion of whether the database su...
not_most_recent_value
ruby
gocardless/statesman
lib/statesman/adapters/active_record.rb
https://github.com/gocardless/statesman/blob/master/lib/statesman/adapters/active_record.rb
MIT
def initialize(transition_class, parent_model, observer, _opts = {}) @history = [] @transition_class = transition_class @parent_model = parent_model @observer = observer end
We only accept mode as a parameter to maintain a consistent interface with other adapters which require it.
initialize
ruby
gocardless/statesman
lib/statesman/adapters/memory.rb
https://github.com/gocardless/statesman/blob/master/lib/statesman/adapters/memory.rb
MIT
def testcase_crash( hash ) thread = ::Thread.new do finished_pass = false # if this is a new crash for this reduction, log the hash if( @crash_hashes.has_key?( hash ) ) @crash_hashes[hash] += 1 else @crash_hashes[hash] = 1 end # flag the current testcase as being able to trigge...
def previous_crash( hash ) if( @crash_hashes.index( hash ) > 0 ) return @crash_hashes[ @crash_hashes.index( hash ) - 1 ] end return nil end
testcase_crash
ruby
stephenfewer/grinder
node/reduction.rb
https://github.com/stephenfewer/grinder/blob/master/node/reduction.rb
BSD-3-Clause
def testcase_generate html = '' thread = ::Thread.new do finished_pass = false case @current_pass when 1 # Initial verification finished_pass = @genopts.finished? @genopts.skip().call if not finished_pass when 2 # Reducing elements finished_pass = @elems.finished? ...
generate the next testcase to try
testcase_generate
ruby
stephenfewer/grinder
node/reduction.rb
https://github.com/stephenfewer/grinder/blob/master/node/reduction.rb
BSD-3-Clause
def testcase_processed continue = true thread = ::Thread.new do kill_browser case @current_pass when 1 # Initial verification @genopts.keep when 2 # Reducing elements @elems.keep when 3 # Reducing idx's @idxs.keep when 4 # Final verification # boo...
return true if we are to continue generating and serving out testcases, or false if its time to finish.
testcase_processed
ruby
stephenfewer/grinder
node/reduction.rb
https://github.com/stephenfewer/grinder/blob/master/node/reduction.rb
BSD-3-Clause
def reduction( pass ) return false if pass > 4 @current_pass = pass case @current_pass when 1 p = [ ::Proc.new do @opts['print_message_comments'] = false @opts['uncomment_code_comments'] = @opts['print_code_comments'] = false end, ::Proc.new do @opts['uncomment_...
pass 1: initial verification (find out if we can cause a crash, do we need to enable code comments, do we need to tickle?) pass 2: skip elements (find what elements we can skip to still cause a crash) pass 3: skip idxs (find out what idxs we can remove to still generate a crash) pass 4: final verification (finally veri...
reduction
ruby
stephenfewer/grinder
node/reduction.rb
https://github.com/stephenfewer/grinder/blob/master/node/reduction.rb
BSD-3-Clause
def loader_javascript_chrome( pid, imagebase, chrome_dll ) print_status( "#{chrome_dll} DLL loaded into process #{pid} at address 0x#{'%08X' % imagebase }" ) if( not @attached[pid].logmessage or not @attached[pid].finishedtest ) print_error( "Unable to hook JavaScript parseFloat() in process #{pid}, g...
hook chrome.dll!v8::internal::Runtime_StringParseFloat to call LOGGER_logMessage/LOGGER_finishedTest
loader_javascript_chrome
ruby
stephenfewer/grinder
node/browser/chrome.rb
https://github.com/stephenfewer/grinder/blob/master/node/browser/chrome.rb
BSD-3-Clause
def use_heaphook?( pid ) return use_logger?( pid ) end
we dont want to use grinder_heaphook.dll in the broker process...
use_heaphook?
ruby
stephenfewer/grinder
node/browser/internetexplorer.rb
https://github.com/stephenfewer/grinder/blob/master/node/browser/internetexplorer.rb
BSD-3-Clause
def use_logger?( pid ) if( ie_major_version == 8 ) return true elsif( ie_major_version >= 9 && @attached[pid].commandline =~ /SCODEF:/i ) return true end return false end
we dont want to use grinder_logger.dll in the broker process...
use_logger?
ruby
stephenfewer/grinder
node/browser/internetexplorer.rb
https://github.com/stephenfewer/grinder/blob/master/node/browser/internetexplorer.rb
BSD-3-Clause
def generate_idxs( opts={}, skip_elem=[], skip_idx=[], level=nil ) idx = [] enumerate_log( opts, skip_elem, skip_idx, level ) do | log | idx << log['idx'] if log['message'] end return idx end
returns an array of log idx's which pass any restrictions (via opts/skip_elem/skip_idx)
generate_idxs
ruby
stephenfewer/grinder
node/core/xmlcrashlog.rb
https://github.com/stephenfewer/grinder/blob/master/node/core/xmlcrashlog.rb
BSD-3-Clause
def generate_elems( opts={}, skip_elem=[], skip_idx=[] ) elems = [] 0.upto( @log_elems ) do | i | elem = @elem_prefix + i.to_s if( skip_elem.include?( elem ) ) next end elems << elem end return elems end
returns an array of log elements which pass any restrictions (via opts/skip_elem/skip_idx)
generate_elems
ruby
stephenfewer/grinder
node/core/xmlcrashlog.rb
https://github.com/stephenfewer/grinder/blob/master/node/core/xmlcrashlog.rb
BSD-3-Clause
def generate_html( opts={}, skip_elem=[], skip_idx=[] ) html = '' result = @log_file.scan( /([a-fA-F0-9]{8}\.[a-fA-F0-9]{8})/ ) if( not result.empty? ) title = result.first.first else title = @log_file end html << "<!doctype html>\n" html << "<html>\n" html << "\t<head>\n" html << "\t\t<m...
def find_log( idx ) @log_lines.each do | log | if( log['idx'] and log['idx'] == idx ) return log end end return nil end
generate_html
ruby
stephenfewer/grinder
node/core/xmlcrashlog.rb
https://github.com/stephenfewer/grinder/blob/master/node/core/xmlcrashlog.rb
BSD-3-Clause
def inject_dll( library_name, pid ) # we try to pull the kernel32 base address from our shadow module list # first, this is in case we have a 64bit ruby and a 32bit target process, # in this instance LoadLibraryA would return the 64bit kernel32 address in # our ruby vm and not the 32bit wow...
inject via the standard CreateRemoteThread/LoadLibrary technique...
inject_dll
ruby
stephenfewer/grinder
node/core/debug/debugger.rb
https://github.com/stephenfewer/grinder/blob/master/node/core/debug/debugger.rb
BSD-3-Clause
def mem_prot( address ) info = ::Metasm::WinAPI.alloc_c_struct( "MEMORY_BASIC_INFORMATION#{::Metasm::WinAPI.host_cpu.size}" ) ::Metasm::WinAPI.virtualqueryex( @os_process.handle, address, info, info.sizeof ) if( (info[:state] & ::Metasm::WinAPI::MEM_COMMIT) > 0 ) return { :...
Modified from METASM WinOS::Process.mappings (\metasm\os\windows.rb:899)
mem_prot
ruby
stephenfewer/grinder
node/core/debug/debugger.rb
https://github.com/stephenfewer/grinder/blob/master/node/core/debug/debugger.rb
BSD-3-Clause
def get_current_fuzzer fuzzer = nil begin uri = ::URI.parse( "http://#{$server_address}:#{$server_port}/current_fuzzer" ) http = Net::HTTP.new( uri.host, uri.port ) request = Net::HTTP::Post.new( uri.request_uri ) response = http.request( request ) if( response....
def get_previous_crash result = '' begin uri = ::URI.parse( "http://#{$server_address}:#{$server_port}/previous_crash" ) http = Net::HTTP.new( uri.host, uri.port ) request = Net::HTTP::Post.new( uri.request_uri ) request.set_form_data( { 'hash' => "#{@hash[0]}.#{@hash[1]}" } ) response = http.request( reque...
get_current_fuzzer
ruby
stephenfewer/grinder
node/core/debug/debuggerexception.rb
https://github.com/stephenfewer/grinder/blob/master/node/core/debug/debuggerexception.rb
BSD-3-Clause
def contains?( pointer ) if( pointer >= @address and pointer < (@address + @size) ) return true end return false end
def object_type @callstack.each do | caller | result = caller.scan( /\w{1,}!([\w\:]{0,})::operator new/ ) if( not result.empty? ) return result.first.first end end return '' end
contains?
ruby
stephenfewer/grinder
node/core/debug/heaphook.rb
https://github.com/stephenfewer/grinder/blob/master/node/core/debug/heaphook.rb
BSD-3-Clause
def exception(msg='EOF unexpected') ParseError.new "near #@curexpr: #{msg}" end
allows 'raise self' (eg struct.offsetof)
exception
ruby
stephenfewer/grinder
node/lib/metasm/metasm/compile_c.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/compile_c.rb
BSD-3-Clause
def initialize(parser, exeformat=nil, source=[]) exeformat ||= ExeFormat.new @parser, @exeformat, @source = parser, exeformat, source @auto_label_list = {} @label_oldname = {} end
creates a new CCompiler from an ExeFormat and a C Parser
initialize
ruby
stephenfewer/grinder
node/lib/metasm/metasm/compile_c.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/compile_c.rb
BSD-3-Clause
def compile cf = @exeformat.unique_labels_cache.keys & @auto_label_list.keys raise "compile_c name conflict: #{cf.inspect}" if not cf.empty? @exeformat.unique_labels_cache.update @auto_label_list @parser.toplevel.precompile(self) # reorder statements (arrays of Variables) following exe section typical ...
compiles the c parser toplevel to assembler statements in self.source (::Array of ::String) starts by precompiling parser.toplevel (destructively): static symbols are converted to toplevel ones, as nested functions uses an ExeFormat (the argument) to create unique label/variable names remove typedefs/enums CExpressio...
compile
ruby
stephenfewer/grinder
node/lib/metasm/metasm/compile_c.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/compile_c.rb
BSD-3-Clause
def c_function(func) # must wait the Declaration to run the CExpr for dynamic auto offsets, # and must run those statements once only # TODO alloc a stack variable to maintain the size for each dynamic array # TODO offset of arguments # TODO nested function c_init_state(func) # hide the full @sour...
compiles a C function +func+ to asm source into the array of strings +str+ in a first pass the stack variable offsets are computed, then each statement is compiled in turn
c_function
ruby
stephenfewer/grinder
node/lib/metasm/metasm/compile_c.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/compile_c.rb
BSD-3-Clause
def c_reserve_stack(block, off = 0) block.statements.each { |stmt| case stmt when Declaration next if stmt.var.type.kind_of? Function off = c_reserve_stack_var(stmt.var, off) @state.offset[stmt.var] = off when Block c_reserve_stack(stmt, off) # do not update off, not nested subbl...
fills @state.offset (empty hash) automatic variable => stack offset, (recursive) offset is an ::Integer or a CExpression (dynamic array) assumes offset 0 is a ptr-size-aligned address TODO registerize automatic variables
c_reserve_stack
ruby
stephenfewer/grinder
node/lib/metasm/metasm/compile_c.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/compile_c.rb
BSD-3-Clause
def c_reserve_stack_var(var, off) if (arr_type = var.type).kind_of? Array and (arr_sz = arr_type.length).kind_of? CExpression # dynamic array ! arr_sz = CExpression.new(arr_sz, :*, sizeof(nil, arr_type.type), BaseType.new(:long, :unsigned)).precompile_inner(@parser, nil) off = CExpression.new...
computes the new stack offset for var off is either an offset from stack start (:ptr-size-aligned) or a CExpression [[[expr, +, 7], &, -7], +, off]
c_reserve_stack_var
ruby
stephenfewer/grinder
node/lib/metasm/metasm/compile_c.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/compile_c.rb
BSD-3-Clause
def c_idata(data, align) w = data.type.align(@parser) @source << ".align #{align = w}" if w > align @source << "#{@label_oldname[data.name]}:" if @label_oldname[data.name] @source << data.name.dup len = c_idata_inner(data.type, data.initializer) len %= w len == 0 ? w : len end
compiles a C static data definition into an asm string returns the new alignment value
c_idata
ruby
stephenfewer/grinder
node/lib/metasm/metasm/compile_c.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/compile_c.rb
BSD-3-Clause
def c_idata_inner(type, value) case type when BaseType value ||= 0 if type.name == :void @source.last << ':' if not @source.last.empty? return 0 end @source.last << case type.name when :__int8; ' db ' when :__int16; ' dw ' when :__int32; ' dd ' when :__int64; ' dq ...
dumps an anonymous variable definition, appending to the last line of source source.last is a label name or is empty before calling here return the length of the data written
c_idata_inner
ruby
stephenfewer/grinder
node/lib/metasm/metasm/compile_c.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/compile_c.rb
BSD-3-Clause
def check_reserved_name(var) return true if @exeformat.cpu and @exeformat.cpu.check_reserved_name(var.name) %w[db dw dd dq].include?(var.name) end
return non-nil if the variable name is unsuitable to appear as is in the asm listing eg filter out asm instruction names
check_reserved_name
ruby
stephenfewer/grinder
node/lib/metasm/metasm/compile_c.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/compile_c.rb
BSD-3-Clause
def precompile_make_block(scope) b = Block.new scope b.statements << self b end
all Statements/Declaration must define a precompile(compiler, scope) method it must append itself to scope.statements turns a statement into a new block
precompile_make_block
ruby
stephenfewer/grinder
node/lib/metasm/metasm/compile_c.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/compile_c.rb
BSD-3-Clause
def precompile(compiler, scope=nil) stmts = @statements.dup @statements.clear stmts.each { |st| compiler.curexpr = st st.precompile(compiler, self) } # cleanup declarations @symbol.delete_if { |n, s| not s.kind_of? Variable } @struct.delete_if { |n, s| not s.kind_of? Union } @symbol.eac...
precompile all statements, then simplifies symbols/structs types
precompile
ruby
stephenfewer/grinder
node/lib/metasm/metasm/compile_c.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/compile_c.rb
BSD-3-Clause
def precompile_optimize list = [] precompile_optimize_inner(list, 1) precompile_optimize_inner(list, 2) end
removes unused labels, and in-place goto (goto toto; toto:)
precompile_optimize
ruby
stephenfewer/grinder
node/lib/metasm/metasm/compile_c.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/compile_c.rb
BSD-3-Clause
def precompile_optimize_inner(list, step) lastgoto = nil hadref = false walk = lambda { |expr| next if not expr.kind_of? CExpression # gcc's unary && support if not expr.op and not expr.lexpr and expr.rexpr.kind_of? Label list << expr.rexpr.name else walk[expr.lexpr] if expr.rexp...
step 1: list used labels/unused goto step 2: remove unused labels
precompile_optimize_inner
ruby
stephenfewer/grinder
node/lib/metasm/metasm/compile_c.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/compile_c.rb
BSD-3-Clause
def precompile_inner(compiler, scope, nested = true) case @op when :'.' # a.b => (&a)->b lexpr = CExpression.precompile_inner(compiler, scope, @lexpr) ll = lexpr ll = lexpr.rexpr while ll.kind_of? CExpression and not ll.op if ll.kind_of? CExpression and ll.op == :'*' and not ll.lexpr # do...
returns a new CExpression with simplified self.type, computes structure offsets turns char[]/float immediates to reference to anonymised const TODO 'a = b += c' => 'b += c; a = b' (use nested argument) TODO handle precompile_inner return nil TODO struct.bits
precompile_inner
ruby
stephenfewer/grinder
node/lib/metasm/metasm/compile_c.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/compile_c.rb
BSD-3-Clause
def add_bpm m = @address + @internal[:len] a = @address & -0x1000 @hash_shared = [self] @internal ||= {} @internal[:orig_prot] ||= {} while a < m if pv = @hash_owner[a] if not pv.hash_shared.include?(self) pv.hash_shared.concat @hash_shared-pv.hash_shared @hash_shared.each { |bpm...
register a bpm: add references to all page start covered in @hash_owner
add_bpm
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def del return del_bpm if @type == :bpm @hash_shared.delete self if @hash_shared.empty? @hash_owner.delete @hash_key elsif @hash_owner[@hash_key] == self @hash_owner[@hash_key] = @hash_shared.first end end
delete the breakpoint from hash_shared, and hash_owner if empty
del
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def initialize @pid_stuff = {} @tid_stuff = {} @log_proc = nil @state = :dead @info = '' # stuff saved when we switch pids @pid_stuff_list = [:memory, :cpu, :disassembler, :symbols, :symbols_len, :modulemap, :breakpoint, :breakpoint_memory, :tid, :tid_stuff, :dead_process] @tid_stuff_list = [:stat...
initializes the disassembler internal data - subclasses should call super()
initialize
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def initialize_newpid return if not pid @pid_stuff_list.each { |s| instance_variable_set("@#{s}", nil) } @symbols = {} @symbols_len = {} @modulemap = {} @breakpoint = {} @breakpoint_memory = {} @tid_stuff = {} initialize_cpu initialize_memory initialize_disassembler end
creates stuff related to a new process being debugged includes disassembler, modulemap, symbols, breakpoints subclasses should check that @pid maps to a real process and raise() otherwise to be called with @pid/@tid set, calls initialize_memory+initialize_cpu
initialize_newpid
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def initialize_newtid return if not tid @tid_stuff_list.each { |s| instance_variable_set("@#{s}", nil) } @state = :stopped @info = 'new' @breakpoint_thread = {} gui.swapin_tid if @disassembler and gui.respond_to?(:swapin_tid) end
subclasses should check that @tid maps to a real thread and raise() otherwise
initialize_newtid
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def initialize_disassembler return if not @memory or not @cpu @disassembler = Shellcode.decode(@memory, @cpu).disassembler gui.swapin_pid if gui.respond_to?(:swapin_pid) end
initialize the disassembler from @cpu/@memory
initialize_disassembler
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def swapout_pid return if not pid swapout_tid gui.swapout_pid if gui.respond_to?(:swapout_pid) @pid_stuff[@pid] ||= {} @pid_stuff_list.each { |fld| @pid_stuff[@pid][fld] = instance_variable_get("@#{fld}") } end
we're switching focus from one pid to another, save current pid data
swapout_pid
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def swapout_tid return if not tid gui.swapout_tid if gui.respond_to?(:swapout_tid) @tid_stuff[@tid] ||= {} @tid_stuff_list.each { |fld| @tid_stuff[@tid][fld] = instance_variable_get("@#{fld}") } end
we're switching focus from one tid to another, save current tid data
swapout_tid
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def swapin_pid return initialize_newpid if not @pid_stuff[@pid] @pid_stuff_list.each { |fld| instance_variable_set("@#{fld}", @pid_stuff[@pid][fld]) } swapin_tid gui.swapin_pid if gui.respond_to?(:swapin_pid) end
we're switching focus from one pid to another, load current pid data
swapin_pid
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def swapin_tid return initialize_newtid if not @tid_stuff[@tid] @tid_stuff_list.each { |fld| instance_variable_set("@#{fld}", @tid_stuff[@tid][fld]) } gui.swapin_tid if gui.respond_to?(:swapin_tid) end
we're switching focus from one tid to another, load current tid data
swapin_tid
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def del_pid @pid_stuff.delete @pid if @pid = @pid_stuff.keys.first swapin_pid else @state = :dead @info = '' @tid = nil end end
delete references to the current pid switch to another pid, set @state = :dead if none available
del_pid
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def del_tid @tid_stuff.delete @tid if @tid = @tid_stuff.keys.first swapin_tid else del_tid_notid end end
delete references to the current thread
del_tid
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def switch_context(npid, ntid=nil, &b) if npid.respond_to?(:pid) ntid ||= npid.tid npid = npid.pid end oldpid = pid oldtid = tid set_pid npid set_tid ntid if ntid if b # shortcut begin..ensure overhead return b.call if oldpid == pid and oldtid == tid begin b.call ensure set_pid ...
change the debugger to a specific pid/tid if given a block, run the block and then restore the original pid/tid pid may be an object that respond to #pid/#tid
switch_context
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def each_pid(&b) # ensure @pid is last, so that we finish in the current context lst = @pid_stuff.keys - [@pid] lst << @pid return lst if not b lst.each { |p| set_pid p b.call } end
iterate over all pids, yield in the context of this pid
each_pid
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def each_tid(&b) lst = @tid_stuff.keys - [@tid] lst << @tid return lst if not b lst.each { |t| set_tid t rescue next b.call } end
iterate over all tids of the current process, yield in its context
each_tid
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def each_pid_tid(&b) each_pid { each_tid { b.call } } end
iterate over all tids of all pids, yield in their context
each_pid_tid
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def add_bp(addr, info={}) info[:pid] ||= @pid # dont define :tid for bpx, otherwise on del_bp we may switch_context to this thread that may not be stopped -> cant ptrace_write info[:tid] ||= @tid if info[:pid] == @pid and info[:type] == :hwbp b = Breakpoint.new info.each { |k, v| b.send("#{k}=", v) } ...
create a thread/process breakpoint addr can be a numeric address, an Expression that is resolved, or a String that is parsed+resolved info's keys are set to the breakpoint standard keys are :type, :oneshot, :condition, :action returns the Breakpoint object
add_bp
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def del_all_breakpoints_thread @breakpoint_thread.values.map { |b| b.hash_shared }.flatten.uniq.each { |b| del_bp(b) } end
delete all breakpoints defined in the current thread
del_all_breakpoints_thread
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def del_all_breakpoints each_tid { del_all_breakpoints_thread } @breakpoint.values.map { |b| b.hash_shared }.flatten.uniq.each { |b| del_bp(b) } @breakpoint_memory.values.uniq.map { |b| b.hash_shared }.flatten.uniq.each { |b| del_bp(b) } end
delete all breakpoints for the current process and all its threads
del_all_breakpoints
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def init_bpx(b) # dont bother setting stuff up if it is never to be used return if b.oneshot and not b.condition # lazy setup of b.emul_instr: delay building emulating lambda to if/when actually needed # we still need to disassemble now and update @disassembler, before we patch the memory for the bpx di = in...
called in the context of the target when a bpx is to be initialized may (lazily) initialize b.emul_instr for virtual singlestep
init_bpx
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def init_bpx_disassemble(addr) @disassembler.disassemble_fast_block(addr) @disassembler.di_at(addr) end
retrieve the di at a given address, disassemble if needed TODO make it so this doesn't interfere with other 'real' disassembler later commands, eg disassemble() or disassemble_fast_deep() (right now, when they see the block already present they stop all processing)
init_bpx_disassemble
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def has_emul_instr(bp) if bp.emul_instr.kind_of?(DecodedInstruction) if di = bp.emul_instr and fdbd = @disassembler.get_fwdemu_binding(di, register_pc) and fdbd.all? { |k, v| (k.kind_of?(Symbol) or k.kind_of?(Indirection)) and k != :incomplete_binding and v != Expression::Unknown } # setup a lambda ...
checks if bp has an emul_instr do the lazy initialization if needed
has_emul_instr
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def hwbp(addr, mtype=:x, mlen=1, oneshot=false, cond=nil, &action) h = { :type => :hwbp } h[:hash_owner] = @breakpoint_thread addr = resolve_expr(addr) if not addr.kind_of? ::Integer mtype = mtype.to_sym h[:hash_key] = [addr, mtype, mlen] h[:internal] = { :type => mtype, :len => mlen } h[:oneshot] = true ...
sets a hardware breakpoint mtype in :r :w :x mlen is the size of the memory zone to cover mlen may be constrained by the architecture
hwbp
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def bpm(addr, mtype=:r, mlen=4096, oneshot=false, cond=nil, &action) h = { :type => :bpm } addr = resolve_expr(addr) if not addr.kind_of? ::Integer h[:hash_key] = addr & -4096 # XXX actually referenced at addr, addr+4096, ... addr+len h[:internal] = { :type => mtype, :len => mlen } h[:oneshot] = true if onesh...
sets a memory breakpoint mtype is :r :w :rw or :x mlen is the size of the memory zone to cover
bpm
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def set_log_proc(l=nil, &b) @log_proc = l || b end
define the lambda to use to log stuff
set_log_proc
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def log(*a) if @log_proc a.each { |aa| @log_proc[aa] } else puts(*a) if $VERBOSE end end
show information to the user, uses log_proc if defined
log
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def invalidate @memory.invalidate if @memory end
marks the current cache of memory/regs invalid
invalidate
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def dasm_invalidate disassembler.sections.each_value { |s| s.data.invalidate if s.data.respond_to?(:invalidate) } if disassembler end
invalidates the EncodedData backend for the dasm sections
dasm_invalidate
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def all_breakpoints(addr=nil) ret = [] if addr if b = @breakpoint[addr] ret |= b.hash_shared end else @breakpoint.each_value { |bb| ret |= bb.hash_shared } end @breakpoint_thread.each_value { |bb| next if addr and bb.address != addr ret |= bb.hash_shared } @breakpoint_memory.each_valu...
return all breakpoints set on a specific address (or all bp)
all_breakpoints
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def find_breakpoint(addr=nil, &b) return @breakpoint[addr] if @breakpoint[addr] and (not b or b.call(@breakpoint[addr])) all_breakpoints(addr).find { |bp| b.call bp } end
return on of the breakpoints at address addr
find_breakpoint
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def check_pre_run(run_m, *run_a) if @dead_process del_pid return elsif @dead_thread del_tid return elsif @state == :running return end @cpu.dbg_check_pre_run(self) if @cpu.respond_to?(:dbg_check_pre_run) @breakpoint_cause = nil @run_method = run_m @run_args = run_a @info = nil true e...
to be called right before resuming execution of the target run_m is the method that should be called if the execution is stopped due to a side-effect of the debugger (bpx with wrong condition etc) returns nil if the execution should be avoided (just deleted the dead thread/process)
check_pre_run
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def evt_singlestep(b=nil) b ||= find_singlestep return evt_exception(:type => 'singlestep') if not b @state = :stopped @info = 'singlestep' @cpu.dbg_evt_singlestep(self) if @cpu.respond_to?(:dbg_evt_singlestep) callback_singlestep[] if callback_singlestep if cb = @singlestep_cb @singlestep_cb = nil ...
called when the target stops due to a singlestep exception
evt_singlestep
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def find_singlestep return @cpu.dbg_find_singlestep(self) if @cpu.respond_to?(:dbg_find_singlestep) @run_method == :singlestep end
returns true if the singlestep is due to us
find_singlestep
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def evt_bpx(b=nil) b ||= find_bp_bpx # TODO handle race: # bpx foo ; thread hits foo ; we bc foo ; os notify us of bp hit but we already cleared everything related to 'bpx foo' -> unhandled bp exception return evt_exception(:type => 'breakpoint') if not b @state = :stopped @info = 'breakpoint' @cpu.dbg_e...
called when the target stops due to a soft breakpoint exception
evt_bpx
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def find_bp_bpx return @cpu.dbg_find_bpx(self) if @cpu.respond_to?(:dbg_find_bpx) @breakpoint[pc] end
return the breakpoint that is responsible for the evt_bpx
find_bp_bpx
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def evt_hwbp(b=nil) b ||= find_bp_hwbp return evt_exception(:type => 'hwbp') if not b @state = :stopped @info = 'hwbp' @cpu.dbg_evt_hwbp(self, b) if @cpu.respond_to?(:dbg_evt_hwbp) callback_hwbp[b] if callback_hwbp post_evt_bp(b) end
called when the target stops due to a hwbp exception
evt_hwbp
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def find_bp_hwbp return @cpu.dbg_find_hwbp(self) if @cpu.respond_to?(:dbg_find_hwbp) @breakpoint_thread.find { |b| b.address == pc } end
return the breakpoint that is responsible for the evt_hwbp
find_bp_hwbp
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def evt_hwbp_singlestep if b = find_bp_hwbp evt_hwbp(b) else evt_singlestep end end
called for archs where the same interrupt is generated for hwbp and singlestep checks if a hwbp matches, then call evt_hwbp, else call evt_singlestep (which will forward to evt_exception if singlestep does not match either)
evt_hwbp_singlestep
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def evt_bpm(b) @state = :stopped @info = 'bpm' callback_bpm[b] if callback_bpm post_evt_bp(b) end
called when the target stops due to a memory exception caused by a memory bp called by evt_exception
evt_bpm
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def find_bp_bpm(info) @breakpoint_memory[info[:fault_addr] & -0x1000] end
return a bpm whose page coverage includes the fault described in info
find_bp_bpm
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def check_bpm_range(b, info) return if b.address+b.internal[:len] <= info[:fault_addr] return if b.address >= info[:fault_addr] + info[:fault_len] case b.internal[:type] when :r; info[:fault_access] == :r # or info[:fault_access] == :x when :w; info[:fault_access] == :w when :x; info[:fault_access] == :x # ...
returns true if the fault described in info is valid to trigger b
check_bpm_range
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def evt_exception(info={}) if info[:type] == 'access violation' and b = find_bp_bpm(info) info[:fault_len] ||= 1 b.internal.update info return evt_bpm(b) end @state = :stopped @info = "exception #{info[:type]}" callback_exception[info] if callback_exception pass = pass_all_exceptions pass = pa...
called whenever the target stops due to an exception type may be: * 'access violation', :fault_addr, :fault_len, :fault_access (:r/:w/:x) anything else for other exceptions (access violation is special to handle bpm) ...
evt_exception
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def resume_badbreak(b=nil) # ensure we didn't delete b if b and b.hash_shared.find { |bb| bb.state == :active } rm = @run_method if rm == :singlestep singlestep_bp(b) else ra = @run_args singlestep_bp(b) { send rm, *ra } end else send @run_method, *@run_args end end
called when we did break due to a breakpoint whose condition is invalid resume execution as if we never stopped disable offending bp + singlestep if needed
resume_badbreak
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def singlestep_bp(bp, &b) if has_emul_instr(bp) @state = :stopped bp.emul_instr.call b.call if b else bp.hash_shared.each { |bb| disable_bp(bb, :temp_inactive) if bb.state == :active } # this *should* work with different bps stopping the current instr prev_sscb = @singlestep_cb singleste...
singlesteps over an active breakpoint and run its block if the breakpoint provides an emulation stub, run that, otherwise disable the breakpoint, singlestep, and re-enable
singlestep_bp
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def check_breakpoint_cause if bp = @breakpoint_cause and (bp.type == :bpx or (bp.type == :hwbp and bp.internal[:type] == :x)) and pc != bp.address bp = @breakpoint_cause = nil end bp end
checks if @breakpoint_cause is valid, or was obsoleted by the user changing pc
check_breakpoint_cause
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def wait_target do_wait_target while @state == :running end
waits until the running target stops (due to a breakpoint, fault, etc)
wait_target
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def continue if b = check_breakpoint_cause and b.hash_shared.find { |bb| bb.state == :active } singlestep_bp(b) { next if not check_pre_run(:continue) do_continue } else return if not check_pre_run(:continue) do_continue end end
resume execution of the target bypasses a software breakpoint on pc if needed thread breakpoints must be manually disabled before calling continue
continue
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def singlestep(&b) @singlestep_cb = b bp = check_breakpoint_cause return if not check_pre_run(:singlestep) if bp and bp.hash_shared.find { |bb| bb.state == :active } and has_emul_instr(bp) @state = :stopped bp.emul_instr.call invalidate evt_singlestep(true) else do_singlestep end end
resume execution of the target one instruction at a time
singlestep
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def need_stepover(di = di_at(pc)) di and @cpu.dbg_need_stepover(self, di.address, di) end
tests if the specified instructions should be stepover() using singlestep or by putting a breakpoint at next_addr
need_stepover
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def stepover di = di_at(pc) if need_stepover(di) bpx di.next_addr, true, Expression[:tid, :==, @tid] continue else singlestep end end
stepover: singlesteps, but do not enter in subfunctions
stepover
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def end_stepout(di = di_at(pc)) di and @cpu.dbg_end_stepout(self, di.address, di) end
checks if an instruction should stop the stepout() (eg it is a return instruction)
end_stepout
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def stepout # TODO thread-local bps while not end_stepout stepover wait_target end do_singlestep end
stepover until finding the last instruction of the function
stepout
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def go(target, cond=nil) bpx(target, true, cond) continue_wait end
set a singleshot breakpoint, run the process, and wait
go
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def di_at(addr) @disassembler.di_at(addr) || @disassembler.disassemble_instruction(addr) end
decode the Instruction at the address, use the @disassembler cache if available
di_at
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def get_flag(f) get_flag_value(f) != 0 end
retrieve the value of a flag (true/false)
get_flag
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause
def toggle_flag(f) set_flag_value(f, 1-get_flag_value(f)) end
switch the value of a flag (true->false, false->true)
toggle_flag
ruby
stephenfewer/grinder
node/lib/metasm/metasm/debug.rb
https://github.com/stephenfewer/grinder/blob/master/node/lib/metasm/metasm/debug.rb
BSD-3-Clause