node/lib/metasm/metasm/gui/debug.rb
# keyboard binding
# basic navigation (arrows, pgup etc)
keyboard binding
basic navigation (arrows, pgup etc)
keyboard binding basic navigation ( arrows pgup etc )
def keypress(key)
		case key
		when :left
			if @caret_x > 0
				@caret_x -= 1
				update_caret
			end
		when :right
			if @caret_x < @register_size[@registers[@caret_reg]]-1
				@caret_x += 1
				update_caret
			end
		when :up
			if @caret_reg > 0
				@caret_reg -= 1
			else
				@caret_reg = @registers.length+@flags.length-1
			end
			@caret_x = 0
			update_caret
		when :down
			if @caret_reg < @registers.length+@flags.length-1
				@caret_reg += 1
			else
				@caret_reg = 0
			end
			@caret_x = 0
			update_caret
		when :home
			@caret_x = 0
			update_caret
		when :end
			@caret_x = @register_size[@registers[@caret_reg]]-1
			update_caret
		when :tab
			if @caret_reg < @registers.length+@flags.length-1
				@caret_reg += 1
			else
				@caret_reg = 0
			end
			@caret_x = 0
			update_caret
		when :backspace
		when :enter
			commit_writes
			redraw
		when :esc
			@write_pending.clear
			redraw
		when ?\x20..?\x7e
			if ?a.kind_of?(String)
				v = key.ord
				case key
				when ?\x20; v = nil	
				when ?0..?9; v -= ?0.ord
				when ?a..?f; v -= ?a.ord-10
				when ?A..?F; v -= ?A.ord-10
				else return false
				end
			else
				case v = key
				when ?\x20; v = nil
				when ?0..?9; v -= ?0
				when ?a..?f; v -= ?a-10
				when ?A..?F; v -= ?A-10
				else return false
				end
			end
			reg = @registers[@caret_reg] || @flags[@caret_reg-@registers.length]
			rsz = @register_size[reg]
			if v and rsz != 1
				oo = 4*(rsz-@caret_x-1)
				ov = @write_pending[reg] || @reg_cache[reg]
				ov &= ~(0xf << oo)
				ov |= v << oo
				@write_pending[reg] = ov
			elsif v and (v == 0 or v == 1)	 change z flag by typing 'z' or 'Z'
				@write_pending[reg] = v
				rsz = 1
			end
			if rsz == 1
				@caret_reg += 1
				@caret_reg = @registers.length if @caret_reg >= @registers.length + @flags.length
			elsif @caret_x < rsz-1
				@caret_x += 1
			else
				@caret_x = 0
			end
			redraw
		else return false
		end
		true
	end
def keypress ( key ) case key when :left if @caret_x > 0 @caret_x -= 1 update_caret end when :right if @caret_x < @register_size [ @registers [ @caret_reg ] ] - 1 @caret_x += 1 update_caret end when :up if @caret_reg > 0 @caret_reg -= 1 else @caret_reg = @registers . length + @flags . length - 1 end @caret_x = 0 update_caret when :down if @caret_reg < @registers . length + @flags . length - 1 @caret_reg += 1 else @caret_reg = 0 end @caret_x = 0 update_caret when :home @caret_x = 0 update_caret when :end @caret_x = @register_size [ @registers [ @caret_reg ] ] - 1 update_caret when :tab if @caret_reg < @registers . length + @flags . length - 1 @caret_reg += 1 else @caret_reg = 0 end @caret_x = 0 update_caret when :backspace when :enter commit_writes redraw when :esc @write_pending . clear redraw when ?\x20 .. ?\x7e if ?a . kind_of? ( String ) v = key . ord case key when ?\x20 ; v = nil when ?0 .. ?9 ; v -= ?0 . ord when ?a .. ?f ; v -= ?a . ord - 10 when ?A .. ?F ; v -= ?A . ord - 10 else return false end else case v = key when ?\x20 ; v = nil when ?0 .. ?9 ; v -= ?0 when ?a .. ?f ; v -= ?a - 10 when ?A .. ?F ; v -= ?A - 10 else return false end end reg = @registers [ @caret_reg ] || @flags [ @caret_reg - @registers . length ] rsz = @register_size [ reg ] if v and rsz != 1 oo = 4 * ( rsz - @caret_x - 1 ) ov = @write_pending [ reg ] || @reg_cache [ reg ] ov &= ~ ( 0xf << oo ) ov |= v << oo @write_pending [ reg ] = ov elsif v and ( v == 0 or v == 1 ) @write_pending [ reg ] = v rsz = 1 end if rsz == 1 @caret_reg += 1 @caret_reg = @registers . length if @caret_reg >= @registers . length + @flags . length elsif @caret_x < rsz - 1 @caret_x += 1 else @caret_x = 0 end redraw else return false end true end
keyboard binding
basic navigation (arrows, pgup etc)
keyboard binding basic navigation ( arrows pgup etc )
# TODO # keep current value # TODO change z flag by typing 'z' or 'Z'
key