diff --git a/lib/rex/assembly/nasm.rb b/lib/rex/assembly/nasm.rb index e2ab338397..281ac48d1f 100644 --- a/lib/rex/assembly/nasm.rb +++ b/lib/rex/assembly/nasm.rb @@ -37,7 +37,7 @@ class Nasm # # Assembles the supplied assembly and returns the raw opcodes. # - def self.assemble(assembly) + def self.assemble(assembly, bits=32) check # Open the temporary file @@ -48,7 +48,7 @@ class Nasm opath = tmp.path + '.out' # Write the assembly data to a file - tmp.write("BITS 32\n" + assembly) + tmp.write("BITS #{bits}\n" + assembly) tmp.flush() tmp.seek(0) @@ -70,7 +70,7 @@ class Nasm # # Disassembles the supplied raw opcodes # - def self.disassemble(raw) + def self.disassemble(raw, bits=32) check tmp = Tempfile.new('nasmout') @@ -82,7 +82,7 @@ class Nasm tfd.flush() tfd.close - p = ::IO.popen("\"#{@@ndisasm_path}\" -u \"#{tmp.path}\"") + p = ::IO.popen("\"#{@@ndisasm_path}\" -b #{bits} \"#{tmp.path}\"") o = '' begin diff --git a/tools/nasm_shell.rb b/tools/nasm_shell.rb index 262539a8c8..5a2859cd71 100755 --- a/tools/nasm_shell.rb +++ b/tools/nasm_shell.rb @@ -22,6 +22,12 @@ rescue RuntimeError exit end +bits = ARGV.length > 0 ? ARGV[0].to_i : 32 +if ! [16, 32, 64].include?(bits) then + puts "#{bits} bits not supported" + exit 1 +end + # Start a pseudo shell and dispatch lines to be assembled and then # disassembled. shell = Rex::Ui::Text::PseudoShell.new("%bldnasm%clr") @@ -35,7 +41,7 @@ shell.run { |line| begin puts(Rex::Assembly::Nasm.disassemble( - Rex::Assembly::Nasm.assemble(line))) + Rex::Assembly::Nasm.assemble(line, bits), bits)) rescue RuntimeError puts "Error: #{$!}" end