Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import sys
- import os
- filename = "FILE0"
- funcname = "FUNC0"
- start_writren = True
- def debash(filename):
- inputFile = open(filename, "r" )
- sourceArray = []
- for line in inputFile:
- sourceArray.append( line )
- inputFile.close()
- print "DEBASH: [%s][Read done]." % (filename)
- if (len(sys.argv) == 4 and sys.argv[2] == "-d"):
- destFile = open(sys.argv[3], "w")
- else:
- destFile = open(sys.argv[1], "w")
- sourceArray[0] = "%s %s" % (sourceArray[0], 'echo "Entered[%s]" >> /tmp/wisc.log; #DEBASH\n' % (filename))
- start_writren = True
- for line in sourceArray:
- # hard
- if(line.find("()") != -1):
- funcname = line[0:line.find("()")+2]
- start_writren = False
- if(line.find("{") == -1 and line.find("}") == -1):
- destFile.write(line)
- else:
- if(line.find("{") != -1 and line.find("}") == -1 and start_writren == False): # found only for the first time{
- destFile.write(line)
- destFile.write('\techo "[%s]:[%s]:[%s]" >> /tmp/wisc.log #DEBASH\n' % (filename, funcname, "start") )
- start_writren = True
- elif(line.find("{") == -1 and line.find("}") != -1 and line == '}\n' ): # found only }
- destFile.write('\techo "[%s]:[%s]:[%s]" >> /tmp/wisc.log #DEBASH\n' % (filename, funcname, "end") )
- destFile.write(line)
- else:
- destFile.write(line)
- # hard done
- destFile.write('echo "Exited[%s]" >> /tmp/wisc.log #DEBASH\n' % (filename))
- destFile.close()
- print "DEBASH: [%s][Write done]." % (filename)
- def undebash(filename):
- targetfile = open(filename, "r" )
- sourceArray = []
- for line in targetfile:
- sourceArray.append( line )
- targetfile.close()
- destFile = open(filename, "w" )
- for line in sourceArray:
- if(line.find("#DEBASH") == -1):
- destFile.write(line)
- def debash_help():
- print "debash.py [SOURCE] {-u | -d [DESTFILE]}"
- def debash_descr():
- debash_help()
- print "\t[SOURCE] - file to debash"
- print "\t-u - causes UNDEBASH"
- print "\t-d - to determine another destination file.\n\t If you want to keep debashed file with different name."
- if (len(sys.argv) > 1 ):
- if(os.path.isfile(sys.argv[1]) == True and os.path.islink(sys.argv[1]) == False):
- isdebashed = False
- tmpfile = open(sys.argv[1], 'r')
- content = tmpfile.read()
- if(content.find("#DEBASH") != -1):
- isdebashed = True
- if(len(sys.argv) > 1):
- if(len(sys.argv) == 3):
- if(sys.argv[2] == "-u"):
- if(isdebashed == True):
- undebash(sys.argv[1])
- else:
- print"DEBASH: File [%s] is undebashed. Nothing done." % (sys.argv[1])
- else:
- if(isdebashed == False):
- debash(sys.argv[1])
- else:
- print"DEBASH: File [%s] is already debashed. Nothing done." % (sys.argv[1])
- else:
- if(sys.argv[1] == "-v"):
- print "DEBASH v0.1"
- elif(sys.argv[1] == "-h"):
- debash_descr()
- else:
- if(len(sys.argv) < 2):
- print "DEBASH: ERROR! NO FILENAME DIVEN!"
- elif(os.path.isfile(sys.argv[1]) == False):
- print "DEBASH: ERROR! NOT A FILE!"
- elif(os.path.islink(sys.argv[1]) == False):
- print "DEBASH: FILE IS A LINK!"
- else:
- print "DEBASH: UNKNOWN ERROR LOL xD"
- debash_help()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement