def calculate_geodesic(X, Gamma, v=False): from sympy import Symbol, Derivative N = len(X) tau = Symbol('tau') acceleration_vector = [] for mu in range(N): if v: Print(r'$\ddot{x}^%s = $' % mu) accel_mu = 0 for alpha in range(N): for beta in range(N): one = -Gamma[mu][alpha][beta] # How do I do this ... two = Derivative(X[alpha], tau) # How do I do this ... three = Derivative(X[beta], tau) value = one * two * three if v: Print(r'$\;\;\;\; -\Gamma^%s{}_{%s %s}\,$' % (L(X[mu]), L(X[alpha]), L(X[beta])) + r'$\dot{x}^%s\dot{x}^%s$' % (L(X[mu]), L(X[alpha])) + r'$(%s)\,(%s)\,(%s) = %s$' % (L(one), L(two), L(three), L(value))) accel_mu += value acceleration_vector += [ accel_mu, ] return (acceleration_vector)
def flatten(self,seq): for item in seq: if isinstance(item,(etree._Element,)): # if item.tag == "ifConditionMultiple": # with open("IfConditionMultipleXmlTemp.xml", "w") as myfile: # myfile.write(etree.tostring(item,with_tail=False)) # myfile.close() # outputIfBasic = "" # outputIfBasic = subprocess.check_output(('python IfConditionMultiple.py IfConditionMultipleXmlTemp.xml ' +str(depthCheck)),shell=True) # if ifMultipleOperator == "or" and outputIfBasic == "true": # print "true" # sys.exit() # if ifMultipleOperator == "and" and outputIfBasic == "false": # print "false" # sys.exit() # else: with open("IfConditionBasicXmlTemp.xml", "w") as myfile: myfile.write(etree.tostring(item,with_tail=False)) myfile.close() outputIfBasic = "" outputIfBasic = subprocess.check_output(('python IfConditionBasic.py IfConditionBasicXmlTemp.xml'),shell=True) IfConditionBasicObject = IfConditionBasic('IfConditionBasicXmlTemp.xml') outputIfBasic = IfConditionBasicObject.evaluate() Print.Print(PrintLevel.IfConditionAnswerMultiple, "Basic If Condition Output "+str(outputIfBasic)) if self.ifMultipleOperator == "or" and outputIfBasic ==True: Print.Print(PrintLevel.NewLine,"") Print.Print(PrintLevel.IfConditionAnswerMultiple, "If Condition Multiple: True")
def create_printer(self, result, dir_name): path = self._setup_dir(dir_name) file_path = os.path.join(path, "result.txt") p = Print(result) if file_path: p.add_file_output(file_path) return p
def calc_christoffel_symbol(X, g, v=False): from sympy import diff, Rational N = len(X) g_inv = g.inv() if v: Print(r'Calculating: $ \Gamma^\sigma{}_{\alpha\beta} ' + r'= \frac{1}{2} g^{\sigma\rho}' + r'\left( \partial_\beta g_{\rho\alpha} ' + r'+ \partial_\alpha g_{\rho\beta}' + r'- \partial_\rho g_{\alpha\beta}\right)$') Gamma = [] for sigma in range(N): new_sigma = [] for alpha in range(N): new_alpha = [] for beta in range(N): new_beta = 0 # Each sigma is a scalar # Now we have to sum the right had side over rho for rho in range(N): diff1 = diff(g[rho, alpha], X[beta]) diff2 = diff(g[rho, beta], X[alpha]) diff3 = diff(g[alpha, beta], X[rho]) if v: print(' alpha=%s, beta=%s, sigma=%s, rho=%s' % (alpha, beta, sigma, rho)) if v: Print(r'$\;\; \Gamma^%s_{%s%s} += $' % (sigma, alpha, beta) + r'$\frac{1}{2} g^{%s%s}$' % (sigma, rho) + r'$(\partial_%s g_{%s%s}$' % (beta, rho, alpha) + r'$+ \partial_%s g_{%s%s}$' % (alpha, rho, beta) + r'$- \partial_%s g_{%s%s})$' % (rho, alpha, beta)) Print(r'$\;\; \Gamma^%s_{%s%s} += $' % (sigma, alpha, beta) + r'$\frac{1}{2} (%s) $' % L(g_inv[sigma, rho]) + r'$((%s) + (%s) - (%s))$' % (L(diff1), L(diff2), L(diff3))) value = Rational(1,2) * \ g_inv[sigma,rho] * \ (diff1 + diff2 - diff3) new_beta += value if v: Print(r'$\Gamma^%s_{%s%s} = %s$' % (sigma, alpha, beta, new_beta)) new_alpha += [ new_beta, ] new_sigma += [ new_alpha, ] Gamma += [ new_sigma, ] return (Gamma)
def inner_product(g, U, V, v=False): IP = 0 N = len(U) for m in range(N): for n in range(N): value = g[m, n] * U[m] * V[n] if v: Print('Adding: $g_{%s%s} U^%s V^%s = %s$' % (L(m), L(n), L(m), L(n), L(value))) IP += value if v: Print('Product now = $%s$' % L(IP)) return (IP)
def evaluate(self): e = etree.parse(self.fileName) Print.Print(PrintLevel.BaseClass, "In Multiple If Condition") xmldoc = minidom.parse(self.fileName) ifMultiple = xmldoc.getElementsByTagName('ifConditionMultiple') self.ifMultipleOperator = "and"#ifMultiple[0].attributes['myvalue'].value depthCheck = int(0) self.result = "True" if depthCheck >10: sys.exit() depthCheck = depthCheck+1 self.flatten(e.xpath('/ifConditionMultiple/node()')) if self.ifMultipleOperator == "and": Print.Print(PrintLevel.NewLine,"")
def process(k, v): #Person Table global insertString, voice1, voice2 if k == 'Print Number': voice1 = "" voice2 = "" insertString = "INSERT STRING START" insertString += "\nPrint Number:" + v if k == 'Composer': for c in v.split(';'): p = Person(conn, c.strip()) p.store() insertString += "\nComposer:" + c.strip() if k == 'Editor': p = Person(conn, v.strip()) p.store() insertString += "\nEditor:" + v #Score Table if k == 'Genre': insertString += "\nGenre:" + v if k == 'Key': insertString += "\nKey:" + v if k == 'Composition Year': insertString += "\nComposition Year:" + v if k == 'Incipit': insertString += "\nIncipit:" + v #push it in! Score(conn, insertString).store() if voice1 != "": Voice(conn, (insertString + voice1)).store() if voice2 != "": Voice(conn, (insertString + voice2)).store() Edition(conn, insertString).store() getAuthors(insertString) Print(conn, insertString).store() #Voice Table if k == 'Voice 1': voice1 = "\nVoice 1:" + v if k == 'Voice 2': voice2 = "\nVoice 2:" + v if k == 'Voice 3': voice2 = "\nVoice 3:" + v #Edition Table if k == 'Publication Year': insertString += "\nPublication Year:" + v if k == 'Edition': insertString += "\nEdition:" + v #Print Table if k == 'Partiture': insertString += "\nPartiture:" + v
def __init__(self, parent): Frame.__init__(self, parent) self.client = [] self.clientPanel = Client(self) self.clientPanel.pack(fill=X) f2 = Frame(self) self.studiesB = Button(f2, text="Studies", command=lambda: self.changeTab(0)) self.studiesB.grid(row=0, column=0) self.echoB = Button(f2, text="Echo", command=lambda: self.changeTab(1)) self.echoB.grid(row=0, column=1) self.rdvmsB = Button(f2, text="RDVMs", command=lambda: self.changeTab(2)) self.rdvmsB.grid(row=0, column=2) self.printB = Button(f2, text="Print", command=lambda: self.changeTab(3)) self.printB.grid(row=0, column=3) f2.pack(fill=X) self.studies = Studies(self) self.echo = Echo(self) self.rdvms = RDVMs(self) self.print = Print(self) self.tabs = [self.studies, self.echo, self.rdvms, self.print] self.buttons = [self.studiesB, self.echoB, self.rdvmsB, self.printB] self.button = self.rdvmsB self.button.configure(state="disabled") self.tab = self.rdvms self.tab.pack(fill=X, pady=(10, 0))
"$group": { "_id": "$SenderIP", "count": { "$sum": 1 } } }])) if operatorValue == "average": countOfDocuments = 0 countOfPackets = 0 for document in cursor: countOfDocuments = countOfDocuments + 1 countOfPackets += document["count"] averageValue = countOfPackets / countOfDocuments if averageValue > int(rightValue): Print.Print(PrintLevel.IfConditionAnswerBasic, "true") return True else: Print.Print(PrintLevel.IfConditionAnswerBasic, "false") return False sys.exit() if operatorValue == "sum": countOfDocuments = 0 countOfPackets = 0 for document in cursor: countOfPackets += document["count"] if countOfPackets > int(rightValue): Print.Print(PrintLevel.IfConditionAnswerBasic, "true") return True else:
with open("IfConditionBasicXmlTemp.xml", "w") as myfile: myfile.write(etree.tostring(item,with_tail=False)) myfile.close() outputIfBasic = "" outputIfBasic = subprocess.check_output(('python IfConditionBasic.py IfConditionBasicXmlTemp.xml'),shell=True) IfConditionBasicObject = IfConditionBasic('IfConditionBasicXmlTemp.xml') outputIfBasic = IfConditionBasicObject.evaluate() Print.Print(PrintLevel.IfConditionAnswerMultiple, "Basic If Condition Output "+str(outputIfBasic)) if self.ifMultipleOperator == "or" and outputIfBasic ==True: Print.Print(PrintLevel.NewLine,"") Print.Print(PrintLevel.IfConditionAnswerMultiple, "If Condition Multiple: True") <<<<<<< HEAD ======= sys.exit() if self.ifMultipleOperator == "and" and outputIfBasic == False: Print.Print(PrintLevel.NewLine,"") Print.Print(PrintLevel.IfConditionAnswerMultiple,"If Condition Multiple: False") >>>>>>> eecd91e9fd97390d6cb0f1c5da81cdc0f38db5aa sys.exit() if self.ifMultipleOperator == "and" and outputIfBasic == False: Print.Print(PrintLevel.NewLine,"") Print.Print(PrintLevel.IfConditionAnswerMultiple,"If Condition Multiple: False") # sys.exit() self.result = "False" def evaluate(self): e = etree.parse(self.fileName) Print.Print(PrintLevel.BaseClass, "In Multiple If Condition") xmldoc = minidom.parse(self.fileName) ifMultiple = xmldoc.getElementsByTagName('ifConditionMultiple') self.ifMultipleOperator = "and"#ifMultiple[0].attributes['myvalue'].value depthCheck = int(0)
#coding:utf8 import numpy as np from Print import Print if __name__ == "__main__": np.set_printoptions(precision=4, suppress=True) A = np.array([[2., 2., 3.], [4., 7., 7.], [-2., 4., 5.]], dtype=float) print("=======Matrix factorization========") _str = str(input("Please Select Decomposition Type(LU GS HH or GV):")) control = "N" while control == 'N': try: if _str == 'LU': Print.printLU(A) elif _str == 'GS': Print.printGram_schmidt(A) elif _str == 'HH': Print.printHouseholder(A) elif _str == 'GV': Print.printGivens(A) except ValueError: print("Input is illegal") control = input("EXIT(Y/N)?")
def nestedOperationFunc(nestedOperationXmlFile): Print.Print(PrintLevel.Command, "in nestedOperationFunc " + nestedOperationXmlFile) os.system('python MultipleOperations.py ' + nestedOperationXmlFile)
def cybox(self, fileNameTemporary): Print.Print(PrintLevel.Command, "In cybox " + fileNameTemporary)
import os import subprocess import sys from pymongo import MongoClient from Print import Print from Constants import PrintLevel Print.Print(PrintLevel.Command, "Psscan Starting") commandToExecute = 'python vol.py -f ' + sys.argv[1] + " psscan" proc = subprocess.Popen( commandToExecute, shell=True, stdout=subprocess.PIPE, ) Print.Print(PrintLevel.Command, "Psscan Ended") output = proc.communicate()[0] count = 0 index = 0 aDict = [] aDict2 = {} line2 = [ 'Psscan-Offset', 'Psscan-Name', 'Psscan-PID', 'Psscan-PPID', 'Psscan-PDB', 'Psscan-Time-Created', 'Psscan-Time-Created', 'Psscan-Time-Created', 'Psscan-Time-Exited', 'Psscan-Time-Exited', 'Psscan-Time-Exited' ] for line in output.split("\n"): count = count + 1 if count == 1: continue
def calc_riemann_tensor(X, g, Gamma, v=False): from sympy import Symbol, diff N = len(X) # Symbol names from Franklin page 131 (4.13) k = [Symbol('alpha'), Symbol('rho'), Symbol('gamma'), Symbol('beta')] sum_sym = Symbol('sigma') pre1 = ' ' pre2 = pre1 + ' ' R = [] if v: Print('Calculating the Riemann Tensor, by the formula:') Print('<font size=4> ' + r'$R^{%s}{}_{%s%s%s} =\ $' % (L(k[0]), L(k[1]), L(k[2]), L(k[3])) + r'$\Gamma^{%s}{}_{%s%s}\,\Gamma^{%s}{}_{%s%s}$' % (L(k[0]), L(k[2]), L(sum_sym), L(sum_sym), L(k[3]), L(k[1])) + r'$\;-\;\Gamma^{%s}{}_{%s%s}\,\Gamma^{%s}{}_{%s%s}$' % (L(k[0]), L(k[3]), L(sum_sym), L(sum_sym), L(k[2]), L(k[1])) + r'$\;+\;\partial_{%s} \Gamma^{%s}{}_{%s%s}$' % (L(k[2]), L(k[0]), L(k[3]), L(k[1])) + r'$\;-\;\partial_{%s} \Gamma^{%s}{}_{%s%s}$' % (L(k[3]), L(k[0]), L(k[2]), L(k[1])) + '</font>') for k0 in range(N): k0_list = [] for k1 in range(N): k1_list = [] for k2 in range(N): k2_list = [] for k3 in range(N): if v: Print('Doing $R^{%s=%s}_{%s=%s, %s=%s, %s=%s}$' % (L( k[0]), k0, L(k[1]), k1, L(k[2]), k2, L(k[3]), k3)) k3_value = 0 # We have two products, each of which needs to be summed # over the summation variable. # Then the second product is subtracted from the first. first_product = 0 for sumv in range(N): foo = Gamma[k0][k2][sumv] * Gamma[sumv][k3][k1] if v: Print( pre2 + r'$%s=%s:\;$' % (L(sum_sym), L(sumv)) + r'$\Gamma^{%s}{}_{%s%s} \Gamma^{%s}{}_{%s%s} = %s$' % (L(X[k0]), L(X[k2]), L(X[sumv]), L(X[sumv]), L(X[k3]), L(X[k1]), L(foo))) first_product += foo if v: Print(pre1 + '1st product = %s' % first_product) second_product = 0 for sumv in range(N): foo = Gamma[k0][k3][sumv] * Gamma[sumv][k2][k1] if v: Print( pre2 + r'$%s=%s:\;$' % (L(sum_sym), L(sumv)) + r'$\Gamma^{%s}{}_{%s%s} \Gamma^{%s}{}_{%s%s} = %s$' % (L(X[k0]), L(X[k3]), L(X[sumv]), L(X[sumv]), L(X[k2]), L(X[k1]), L(foo))) second_product += foo if v: Print(pre1 + '2nd product = %s' % second_product) D1 = diff(Gamma[k0][k3][k1], X[k2]) if v: Print(pre1 + r'$\partial_{%s} \Gamma^{%s}{}_{%s%s} = %s$' % (L(X[k2]), L(X[k0]), L(X[k3]), L(X[k1]), L(D1))) D2 = diff(Gamma[k0][k2][k1], X[k3]) if v: Print(pre1 + r'$\partial_{%s} \Gamma^{%s}{}_{%s%s} = %s$' % (L(X[k3]), L(X[k0]), L(X[k2]), L(X[k1]), L(D2))) k3_value = first_product - second_product + D1 - D2 if v: Print('$R^{%s}{}_{%s%s%s}$' % (L(X[k0]), L(X[k1]), L(X[k2]), L(X[k3]))) Print('$ = (%s)-(%s)+(%s)-(%s)$' % (L(first_product), L(second_product), L(D1), L(D2))) Print('$ = %s$' % L(k3_value)) if v: print k2_list += [ k3_value, ] k1_list += [ k2_list, ] k0_list += [ k1_list, ] R += [ k0_list, ] return (R)
def __init__(self, *args, **kwargs): Print.__init__(self, *args, **kwargs)
def Sporttery( self, odds, nshow=5, which=[], order=[], chinese=True, N=6 ) : from Print import Print import numpy as np total_number0 = np.array([N, N, N], int) if (len(order) == 0) : order = ['mean', 'max', 'min'] if (len(which) == 0) : which = ['ms', 'lm', 'ls'] # ms=MiddleSmall, lm=LargeMiddle, ls=LargeSmall odds_name = ['win', 'draw', 'loss'] odds = np.array(odds, float) if (odds.sum() < 1e-6) : print 'NO cheat ball odds' return #---------------------------------------- #---------------------------------------- # number0, earn0: 无论什么结果,均净赚 total_number = [100, 100, 100] total_number = np.array(total_number, int) number = np.zeros([total_number.prod(), total_number.size]) for i in xrange(total_number.size) : N = total_number[i+1:].prod() n = n1 = n2 = m = 0 while (n2 < len(number)) : n1, n2 = n*N, (n+1)*N number[n1:n2,i] = m % total_number[i] n, m = n+1, m+1 number = number[1:] back = np.zeros(number.shape) for i in xrange(odds.size) : back[:,i] = number[:,i] * odds[i] earn = back - number.sum(1)[:,None] sign = np.sign(earn).sum(1) n = np.arange(sign.size)[sign>2.5] number0, earn0 = number[n], earn[n] #---------------------------------------- #---------------------------------------- # number: 买注组合 total_number = total_number0 number = np.zeros([total_number.prod(), total_number.size]) for i in xrange(total_number.size) : N = total_number[i+1:].prod() n = n1 = n2 = m = 0 while (n2 < len(number)) : n1, n2 = n*N, (n+1)*N number[n1:n2,i] = m % total_number[i] n, m = n+1, m+1 number = number[1:] n = np.arange(total_number.max()-1, 1, -1) for i in xrange(len(number)) : m = number[i:i+1] / n[:,None] m = abs(m - m.astype(int)).sum(1) m = n[m<1e-6] if (m.size > 0) : number[i] /= m[0] scale = list((total_number-1).astype(str)) for i in xrange(len(scale)) : scale[i] = len(scale[i]) scale = np.append(np.cumsum(scale[::-1])[::-1][1:], [0]) n = (number * 10**scale).sum(1) + 1j*np.arange(len(number)) m = [] while (len(n) > 0) : m.append(n[0].imag) n = n[n.real!=n[0].real] number = number[np.array(m,int)] #---------------------------------------- #---------------------------------------- # earn: 每付出1元净赚 pay = number.sum(1)[:,None] back = np.zeros(number.shape) for i in xrange(odds.size) : back[:,i]=number[:,i]*odds[i] earn = (back - pay)/pay # earn per yuan #---------------------------------------- #---------------------------------------- # number1, earn1: 每个组合,均有两种结果能净赚,一种结果净亏。而两种净赚结果,是赔率最低的两个,即概率最高的两个。这里“拒绝爆冷”。 # sign= 3: 3 True # sign= 1: 2 True 1 False # sign=-1: 1 True 2 False # sign=-3: 3 False n = [0, 1, 2] m = np.where(odds==odds.max())[0][0] n.remove(m) sign = np.sign(earn)[:,np.array(n)].sum(1) n = np.arange(sign.size)[sign>0.5] number1, earn1 = number[n], earn[n] earn1 /= abs(earn1[:,m:m+1]) # number2, earn2: 每个组合,均有两种结果能净赚,一种结果净亏。而两种净赚结果,是赔率最高的两个,即概率最低的两个。这里“期待爆冷”。 n = [0, 1, 2] m = np.where(odds==odds.min())[0][0] n.remove(m) sign = np.sign(earn)[:,np.array(n)].sum(1) n = np.arange(sign.size)[sign>0.5] number2, earn2 = number[n], earn[n] earn2 /= abs(earn2[:,m:m+1]) # number3, earn3: 每个组合,均有两种结果能净赚,一种结果净亏。而两种净赚结果,是赔率最高和最低的两个,“兼顾爆冷和保底”。 m1 = np.where(odds==odds.min())[0][0] m2 = np.where(odds==odds.max())[0][0] n = [m1, m2] m = [0, 1, 2] m.remove(m1) m.remove(m2) m = m[0] sign = np.sign(earn)[:,np.array(n)].sum(1) n = np.arange(sign.size)[sign>0.5] number3, earn3 = number[n], earn[n] earn3 /= abs(earn3[:,m:m+1]) #---------------------------------------- #---------------------------------------- if (len(earn1) > 0) : e1 = earn1.copy() e1[e1<-0.5] = e1.max()*2 nmin1 = e1.min(1) + 1j*np.arange(len(earn1)) nmin1 = np.sort(nmin1)[::-1].imag.astype(int) nmax1 = earn1.max(1) + 1j*np.arange(len(earn1)) nmax1 = np.sort(nmax1)[::-1].imag.astype(int) nmean1=e1.min(1)+earn1.max(1)+1j*np.arange(len(earn1)) nmean1 = np.sort(nmean1)[::-1].imag.astype(int) else : nmin1 = nmax1 = nmean1 = np.array([]) if (len(earn2) > 0) : e2 = earn2.copy() e2[e2<-0.5] = e2.max()*2 nmin2 = e2.min(1) + 1j*np.arange(len(earn2)) nmin2 = np.sort(nmin2)[::-1].imag.astype(int) nmax2 = earn2.max(1) + 1j*np.arange(len(earn2)) nmax2 = np.sort(nmax2)[::-1].imag.astype(int) nmean2=e2.min(1)+earn2.max(1)+1j*np.arange(len(earn2)) nmean2 = np.sort(nmean2)[::-1].imag.astype(int) else : nmin2 = nmax2 = nmean2 = np.array([]) if (len(earn3) > 0) : e3 = earn3.copy() e3[e3<-0.5] = e3.max()*2 nmin3 = e3.min(1) + 1j*np.arange(len(earn3)) nmin3 = np.sort(nmin3)[::-1].imag.astype(int) nmax3 = earn3.max(1) + 1j*np.arange(len(earn3)) nmax3 = np.sort(nmax3)[::-1].imag.astype(int) nmean3=e3.min(1)+earn3.max(1)+1j*np.arange(len(earn3)) nmean3 = np.sort(nmean3)[::-1].imag.astype(int) else : nmin3 = nmax3 = nmean3 = np.array([]) n1 = np.array([nmean1, nmax1, nmin1]) n2 = np.array([nmean2, nmax2, nmin2]) n3 = np.array([nmean3, nmax3, nmin3]) N = total_number[0]-1. a = number1.max(1) number1[a==1] *= N number1[a==2] *= round(N/2) number1[a==3] *= round(N/3) a = number2.max(1) number2[a==1] *= N number2[a==2] *= round(N/2) number2[a==3] *= round(N/3) a = number3.max(1) number3[a==1] *= N number3[a==2] *= round(N/2) number3[a==3] *= round(N/3) earn0 = np.concatenate([number0, earn0], 1) earn1 = np.concatenate([number1, earn1], 1) earn2 = np.concatenate([number2, earn2], 1) earn3 = np.concatenate([number3, earn3], 1) #---------------------------------------- Print('***** 大中小 *****', precision=2) print earn0 if ('ms' in which) : if (chinese) : print '***** 中小 *****' if ('mean' in order) : if (chinese) : print '平均' if (n1[0].size > 0) : print earn1[n1[0]][:nshow] else : print earn1 if ('max' in order) : if (chinese) : print '最大' if (n1[1].size > 0) : print earn1[n1[1]][:nshow] else : print earn1
from pymongo import MongoClient import json import sys import os import subprocess import sys from Print import Print from Constants import PrintLevel Print.Print(PrintLevel.Command, "Connscan Starting ") commandToExecute = 'python vol.py -f ' + sys.argv[1] + " connscan" proc = subprocess.Popen( commandToExecute, shell=True, stdout=subprocess.PIPE, ) f = proc.communicate()[0] Print.Print(PrintLevel.Command, "Connscan done") count = 0 aDict = [] aDict2 = {} line2 = [ 'Connscan-Offset', 'Connscan-Local-Address', 'Connscan-Remote-Address', 'Connscan-Pid' ] for line in f.split("\n"): count = count + 1 if count == 1: continue else:
from Constants import ConstantsClass from Print import Print ConstantsClass.printLevel =1 Print.p(Print.Everthing,"Everthing") Print.p(Print.Basic,"Basic") Print.p(Print.OnlyImp,"OnlyImp")
import os import subprocess import sys from pymongo import MongoClient from Print import Print from Constants import PrintLevel Print.Print(PrintLevel.Command, "PsList Starting") proc = subprocess.Popen( 'python vol.py -f ' + sys.argv[1] + ' pslist', shell=True, stdout=subprocess.PIPE, ) output = proc.communicate()[0] Print.Print(PrintLevel.Command, "PsList Done") count = 0 index = 0 aDict = [] aDict2 = {} # line3={'PsList-Offset' :'1','PsList-Name':'keylogger.exe','PsList-PID':'10','PsList-PPID':'100'} # aDict.append(line3) # line3={'PsList-Offset' :'1','PsList-Name':'keyloggerxyz.exe','PsList-PID':'10','PsList-PPID':'100'} # aDict.append(line3) line2 = [ 'PsList-Offset', 'PsList-Name', 'PsList-PID', 'PsList-PPID', 'PsList-Thds', 'PsList-Hnds', 'PsList-Sess', 'PsList-Wow64', 'PsList-Start', 'PsList-Start', 'PsList-Start', 'PsList-Exit', 'PsList-Exit', 'PsList-Exit', 'PsList-temp' ] # for x in arrayOfFiles: # if os.path.exists(x):
import os import subprocess import sys from pymongo import MongoClient from Print import Print from Constants import PrintLevel Print.Print(PrintLevel.Command, "PsxView Starting") proc = subprocess.Popen( 'python vol.py -f ' + sys.argv[1] + ' psxview', shell=True, stdout=subprocess.PIPE, ) output = proc.communicate()[0] Print.Print(PrintLevel.Command, "PsxView Done") count = 0 index = 0 aDict = [] aDict2 = {} line2 = [ 'PsxView-Offset', 'PsxView-Name', 'PsxView-PID', 'PsxView-pslist', 'PsxView-psscan', 'PsxView-thrdproc', 'PsxView-pspcdid', 'PsxView-csrss', 'PsxView-session', 'PsxView-deskthrd', 'PsxView-ExitTime' ] for line in output.split("\n"): count = count + 1 if count == 1: continue else:
import os import subprocess import sys from pymongo import MongoClient from Print import Print from Constants import PrintLevel Print.Print(PrintLevel.Command, "PsxView Starting") proc = subprocess.Popen( 'python vol.py -f ' + sys.argv[1] + ' psxview', shell=True, stdout=subprocess.PIPE, ) output = proc.communicate()[0] Print.Print(PrintLevel.Command, "PsxView Done") Print.Print(PrintLevel.RawOutput, output) count = 0 index = 0 aDict = [] aDict2 = {} line2 = [ 'PsxView-Offset', 'PsxView-Name', 'PsxView-PID', 'PsxView-pslist', 'PsxView-psscan', 'PsxView-thrdproc', 'PsxView-pspcdid', 'PsxView-csrss', 'PsxView-session', 'PsxView-deskthrd', 'PsxView-ExitTime' ] for line in output.split("\n"): count = count + 1 if count == 1: continue
from pymongo import MongoClient import json import sys import os import subprocess import sys from Print import Print from Constants import PrintLevel import yara def mycallBack(data): print data yara.CALLBACK_CONTINUE Print.Print(PrintLevel.Command, "Yara Starting ") rules = yara.compile('crypto.yar') matches = rules.match(sys.argv[1]) print matches # commandToExecute = "yara -r main.yara "+sys.argv[1] # proc=subprocess.Popen(commandToExecute, shell=True, stdout=subprocess.PIPE, ) # f=proc.communicate()[0] # print f Print.Print(PrintLevel.Command, "Yara done")
def evaluate(self): Print.Print(PrintLevel.Command, "In One Operation") xmldoc = minidom.parse(self.fileName) operationName = xmldoc.getElementsByTagName('operationName') operationNameValue = operationName[0].attributes['myvalue'].value if operationNameValue == "cybox": e = etree.parse(self.fileName) fileNameTemporary = "CyboxOneOperationXmlTemp" + str( time()) + ".xml" self.flattenCybox(e.xpath('/operation/node()'), fileNameTemporary) cybox(fileNameTemporary) return if operationNameValue == "nestedSchema": e = etree.parse(self.fileName) fileNameTemporary = "MultipleOperationsTempXml" + str( time()) + ".xml" self.flattenCybox(e.xpath('/operation/node()'), fileNameTemporary) commandToExecute = "python MultipleOperations.py " + fileNameTemporary Print.Print(PrintLevel.Command, "Command " + operationNameValue) Print.Print(PrintLevel.Command, commandToExecute) os.system(commandToExecute) return if operationNameValue == "IfCondition": condition = xmldoc.getElementsByTagName('condition') conditionValue = condition[0].attributes['myvalue'].value left = xmldoc.getElementsByTagName('left') leftValue = left[0].attributes['myvalue'].value right = xmldoc.getElementsByTagName('right') rightValue = right[0].attributes['myvalue'].value yesaction = xmldoc.getElementsByTagName('yesaction') yesactionValue = yesaction[0].attributes['myvalue'].value noaction = xmldoc.getElementsByTagName('noaction') noactionValue = noaction[0].attributes['myvalue'].value ifCondition(conditionValue, leftValue, rightValue, yesactionValue, noactionValue) sys.exit(0) if operationNameValue == "ifMultiple": e = etree.parse(self.fileName) self.flatten(e.xpath('/operation/node()'), "IfConditionMultipleXmlTemp.xml") sys.exit(0) if operationNameValue == "nestedOperations": nestedOperation = xmldoc.getElementsByTagName('nestedOperationXml') nestedOperationValue = nestedOperation[0].attributes[ 'myvalue'].value nestedOperationFunc(nestedOperationValue) sys.exit(0) if operationNameValue == "DOS": operationInputFile = xmldoc.getElementsByTagName('operationPath') operationInputFilevalue = operationInputFile[0].attributes[ 'myvalue'].value vmName = xmldoc.getElementsByTagName('vmName') vmNameValue = vmName[0].attributes['myvalue'].value minPacket = xmldoc.getElementsByTagName('minPacket') minPacketvalue = minPacket[0].attributes['myvalue'].value command = "" + operationInputFilevalue + "/DOSOperation.sh " + vmNameValue + " " + minPacketvalue Print.Print(PrintLevel.Command, command) os.system(command) sys.exit(0) if operationNameValue == "getDump": operationInputFile = xmldoc.getElementsByTagName( 'operationInputFile') operationInputFilevalue = operationInputFile[0].attributes[ 'myvalue'].value operationPath = xmldoc.getElementsByTagName('operationPath') operationPathValue = operationPath[0].attributes['myvalue'].value vmName = xmldoc.getElementsByTagName('vmName') vmNameValue = vmName[0].attributes['myvalue'].value command = "python " + operationPathValue + "/getDump.py " + vmNameValue + " " + operationInputFilevalue Print.Print(PrintLevel.Command, command) os.system(command) sys.exit(0) if operationNameValue == "exit": exitCommand = "exit" Print.Print(PrintLevel.Command, exitCommand) return "exit" sys.exit(0) if operationNameValue == "Bulk_Extractor": Print.Print(PrintLevel.Command, "Bulk_Extractor") operationInputFile = xmldoc.getElementsByTagName( 'operationInputFile') operationInputFilevalue = operationInputFile[0].attributes[ 'myvalue'].value operationInputFilevalue = ConstantsClass.pathValue + operationInputFilevalue operationPath = xmldoc.getElementsByTagName('operationPath') operationPathValue = operationPath[0].attributes['myvalue'].value operationPathValue = ConstantsClass.pathValue + operationPathValue command = "bulk_extractor -E net -o " + operationPathValue + " " + operationInputFilevalue Print.Print(PrintLevel.Command, command) os.system(command) return if operationNameValue == "TCP_DUMP": Print.Print(PrintLevel.Command, "TCP DUMP") operationInputFile = xmldoc.getElementsByTagName( 'operationInputFile') operationInputFilevalue = operationInputFile[0].attributes[ 'myvalue'].value operationInputFilevalue = ConstantsClass.pathValue + operationInputFilevalue command = "sudo tcpdump -tttttnnr " + operationInputFilevalue + " | grep IP" Print.Print(PrintLevel.Command, command) outputTcpDump = subprocess.check_output((command), shell=True) aDict = [] for lines in outputTcpDump.split('\n'): count = 0 aDict2 = {} for word in lines.split(' '): if count == 2: # insert sender IP here aDict2["SenderIP"] = word elif count == 4: # insert recieve IP here aDict2["ReceiverIP"] = word break count = count + 1 aDict.append(aDict2) aDict2 = {} client = MongoClient() db = client.test db.DOSCollection.insert_many(aDict) return if operationNameValue == "CustomPython": operationInputFile = xmldoc.getElementsByTagName( 'operationInputFile') operationInputFilevalue = operationInputFile[0].attributes[ 'myvalue'].value operationPath = xmldoc.getElementsByTagName('operationPath') operationPathValue = operationPath[0].attributes['myvalue'].value operationPathValue = ConstantsClass.pathValue + operationPathValue + "/" + operationInputFilevalue commandToExecute = "python " + operationPathValue Print.Print(PrintLevel.Command, "Command " + operationNameValue) Print.Print(PrintLevel.Command, commandToExecute) os.system(commandToExecute) #cursor = list(db.randCollection.aggregate([ # {"$group" : {"_id" : "$SenderIP", "count": { "$sum" : 1}} # } # ])) # for document in cursor: # print document # # print ' '.join('| {} : {} |'.format(key, val) for key, val in sorted(document.items())) # db.DOSCollection.insert(cursor) # db.DOSCollection.remove() # cursor = db.DOSCollection.find() # print "after cursor is obtained" # for document in cursor: # print "oneline" # print ' '.join('| {} : {} |'.format(key, val) for key, val in sorted(document.items())) sys.exit() if operationNameValue == "Alert": operationWords = xmldoc.getElementsByTagName('operationWords') operationWordsValue = operationWords[0].attributes['myvalue'].value operationLevel = xmldoc.getElementsByTagName('operationLevel') operationLevelValue = operationLevel[0].attributes['myvalue'].value if operationLevelValue == "Alpha": Print.Print(PrintLevel.Alpha, operationWordsValue) elif operationLevelValue == "Beta": Print.Print(PrintLevel.Beta, operationWordsValue) elif operationLevelValue == "Gamma": Print.Print(PrintLevel.Gamma, operationWordsValue) return operationInputFile = xmldoc.getElementsByTagName('operationInputFile') operationInputFilevalue = operationInputFile[0].attributes[ 'myvalue'].value operationInputFilevalue = ConstantsClass.pathValue + operationInputFilevalue operationPath = xmldoc.getElementsByTagName('operationPath') operationPathValue = operationPath[0].attributes['myvalue'].value operationPathValue = ConstantsClass.pathValue + operationPathValue commandToExecute = "python " + operationPathValue + "/" + operationNameValue + ".py " + operationInputFilevalue Print.Print(PrintLevel.Command, "Command : " + operationNameValue) # Print.Print(PrintLevel.Command, commandToExecute) os.system(commandToExecute)
import os import subprocess import sys from pymongo import MongoClient from Print import Print from Constants import PrintLevel from Constants import ConstantsClass if len(sys.argv) < 2: Print.Print(PrintLevel.Error, 'Arguments not given') sys.exit() Print.Print(PrintLevel.Command, "DllList Starting") commandToExecute = 'python vol.py -f ' + sys.argv[1] + " dlllist" proc = subprocess.Popen( commandToExecute, shell=True, stdout=subprocess.PIPE, ) Print.Print(PrintLevel.Command, "DllList Ended") output = proc.communicate()[0] count = 0 index = 0 aDict = [] aDict2 = {} line2 = [ 'DllList-Base', 'DllList-Size', 'DllList-Path', 'DllList-Path', 'DllList-Path', 'DllList-Path', 'DllList-Path', 'DllList-Path', 'DllList-Path', 'DllList-Path', 'DllList-Path', 'DllList-Path', 'DllList-Path', 'DllList-Path', 'DllList-Path', 'DllList-Path', 'DllList-Path', 'DllList-Path', 'DllList-Path', 'DllList-Path', 'DllList-Path', 'DllList-Path', 'DllList-Path', 'DllList-Path',
import json from pprint import pprint import random import numpy as np import pandas as pd import csv import sys import os import matplotlib.pyplot as plt plt.rcdefaults() import Paths from Print import Print #pylint: disable=E0401 print = Print() np.random.seed(1337) #prevent plt.show() making terminal hang plt.interactive(True) # Clean the data # List all files types # find . -type f | sed 's/.*\.//' | sort | uniq -c # delete everything but json and php # find temp4 -type f ! -name '*.php' ! -name '*.json' -print0 | xargs -0 rm -vf df = pd.read_csv(os.path.join(Paths.processed, 'migrations_metadata.csv')) # COUNT plt.bar([""], df.shape[0], align='center', alpha=0.5)
def print(self): _ = Print(self.SubjectList)
import os import subprocess import sys from pymongo import MongoClient from Print import Print from Constants import PrintLevel Print.Print(PrintLevel.Command, "CmdScan Starting") proc = subprocess.Popen( 'python vol.py -f ' + sys.argv[1] + ' cmdscan', shell=True, stdout=subprocess.PIPE, ) output = proc.communicate()[0] Print.Print(PrintLevel.Command, "CmdScan Done") Print.Print(PrintLevel.RawOutput, output) sys.exit() count = 0 index = 0 aDict = [] aDict2 = {} line2 = ['CmdScan-Name', 'CmdScan-PID', 'CmdScan-ID', 'CmdScan-Privilage'] for line in output.split("\n"): count = count + 1 if count == 1: continue else: if count > 2:
import os import sys from lxml import etree import xml.etree.ElementTree from Constants import PrintLevel from Constants import ConstantsClass from Print import Print Print.Print(PrintLevel.BaseClass, "In Custom python file")
from Constants import ConstantsClass from Print import Print ConstantsClass.printLevel = 1 Print.p(Print.Everthing, "Everthing") Print.p(Print.Basic, "Basic") Print.p(Print.OnlyImp, "OnlyImp")
import os import sys import base64 import time import datetime from datetime import timedelta from github import Github from Print import Print print = Print() # add glorious indentation and colors to print class GithubScraper(object): def __init__( self, max_repos = float('inf'), query = "Laravel", overwrite_repos = True, filters = [], start_date = datetime.datetime.strptime('20080401', r'%Y%m%d').date(), interval_length = 10000, # Default interval in days so big it will be only one interval ): self.max_repos = max_repos self.query = query self.filters = filters self.start_date = start_date self.interval_length = interval_length self.github = Github(os.getenv("GITHUB_ACCESS_TOKEN")) self.root = os.path.join(os.path.dirname(os.path.realpath(__file__)), "../") def scrape(self):
from torch.utils.data import Dataset, DataLoader import torch.nn as nn import torch.optim as optim import torch import sys from torch.autograd import Variable import json import csv import numpy as np import torch.utils.data as data import time import operator from Print import Print print = Print() from Network import Network from MigrationsDataset import MigrationsDataset # SAMPLE DATA # id,user,repo,filename,table,column_name,column_data_type # 0,ahmadeyamin,laravel-blog-relation,2014_10_12_100000_create_password_resets_table.php,password_resets,email,string # 1,ahmadeyamin,laravel-blog-relation,2014_10_12_100000_create_password_resets_table.php,password_resets,token,string # 2,ahmadeyamin,laravel-blog-relation,2014_10_12_100000_create_password_resets_table.php,password_resets,created_at,timestamp # 3,ahmadeyamin,laravel-blog-relation,2018_06_29_113550_create_tags_table.php,tags,id,increments # 4,ahmadeyamin,laravel-blog-relation,2018_06_29_113550_create_tags_table.php,tags,name,string migration_train_dataset = MigrationsDataset(train=True, limit_rows=10000) migration_test_dataset = MigrationsDataset(test=True, limit_rows=10000) train_loader = DataLoader(dataset=migration_train_dataset,