samples/exeencode.rb in metasm-1.0.1 vs samples/exeencode.rb in metasm-1.0.2
- old
+ new
@@ -24,11 +24,12 @@
:macros => {}
}.merge($opts)
OptionParser.new { |opt|
opt.on('-o file', 'output filename') { |f| $opts[:outfilename] = f }
- opt.on('-f') { $opts[:overwrite_outfile] = true }
+ opt.on('-i', 'dont overwrite existing outfile') { $opts[:nooverwrite_outfile] = true }
+ opt.on('-f', 'overwrite existing outfile (default)') { $opts.delete :nooverwrite_outfile } # without this, optparse autocomplete to --fno-pic and break older scripts...
opt.on('--c', 'parse source as a C file') { $opts[:srctype] = 'c' }
opt.on('--asm', 'parse asm as an ASM file') { $opts[:srctype] = 'asm' }
opt.on('--stdin', 'parse source on stdin') { ARGV << '-' }
opt.on('-v', '-W', 'verbose') { $VERBOSE=true }
opt.on('-d', 'debug') { $DEBUG=$VERBOSE=true }
@@ -42,11 +43,11 @@
# must come after --cpu in commandline
opt.on('--16', 'set cpu in 16bit mode') { $opts[:cpu].size = 16 }
opt.on('--le', 'set cpu in little-endian mode') { $opts[:cpu].endianness = :little }
opt.on('--be', 'set cpu in big-endian mode') { $opts[:cpu].endianness = :big }
opt.on('--fno-pic', 'generate position-dependant code') { $opts[:cpu].generate_PIC = false }
- opt.on('--shared', 'generate shared library') { $opts[:exetype] = :lib }
+ opt.on('--shared', '--lib', '--dll', 'generate shared library') { $opts[:exetype] = :lib }
opt.on('--ruby-module-hack', 'use the dynldr module hack to use any ruby lib available for ruby symbols') { $opts[:dldrhack] = true }
}.parse!
src = $opts[:macros].map { |k, v| "#define #{k} #{v}\n" }.join
@@ -60,11 +61,11 @@
else
$opts[:srctype] ||= $opts[:srctype_data]
src << DATA.read # the text after __END__ in this file
end
-if $opts[:outfilename] and not $opts[:overwrite_outfile] and File.exist?($opts[:outfilename])
+if $opts[:outfilename] and $opts[:nooverwrite_outfile] and File.exist?($opts[:outfilename])
abort "Error: target file exists !"
end
if $opts[:srctype] == 'c'
exe = $opts[:execlass].compile_c($opts[:cpu], src, file)
@@ -91,18 +92,18 @@
}
str.last[-1] = ?;
end
if of = $opts[:outfilename]
- abort "Error: target file #{of.inspect} exists !" if File.exists? of and not $opts[:overwrite_outfile]
+ abort "Error: target file #{of.inspect} exists !" if File.exists?(of) and $opts[:nooverwrite_outfile]
File.open(of, 'w') { |fd| fd.puts str }
puts "saved to file #{of.inspect}"
else
puts str
end
else
of = $opts[:outfilename] ||= 'a.out'
- abort "Error: target file #{of.inspect} exists !" if File.exists? of and not $opts[:overwrite_outfile]
+ abort "Error: target file #{of.inspect} exists !" if File.exists?(of) and $opts[:nooverwrite_outfile]
Metasm::DynLdr.compile_binary_module_hack(exe) if $opts[:dldrhack]
exe.encode_file(of, $opts[:exetype])
puts "saved to file #{of.inspect}"
end