metasm/exe_format/serialstruct.rb in metasm-1.0.2 vs metasm/exe_format/serialstruct.rb in metasm-1.0.3
- old
+ new
@@ -54,10 +54,10 @@
}
end
# a fixed-size memory chunk
def mem(name, len, defval='')
- new_field(name, lambda { |exe, me| exe.curencoded.read(len) }, lambda { |exe, me, val| val[0, len].ljust(len, 0.chr) }, lambda { |exe, me| len }, defval)
+ new_field(name, lambda { |exe, me| exe.curencoded.read(len) }, lambda { |exe, me, val| d = val[0, len].ljust(len, 0.chr) ; d.force_encoding('BINARY') if d.respond_to?(:force_encoding) ; d }, lambda { |exe, me| len }, defval)
end
# a fixed-size string, 0-padded
def str(name, len, defval='')
d = lambda { |exe, me| v = exe.curencoded.read(len) ; v = v[0, v.index(?\0)] if v.index(?\0) ; v }
e = lambda { |exe, me, val| val[0, len].ljust(len, 0.chr) }