View difference between Paste ID: 868suVA4 and ghQVhxuj
SHOW: | | - or go back to the newest paste.
1
#!/usr/bin/env python
2
3
import sys
4
import os
5
6
filename = "FILE0"
7
funcname = "FUNC0"
8
start_writren = True
9
10-
if len(sys.argv) < 2:
10+
def debash(filename):
11-
	print "ERROR: NO FILENAME DIVEN!"
11+
		inputFile = open(filename, "r" )
12
		sourceArray = []
13-
	inputFile = open( sys.argv[1], "r" )
13+
		for line in inputFile:
14-
	filename = sys.argv[1]
14+
		    sourceArray.append( line )
15
		inputFile.close()
16-
	for line in inputFile:
16+
		print "DEBASH: [%s][Read done]." % (filename)    
17
18-
	print "EXEC: Read done."	    
18+
		if (len(sys.argv) == 4 and sys.argv[2] == "-d"):
19
			destFile = open(sys.argv[3], "w")
20-
# print sourceArray
20+
		else:	
21-
	if (len(sys.argv) == 3):
21+
			destFile = open(sys.argv[1], "w")
22-
		destFile = open(sys.argv[2], "w")
22+
23-
	else:	
23+
		sourceArray[0] = "%s %s" % (sourceArray[0], 'echo "Entered[%s]" >> /tmp/wisc.log; #DEBASH\n' % (filename))
24-
		destFile = open(sys.argv[1], "w")
24+
		start_writren = True
25
		for line in sourceArray:
26-
	sourceArray[0] = "%s %s" % (sourceArray[0], 'echo "Entered[%s]" >> /tmp/wisc.log\n' % (filename))
26+
			# hard
27
			if(line.find("()") != -1):
28-
		# hard
28+
				funcname = line[0:line.find("()")+2]
29-
		if(line.find("()") != -1):
29+
				start_writren = False
30-
			funcname = line[0:line.find("()")+2]
30+
31-
			start_writren = False
31+
32
			if(line.find("{") == -1 and line.find("}") == -1):
33
				destFile.write(line)
34-
		if(line.find("{") == -1 and line.find("}") == -1):
34+
35
				if(line.find("{") != -1 and line.find("}") == -1 and start_writren == False): # found only for the first time{
36-
		else:
36+
					destFile.write(line)
37-
			if(line.find("{") != -1 and line.find("}") == -1 and start_writren == False): # found only for the first time{
37+
					destFile.write('\techo "[%s]:[%s]:[%s]" >> /tmp/wisc.log #DEBASH\n' % (filename, funcname, "start") )
38
					start_writren = True
39-
				destFile.write('\techo "[%s]:[%s]:[%s]" >> /tmp/wisc.log\n' % (filename, funcname, "start") )
39+
				elif(line.find("{") == -1 and line.find("}") != -1 and line == '}\n' ): # found only }
40-
				start_writren = True
40+
					destFile.write('\techo "[%s]:[%s]:[%s]" >> /tmp/wisc.log #DEBASH\n' % (filename, funcname, "end") )
41-
			elif(line.find("{") == -1 and line.find("}") != -1 and line == '}\n' ): # found only }
41+
					destFile.write(line)
42-
				destFile.write('\techo "[%s]:[%s]:[%s]" >> /tmp/wisc.log\n' % (filename, funcname, "end") )
42+
				else:
43
					destFile.write(line)
44
			#	hard done
45
		destFile.write('echo "Exited[%s]" >> /tmp/wisc.log #DEBASH\n' % (filename))
46-
		#	hard done
46+
		destFile.close()
47-
	destFile.write('echo "Exited[%s]" >> /tmp/wisc.log\n' % (filename))
47+
		print "DEBASH: [%s][Write done]." % (filename)
48-
	print "EXEC: Write done."
48+
49
def undebash(filename):
50
	targetfile =  open(filename, "r" )
51
	sourceArray = []
52
	for line in targetfile:
53
	    sourceArray.append( line )
54
	targetfile.close()
55
	destFile = open(filename, "w" )
56
	for line in sourceArray:
57
		if(line.find("#DEBASH") == -1):
58
			destFile.write(line)
59
def debash_help():
60
	print "debash.py [SOURCE] {-u | -d [DESTFILE]}"
61
def debash_descr():
62
	debash_help()
63
	print "\t[SOURCE] - file to debash"
64
	print "\t-u - causes UNDEBASH"
65
	print "\t-d - to determine another destination file.\n\t     If you want to keep debashed file with different name."
66
67
if (len(sys.argv) > 1 ):
68
	if(os.path.isfile(sys.argv[1]) == True and os.path.islink(sys.argv[1]) == False):
69
		isdebashed = False
70
		tmpfile = open(sys.argv[1], 'r')
71
		content = tmpfile.read()
72
		if(content.find("#DEBASH") != -1):
73
			isdebashed = True
74
75
		if(len(sys.argv) > 1):
76
			if(len(sys.argv) == 3):
77
				if(sys.argv[2] == "-u"):
78
					if(isdebashed == True):
79
						undebash(sys.argv[1])
80
					else:
81
						print"DEBASH: File [%s] is undebashed. Nothing done." % (sys.argv[1])
82
			else:
83
				if(isdebashed == False):
84
					debash(sys.argv[1])
85
				else:
86
					print"DEBASH: File [%s] is already debashed. Nothing done." % (sys.argv[1])
87
	else:
88
		if(sys.argv[1] == "-v"):
89
			print "DEBASH v0.1"
90
		elif(sys.argv[1] == "-h"):
91
			debash_descr()
92
else:
93
	if(len(sys.argv) < 2):
94
		print "DEBASH: ERROR! NO FILENAME DIVEN!"
95
	elif(os.path.isfile(sys.argv[1]) == False):
96
		print "DEBASH: ERROR! NOT A FILE!"
97
	elif(os.path.islink(sys.argv[1]) == False):
98
		print "DEBASH: FILE IS A LINK!"
99
	else:
100
		print "DEBASH: UNKNOWN ERROR LOL xD"
101
	debash_help()