Module: WWMD::ViewStateUtils
- Included in:
- VSStubHelpers, ViewState
- Defined in:
- lib/wwmd/viewstate/viewstate_utils.rb
Instance Method Summary collapse
- #deserialize_type(t = nil) ⇒ Object
- #dlog(t, msg) ⇒ Object
- #magic? ⇒ Boolean
- #next_type ⇒ Object
- #offset(cur = nil) ⇒ Object
- #putd(msg) ⇒ Object
- #read(count) ⇒ Object
-
#read_7bit_encoded_int(buf = nil) ⇒ Object
why oh why did I have to go find this? System.IO.BinaryReader.Read7BitEncodedInt.
- #read_double ⇒ Object
- #read_int ⇒ Object (also: #read_byte)
- #read_int32 ⇒ Object (also: #read_single)
- #read_raw_byte ⇒ Object
- #read_short ⇒ Object
- #read_string ⇒ Object
- #serialize_type(op, ref) ⇒ Object
- #slog(obj, msg = nil) ⇒ Object
- #throw(t = nil) ⇒ Object
- #write_7bit_encoded_int(val) ⇒ Object
- #write_double(val) ⇒ Object
- #write_int(val) ⇒ Object (also: #write_byte)
- #write_int32(val) ⇒ Object (also: #write_single)
- #write_short(val) ⇒ Object
Instance Method Details
#deserialize_type(t = nil) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/wwmd/viewstate/viewstate_utils.rb', line 128 def deserialize_type(t=nil) op = self.read_byte case op when VIEWSTATE_TYPES.index(:typeref) type = read_7bit_encoded_int return [op,type] when VIEWSTATE_TYPES.index(:typeref_add_local) name = read_string return [op,name] when VIEWSTATE_TYPES.index(:typeref_add) name = read_string return [op,name] else raise "Invalid Type Error 0x#{op.to_s(16)}" end end |
#dlog(t, msg) ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/wwmd/viewstate/viewstate_utils.rb', line 15 def dlog(t,msg) raise "null token passed to dlog()" if t.nil? o = WWMD::VIEWSTATE_TYPES[t] @obj_counts[o] ||= 0 @obj_counts[o] += 1 return nil if !self.debug putd "#{self.last_offset} [0x#{t.to_s(16).rjust(2,"0")}] #{VIEWSTATE_TYPES[t]}: #{msg}" end |
#magic? ⇒ Boolean
101 102 103 104 |
# File 'lib/wwmd/viewstate/viewstate_utils.rb', line 101 def magic? @magic = [@bufarr.shift,@bufarr.shift].join("") VIEWSTATE_MAGIC.include?(@magic) end |
#next_type ⇒ Object
156 157 158 159 160 |
# File 'lib/wwmd/viewstate/viewstate_utils.rb', line 156 def next_type t = @bufarr.first.unpack("C").first throw(t) if not VIEWSTATE_TYPES.include?(t) VIEWSTATE_TYPES[t] end |
#offset(cur = nil) ⇒ Object
145 146 147 |
# File 'lib/wwmd/viewstate/viewstate_utils.rb', line 145 def offset(cur=nil) (self.size - @bufarr.size).to_s(16).rjust(8,"0") end |
#putd(msg) ⇒ Object
4 5 6 |
# File 'lib/wwmd/viewstate/viewstate_utils.rb', line 4 def putd(msg) puts(msg) if self.debug end |
#read(count) ⇒ Object
61 62 63 |
# File 'lib/wwmd/viewstate/viewstate_utils.rb', line 61 def read(count) @bufarr.slice!(0..(count - 1)).join("") end |
#read_7bit_encoded_int(buf = nil) ⇒ Object
why oh why did I have to go find this? System.IO.BinaryReader.Read7BitEncodedInt
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/wwmd/viewstate/viewstate_utils.rb', line 36 def read_7bit_encoded_int(buf=nil) l = 0 # length s = 0 # shift b = "" # byte buf = buf.scan(/./m) if buf begin if not buf b = self.read_int else b = buf.shift.unpack("C").first end l |= (b & 0x7f) << s s += 7 end while ((b & 0x80) != 0) return l end |
#read_double ⇒ Object
93 94 95 |
# File 'lib/wwmd/viewstate/viewstate_utils.rb', line 93 def read_double @bufarr.slice!(0..7).join("").unpack("Q").first end |
#read_int ⇒ Object Also known as: read_byte
65 66 67 |
# File 'lib/wwmd/viewstate/viewstate_utils.rb', line 65 def read_int @bufarr.shift.unpack("C").first end |
#read_int32 ⇒ Object Also known as: read_single
83 84 85 |
# File 'lib/wwmd/viewstate/viewstate_utils.rb', line 83 def read_int32 @bufarr.slice!(0..3).join("").unpack("L").first end |
#read_raw_byte ⇒ Object
106 107 108 |
# File 'lib/wwmd/viewstate/viewstate_utils.rb', line 106 def read_raw_byte @bufarr.shift end |
#read_short ⇒ Object
75 76 77 |
# File 'lib/wwmd/viewstate/viewstate_utils.rb', line 75 def read_short self.read(2).unpack("S").first end |
#read_string ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/wwmd/viewstate/viewstate_utils.rb', line 53 def read_string len = read_7bit_encoded_int starr = [] (1..len).each { |i| starr << @bufarr.shift } return starr.to_s # @bufarr.slice!(0..(len - 1)).join("") end |
#serialize_type(op, ref) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/wwmd/viewstate/viewstate_utils.rb', line 110 def serialize_type(op,ref) op_str = [op].pack("C") s = op_str case op when VIEWSTATE_TYPES.index(:typeref) s << write_7bit_encoded_int(ref) when VIEWSTATE_TYPES.index(:typeref_add_local) s << write_7bit_encoded_int(ref.size) s << ref when VIEWSTATE_TYPES.index(:typeref_add) s << write_7bit_encoded_int(ref.size) s << ref else raise "Invalid Type Error #{op.to_s(16)}" end return s end |
#slog(obj, msg = nil) ⇒ Object
8 9 10 11 12 13 |
# File 'lib/wwmd/viewstate/viewstate_utils.rb', line 8 def slog(obj,msg=nil) raise "No @value" if not obj.respond_to?(:value) raise "No @size" if not obj.respond_to?(:size) return nil if !self.debug putd "#{@stack.size.to_s(16).rjust(8,"0")} [0x#{obj.opcode.to_s(16)}] #{obj.class}: #{msg}" end |
#throw(t = nil) ⇒ Object
149 150 151 152 153 154 |
# File 'lib/wwmd/viewstate/viewstate_utils.rb', line 149 def throw(t=nil) STDERR.puts "==== Error at Type 0x#{t.to_s(16).rjust(2,"0")}" STDERR.puts "offset: #{self.offset}" STDERR.puts "left: #{@bufarr.size}" STDERR.puts @bufarr[0..31].join("").hexdump end |
#write_7bit_encoded_int(val) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/wwmd/viewstate/viewstate_utils.rb', line 24 def write_7bit_encoded_int(val) s = "" while (val >= 0x80) do s << [val | 0x80].pack("C") val = val >> 7 end s << [val].pack("C") return s end |
#write_double(val) ⇒ Object
97 98 99 |
# File 'lib/wwmd/viewstate/viewstate_utils.rb', line 97 def write_double(val) [val].pack("Q") end |
#write_int(val) ⇒ Object Also known as: write_byte
70 71 72 |
# File 'lib/wwmd/viewstate/viewstate_utils.rb', line 70 def write_int(val) [val].pack("C") end |
#write_int32(val) ⇒ Object Also known as: write_single
88 89 90 |
# File 'lib/wwmd/viewstate/viewstate_utils.rb', line 88 def write_int32(val) [val].pack("I") end |
#write_short(val) ⇒ Object
79 80 81 |
# File 'lib/wwmd/viewstate/viewstate_utils.rb', line 79 def write_short(val) [val].pack("n") end |