Created
April 15, 2025 17:47
-
-
Save kernelsmith/527127c05667548b124b97f069665b5c to your computer and use it in GitHub Desktop.
Print out a tree of ruby exceptions for a given context
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Generated using this code from http://blog.nicksieger.com/articles/2006/09/06/rubys-exception-hierarchy/ | |
exceptions = [] | |
tree = {} | |
ObjectSpace.each_object(Class) do |cls| | |
next unless cls.ancestors.include? Exception | |
next if exceptions.include? cls | |
next if cls.superclass == SystemCallError # avoid dumping Errno's | |
exceptions << cls | |
cls.ancestors.delete_if {|e| [Object, Kernel].include? e }.reverse.inject(tree) {|memo,cls| memo[cls] ||= {}} | |
end | |
indent = 0 | |
tree_printer = Proc.new do |t| | |
t.keys.sort { |c1,c2| c1.name <=> c2.name }.each do |k| | |
space = (' ' * indent); space ||= '' | |
puts space + k.to_s | |
indent += 2; tree_printer.call t[k]; indent -= 2 | |
end | |
end | |
tree_printer.call tree | |
# | |
# Exception tree from MSF when in exploit context (psexec in this case) | |
# | |
# BasicObject | |
# PP::ObjectMixin | |
# ERB::Util | |
# PCAPRUB | |
# JSON::Ext::Generator::GeneratorMethods::Object | |
# SNMP::BER | |
# ActiveSupport::Dependencies::Loadable | |
# ActiveSupport::Dependencies::Blamable | |
# Exception | |
# StandardError | |
# ArgumentError | |
# Rex::Exception | |
# Msf::Exception | |
# Msf::AuxiliaryError | |
# Msf::MissingActionError | |
# Msf::ExploitError | |
# Msf::IncompatiblePayloadError | |
# Msf::MissingPayloadError | |
# Msf::MissingTargetError | |
# Msf::NoCompatiblePayloadError | |
# Msf::OptionValidateError | |
# Msf::ValidationError | |
# RuntimeError | |
# Rex::Exception | |
# Msf::Exception | |
# Msf::EncodingError | |
# Msf::BadGenerateError | |
# Msf::BadcharError | |
# Msf::NoEncodersSucceededError | |
# Msf::NoKeyError | |
# Msf::NopError | |
# Msf::NoNopsSucceededError | |
# Msf::PluginLoadError | |
# Generated using this code from http://blog.nicksieger.com/articles/2006/09/06/rubys-exception-hierarchy/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment