Browse Source

Updated: added --quick

bugz 5 years ago
parent
commit
40abe008fe
2 changed files with 239 additions and 147 deletions
  1. 239 144
      dataLoad.py
  2. 0 3
      imager.py

+ 239 - 144
dataLoad.py

@@ -17,24 +17,13 @@ import imager
 parser = argparse.ArgumentParser(description="S0urce.io utility program.")
 parser.add_argument("--download", help="Download Images", action="store_true")
 parser.add_argument("--train", help="Convert Images to Text", action="store_true")
+parser.add_argument("--quick", help="Quick convert Images to Text", action="store_true")
 parser.add_argument("--update", help="Update s0urce.js script", action="store_true")
-parser.add_argument(
-    "JSON", type=str, nargs="?", help="Filename to save results", default="test.js"
+parser.add_argument("JSON", type=str, nargs="?", help="Filename to save results", default="test.js"
 )
 args = parser.parse_args()
 # pprint(args)
 
-# Should we add the JSON in a file? (True is filename, False = do not do)
-# JSONME = 'test.js'
-JSONME = args.JSON
-
-# NOTE: To begin the insert of the JSONIFIED image and word its
-# // T
-# A JS comment with a uppercase T
-# To stop its
-# // t
-# A JS comment with a lowercase t
-
 # httpbin.org/headers
 sess = requests.Session()
 head = {
@@ -144,134 +133,6 @@ def download(howhard, index):
             )
         )
 
-
-def img_point(pix, x, y):
-    """
-    img_point, returns a pixel of an image,
-    given the x and y on the image.
-    """
-    return pix[x, y]
-
-
-def img_avg(pix, x, y):
-    """
-    img_avg, returns the average brightness 0-255,
-    given pixel, and the x and y on the image calls img_point,
-    to get the individual rgb values to calculate,
-    brightness. (Grey scale)
-    """
-    rgb = img_point(pix, x, y)
-    # if(im.mode == 'P'):
-    #    rgb = pal[rgb*3:(rgb+1)*3]
-
-    # if(im.mode == 'I'):
-    #    return rgb >> 8
-
-    return int((rgb[0] + rgb[1] + rgb[2]) / 3)
-
-
-def is_set(pix, x, y):
-    global INTENSITY
-    """
-    is_set, returns True or False of calculating,
-    the brightness of the given point on a image,
-    compared to given intensity.
-    
-    True means the brightness at the given x and y,
-    is Less Than which means its dark.
-    
-    False means the brightness at the given x and y,
-    is Greater Than which means its bright. (Grey Scale)
-    """
-    avg = img_avg(pix, x, y)
-    return avg < INTENSITY
-
-
-def is_green(pix, x, y):
-    """
-    Is this pixel Green?
-    """
-    (red, green, blue, _) = img_point(pix, x, y)
-    # Find the difference between green and the other values.
-    other = red
-    if blue > other:
-        other = blue
-    diff = green - other
-    return diff > GREEN_DIFF
-
-
-def scan_img(pix, size):
-    """
-    scan_img, looks at a image and looks for dark pixels,
-    if it is a dark pixel record the number and resize the,
-    returned values to show where the most dark pixels on the,
-    image are located. (Grey Scale)
-    
-    given pixel, and image size.
-    returns start x, y and end x, y and total number of dark pixels.
-    """
-    total = 0
-    sx = size[0]
-    ex = 0
-    sy = size[1]
-    ey = 0
-
-    for y in range(0, size[1]):
-        for x in range(0, size[0]):
-            pnt_is = is_set(pix, x, y)
-            if pnt_is:
-                total += 1
-                if x < sx:
-                    sx = x
-                if x > ex:
-                    ex = x
-                if y < sy:
-                    sy = y
-                if y > ey:
-                    ey = y
-
-    # print (sx,ex,sy,ey)
-    # give us a little border to work with
-    if sx > 0:
-        sx -= 1
-    if ex < size[0]:
-        ex += 1
-
-    if sy > 0:
-        sy -= 1
-    if ey < size[1]:
-        ey += 1
-
-    # print (sx,ex,sy,ey)
-    return (sx, sy, ex, ey, total)
-
-
-def output_image(pix, size):
-    """
-    For the size of the area we have reduced down to where the majority of dark pixels,
-    are located, store all that into a list and return the list.
-    
-    given pixel for function passing.
-    returns multiple strings in a list that are edited to use characters to represent,
-    the dark and light pixels of the image. (Grey Scale)
-    """
-    result = []
-    ex = size[0]
-    sx = 0
-    ey = size[1]
-    sy = 0
-    for y in range(sy, ey):
-        s = ""
-        for x in range(sx, ex):
-            # if is_set(pix, x, y):
-            if not is_green(pix, x, y):
-                s += ON
-            else:
-                s += OFF
-        result.append(s)
-
-    return result
-
 def run(difficult, index):
     """
     run, represents a single execution of components to the image, (Actuall we do it 1 category at a time instead of just 1 single execution )
@@ -323,6 +184,221 @@ def run(difficult, index):
 
 
 key_word = {}
+misery = {}
+
+def quicktrain(difficult):
+    """
+    Quickly convert the images to text based upon filesize and image size.
+    """
+
+    quick = {
+  "100_24_7874": "client",
+  "100_24_7897": "status",
+  "100_24_7929": "vector",
+  "100_24_7937": "encode",
+  "101_24_7761": "getkey",
+  "101_24_7906": "server",
+  "101_24_7922": "module",
+  "101_24_7968": "socket",
+  "101_24_7984": "config",
+  "102_24_7983": "export",
+  "102_24_7987": "number",
+  "102_24_7997": "buffer",
+  "102_24_8000": "getlog",
+  "102_24_8010": "length",
+  "102_24_8019": "global",
+  "102_24_8075": "delete",
+  "102_24_8087": "domain",
+  "103_24_8085": "remove",
+  "103_24_8099": "upload",
+  "103_24_8102": "sizeof",
+  "103_24_8122": "system",
+  "103_24_8139": "threat",
+  "103_24_8159": "userid",
+  "104_24_8146": "thread",
+  "114_24_9012": "getpass",
+  "115_24_8980": "filedir",
+  "115_24_9063": "account",
+  "115_24_9113": "cookies",
+  "116_24_9036": "newline",
+  "116_24_9072": "getfile",
+  "116_24_9089": "newhost",
+  "116_24_9090": "process",
+  "116_24_9122": "channel",
+  "116_24_9136": "connect",
+  "117_24_9101": "setping",
+  "117_24_9168": "encrypt",
+  "117_24_9176": "decrypt",
+  "117_24_9182": "setport",
+  "117_24_9248": "package",
+  "117_24_9297": "hexagon",
+  "118_24_9280": "getinfo",
+  "118_24_9310": "getping",
+  "119_24_9300": "syscall",
+  "119_24_9321": "command",
+  "131_24_10113": "generate",
+  "131_24_10275": "userport",
+  "132_24_10329": "download",
+  "132_24_10342": "datatype",
+  "132_24_10356": "username",
+  "132_24_10379": "filetype",
+  "132_24_10395": "protocol",
+  "132_24_10404": "urlcheck",
+  "133_24_10292": "response",
+  "134_24_10420": "setstats",
+  "134_24_10531": "setnewid",
+  "134_24_10557": "password",
+  "136_24_10707": "fillgrid",
+  "145_24_11396": "loadbytes",
+  "146_24_11393": "writefile",
+  "147_24_11595": "setcookie",
+  "148_24_11374": "eventtype",
+  "148_24_11610": "newserver",
+  "148_24_11626": "responder",
+  "149_24_11614": "gridwidth",
+  "161_24_12648": "hostserver",
+  "163_24_12693": "listconfig",
+  "163_24_12750": "callmodule",
+  "164_24_12800": "disconnect",
+  "164_24_12835": "gridheight",
+  "176_24_13510": "mergesocket",
+  "177_24_13789": "wordcounter",
+  "177_24_13819": "accountname",
+  "177_24_13824": "encryptfile",
+  "177_24_13855": "serverproxy",
+  "177_24_13871": "decryptfile",
+  "177_24_13873": "constructor",
+  "178_24_13825": "findpackage",
+  "179_24_13843": "blockthreat",
+  "179_24_14001": "setnewproxy",
+  "192_24_14660": "dodecahedron",
+  "192_24_15084": "destroybatch",
+  "193_24_14925": "tempdatapass",
+  "193_24_14979": "eventlistdir",
+  "194_24_15129": "deleteallids",
+  "195_24_15252": "loadaltevent",
+  "207_24_16020": "batchallfiles",
+  "207_24_16074": "sendintelpass",
+  "208_24_16209": "getpartoffile",
+  "208_24_16274": "unpacktmpfile",
+  "208_24_16287": "hostnewserver",
+  "208_24_16317": "systemportkey",
+  "209_24_15651": "rootcookieset",
+  "209_24_16185": "bufferpingset",
+  "209_24_16243": "sizeofhexagon",
+  "209_24_16338": "patcheventlog",
+  "209_24_16357": "checkhttptype",
+  "223_24_17412": "changeusername",
+  "223_24_17418": "systemgridtype",
+  "224_24_17265": "fileexpresslog",
+  "224_24_17287": "getmysqldomain",
+  "224_24_17484": "getxmlprotocol",
+  "224_24_17487": "httpbuffersize",
+  "224_24_17506": "emitconfiglist",
+  "225_24_17005": "changepassword",
+  "237_24_18534": "uploaduserstats",
+  "238_24_18712": "encodenewfolder",
+  "239_24_18670": "ghostfilesystem",
+  "239_24_18700": "getdatapassword",
+  "239_24_18710": "statusofprocess",
+  "239_24_18713": "removeoldcookie",
+  "239_24_18744": "removenewcookie",
+  "241_24_18811": "createnewsocket",
+  "253_24_19681": "generatecodepack",
+  "254_24_19585": "createnewpackage",
+  "254_24_19791": "disconnectserver",
+  "254_24_19901": "decryptdatabatch",
+  "255_24_19874": "includedirectory",
+  "255_24_19938": "loadregisterlist",
+  "256_24_19399": "createfilethread",
+  "256_24_19577": "respondertimeout",
+  "268_24_20945": "channelsetpackage",
+  "268_24_20953": "disconnectchannel",
+  "269_24_20857": "create2axisvector",
+  "270_24_21037": "create3axisvector",
+  "271_24_21016": "joinnetworkclient",
+  "285_24_22237": "getfirewallchannel",
+  "288_24_22241": "loadloggedpassword",
+  "300_24_23305": "exportconfigpackage",
+  "314_24_24079": "encryptunpackedbatch",
+  "52_24_4127": "xml",
+  "52_24_4170": "val",
+  "53_24_4188": "url",
+  "54_24_4316": "net",
+  "54_24_4350": "key",
+  "55_24_4381": "log",
+  "55_24_4393": "set",
+  "55_24_4417": "dir",
+  "56_24_4487": "get",
+  "57_24_4504": "num",
+  "57_24_4524": "com",
+  "57_24_4553": "bit",
+  "57_24_4593": "add",
+  "60_24_4770": "add",
+  "68_24_5431": "http",
+  "69_24_5525": "pass",
+  "70_24_5392": "temp",
+  "70_24_5444": "type",
+  "70_24_5469": "list",
+  "70_24_5529": "file",
+  "70_24_5545": "loop",
+  "70_24_5579": "ping",
+  "70_24_5591": "port",
+  "71_24_5544": "left",
+  "71_24_5572": "size",
+  "71_24_5610": "call",
+  "71_24_5612": "root",
+  "71_24_5632": "part",
+  "71_24_5644": "init",
+  "71_24_5649": "host",
+  "71_24_5656": "poly",
+  "71_24_5667": "info",
+  "71_24_5748": "user",
+  "72_24_5559": "join",
+  "72_24_5699": "anon",
+  "72_24_5753": "data",
+  "73_24_5678": "stat",
+  "74_24_5861": "send",
+  "75_24_6004": "load",
+  "83_24_6579": "proxy",
+  "84_24_6417": "event",
+  "85_24_6661": "intel",
+  "85_24_6693": "right",
+  "85_24_6735": "bytes",
+  "86_24_6678": "mysql",
+  "86_24_6762": "write",
+  "87_24_6800": "ghost",
+  "87_24_6911": "count",
+  "88_24_6908": "reset",
+  "88_24_6946": "point",
+  "88_24_7003": "getid",
+  "99_24_7741": "signal",
+  "99_24_7796": "handle"
+}
+
+    for x in range(0, 70):
+        fname = image_filename(difficult, x)
+
+        if not os.path.exists(fname):
+            break
+
+        # Output the image
+        im = Image.open(fname)
+        # imager.output_image(im)
+        size = im.size
+        filesize = os.path.getsize(fname)
+   
+        k = "{0}_{1}_{2}".format(*size, os.path.getsize(fname))
+        if k in quick:
+            correct = quick[k]
+        else:
+            imager.output_image(im)            
+            print("well, shit.")
+            sys.exit(5)
+        print(fname, correct)            
+        key_word[f'{difficult}_{x}'] = correct
+        # misery[correct] = { 'img_size': "{0},{1}".format(*size), 'filesize': os.path.getsize(fname) }
+        misery[correct] = "{0}_{1}_{2}".format(*size, os.path.getsize(fname))
 
 def autotrain(difficult):
     """
@@ -362,27 +438,38 @@ def autotrain(difficult):
             if (word != '') and (word in VALID_WORDS):
                 key_word[f'{difficult}_{x}'] = word
                 im = Image.open(fname)
-                imager.output_image(im)
-                # pix = im.load()
+                # imager.output_image(im)
                 size = im.size
                 with open('words.txt', 'a') as f:
                     f.write(f'{difficult}_{x} = {size[0]} x {size[1]} is {word}\n')
                 print(word)
+                if word in misery:
+                    print("Awwww SHIT! ", word)
+
+                misery["{0}_{1}_{2}".format(*size, os.path.getsize(fname))] = word
+
+                # misery[word] = { 'img_size': "{0},{1}".format(*size), 'filesize': os.path.getsize(fname) }                
             else:
                 print("UNKNOWN", word)
                 # Output the image
                 im = Image.open(fname)
                 imager.output_image(im)
-                # pix = im.load()
                 size = im.size
                 # img_s = output_image(pix, size)
                 # for l in img_s:
                 #     print(l)
                 correct = input("Word: ")
                 key_word[f'{difficult}_{x}'] = correct
+                # misery[correct] = { 'img_size': "{0},{1}".format(*size), 'filesize': os.path.getsize(fname) }
+                if correct in misery:
+                    print("Awwww SHIT! ", correct)
+                    
+                misery["{0}_{1}_{2}".format(*size, os.path.getsize(fname))] = correct
                 with open('words.txt', 'a') as f:
                     f.write(f'{difficult}_{x} = {size[0]} x {size[1]} is {correct}\n')
 
+    with open('misery.json', 'w') as fp:
+        json.dump(misery, fp, indent=2, sort_keys=True)
 
 # Now to call all the previous functions
 if args.download:
@@ -402,6 +489,14 @@ if args.train:
     with open(args.JSON, 'w') as fp:
         json.dump(key_word, fp, sort_keys=True, indent=2)
 
+if args.quick:
+    # Img Processing: Run thru every single category and every single word
+    for level in ["e", "m", "h"]:
+        quicktrain(level)
+    with open(args.JSON, 'w') as fp:
+        json.dump(key_word, fp, sort_keys=True, indent=2)
+
+
 if args.update:
     with open(args.JSON, 'r') as fp:
         key_word = json.load(fp)

+ 0 - 3
imager.py

@@ -6,9 +6,6 @@ import subprocess
 ON = "X"  # Dark pixel in an image
 OFF = "."  # Light pixel in an image
 
-INTENSITY = 75
-# How bright does something have to be to trigger it being a dark or light pixel?
-# Looks like around 75 removes the extra stuff that s0urce.io does to prevent it from being just matching images.
 
 GREEN_DIFF = 10
 # How much brighter the green channel must be (compared to the others),