Open main menu
Posts
Gists
Guilds
Users
Decipher
Docs
Open user menu
Log in
Sign up
Create a new gist
Posts
Gists
Guilds
Users
Decipher
Docs
Files
shexy.src
shexy.src
// command: shexy (shellexec) v0.4.
1
// command: shexy (shellexec) v0.4.
2
// Changelog
// * Minor
fixes
// * Minor
changes
// * Concentrate on commandline, build and instant exec of src
// * Added more DEBUG msg
// * Introduced error msg
// * Added clean function for cache
DebugOn =
0
BinaryOn =
0
DebugOn =
false
BinaryOn =
true
filepath = ""
allowimport = true
cachepath = home_dir+"/"+"Cache"+"/"+"shexy"
tocolor = function(color)
return "<color="+color+">"+self.str+"</color>"
end function
convert = function(text)
obj = {}
obj.str = str(text)
obj.tocolor = @tocolor
return obj
end function
debug = function(msg)
if DebugOn
== 1 then
print( convert(
"
[DEBUG] "+msg).tocolor("purple") )
if DebugOn
then
current = current_date
date = current.split(" - ")[0].split("/")
time = current.split(" - ")[1].split(":")
stamp = "("+date[1]+" "+date[0]+" "+time[0]+":"+time[1]+")"
print( convert(
stamp+"
[DEBUG] "+msg).tocolor("purple") )
end if
end function
error = function(msg)
current = current_date
date = current.split(" - ")[0].split("/")
time = current.split(" - ")[1].split(":")
stamp = "("+date[1]+" "+date[0]+" "+time[0]+":"+time[1]+")"
exit( convert(stamp+" [ERROR] "+msg).tocolor("red") )
end function
help = function()
helptext = []
sl = []
sl.push(convert("Help Text:"+char(9)).tocolor("#5E6EBBFF"))
sl.push(convert(launch_path.split("/")[-1]).tocolor("#6FAD69FF"))
sl.push(convert("help").tocolor("#B1B629FF"))
helptext.push(sl.join(char(9)))
sl = []
sl.push(convert("Run Source:"+char(9)).tocolor("#5E6EBBFF"))
sl.push(convert(launch_path.split("/")[-1]).tocolor("#6FAD69FF"))
sl.push(convert("[source] [args]").tocolor("#B1B629FF"))
helptext.push(sl.join(char(9)))
sl = []
sl.push(convert("Build Source:").tocolor("#5E6EBBFF"))
sl.push(convert(launch_path.split("/")[-1]).tocolor("#6FAD69FF"))
sl.push(convert("build [source]
[|allowimport]").tocolor("#B1B629FF"))
sl.push(convert("(only pwd)").tocolor("#96528CFF"))
helptext.push(sl.join(char(9)))
sl = []
sl.push(convert("Command Line:").tocolor("#5E6EBBFF"))
sl.push(convert(launch_path.split("/")[-1]).tocolor("#6FAD69FF"))
sl.push(convert("line").tocolor("#B1B629FF"))
helptext.push(sl.join(char(9)))
sl = []
sl.push(convert("Make Binary:").tocolor("#5E6EBBFF"))
sl.push(convert(launch_path.split("/")[-1]).tocolor("#6FAD69FF"))
sl.push(convert("make").tocolor("#B1B629FF"))
helptext.push(sl.join(char(9)))
sl = []
sl.push(convert("Run on change:").tocolor("#5E6EBBFF"))
sl.push(convert(launch_path.split("/")[-1]).tocolor("#6FAD69FF"))
sl.push(convert("watch
").tocolor("#B1B629FF"))
sl.push(convert("build [source]").tocolor("#B1B629FF"))
helptext.push(sl.join(char(9)))
sl = []
sl.push(convert("
Debug:"+char(9)*2
).tocolor("#5E6EBBFF"))
sl.push(convert("
Clean Cache:"
).tocolor("#5E6EBBFF"))
sl.push(convert(launch_path.split("/")[-1]).tocolor("#6FAD69FF"))
sl.push(convert("
-d [ source [args] | build | line ]
").tocolor("#B1B629FF"))
sl.push(convert("
clean
").tocolor("#B1B629FF"))
helptext.push(sl.join(char(9)))
for line in helptext
print(line)
end for
end function
mkdirparent = function(dirpath)
if typeof(get_shell.host_computer.File(dirpath)) != "file" then
debug(dirpath+" doesn't exist. Creating.")
pth = []
for index in dirpath.split("/")
if index == "" then continue
pth.push(index)
debug("Check: "+"/"+pth.join("/"))
if typeof(get_shell.host_computer.File("/"+pth.join("/"))) != "file" then
debug("/"+pth.join("/")+" doesn't exist.")
if get_shell.host_computer.File(parent_path("/"+pth.join("/"))).has_permission("w") then
debug("Create folder: "+"/"+pth.join("/"))
get_shell.host_computer.create_folder(parent_path("/"+pth.join("/")),pth[-1])
else if not get_shell.host_computer.File(parent_path("/"+pth.join("/"))).has_permission("w") then
error("Cannot create folder "+"/"+pth.join("/"))
end if
else if typeof(get_shell.host_computer.File("/"+pth.join("/"))) == "file" then
debug("/"+pth.join("/")+" exists.")
end if
end for
end if
end function
commandline = function()
filename = "tmp.src"
tmp_path = home_dir+"/"+"Cache"
ful_path = tmp_path+"/"+filename
if typeof(get_shell.host_computer.File(ful_
path
)) != "file" then
get_shell.host_computer.create_folder(home_dir,"C
ache
")
end if
get_shell.host_computer.touch(tmp_
path
,
filename
)
full
path
= c
achepath
+"/"+
filename
mkdirparent(cachepath)
get_shell.host_computer.touch(cachepath,filename)
clear_screen
print(convert("~ Shexy - Command Line ~").tocolor("#5E6EBBFF"))
print(convert("
(
Here you can run GreyHackCode instantly.
)
").tocolor("#96528CFF"))
print(convert("Here you can run GreyHackCode instantly.
Exit with [q|quit].
").tocolor("#96528CFF"))
while true
input = user_input("> ",false,false)
get_shell.host_computer.File(ful
_
path).set_content(input)
get_shell.build(ful
_
path,
tmp_
path,false)
get_shell.launch(
tmp_
path+"/"+filename.remove(".src"))
if input == "quit" or "q" then exit
get_shell.host_computer.File(ful
l
path).set_content(input)
get_shell.build(ful
l
path,
cache
path,false)
get_shell.launch(
cache
path+"/"+filename.remove(".src"))
end while
end function
compile = function()
allowimport = false
if params[1] == "allowimport" then allowimport = true
Path = current_path
Filename = params[1]
Source = Path+"/"+Filename
Target = Path
get_shell.build(Source,Target,allowimport)
end function
make
= function()
print(" ")
print("This will be a function, that will read a MakeFile.")
print(" ")
print("Possible Features:")
print("* Create a Template of a MakeFile.")
print("* Build binaries by reading rules of a MakeFile")
print("* Include dependencies automatically/dynamically and don't mess with import_code alone.")
print("* Install and Uninstall binaries and purge remaining data.")
print("* Include Patches.")
print("That are just ideas. I will see if it possible.")
end function
watch = function()
print(" ")
print("This function will watch a source
file.
")
print("* It will read
the
file
and generate a md5sum.")
print("* If the md5sum has been changed (so you saved the source), it will build and run it automatically.")
print("* After running it will wait again.")
cleanup
= function()
for file in get_shell.host_computer.File(cachepath).get_files
if
file.
has_permission("w")
the
n
file
.delete
end if
end for
end function
if params.len == 0 then commandline
for parm in params
if parm == "help" then
help()
exit
end if
if parm == "-d" then
DebugOn = 1
continue
end if
if parm == "line" then
commandline()
exit
end if
if parm == "build" then
compile()
exit
end if
if parm == "
make" then
make()
exit
end if
if parm == "watch
" then
watch
()
if parm == "
clean
" then
cleanup
()
exit
end if
check_path = function(input)
for x in input
NewPath = x
Object = get_shell.host_computer.File(NewPath)
Type = typeof(Object)
if Type != "file" and Type == "null" then
debug(NewPath+" is "+Type)
debug(NewPath+" is
a
"+Type
+" object"
)
continue
else if Type == "file" and Type != "null" then
debug(NewPath+" is "+Type)
debug(NewPath+" is
a
"+Type
+" object"
)
output = NewPath
return output
break
end if
end for
end function
Paths = []
Paths.push(parent_path(launch_path)+"/"+parm)
Paths.push(parent_path(program_path)+"/"+parm)
Paths.push(current_path+"/"+parm)
Paths.push(parm)
filepath = check_path(Paths)
args = params[1:].join(" ")
debug("Arguments: "+args)
end for
debug("Path: "+filepath)
if filepath == "" then
debug
("No valid path")
exit()
end if
cache_path = home_dir+"/"+"Cache"+"/"+"shexy"
if filepath == "" then
error
("No valid path")
source = get_shell.host_computer.File(filepath)
if source.is_binary then
debug("Target is not a Source File.")
exit
else
if not source.has_permission("r") then
debug(
"Target
has no read permissions.")
exit
else if not filepath.indexOf(".src") then
debug("Target must have the suffix [*.src].")
if not source.has_permission("r") then
debug(
source.path+"
has no read permissions.")
exit
end if
if filepath.indexOf(".src") then
if filepath.indexOf(".src")
and not get_shell.host_computer.File(filepath).is_binary
then
if source != null then
if typeof(get_shell.host_computer.File(cache_path)) != "file" then
get_shell.host_computer.create_folder(home_dir,"C
ache
")
get_shell.host_computer.create_folder(home_dir+"/"+"Cache","shexy")
end if
mkdirparent(c
ache
path)
src = get_shell.host_computer.File(current_path+"/"+params[0])
md5sum = md5(get_shell.host_computer.File(filepath).get_content)
BinName = filepath.split("/")[-1].remove(".src")
program = cache
_
path+"/"+BinName+"-"+md5sum
for file in get_shell.host_computer.File(cache
_
path).get_files
program = cachepath+"/"+BinName+"-"+md5sum
for file in get_shell.host_computer.File(cachepath).get_files
if file.name == "tmp" or "tmp.src" then continue
FileName = file.name.split("-")[0]
FileSum = file.name.split("-")[1]
debug(FileName+"-"+FileSum)
if FileSum != md5sum and FileName == BinName then
file.delete
continue
end if
if FileSum == md5sum and FileName == BinName then
debug("Run: "+cachepath+"/"+FileName+"-"+FileSum)
get_shell.launch(file.path, args)
OnlyRuntime = round(time,2)
debug("Run Time => "+str(OnlyRuntime)+" sec")
exit
end if
end for
debug("Source file: "+filepath)
debug("Target Path: "+cache
_
path)
print(
get_shell.build(filepath,cache
_
path,false)
)
BinPath = get_shell.host_computer.File(cache
_
path+"/"+BinName)
debug("Target Path: "+cachepath)
get_shell.build(filepath,cachepath,false)
BinPath = get_shell.host_computer.File(cachepath+"/"+BinName)
if BinPath != null then
get_shell.host_computer.File(cache
_
path+"/"+BinName).rename(BinName+"-"+md5sum)
get_shell.host_computer.File(cachepath+"/"+BinName).rename(BinName+"-"+md5sum)
BuildTime = round(time,2)
debug("Build Time => "+str(BuildTime)+" sec")
else
exit("File not compiled")
end if
get_shell.launch(cache
_
path+"/"+BinName+"-"+md5sum, args)
get_shell.launch(cachepath+"/"+BinName+"-"+md5sum, args)
RunTime = time
RunTime = round(RunTime - BuildTime,2)
debug("Run Time => "+str(RunTime)+" sec")
exit
end if
else if get_shell.host_computer.File(filepath).is_binary and BinaryOn then
get_shell.launch(filepath)
end if