Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- By Dan Jones - 2014
- Contents of 'critical.fag' (needed script, without it, it will refuse everything)
- _______________________________________
- # critical example script
- [green];
- //
- Multi line comment
- everything here is ignored
- \\
- print; Hello, World!
- _______________________________________
- """
- try:
- from Tkinter import *
- import tkFileDialog
- import re
- import Tkinter
- import os
- import time
- import tkMessageBox
- import calendar
- import socket
- from random import *
- import sys
- import autopy # (
- import winsound
- import win32com
- import win32com.client # downloaded libraries
- import ctypes
- import pyttsx # )
- except:
- print '******************************************\nA number of libraries are missing.\nYou may be unable to run certain scripts.\n******************************************'
- class WTCW: # Huge thanks to Thomas Fischer (tdev) for this
- WRAPPERS = ['{', '}']
- STD_INPUT_HANDLE = -10 ; STD_OUTPUT_HANDLE= -11 ; STD_ERROR_HANDLE = -12
- FG_BLUE = 0x01 ; FG_GREEN= 0x02 ; FG_RED = 0x04 ; FG_INTENSITY = 0x08 ; BG_BLUE = 0x10 ; BG_GREEN= 0x20 ; BG_RED = 0x40 ; BG_INTENSITY = 0x80
- colors = {'r': FG_RED, 'g':FG_GREEN, 'b':FG_BLUE, 'R':BG_RED, 'G':BG_GREEN, 'B':BG_BLUE, 'i':FG_INTENSITY, 'I':BG_INTENSITY, 'w':FG_RED|FG_GREEN|FG_BLUE }
- def _get_csbi_attributes(self):
- import struct
- csbi = ctypes.create_string_buffer(22) ; res = ctypes.windll.kernel32.GetConsoleScreenBufferInfo(self.handle, csbi) ; assert res
- (bufx, bufy, curx, cury, wattr, left, top, right, bottom, maxx, maxy) = struct.unpack("hhhhHhhhhhh", csbi.raw)
- return wattr
- def __init__(self, stream, defColor = ''):
- self.stream = stream ; self.defColor = self._parseColor(defColor)
- self.handle = ctypes.windll.kernel32.GetStdHandle(self.STD_OUTPUT_HANDLE)
- self.reset = self._get_csbi_attributes()
- def __del__(self): self.resetColor()
- def _parseColor(self, str):
- colval = 0
- for c in str:
- if c.lower() == 'x':
- self.resetColor()
- break
- colval |= self.colors[c]
- return colval
- def write(self, data):
- if self.defColor != 0:
- self.setColour(defColor)
- parts = data.split(self.WRAPPERS[0])
- for part in parts:
- f = part.find(self.WRAPPERS[1])
- if f != -1:
- self.setColour(self._parseColor(part[0:f]))
- self.stream.write(part[f+len(self.WRAPPERS[1]):])
- else:
- self.stream.write(part)
- self.stream.flush()
- #self.resetColor() #uncomment this to reset the color after every invocation
- def __getattr__(self, attr): return getattr(self.stream, attr)
- def setColour(self, col): ctypes.windll.kernel32.SetConsoleTextAttribute(self.handle, col)
- def resetColor(self): ctypes.windll.kernel32.SetConsoleTextAttribute(self.handle, self.reset)
- sys.stdout = WTCW(sys.stdout)
- def main():
- global commands, color, substring, line, reason, noerror, mlcomment, arg, com, file, script, file_path # globalise for use outside of main()
- debug = 0 # switch to 1 for debugging information
- if os.path.isfile("critical.fag") == False: # before anything check for this script, if it doesn't exist, make it
- file = open("critical.fag", "ab+") # lets make the file
- file.write('# critical example script\n')
- file.write('[green];\n')
- file.write('//\n')
- file.write('Multi line comment\n')
- file.write('everything here is ignored\n')
- file.write('\\\\\n') # needed due to escape characters
- file.write('retype; Hello, World!')
- file.close()
- print 'created default script'
- mlcomment = 0
- file_path = 'null'
- color = ''
- commands = ['msgbox','retype','print','//','\\','[debug]','speak','beep','made','test','mouse','mouse_snap','wait','length','cal','getsubstring','[green]','binary','[red]','[blue]','list','send','randint','input','randstring','commands']
- noerror = 0 # allows error script to be raised
- args = 0
- arg = str(sys.argv) # command line argument
- try:
- file = 'null' # set to null for the error script
- arg = arg.split(" ")[1] # command line argument
- arg = arg.replace("]","").replace("'","") # command line argument
- args = 1
- if arg[-4:] != '.fag':
- print 'Unknown file format, attempting to open..'
- except:
- args = 0 # disables argument if none given
- line = 0
- run = 0 # run == 1 if no script found
- if args == 0:
- try: # the humor of a programmer is quite broad. script is .fag hahaha
- # FAG = File Application Generator
- file = open("critical.fag") # default script, if all else fails, open this
- master = Tk() # start open file dialog
- master.withdraw() # hiding tkinter window
- file_path = tkFileDialog.askopenfilename(title="Open Script - (*.FAG)", filetypes=[("File App Generator",".FAG")]) # what kind of dialog?
- if file_path != "":
- file = open((file_path)) # final file
- else:
- window = Tkinter.Tk()
- window.wm_withdraw()
- tkMessageBox.showinfo(title='Error', message='No script selected, running default script')
- master.quit()
- except:
- reason = 'Internal script reading error\n\nDoes the default script exist?' # theoretically, this should never occur
- com = 'null error'
- arg = ' internal' # space at begining is critical!
- print '\n' # for looks
- error()
- arg = '', str(file) # space at the start is critical!
- else:
- try:
- file = open((arg)[1:])
- except:
- arg = arg.replace('-','')
- reason = 'Unable to locate script: ' + arg # had to do it this way, otherwise it's a tuple
- noerror = 1 # avoids calling error on a script line
- error()
- while 1: # script loop starts here
- line = int((line)) + 1 # set line to line + 1 = current line
- com = file.readline() # set com to contain current lines content
- if com.isspace():
- ignore()
- if not com: # the following code executes once parsing of the file is done
- if run == 0: # run will == 0 if no script was executed (this excludes comments)
- print '{ri}***********************************'
- print 'Error: No script found to execute!'
- print '***********************************'
- break # ends the script, there has to be a better way!
- if com.find('//') != -1:
- mlcomment = 1
- if com.find('\\') != -1:
- mlcomment = 0 # makes the script start reading script again!
- com = '# multi lined comment' # really a hack, it is horrible script lol
- if mlcomment == 1:
- com = '# multil lined comment' # really a hack, it is horrible script lol
- try:
- comment = com[0]
- prefix = com.split(';')[0]
- reason = 'Unknown command: "' + prefix + '"' # again, had to do it this way
- leng = len((prefix)) + 1
- script = com.split(';')[1]
- if prefix not in commands:
- error()
- except:
- if comment.find('#') != -1 or com.isspace():
- ignore()
- else:
- error()
- if comment.find('#') != -1:
- code = 3
- else:
- com = com[(leng):]
- if prefix == 'list':
- run = 1 # tells the parser that a valid command was found
- count = 0
- for x in com:
- if script[0].isspace():
- script = script[1:]
- else:
- count = count + 1
- if script[-1:] == '=':
- script.replace('=', '')
- if x == '=':
- count = count - 1
- print x, count
- else:
- print x
- parse = script
- getsubstring(parse) # get substring
- script = re.sub(r'\(.+?\)\s?','',script) # remove ()
- if prefix == 'print':
- run = 1
- if script[0].isspace():
- script = script[1:]
- print script
- if prefix == 'msgbox':
- run = 1
- if script[0].isspace():
- script = script[1:]
- try:
- title = script.split(',')[0]
- msg = script.split(',')[1]
- window = Tkinter.Tk()
- window.wm_withdraw()
- tkMessageBox.showinfo(title=(title), message=(msg))
- except:
- reason = 'Syntax error, try: msgbox; title,message'
- error()
- if prefix == 'send':
- run = 1
- if script[0].isspace():
- script = script[1:]
- send = script
- s = socket.socket()
- host = socket.gethostname()
- port = 1234
- s.bind((host, port))
- print 'waiting to accept client...'
- s.listen(5)
- c, addr = s.accept()
- c.send(str((send)))
- s.close()
- print 'sent!'
- if prefix == 'input':
- run = 1
- if script[0].isspace():
- script = script[1:]
- com = script
- input = raw_input((com))
- print 'your input:', input
- if prefix == 'length':
- run = 1
- if script[0].isspace():
- script = script[1:]
- size = len((script)) - 1
- print 'string length:', size
- if prefix == 'randint':
- run = 1
- if script[0].isspace():
- script = script[1:]
- try:
- low = script.split('-')[0]
- high = script.split('-')[1]
- num = randint(int((low)),int((high)))
- print num
- except:
- reason = 'Syntax error, try: randint; 0-100'
- error()
- if prefix == 'commands':
- run = 1
- print commands
- if prefix == 'randstring':
- run = 1
- if script[0].isspace():
- script = script[1:]
- try:
- print os.urandom(int(script)) # spices things up, not the same old try: except: crap
- except:
- reason = 'String found, you must use an integer (number)'
- error()
- if prefix == '[red]':
- print '{ri}' # sets color to red
- color = '{ri}'
- if prefix == '[green]':
- print '{gi}' # sets color to green # RGB colors
- color = '{gi}'
- if prefix == '[blue]':
- print '{bi}' # sets color to blue
- color = '{bi}'
- if prefix == '[debug]':
- if debug == 0:
- debug = 1
- else:
- debug = 0
- if prefix == 'cal':
- run = 1
- if script[0].isspace(): # if script[0] == only space do the following
- script = script[1:]
- try:
- year = script.split(',')[0]
- day = script.split(',')[1]
- cal = calendar.month(int((year)),int((day)))
- print cal
- except:
- reason = 'Calendar error, try: cal; 2015,9'
- error()
- if debug == 1: # debug information
- if script == '' or script.isspace():
- script = '(no script found)'
- if prefix == '[debug]':
- ignore()
- else:
- print 'line:', str((line)) + ' prefix:', prefix + ' script:', script
- if prefix == 'binary':
- run = 1
- if script[0].isspace():
- script = script[1:]
- binary = bin(reduce(lambda x, y: 256*x+y, (ord(c) for c in (script)), 0))
- print binary
- if prefix == 'getsubstring': # used in debugging
- run = 1
- if script.find('(') != -1 and script.find (')') != -1:
- parse = script
- getsubstring(parse)
- print substring
- else:
- reason = 'no () found to get substring'
- error()
- if prefix == 'wait':
- run = 1
- if script[0].isspace(): # if script = only space do the following
- script = script[1:]
- try:
- time.sleep(int(script))
- except:
- reason = 'Wait error, try: wait; 5'
- error()
- if prefix == 'mouse':
- if script[0].isspace(): # if script = only space do the following
- script = script[1:]
- run = 1
- try:
- x = script.split(',')[0]
- y = script.split(',')[1]
- autopy.mouse.smooth_move(int((x)),int((y)))
- except:
- reason = 'invalid X,Y'
- error()
- if prefix == 'mouse_snap':
- if script[0].isspace(): # if script = only space do the following
- script = script[1:]
- run = 1
- try:
- x = script.split(',')[0]
- y = script.split(',')[1]
- autopy.mouse.move(int((x)),int((y)))
- except:
- reason = 'invalid X,Y'
- error()
- if prefix == 'made':
- run = 1
- shell = win32com.client.Dispatch('WScript.Shell')
- shell.Run('notepad')
- time.sleep(0.1)
- shell.AppActivate('notepad')
- shell.SendKeys("Made by Dan Jones, for Windows", 0)
- shell.SendKeys("{Enter}", 0)
- shell.SendKeys("{F5}", 0) # F5 prints the time/date
- if prefix == 'beep':
- run = 1
- try:
- x = script.split(',')[0]
- y = script.split(',')[1]
- winsound.Beep(int((x)),int((y)))
- except:
- reason = 'beep error'
- error()
- if prefix == 'speak':
- if script[0].isspace(): # if script = only space do the following
- script = script[1:]
- run = 1
- engine = pyttsx.init()
- engine.say((script))
- engine.runAndWait()
- if prefix == 'retype':
- if script[0].isspace(): # if script = only space do the following
- script = script[1:]
- run = 1
- pause = script.split(':')[0]
- text = script.split(':')[1]
- for x in range(len(text)):
- sys.stdout.write(text[x])
- time.sleep(float(pause))
- script = '' # fixes repeated prints of script - always at bottom
- def getsubstring(string):
- global substring
- substring = string[string.find('(')+1:string.find(')')] # parse () inside a command for example getsubstring((parse))
- def ignore():
- pass # skips the line of script, used mainly for comments
- def error():
- print '{ri}'
- if noerror == 0:
- print 'File:{gi}', (arg)[1:], '{ri}Line:{gi}', str((line)) + '{ri}\n\n', com
- reason.replace('\n', '') # i don't know why, but a \n occurs in (reason)
- print '************************************\n'
- print reason, '\n'
- print '************************************'
- sys.exit('Script Halted') # comment this line to continue the script when an error is found
- main() # starts the main script
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement