1
mirror of https://github.com/rapid7/metasploit-framework synced 2024-11-12 11:52:01 +01:00
metasploit-framework/external/source/msfJavaToolkit/testCompilation.rb
natron 69ad365b46 Added STDERR to pure java payload, cleaned up user's view.
git-svn-id: file:///home/svn/framework3/trunk@8308 4d416f70-5f16-0410-b530-b9f4589650da
2010-01-28 22:53:36 +00:00

43 lines
1.2 KiB
Ruby
Executable File

#!/usr/bin/ruby
require 'rubygems'
require 'rjb'
#Rjb::load('.', jvmargs=[])
Rjb::load("#{ENV['JAVA_HOME']}/lib/tools.jar:.",jvmargs=[])
clsJavaCompile = Rjb::import('javaCompile.CompileSourceInMemory')
clsCreateJar = Rjb::import('javaCompile.CreateJarFile')
clsFile = Rjb::import('java.io.File')
system = Rjb::import('java.lang.System')
#clsString = Rjb::import('java.lang.String')
classNames = [ "HelloWorld1", "HelloWorld2" ]
codez = Array.new
classNames.each { |name|
codez << %Q^
public class #{name} {
public static void main(String args[]) {
System.out.println("This is from #{name}.");
}
}^}
#compileOpts = [""]
#outputDir = system.getProperty('java.io.tmpdir')
outputDir = "testoutdir"
compileOpts = [ "-target", "1.3", "-source", "1.3", "-d", outputDir ]
success = clsJavaCompile._invoke('CompileFromMemory','[Ljava.lang.String;[Ljava.lang.String;[Ljava.lang.String;', classNames, codez, compileOpts)
fileOutJar = clsFile.new_with_sig('Ljava.lang.String;', 'output.jar')
filesIn = Array.new
classNames.each { |name|
filesIn << clsFile.new_with_sig('Ljava.lang.String;', "#{outputDir}/#{name}.class")
}
clsCreateJar._invoke('createJarArchive', 'Ljava.io.File;[Ljava.io.File;', fileOutJar, filesIn)