ronin-asm 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. data/.ruby-version +1 -0
  2. data/.travis.yml +12 -0
  3. data/ChangeLog.md +32 -6
  4. data/Gemfile +2 -2
  5. data/README.md +30 -22
  6. data/Rakefile +5 -4
  7. data/gemspec.yml +1 -0
  8. data/lib/ronin/asm.rb +1 -1
  9. data/lib/ronin/asm/archs.rb +1 -1
  10. data/lib/ronin/asm/archs/amd64.rb +53 -53
  11. data/lib/ronin/asm/archs/x86.rb +48 -48
  12. data/lib/ronin/asm/asm.rb +1 -1
  13. data/lib/ronin/asm/config.rb +1 -1
  14. data/lib/ronin/asm/immediate_operand.rb +18 -11
  15. data/lib/ronin/asm/instruction.rb +1 -1
  16. data/lib/ronin/asm/memory_operand.rb +22 -16
  17. data/lib/ronin/asm/os.rb +1 -1
  18. data/lib/ronin/asm/os/freebsd.rb +1 -1
  19. data/lib/ronin/asm/os/linux.rb +1 -1
  20. data/lib/ronin/asm/os/os.rb +1 -1
  21. data/lib/ronin/asm/program.rb +60 -33
  22. data/lib/ronin/asm/register.rb +1 -1
  23. data/lib/ronin/asm/shellcode.rb +2 -2
  24. data/lib/ronin/asm/syntax.rb +1 -1
  25. data/lib/ronin/asm/syntax/att.rb +39 -12
  26. data/lib/ronin/asm/syntax/common.rb +40 -2
  27. data/lib/ronin/asm/syntax/intel.rb +27 -28
  28. data/lib/ronin/asm/version.rb +2 -2
  29. data/spec/{asm_spec.rb → asm/asm_spec.rb} +0 -0
  30. data/spec/{immediate_operand_spec.rb → asm/immediate_operand_spec.rb} +2 -0
  31. data/spec/{instruction_spec.rb → asm/instruction_spec.rb} +0 -0
  32. data/spec/{memory_operand_spec.rb → asm/memory_operand_spec.rb} +0 -0
  33. data/spec/{program_spec.rb → asm/program_spec.rb} +106 -50
  34. data/spec/{register_spec.rb → asm/register_spec.rb} +0 -0
  35. data/spec/{shellcode_spec.rb → asm/shellcode_spec.rb} +15 -7
  36. data/spec/{syntax → asm/syntax}/att_spec.rb +15 -5
  37. data/spec/{syntax → asm/syntax}/common_spec.rb +0 -0
  38. data/spec/{syntax → asm/syntax}/intel_spec.rb +24 -6
  39. metadata +16 -16
  40. data/.gemtest +0 -0
  41. data/spec/helpers/database.rb +0 -7
@@ -93,7 +93,7 @@ describe ASM::Syntax::ATT do
93
93
  context "with multiple operands" do
94
94
  let(:register) { Register.new(:eax, 4) }
95
95
  let(:immediate) { ImmediateOperand.new(0xff, 1) }
96
- let(:instruction) { Instruction.new(:mov, [immediate, register]) }
96
+ let(:instruction) { Instruction.new(:mov, [register, immediate]) }
97
97
 
98
98
  it "should add a size specifier to the instruction name" do
99
99
  subject.emit_instruction(instruction).should =~ /^movl/
@@ -105,10 +105,16 @@ describe ASM::Syntax::ATT do
105
105
  end
106
106
  end
107
107
 
108
+ describe "emit_section" do
109
+ it "should emit the section name" do
110
+ subject.emit_section(:text).should == ".text"
111
+ end
112
+ end
113
+
108
114
  describe "emit_program" do
109
115
  let(:program) do
110
116
  Program.new do
111
- mov 0xff, eax
117
+ mov eax, 0xff
112
118
  ret
113
119
  end
114
120
  end
@@ -117,6 +123,8 @@ describe ASM::Syntax::ATT do
117
123
  asm = subject.emit_program(program)
118
124
 
119
125
  asm.should == [
126
+ ".code32",
127
+ ".text",
120
128
  "_start:",
121
129
  "\tmovl\t$0xff,\t%eax",
122
130
  "\tret",
@@ -127,7 +135,7 @@ describe ASM::Syntax::ATT do
127
135
  context "when emitting labels" do
128
136
  let(:program) do
129
137
  Program.new do
130
- mov 0, eax
138
+ mov eax, 0
131
139
 
132
140
  _loop do
133
141
  inc eax
@@ -141,11 +149,13 @@ describe ASM::Syntax::ATT do
141
149
 
142
150
  it "should emit both labels and instructions" do
143
151
  subject.emit_program(program).should == [
152
+ ".code32",
153
+ ".text",
144
154
  "_start:",
145
155
  "\tmovl\t$0x0,\t%eax",
146
156
  "_loop:",
147
157
  "\tincl\t%eax",
148
- "\tcmpl\t%eax,\t$0xa",
158
+ "\tcmpl\t$0xa,\t%eax",
149
159
  "\tjl\t_loop",
150
160
  "\tret",
151
161
  ""
@@ -155,7 +165,7 @@ describe ASM::Syntax::ATT do
155
165
 
156
166
  context "when the program arch is :amd64" do
157
167
  let(:program) do
158
- Program.new(:arch => :amd64) do
168
+ Program.new(arch: :amd64) do
159
169
  push rax
160
170
  push rbx
161
171
  mov 0xff, rax
@@ -34,6 +34,14 @@ describe ASM::Syntax::Intel do
34
34
  subject.emit_memory_operand(operand).should == "[eax]"
35
35
  end
36
36
 
37
+ context "when operand width does not match the base width" do
38
+ before { operand.width = 2 }
39
+
40
+ it "should specify the width" do
41
+ subject.emit_memory_operand(operand).should == "WORD [eax]"
42
+ end
43
+ end
44
+
37
45
  context "with an offset" do
38
46
  let(:offset) { 255 }
39
47
  let(:operand) { MemoryOperand.new(register,offset) }
@@ -82,7 +90,7 @@ describe ASM::Syntax::Intel do
82
90
  context "with multiple operands" do
83
91
  let(:register) { Register.new(:eax, 4) }
84
92
  let(:immediate) { ImmediateOperand.new(0xff, 1) }
85
- let(:instruction) { Instruction.new(:mov, [immediate, register]) }
93
+ let(:instruction) { Instruction.new(:mov, [register, immediate]) }
86
94
 
87
95
  it "should emit the operands" do
88
96
  subject.emit_instruction(instruction).should == "mov\teax,\tBYTE 0xff"
@@ -90,10 +98,16 @@ describe ASM::Syntax::Intel do
90
98
  end
91
99
  end
92
100
 
101
+ describe "emit_section" do
102
+ it "should emit the section name" do
103
+ subject.emit_section(:text).should == "section .text"
104
+ end
105
+ end
106
+
93
107
  describe "emit_program" do
94
108
  let(:program) do
95
109
  Program.new do
96
- mov 0xff, eax
110
+ mov eax, 0xff
97
111
  ret
98
112
  end
99
113
  end
@@ -102,6 +116,8 @@ describe ASM::Syntax::Intel do
102
116
  asm = subject.emit_program(program)
103
117
 
104
118
  asm.should == [
119
+ "BITS 32",
120
+ "section .text",
105
121
  "_start:",
106
122
  "\tmov\teax,\tBYTE 0xff",
107
123
  "\tret",
@@ -112,7 +128,7 @@ describe ASM::Syntax::Intel do
112
128
  context "when emitting labels" do
113
129
  let(:program) do
114
130
  Program.new do
115
- mov 0, eax
131
+ mov eax, 0
116
132
 
117
133
  _loop do
118
134
  inc eax
@@ -126,11 +142,13 @@ describe ASM::Syntax::Intel do
126
142
 
127
143
  it "should emit both labels and instructions" do
128
144
  subject.emit_program(program).should == [
145
+ "BITS 32",
146
+ "section .text",
129
147
  "_start:",
130
148
  "\tmov\teax,\tBYTE 0x0",
131
149
  "_loop:",
132
150
  "\tinc\teax",
133
- "\tcmp\tBYTE 0xa,\teax",
151
+ "\tcmp\teax,\tBYTE 0xa",
134
152
  "\tjl\t_loop",
135
153
  "\tret",
136
154
  ""
@@ -140,10 +158,10 @@ describe ASM::Syntax::Intel do
140
158
 
141
159
  context "when the program arch is :amd64" do
142
160
  let(:program) do
143
- Program.new(:arch => :amd64) do
161
+ Program.new(arch: :amd64) do
144
162
  push rax
145
163
  push rbx
146
- mov 0xff, rax
164
+ mov rax, 0xff
147
165
  ret
148
166
  end
149
167
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ronin-asm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-27 00:00:00.000000000 Z
12
+ date: 2013-06-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: data_paths
@@ -85,9 +85,10 @@ extra_rdoc_files:
85
85
  - README.md
86
86
  files:
87
87
  - .document
88
- - .gemtest
89
88
  - .gitignore
90
89
  - .rspec
90
+ - .ruby-version
91
+ - .travis.yml
91
92
  - .yardopts
92
93
  - COPYING.txt
93
94
  - ChangeLog.md
@@ -122,18 +123,17 @@ files:
122
123
  - lib/ronin/asm/syntax/intel.rb
123
124
  - lib/ronin/asm/version.rb
124
125
  - ronin-asm.gemspec
125
- - spec/asm_spec.rb
126
- - spec/helpers/database.rb
127
- - spec/immediate_operand_spec.rb
128
- - spec/instruction_spec.rb
129
- - spec/memory_operand_spec.rb
130
- - spec/program_spec.rb
131
- - spec/register_spec.rb
132
- - spec/shellcode_spec.rb
126
+ - spec/asm/asm_spec.rb
127
+ - spec/asm/immediate_operand_spec.rb
128
+ - spec/asm/instruction_spec.rb
129
+ - spec/asm/memory_operand_spec.rb
130
+ - spec/asm/program_spec.rb
131
+ - spec/asm/register_spec.rb
132
+ - spec/asm/shellcode_spec.rb
133
+ - spec/asm/syntax/att_spec.rb
134
+ - spec/asm/syntax/common_spec.rb
135
+ - spec/asm/syntax/intel_spec.rb
133
136
  - spec/spec_helper.rb
134
- - spec/syntax/att_spec.rb
135
- - spec/syntax/common_spec.rb
136
- - spec/syntax/intel_spec.rb
137
137
  homepage: https://github.com/ronin-ruby/ronin-asm#readme
138
138
  licenses:
139
139
  - GPL-3
@@ -146,7 +146,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
146
146
  requirements:
147
147
  - - ! '>='
148
148
  - !ruby/object:Gem::Version
149
- version: '0'
149
+ version: 1.9.1
150
150
  required_rubygems_version: !ruby/object:Gem::Requirement
151
151
  none: false
152
152
  requirements:
@@ -156,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - yasm >= 0.6.0
158
158
  rubyforge_project:
159
- rubygems_version: 1.8.23
159
+ rubygems_version: 1.8.25
160
160
  signing_key:
161
161
  specification_version: 3
162
162
  summary: A Ruby DSL for crafting Assembly programs and Shellcode.
data/.gemtest DELETED
File without changes
@@ -1,7 +0,0 @@
1
- require 'ronin/database'
2
-
3
- require 'spec_helper'
4
-
5
- module Helpers
6
- Database.setup(ENV['DATABASE'] || 'sqlite3::memory:')
7
- end