Call this v0.3.0
This commit is contained in:
parent
ec4e8eaa91
commit
9b29cf8de9
4
Makefile
4
Makefile
@ -2,7 +2,7 @@
|
|||||||
# (C) Copyright 2014-2021 Chris Dorman, some rights reserved (GPLv2)
|
# (C) Copyright 2014-2021 Chris Dorman, some rights reserved (GPLv2)
|
||||||
# Some changes and tweaks from Menchers
|
# Some changes and tweaks from Menchers
|
||||||
|
|
||||||
VERSION = \"0.2.1\"
|
VERSION = \"0.3.0\"
|
||||||
EXTRA ?= dev
|
EXTRA ?= dev
|
||||||
VERSION_EXTRA = \"$(EXTRA)\"
|
VERSION_EXTRA = \"$(EXTRA)\"
|
||||||
|
|
||||||
@ -14,7 +14,7 @@ CPPFLAGS += -DVERSION=$(VERSION) -DVERSION_EXTRA=$(VERSION_EXTRA) -D_FORTIFY
|
|||||||
LDFLAGS += -Wl,-O1,--sort-common,--hash-style=gnu,-z,relro
|
LDFLAGS += -Wl,-O1,--sort-common,--hash-style=gnu,-z,relro
|
||||||
BIN ?= slidescript
|
BIN ?= slidescript
|
||||||
|
|
||||||
OBJECTS = src/main.o src/functions.o src/util.o src/vars.o src/enc.o src/md5.o
|
OBJECTS = src/main.o src/functions.o src/util.o src/vars.o src/enc.o src/md5.o src/pipe.o
|
||||||
|
|
||||||
all: main
|
all: main
|
||||||
|
|
||||||
|
@ -63,6 +63,13 @@ Done
|
|||||||
|
|
||||||
Changelog
|
Changelog
|
||||||
----
|
----
|
||||||
|
V0.3.0
|
||||||
|
* Added simple 2 layer function piping for more useful tasks
|
||||||
|
* Fixed a couple core dump bugs
|
||||||
|
* Now reads files into memory, and then forces text files through SS, allows for in file variables
|
||||||
|
* Added "md5" functionality
|
||||||
|
* Multi-formal working syntax
|
||||||
|
|
||||||
V0.2.1
|
V0.2.1
|
||||||
* Added "dec" decode function
|
* Added "dec" decode function
|
||||||
* Added "enc" encode function
|
* Added "enc" encode function
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
#define MAX_STRING_BUFSIZE (MAX_STRING_LEN + 1)
|
#define MAX_STRING_BUFSIZE (MAX_STRING_LEN + 1)
|
||||||
#define MAX_VAR_DATA_LEN 2048
|
#define MAX_VAR_DATA_LEN 2048
|
||||||
#define MAXVARS 2048
|
#define MAXVARS 2048
|
||||||
|
#define MAX_CONCAT_BUF 2048
|
||||||
|
#define MAX_READFILE_LEN 2097152
|
||||||
#define TOKEN '%'
|
#define TOKEN '%'
|
||||||
#define TOKEN_STR "%"
|
#define TOKEN_STR "%"
|
||||||
#define NULLBYTE '\0'
|
#define NULLBYTE '\0'
|
||||||
|
@ -16,6 +16,9 @@ char *process_line(char *line)
|
|||||||
{
|
{
|
||||||
char *tok_srch;
|
char *tok_srch;
|
||||||
|
|
||||||
|
static char concatbuf[MAX_CONCAT_BUF+1];
|
||||||
|
static char filebuf[MAX_READFILE_LEN+1];
|
||||||
|
|
||||||
tok_srch = strtok(line, "=\" |");
|
tok_srch = strtok(line, "=\" |");
|
||||||
|
|
||||||
/* reuse function */
|
/* reuse function */
|
||||||
@ -105,7 +108,8 @@ char *process_line(char *line)
|
|||||||
/* builtin md5 function */
|
/* builtin md5 function */
|
||||||
else if(strncmp("md5",tok_srch,3) == 0)
|
else if(strncmp("md5",tok_srch,3) == 0)
|
||||||
{
|
{
|
||||||
char *file_line, *file_md5_val;
|
char *file_line, *catfile, *file_md5_val;
|
||||||
|
|
||||||
tok_srch = strtok(NULL, "\"");
|
tok_srch = strtok(NULL, "\"");
|
||||||
if(strcmp(tok_srch, "\n") == 0 ||
|
if(strcmp(tok_srch, "\n") == 0 ||
|
||||||
strcmp(tok_srch, " \n") == 0 || tok_srch == NULL)
|
strcmp(tok_srch, " \n") == 0 || tok_srch == NULL)
|
||||||
@ -113,8 +117,18 @@ char *process_line(char *line)
|
|||||||
|
|
||||||
file_line = parse_vars(tok_srch);
|
file_line = parse_vars(tok_srch);
|
||||||
file_md5_val = md5_file(file_line);
|
file_md5_val = md5_file(file_line);
|
||||||
printf("ss:md5: %s, %s\n", file_md5_val, file_line);
|
catfile = ss_concat(file_md5_val, file_line);
|
||||||
return NULL;
|
if(strlen(catfile) < MAX_CONCAT_BUF)
|
||||||
|
{
|
||||||
|
strcpy(concatbuf, catfile);
|
||||||
|
free(catfile);
|
||||||
|
return concatbuf;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
free(catfile);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* system execute function */
|
/* system execute function */
|
||||||
@ -179,8 +193,9 @@ char *process_line(char *line)
|
|||||||
/* read function */
|
/* read function */
|
||||||
else if(strncmp("read",tok_srch,4) == 0)
|
else if(strncmp("read",tok_srch,4) == 0)
|
||||||
{
|
{
|
||||||
|
unsigned long read_size;
|
||||||
char read_line[1024];
|
char read_line[1024];
|
||||||
char *filename;
|
char *filename, *dynfile;
|
||||||
FILE *read_file = NULL;
|
FILE *read_file = NULL;
|
||||||
|
|
||||||
/* strtok to filename of function */
|
/* strtok to filename of function */
|
||||||
@ -193,9 +208,16 @@ char *process_line(char *line)
|
|||||||
that may be, and BAM, variable fill! */
|
that may be, and BAM, variable fill! */
|
||||||
filename = parse_vars(tok_srch);
|
filename = parse_vars(tok_srch);
|
||||||
|
|
||||||
|
// WERE LOADING FILES INTO MEMORY NOW!
|
||||||
/* open file */
|
/* open file */
|
||||||
read_file = fopen(filename, "r");
|
read_file = fopen(filename, "r");
|
||||||
|
|
||||||
|
fseek(read_file, 0L, SEEK_END);
|
||||||
|
read_size = ftell(read_file);
|
||||||
|
rewind(read_file);
|
||||||
|
|
||||||
|
dynfile = (char *)malloc(read_size + 1);
|
||||||
|
|
||||||
/* Check if file was opened successfully */
|
/* Check if file was opened successfully */
|
||||||
if(read_file == NULL)
|
if(read_file == NULL)
|
||||||
{
|
{
|
||||||
@ -204,11 +226,24 @@ char *process_line(char *line)
|
|||||||
|
|
||||||
while(fgets(read_line, sizeof(read_line), read_file) != NULL)
|
while(fgets(read_line, sizeof(read_line), read_file) != NULL)
|
||||||
{
|
{
|
||||||
printf("%s", read_line);
|
sprintf(dynfile, "%s", read_line);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(read_size <= MAX_READFILE_LEN)
|
||||||
|
{
|
||||||
|
sprintf(filebuf, "%s", dynfile);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
syn_error("ss:error:read, file too large, 2MB max");
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(read_file);
|
fclose(read_file);
|
||||||
return NULL;
|
|
||||||
|
// For now print to test //
|
||||||
|
free(dynfile);
|
||||||
|
|
||||||
|
return strip_nl(filebuf);
|
||||||
} /* read function */
|
} /* read function */
|
||||||
|
|
||||||
else if(strncmp("delete", tok_srch, 6) == 0) {
|
else if(strncmp("delete", tok_srch, 6) == 0) {
|
||||||
|
33
src/main.c
33
src/main.c
@ -8,6 +8,8 @@
|
|||||||
#include "deps.h"
|
#include "deps.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "functions.h"
|
#include "functions.h"
|
||||||
|
#include "pipe.h"
|
||||||
|
#include "vars.h"
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
@ -37,11 +39,34 @@ int main(int argc, char **argv)
|
|||||||
/* parse each line from the script in order. */
|
/* parse each line from the script in order. */
|
||||||
while(fgets(script_line, sizeof(script_line), script) != NULL)
|
while(fgets(script_line, sizeof(script_line), script) != NULL)
|
||||||
{
|
{
|
||||||
char *return_dat;
|
char *return_dat, *pipechk, *return_pipe_dat;
|
||||||
return_dat = process_line(script_line);
|
pipechk = ss_piping(script_line);
|
||||||
|
|
||||||
|
return_dat = process_line(script_line);
|
||||||
|
|
||||||
|
// Blank line, getting up outta here.
|
||||||
if(return_dat == NULL) continue;
|
if(return_dat == NULL) continue;
|
||||||
// If return is not null, provide the return
|
|
||||||
printf("%s\n", return_dat);
|
if(pipechk != NULL)
|
||||||
|
{
|
||||||
|
int varc;
|
||||||
|
varc = get_var_count();
|
||||||
|
set_var(varc, "PIPE", return_dat);
|
||||||
|
// Process functions based on previous pipe return
|
||||||
|
return_pipe_dat = process_line(pipechk);
|
||||||
|
// set PIPE var back to NULL after use, keep the struct clean
|
||||||
|
set_var(varc, "\0", "\0");
|
||||||
|
// Check to see if there's anything to even display
|
||||||
|
if(return_pipe_dat == NULL) continue;
|
||||||
|
|
||||||
|
// Print the pipe line
|
||||||
|
printf("%s\n", return_pipe_dat);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// If return is not null, and no pipe; provide the return
|
||||||
|
printf("%s\n", return_dat);
|
||||||
|
}
|
||||||
} /* end of while */
|
} /* end of while */
|
||||||
} /* file null */
|
} /* file null */
|
||||||
|
|
||||||
|
36
src/pipe.c
Normal file
36
src/pipe.c
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
SlideScript - minimalistic top-down scripting language.
|
||||||
|
(C) Copyright 2014-2021 Chris Dorman - some rights reserved (GPLv2)
|
||||||
|
|
||||||
|
View README file supplied with this software for more details
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "deps.h"
|
||||||
|
#include "pipe.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
|
char *ss_piping(char *string)
|
||||||
|
{
|
||||||
|
char *pipe_tok;
|
||||||
|
|
||||||
|
char *stringmem;
|
||||||
|
|
||||||
|
stringmem = (char *) malloc(strlen(string)+1);
|
||||||
|
if(stringmem == NULL) syn_error("ss:error:memory mapping error...");
|
||||||
|
|
||||||
|
sprintf(stringmem, "%s", string);
|
||||||
|
|
||||||
|
pipe_tok = strtok(stringmem, "|");
|
||||||
|
if(pipe_tok != NULL && strcmp(pipe_tok, string) !=0)
|
||||||
|
{
|
||||||
|
char *second_func;
|
||||||
|
pipe_tok = strtok(NULL, "|");
|
||||||
|
second_func = pipe_tok + 1;
|
||||||
|
return second_func;
|
||||||
|
}
|
||||||
|
|
||||||
|
free(stringmem);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
9
src/pipe.h
Normal file
9
src/pipe.h
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
/*
|
||||||
|
SlideScript - minimalistic top-down scripting language.
|
||||||
|
(C) Copyright 2014-2021 Chris Dorman - some rights reserved (GPLv2)
|
||||||
|
|
||||||
|
View README file supplied with this software for more details
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
char *ss_piping(char *string);
|
@ -31,6 +31,13 @@ char *strip_nl (char *string)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *ss_concat(char *str1, char *str2)
|
||||||
|
{
|
||||||
|
char *dymem = (char *) malloc((strlen(str1)+strlen(str2)) + 3);
|
||||||
|
sprintf(dymem, "%s, %s", str1, str2);
|
||||||
|
return dymem;
|
||||||
|
}
|
||||||
|
|
||||||
void parse_args(int argc, char** argv)
|
void parse_args(int argc, char** argv)
|
||||||
{
|
{
|
||||||
/* -h flag given, show help */
|
/* -h flag given, show help */
|
||||||
|
@ -7,4 +7,5 @@
|
|||||||
|
|
||||||
void syn_error(char *message);
|
void syn_error(char *message);
|
||||||
char *strip_nl(char *string);
|
char *strip_nl(char *string);
|
||||||
|
char *ss_concat(char *str1, char *str2);
|
||||||
void parse_args(int argc, char** argv);
|
void parse_args(int argc, char** argv);
|
||||||
|
110
test.ss
110
test.ss
@ -1,62 +1,76 @@
|
|||||||
#!/usr/bin/slidescript
|
#!/usr/bin/slidescript
|
||||||
# This is a comment
|
#############################################################
|
||||||
|
#### Welcome to the world of SlideScript! ####
|
||||||
|
#### This script is here for the learning purposes of SS ####
|
||||||
|
#### Any line starting with a hashtag will treated as a ####
|
||||||
|
#### comment! ####
|
||||||
|
#############################################################
|
||||||
|
|
||||||
### These are variables in SS
|
# Slide Script, also refered to as SS, is extremely forgiving in
|
||||||
# Sets 'ss_filename' to 'file.txt'
|
# syntax handling!
|
||||||
|
# Example:
|
||||||
|
# print "content"
|
||||||
|
# print "content";
|
||||||
|
# print("content")
|
||||||
|
# print("content");
|
||||||
|
###
|
||||||
|
### These will operate properly, as well as:
|
||||||
|
# Example:
|
||||||
|
# write "filename.txt" "data"
|
||||||
|
# write "filename.txt" "data";
|
||||||
|
# write("filename.txt" "data");
|
||||||
|
# write("filename.txt", "data");
|
||||||
|
#
|
||||||
|
# IT ALL WORKS!
|
||||||
|
# SlideScript really syntaxes based on quotes and key function words,
|
||||||
|
# as well as pipes. It really doesn't mind whats around it otherwise
|
||||||
|
# And every variable is called by %varname%, defining variables, as normal
|
||||||
|
|
||||||
|
# Variables in SS
|
||||||
ss_filename=file.txt
|
ss_filename=file.txt
|
||||||
# Sets 'ss_exec_command' to 'ls -al'
|
ss_stringdata=Data to encrypt and decrypt
|
||||||
ss_exec_command=ls -al
|
ss_exec_command=echo SS executing echo from system shell
|
||||||
# Sets 'ss_decoded' to 'Encrypt This Data!'
|
|
||||||
ss_decoded=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/][-_.,?!
|
|
||||||
ss_encoded2=defejihknknopqrqvutwzwz{|}DCHGFILILMNOPOTSRUXUXYZ[\[4`\0d//B$
|
|
||||||
# Sets 'ss_encoded' to 'Ghfs~su#Yilv#Gduf$'
|
|
||||||
ss_encoded=Ghfs~su#Yilv#Gduf$
|
|
||||||
# Sets 'ss_file_content' to 'This will be written to file.txt!'
|
|
||||||
ss_file_content=Encrypted data: %ss_encoded%
|
|
||||||
|
|
||||||
### The main program ###
|
# Printing function in SS
|
||||||
# Prints 'Writing 'This will be written to file.txt!'
|
print "Welcome to SlideScript!"
|
||||||
# to 'file.txt'
|
# Sleep function in SS
|
||||||
print "Sleeping before writing '%ss_file_content%' to '%ss_filename%'"
|
print "Some content to print, working with '%ss_filename%' today!"
|
||||||
|
# Below demonstrates SS encrypting a string, passing the output
|
||||||
|
# over a pipe, and using the write function and %PIPE% variable
|
||||||
|
# holding the first functions output, writes to %ss_filename%; file.txt
|
||||||
|
### %PIPE% is the output from the first line function, enc
|
||||||
|
### %PIPE% is always applied when a pipe is used!
|
||||||
|
enc "%ss_stringdata%" | write "%ss_filename%" "%PIPE%"
|
||||||
|
# You're left with file.txt, lets move on
|
||||||
|
|
||||||
# Pauses the script parse for x seconds, in this case 1.
|
# Lets read the file we just created and show how SS handles its
|
||||||
sleep 1
|
# own decryption algorithm
|
||||||
|
read "%ss_filename%" | dec "%PIPE%"
|
||||||
|
# Will display the original variable string!
|
||||||
|
|
||||||
# Writes the content of ss_file_content to ss_filename
|
# SS MD5 function
|
||||||
write "%ss_filename%" "%ss_file_content%"
|
# Lets get the md5sum of file.txt with our md5 function
|
||||||
|
md5 "%ss_filename%" | write "%ss_filename%.md5" "%PIPE%"
|
||||||
|
# Use a pipe, and push the md5 into a text file of file.txt
|
||||||
|
|
||||||
print "Getting md5 of %ss_filename%"
|
# Read md5 file
|
||||||
|
read "%ss_filename%.md5"
|
||||||
|
|
||||||
md5 "%ss_filename%"
|
write("test.txt", "testing data");
|
||||||
|
|
||||||
print "Data written to %ss_filename%:"
|
# Delete function, SS can delete files and directories with one function
|
||||||
# Reads data and prints to screen from ss_filename
|
# NOTE: it is extremely powerful and can wreck your system if used in the
|
||||||
|
# wrong way! Proceed with caution, delete "/" WILL send your files to the
|
||||||
read "%ss_filename%"
|
# grave.
|
||||||
|
###
|
||||||
print "Deleting %ss_filename% after 1 second sleep..."
|
# Lets delete the files we've been messing with, no system calls needed
|
||||||
# Sleep again for the giggles :P
|
|
||||||
sleep 1
|
|
||||||
|
|
||||||
# Deletes file written previously from ss_filename
|
|
||||||
delete "%ss_filename%"
|
delete "%ss_filename%"
|
||||||
|
delete "%ss_filename%.md5"
|
||||||
|
# Gone!
|
||||||
|
|
||||||
print "Deleted %ss_filename%, executing '%ss_exec_command%' in 1 second"
|
print("Testing execution functions");
|
||||||
# Sleep some more
|
|
||||||
sleep 1
|
sleep 1
|
||||||
|
|
||||||
# Executes the ss_exec_command variable data, 'ls -al'
|
# Execute function, SS can call unix system calls!
|
||||||
|
# Executes the ss_exec_command variable data, 'ls'
|
||||||
exec "%ss_exec_command%"
|
exec "%ss_exec_command%"
|
||||||
|
|
||||||
print "Encoding '%ss_decoded%' in 1 second"
|
|
||||||
# More snooze
|
|
||||||
sleep 1
|
|
||||||
|
|
||||||
# Encodes 'ss_encode' data
|
|
||||||
enc "%ss_decoded%"
|
|
||||||
|
|
||||||
print "Decoding '%ss_encoded%'"
|
|
||||||
# Decodes 'ss_decode' data
|
|
||||||
dec "%ss_encoded%"
|
|
||||||
|
|
||||||
dec "%ss_encoded2%"
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user