node/lib/metasm/metasm/cpu/ia32/compile_c.rb
# returns a variable storage (ModRM for stack/global, Reg/Composite for register-bound)
returns a variable storage (ModRM for stack/global, Reg/Composite for register-bound)
returns a variable storage ( ModRM for stack / global Reg / Composite for register - bound )
def findvar(var)
		if ret = @state.bound[var]
			return ret
		end
		if ret = @state.cache.index(var)
			ret = ret.dup
			inuse ret
			return ret
		end
		sz = 8*sizeof(var) rescue nil	
		case off = @state.offset[var]
		when C::CExpression
			v = raise "find dynamic addr of #{var.name}"
		when ::Integer
			 -fomit-frame-pointer ( => state.cache dependant on stack_offset... )
			v = ModRM.new(@cpusz, sz, nil, nil, @state.saved_ebp, Expression[-off])
		when nil
			if @exeformat.cpu.generate_PIC
				if not reg = @state.cache.index('metasm_intern_geteip')
					@need_geteip_stub = true
					if @state.used.include? 6	
						reg = findreg
					else
						reg = getreg 6
					end
					if reg.val != 0
						if @state.used.include? 0
							eax = Reg.new(0, @cpusz)
							instr 'mov', reg, eax
						else
							eax = getreg 0
						end
					end
					instr 'call', Expression['metasm_intern_geteip']
					if reg.val != 0
						if @state.used.include? 0
							instr 'xchg', eax, reg
						else
							instr 'mov', reg, eax
						end
					end
					@state.cache[reg] = 'metasm_intern_geteip'
				end
				v = ModRM.new(@cpusz, sz, nil, nil, reg, Expression[var.name, :-, 'metasm_intern_geteip'])
			else
				v = ModRM.new(@cpusz, sz, nil, nil, nil, Expression[var.name])
			end
		end
		case var.type
		when C::Array; inuse Address.new(v)
		else inuse v
		end
	end
def findvar ( var ) if ret = @state . bound [ var ] return ret end if ret = @state . cache . index ( var ) ret = ret . dup inuse ret return ret end sz = 8 * sizeof ( var ) rescue nil case off = @state . offset [ var ] when C :: CExpression v = raise "find dynamic addr of #{var.name}" when :: Integer v = ModRM . new ( @cpusz , sz , nil , nil , @state . saved_ebp , Expression [ - off ] ) when nil if @exeformat . cpu . generate_PIC if not reg = @state . cache . index ( 'metasm_intern_geteip' ) @need_geteip_stub = true if @state . used . include? 6 reg = findreg else reg = getreg 6 end if reg . val != 0 if @state . used . include? 0 eax = Reg . new ( 0 , @cpusz ) instr 'mov' , reg , eax else eax = getreg 0 end end instr 'call' , Expression [ 'metasm_intern_geteip' ] if reg . val != 0 if @state . used . include? 0 instr 'xchg' , eax , reg else instr 'mov' , reg , eax end end @state . cache [ reg ] = 'metasm_intern_geteip' end v = ModRM . new ( @cpusz , sz , nil , nil , reg , Expression [ var . name , :- , 'metasm_intern_geteip' ] ) else v = ModRM . new ( @cpusz , sz , nil , nil , nil , Expression [ var . name ] ) end end case var . type when C :: Array ; inuse Address . new ( v ) else inuse v end end
returns a variable storage (ModRM for stack/global, Reg/Composite for register-bound)
returns a variable storage ( ModRM for stack / global Reg / Composite for register - bound )
# extern char foo[]; # stack, dynamic address # TODO # no need to update state.cache here, never recursive # stack # TODO -fomit-frame-pointer ( => state.cache dependant on stack_offset... ) # global # esi
var