added various scripts
This commit is contained in:
62
codegrab/flm.py
Executable file
62
codegrab/flm.py
Executable file
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/python
|
||||
import sys
|
||||
import re
|
||||
|
||||
pattern=str(sys.argv[1])
|
||||
filename=str(sys.argv[2])
|
||||
shortpattern=""
|
||||
print("Pattern is '%s'" % pattern)
|
||||
chars={}
|
||||
|
||||
for char in pattern:
|
||||
if not char in chars:
|
||||
newchar={}
|
||||
newchar['char']=char
|
||||
newchar['count']=pattern.count(char)
|
||||
newchar['idx']=[m.start() for m in re.finditer(char,pattern)]
|
||||
#print("Char '%s' occurs %d times in pattern %s" % (c,newchar['count'],newchar['idx']))
|
||||
chars[char]=newchar
|
||||
shortpattern=shortpattern + char
|
||||
try:
|
||||
f=file(filename,'r')
|
||||
except:
|
||||
print("[-] Can't open File %s" % filename)
|
||||
exit(1)
|
||||
|
||||
print(shortpattern)
|
||||
longest_match_yet=0
|
||||
|
||||
while longest_match_yet<len(pattern):
|
||||
read_a_char=f.read(1)
|
||||
if read_a_char in shortpattern and read_a_char in chars:
|
||||
#candidate
|
||||
for index in chars[read_a_char]['idx']:
|
||||
#lets see if its long enough
|
||||
possible_length=len(pattern) - index
|
||||
if possible_length>longest_match_yet:
|
||||
sub_pattern=pattern[(index+1):]
|
||||
match_so_far=read_a_char
|
||||
offset=f.tell()
|
||||
# print("Possible new Match starting with %s found at %d" % (read_a_char,offset))
|
||||
# print("trying to find rest of pattern '%s'" % sub_pattern)
|
||||
x=1
|
||||
for char_to_compare in sub_pattern:
|
||||
next_char=f.read(1)
|
||||
if not read_a_char:
|
||||
print("No more Chars to consume in File")
|
||||
break
|
||||
# print("comparing %s <> %s (%d)" % (next_char,char_to_compare,x))
|
||||
if next_char != char_to_compare:
|
||||
break
|
||||
match_so_far=match_so_far+next_char
|
||||
x=x+1
|
||||
# print("matching endet with %d matching chars (%d)" % (x,longest_match_yet))
|
||||
if x > longest_match_yet:
|
||||
#new longest Match
|
||||
print("found new longest match %s at %d" % (match_so_far,offset))
|
||||
longest_match_yet=x
|
||||
f.seek(offset)
|
||||
|
||||
if not read_a_char:
|
||||
print("No more Chars to consume in File")
|
||||
break
|
||||
12
codegrab/ips.awk
Normal file
12
codegrab/ips.awk
Normal file
@@ -0,0 +1,12 @@
|
||||
BEGIN{
|
||||
if (max=="") max=3
|
||||
cmd="for i in {0..255} | shuf "
|
||||
while ( ( cmd | getline result ) > 0 ) {
|
||||
print result
|
||||
}
|
||||
}
|
||||
{
|
||||
print
|
||||
for (i=4; i >max ; i-=1)
|
||||
print $i
|
||||
}
|
||||
50
codegrab/json_save.py
Normal file
50
codegrab/json_save.py
Normal file
@@ -0,0 +1,50 @@
|
||||
import simplejson
|
||||
import json
|
||||
|
||||
def put(data, filename):
|
||||
try:
|
||||
jsondata = simplejson.dumps(data, indent=4, skipkeys=True, sort_keys=True)
|
||||
fd = open(filename, 'w')
|
||||
fd.write(jsondata)
|
||||
fd.close()
|
||||
except Exception as e:
|
||||
print('ERROR writing', filename)
|
||||
print( e)
|
||||
pass
|
||||
|
||||
def get(filename):
|
||||
returndata = {}
|
||||
try:
|
||||
fd = open(filename, 'r')
|
||||
text = fd.read()
|
||||
fd.close()
|
||||
returndata = json.read(text)
|
||||
# Hm. this returns unicode keys...
|
||||
#returndata = simplejson.loads(text)
|
||||
except:
|
||||
print('COULD NOT LOAD:', filename)
|
||||
return returndata
|
||||
|
||||
|
||||
# print(mail.filename)
|
||||
# print(mail.status)
|
||||
|
||||
# import gzip
|
||||
# import json
|
||||
#
|
||||
# # writing
|
||||
# with gzip.GzipFile(jsonfilename, 'w') as outfile:
|
||||
# for obj in objects:
|
||||
# outfile.write(json.dumps(obj) + '\n')
|
||||
#
|
||||
# # reading
|
||||
# with gzip.GzipFile(jsonfilename, 'r') as isfile:
|
||||
# for line in infile:
|
||||
# obj = json.loads(line)
|
||||
# # process obj
|
||||
# picklefile=open("mails.dump",'wb')
|
||||
# for mail in list_of_mail:
|
||||
# pickle.dump(mail, picklefile )
|
||||
#
|
||||
# picklefile.close()
|
||||
|
||||
13
codegrab/sort.py
Normal file
13
codegrab/sort.py
Normal file
@@ -0,0 +1,13 @@
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
import re
|
||||
|
||||
pattern=re.compile("(: )([^;]+)")
|
||||
for file in os.listdir(sys.argv[1]):
|
||||
output=subprocess.check_output(["file","-Ni",file])
|
||||
match=pattern.search(output)
|
||||
mimetype=re.sub(r"\W","_",match.group(2))
|
||||
if not os.path.exists(mimetype):
|
||||
os.makedirs(mimetype)
|
||||
os.rename(file,mimetype+os.sep+file)
|
||||
Reference in New Issue
Block a user