asmrepl 1.0.3 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +43 -36
- data/asmrepl.gemspec +1 -1
- data/lib/asmrepl/repl.rb +53 -6
- data/lib/asmrepl/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7045e3fe0facfdc15e21bb3dfebcaf5232eb68c144ac07e6bf61588979ca3c7f
|
4
|
+
data.tar.gz: 158f3aea1088ae25397dccfc6bf593449df3482f031c025c6dbf33ce372f6a53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d039b567f9cb938f56f86c1ea02a9c16a3c266748fb16d37b5c710c66618010dba32b13755d778c9dded6a56bb521fb61198281297543aad9f3f6c39028510b4
|
7
|
+
data.tar.gz: 7f37562a9568489d61d9eb3144310d3c372fd5fe7ab07b3b0786c268bc8a2b20077a52736723d0f684930924614083cc4df2a817e6f91f8f6b7afae438aeb0fc
|
data/README.md
CHANGED
@@ -2,11 +2,6 @@
|
|
2
2
|
|
3
3
|
This is a REPL for assembly language.
|
4
4
|
|
5
|
-
## Linux requirements
|
6
|
-
```
|
7
|
-
$ sudo apt-get install libcapstone-dev
|
8
|
-
```
|
9
|
-
|
10
5
|
## Usage
|
11
6
|
|
12
7
|
Install the gem:
|
@@ -27,16 +22,16 @@ When the REPL starts, it will display all register values and flags:
|
|
27
22
|
|
28
23
|
```
|
29
24
|
================== CPU STATE ===================
|
30
|
-
rax 000000000000000000 r8
|
31
|
-
rbx 000000000000000000 r9
|
32
|
-
rcx
|
33
|
-
rdx
|
34
|
-
rdi
|
35
|
-
rsi
|
36
|
-
rbp
|
37
|
-
rsp
|
38
|
-
|
39
|
-
rip
|
25
|
+
rax 000000000000000000 r8 0x00007f89d0f04640
|
26
|
+
rbx 000000000000000000 r9 0x0000000000000004
|
27
|
+
rcx 0x00007f89d0f04a50 r10 000000000000000000
|
28
|
+
rdx 0x..fc611d3f0aa2900d4 r11 0x00000001033a4000
|
29
|
+
rdi 0x00007ff7bd126148 r12 000000000000000000
|
30
|
+
rsi 000000000000000000 r13 0x00007ff7bd125dc0
|
31
|
+
rbp 0x00007ff7bd125c40 r14 000000000000000000
|
32
|
+
rsp 0x00007ff7bd125c38 r15 000000000000000000
|
33
|
+
|
34
|
+
rip 0x00000001033a4001
|
40
35
|
rflags 0x0000000000000246
|
41
36
|
cs 0x000000000000002b
|
42
37
|
fs 000000000000000000
|
@@ -44,46 +39,58 @@ gs 000000000000000000
|
|
44
39
|
|
45
40
|
FLAGS: ["PF", "ZF", "IF"]
|
46
41
|
|
47
|
-
|
42
|
+
(rip 0x00000001033a4001)>
|
48
43
|
```
|
49
44
|
|
50
45
|
Then you can issue commands and inspect register values. Let's write to the
|
51
46
|
`rax` register and inspect its value:
|
52
47
|
|
53
48
|
```
|
54
|
-
|
55
|
-
|
49
|
+
(rip 0x00000001033a4001)> mov rax, 5
|
50
|
+
=============== REGISTER CHANGES ===============
|
51
|
+
rax 000000000000000000 => 0x0000000000000005
|
52
|
+
|
53
|
+
(rip 0x00000001033a4009)> rax
|
56
54
|
0x0000000000000005
|
57
|
-
|
55
|
+
(rip 0x00000001033a4009)>
|
58
56
|
```
|
59
57
|
|
60
58
|
Now let's write to the `rbx` register and add the two values:
|
61
59
|
|
62
60
|
```
|
63
|
-
|
64
|
-
|
65
|
-
|
61
|
+
(rip 0x00000001033a4009)> mov rbx, 3
|
62
|
+
=============== REGISTER CHANGES ===============
|
63
|
+
rbx 000000000000000000 => 0x0000000000000003
|
64
|
+
|
65
|
+
(rip 0x00000001033a4011)> add rax, rbx
|
66
|
+
=============== REGISTER CHANGES ===============
|
67
|
+
rax 0x0000000000000005 => 0x0000000000000008
|
68
|
+
rflags 0x0000000000000246 => 0x0000000000000202
|
69
|
+
|
70
|
+
FLAGS: ["IF"]
|
71
|
+
|
72
|
+
(rip 0x00000001033a4015)> rax
|
66
73
|
0x0000000000000008
|
67
|
-
|
74
|
+
(rip 0x00000001033a4015)> rbx
|
68
75
|
0x0000000000000003
|
69
|
-
|
76
|
+
(rip 0x00000001033a4015)>
|
70
77
|
```
|
71
78
|
|
72
79
|
Finally, lets check all values in the CPU:
|
73
80
|
|
74
81
|
```
|
75
|
-
|
82
|
+
(rip 0x00000001033a4015)> cpu
|
76
83
|
================== CPU STATE ===================
|
77
|
-
rax 0x0000000000000008 r8
|
78
|
-
rbx 0x0000000000000003 r9
|
79
|
-
rcx
|
80
|
-
rdx
|
81
|
-
rdi
|
82
|
-
rsi
|
83
|
-
rbp
|
84
|
-
rsp
|
85
|
-
|
86
|
-
rip
|
84
|
+
rax 0x0000000000000008 r8 0x00007f89d0f04640
|
85
|
+
rbx 0x0000000000000003 r9 0x0000000000000004
|
86
|
+
rcx 0x00007f89d0f04a50 r10 000000000000000000
|
87
|
+
rdx 0x..fc611d3f0aa2900d4 r11 0x00000001033a4000
|
88
|
+
rdi 0x00007ff7bd126148 r12 000000000000000000
|
89
|
+
rsi 000000000000000000 r13 0x00007ff7bd125dc0
|
90
|
+
rbp 0x00007ff7bd125c40 r14 000000000000000000
|
91
|
+
rsp 0x00007ff7bd125c38 r15 000000000000000000
|
92
|
+
|
93
|
+
rip 0x00000001033a4015
|
87
94
|
rflags 0x0000000000000202
|
88
95
|
cs 0x000000000000002b
|
89
96
|
fs 000000000000000000
|
@@ -91,5 +98,5 @@ gs 000000000000000000
|
|
91
98
|
|
92
99
|
FLAGS: ["IF"]
|
93
100
|
|
94
|
-
|
101
|
+
(rip 0x00000001033a4015)>
|
95
102
|
```
|
data/asmrepl.gemspec
CHANGED
@@ -20,5 +20,5 @@ Gem::Specification.new do |s|
|
|
20
20
|
s.add_development_dependency 'minitest', '~> 5.14'
|
21
21
|
s.add_development_dependency 'crabstone', '~> 4.0'
|
22
22
|
s.add_development_dependency 'rake', '~> 13.0'
|
23
|
-
s.add_dependency 'fisk', '~> 2'
|
23
|
+
s.add_dependency 'fisk', '~> 2.3.1'
|
24
24
|
end
|
data/lib/asmrepl/repl.rb
CHANGED
@@ -27,13 +27,40 @@ module ASMREPL
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def display_state state
|
30
|
-
puts " CPU STATE ".center(48, "=")
|
30
|
+
puts bold(" CPU STATE ".center(48, "="))
|
31
31
|
puts state
|
32
32
|
puts
|
33
33
|
puts "FLAGS: #{state.flags.inspect}"
|
34
34
|
puts
|
35
35
|
end
|
36
36
|
|
37
|
+
def display_state_change last_state, state
|
38
|
+
puts bold(" REGISTER CHANGES ".center(48, "="))
|
39
|
+
show_flags = false
|
40
|
+
|
41
|
+
state.fields.each do |field|
|
42
|
+
next if field == "rip"
|
43
|
+
|
44
|
+
if last_state[field] != state[field]
|
45
|
+
print "#{field.ljust(6)} "
|
46
|
+
print sprintf("%#018x", last_state[field])
|
47
|
+
print " => "
|
48
|
+
puts bold(sprintf("%#018x", state[field]))
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
if last_state.flags != state.flags
|
53
|
+
puts
|
54
|
+
puts "FLAGS: #{state.flags.inspect}"
|
55
|
+
end
|
56
|
+
|
57
|
+
puts
|
58
|
+
end
|
59
|
+
|
60
|
+
def bold string
|
61
|
+
"\e[1m#{string}\e[0m"
|
62
|
+
end
|
63
|
+
|
37
64
|
def start
|
38
65
|
pid = fork {
|
39
66
|
CFuncs.traceme
|
@@ -42,13 +69,18 @@ module ASMREPL
|
|
42
69
|
|
43
70
|
tracer = CFuncs::Tracer.new pid
|
44
71
|
should_cpu = true
|
72
|
+
last_state = nil
|
73
|
+
|
45
74
|
while tracer.wait
|
46
75
|
state = tracer.state
|
47
76
|
|
48
77
|
# Show CPU state once on boot
|
49
|
-
if
|
78
|
+
if last_state.nil?
|
50
79
|
display_state state
|
51
|
-
|
80
|
+
last_state = state
|
81
|
+
else
|
82
|
+
display_state_change last_state, state
|
83
|
+
last_state = state
|
52
84
|
end
|
53
85
|
|
54
86
|
# Move the JIT buffer to the current instruction pointer
|
@@ -58,7 +90,8 @@ module ASMREPL
|
|
58
90
|
begin
|
59
91
|
loop do
|
60
92
|
cmd = nil
|
61
|
-
|
93
|
+
prompt = sprintf("(rip %#018x)> ", state.rip)
|
94
|
+
text = Reline.readmultiline(prompt, use_history) do |multiline_input|
|
62
95
|
if multiline_input =~ /\A\s*(\w+)\s*\Z/
|
63
96
|
register = $1
|
64
97
|
cmd = [:read, register]
|
@@ -71,8 +104,21 @@ module ASMREPL
|
|
71
104
|
case cmd
|
72
105
|
in :run
|
73
106
|
break if text.chomp.empty?
|
74
|
-
|
75
|
-
|
107
|
+
begin
|
108
|
+
parser_result = @parser.parse text.chomp
|
109
|
+
rescue
|
110
|
+
puts "Invalid intruction"
|
111
|
+
next
|
112
|
+
end
|
113
|
+
|
114
|
+
begin
|
115
|
+
binary = @assembler.assemble parser_result
|
116
|
+
binary.bytes.each { |byte| @buffer.putc byte }
|
117
|
+
rescue Fisk::Errors::InvalidInstructionError => e
|
118
|
+
# Print an error message when the instruction is invalid
|
119
|
+
puts e.message
|
120
|
+
next
|
121
|
+
end
|
76
122
|
break
|
77
123
|
in [:read, "cpu"]
|
78
124
|
display_state state
|
@@ -88,6 +134,7 @@ module ASMREPL
|
|
88
134
|
end
|
89
135
|
end
|
90
136
|
rescue Interrupt
|
137
|
+
puts ""
|
91
138
|
exit 0
|
92
139
|
end
|
93
140
|
tracer.continue
|
data/lib/asmrepl/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asmrepl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aaron Patterson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-12-
|
11
|
+
date: 2021-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 2.3.1
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 2.3.1
|
69
69
|
description: Tired of writing assembly and them assembling it? Now you can write assembly
|
70
70
|
and evaluate it!
|
71
71
|
email: tenderlove@ruby-lang.org
|