metasm/main.rb in metasm-1.0.2 vs metasm/main.rb in metasm-1.0.3
- old
+ new
@@ -305,11 +305,11 @@
# creates a new label, that is guaranteed to never be returned again as long as this object (ExeFormat) exists
def new_label(base = '')
base = base.dup.tr('^a-zA-Z0-9_', '_')
# use %x instead of to_s(16) for negative values
- base = (base << '_uuid' << ('%08x' % base.object_id)).freeze if base.empty? or @unique_labels_cache[base]
+ base = (base << '_uuid' << ('%08x' % (base.object_id & 0xffff_ffff_ffff_ffff))).freeze if base.empty? or @unique_labels_cache[base]
@unique_labels_cache[base] = true
base
end
# share self.unique_labels_cache with other, checks for conflicts, returns self
@@ -890,11 +890,11 @@
return false if not target.kind_of? Expression
[target.lexpr, target.op, target.rexpr].zip([@lexpr, @op, @rexpr]) { |targ, exp|
if targ and vars[targ]
return false if exp != vars[targ]
elsif targ and vars.has_key? targ
- return false if not vars[targ] = exp
+ vars[targ] = exp
elsif targ.kind_of? ExpressionType
return false if not exp.kind_of? ExpressionType or not exp.match_rec(targ, vars)
else
return false if targ != exp
end
@@ -1000,12 +1000,15 @@
# arbitrary pointer, often used when decoding immediates
# may be initialized with an export value
attr_reader :ptr # custom writer
def ptr=(p) @ptr = @export[p] || p end
+ INITIAL_DATA = ''
+ INITIAL_DATA.force_encoding('BINARY') if INITIAL_DATA.respond_to?(:force_encoding)
+
# opts' keys in :reloc, :export, :virtsize, defaults to empty/empty/data.length
- def initialize(data='', opts={})
+ def initialize(data=INITIAL_DATA.dup, opts={})
if data.respond_to?(:force_encoding) and data.encoding.name != 'ASCII-8BIT' and data.length > 0
puts "Forcing edata.data.encoding = BINARY at", caller if $DEBUG
data = data.dup.force_encoding('binary')
end
@data = data
@@ -1126,15 +1129,15 @@
def self.align_size(val, len)
return val if len == 0
((val + len - 1) / len).to_i * len
end
- # concatenation of another +EncodedData+ (or nil/Fixnum/anything supporting String#<<)
+ # concatenation of another +EncodedData+ (or nil/Integer/anything supporting String#<<)
def <<(other)
case other
when nil
- when ::Fixnum
+ when ::Integer
fill
@data = @data.to_str if not @data.kind_of? String
@data << other
@virtsize += 1
when EncodedData
@@ -1149,20 +1152,22 @@
@export[k] = v + @virtsize
}
other.inv_export.each { |k, v| @inv_export[@virtsize + k] = v }
end
if @data.empty?; @data = other.data.dup
+ elsif other.empty?
elsif not @data.kind_of?(String); @data = @data.to_str << other.data
else @data << other.data
end
@virtsize += other.virtsize
else
fill
- if other.respond_to?(:force_encoding) and other.encoding.name != 'ASCII-8BIT'
+ if other.respond_to?(:force_encoding) and other.encoding.name != 'ASCII-8BIT' and other.length > 0
puts "Forcing edata.data.encoding = BINARY at", caller if $DEBUG
other = other.dup.force_encoding('binary')
end
if @data.empty?; @data = other.dup
+ elsif other.empty?
elsif not @data.kind_of?(String); @data = @data.to_str << other
else @data << other
end
@virtsize += other.length
end