Skip to content

Instantly share code, notes, and snippets.

@tenderlove
Last active May 16, 2020 13:13
Show Gist options
  • Save tenderlove/5713415 to your computer and use it in GitHub Desktop.
Save tenderlove/5713415 to your computer and use it in GitHub Desktop.
I am a terrible person
require 'fiddle'
module IAmAHorriblePerson
def unset flag
value = _wrap self
flags = 8.times.map { |i| value[i] }.pack('C8').unpack('Q').first
[flags & ~flag].pack('Q').unpack('C8').each_with_index { |n,i|value[i] = n }
end
def class= k
value = _wrap self
[k.object_id<<1].pack('Q').unpack('C8').each_with_index {|n,i|value[i+8]=n}
end
def _wrap klass; Fiddle::Pointer.new Fiddle.dlwrap klass; end
def unfreeze!; unset(1 << 11); end
def untaint!; unset(1 << 8); end
end
class Object; include IAmAHorriblePerson; end
x = "asdfasdfasdf".taint
x.freeze
p [x.frozen?, x.tainted?] # => [true, true]
x.unfreeze!
x.untaint!
p [x.frozen?, x.tainted?] # => [false, false]
x = Object.new
p x.class # => Object
x.class = Class.new { def lol; 'lol'; end }
p x.class # => #<Class:0x007fccbb06df80>
p x.lol # => "lol"
@oz
Copy link

oz commented Jun 5, 2013

LGTM :p

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment