node/lib/metasm/metasm/cpu/ia32/parse.rb
# parses an arbitrary ia32 instruction argument
parses an arbitrary ia32 instruction argument
parses an arbitrary ia32 instruction argument
def parse_argument(lexer)
		lexer = AsmPreprocessor.new(lexer) if lexer.kind_of? String
		@args_token ||= parse_argregclasslist.map { |a| a.s_to_i.keys }.flatten.inject({}) { |h, e| h.update e => true }
		lexer.skip_space
		return if not tok = lexer.readtok
		if tok.type == :string and tok.raw == 'ST'
			lexer.skip_space
			if ntok = lexer.readtok and ntok.type == :punct and ntok.raw == '('
				lexer.skip_space
				if not nntok = lexer.readtok or nntok.type != :string or nntok.raw !~ /^[0-9]$/ or
						not ntok = (lexer.skip_space; lexer.readtok) or ntok.type != :punct or ntok.raw != ')'
					raise tok, 'invalid FP register'
				else
					tok.raw << '(' << nntok.raw << ')'
					fpr = parse_argregclasslist.last
					if fpr.s_to_i.has_key? tok.raw
						return fpr.new(fpr.s_to_i[tok.raw])
					else
						raise tok, 'invalid FP register'
					end
				end
			else
				lexer.unreadtok ntok
			end
		end
		if ret = parse_modrm(lexer, tok, self)
			ret
		elsif @args_token[tok.raw]
			parse_argregclasslist.each { |a|
				return a.from_str(tok.raw) if a.s_to_i.has_key? tok.raw
			}
			raise tok, 'internal error'
		else
			lexer.unreadtok tok
			expr = Expression.parse(lexer)
			lexer.skip_space
			if expr and ntok = lexer.readtok and ntok.type == :punct and ntok.raw == ':'
				raise tok, 'invalid farptr' if not addr = Expression.parse(lexer)
				Farptr.new expr, addr
			else
				lexer.unreadtok ntok
				Expression[expr.reduce] if expr
			end
		end
	end
def parse_argument ( lexer ) lexer = AsmPreprocessor . new ( lexer ) if lexer . kind_of? String @args_token ||= parse_argregclasslist . map { | a | a . s_to_i . keys } . flatten . inject ( { } ) { | h , e | h . update e => true } lexer . skip_space return if not tok = lexer . readtok if tok . type == :string and tok . raw == 'ST' lexer . skip_space if ntok = lexer . readtok and ntok . type == :punct and ntok . raw == '(' lexer . skip_space if not nntok = lexer . readtok or nntok . type != :string or nntok . raw !~ / ^[0-9]$ / or not ntok = ( lexer . skip_space ; lexer . readtok ) or ntok . type != :punct or ntok . raw != ')' raise tok , 'invalid FP register' else tok . raw << '(' << nntok . raw << ')' fpr = parse_argregclasslist . last if fpr . s_to_i . has_key? tok . raw return fpr . new ( fpr . s_to_i [ tok . raw ] ) else raise tok , 'invalid FP register' end end else lexer . unreadtok ntok end end if ret = parse_modrm ( lexer , tok , self ) ret elsif @args_token [ tok . raw ] parse_argregclasslist . each { | a | return a . from_str ( tok . raw ) if a . s_to_i . has_key? tok . raw } raise tok , 'internal error' else lexer . unreadtok tok expr = Expression . parse ( lexer ) lexer . skip_space if expr and ntok = lexer . readtok and ntok . type == :punct and ntok . raw == ':' raise tok , 'invalid farptr' if not addr = Expression . parse ( lexer ) Farptr . new expr , addr else lexer . unreadtok ntok Expression [ expr . reduce ] if expr end end end
parses an arbitrary ia32 instruction argument
parses an arbitrary ia32 instruction argument
# reserved names (registers/segments etc) # may be a farptr
lexer