Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import base64
- import time
- from io import BytesIO
- import pyocr.builders
- import selenium.webdriver.support.ui as ui
- from PIL import Image
- from selenium import webdriver
- SITE = '' # ovh noVnc site
- tools = pyocr.get_available_tools()
- tool = tools[0]
- ff = webdriver.Firefox()
- ff.get(SITE)
- wait = ui.WebDriverWait(ff, 100)
- canvas = wait.until(lambda ff: ff.find_element_by_css_selector('canvas'))
- time.sleep(3)
- def decode_screen():
- imgb64 = ff.execute_script("return arguments[0].toDataURL('image/png').substring(21);", canvas)
- image = Image.open(BytesIO(base64.b64decode(imgb64)))
- return image
- offsetx = 10
- offsety = 10
- sizex = 8
- sizey = 16
- transbox = {
- 0b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000: ' ',
- 0b00000000000000000000000000000000000110000010010001000010010001100100101001010010011000100100001000100100000110000000000000000000: '0',
- 0b00000000000000000000000000000000000010000001100000101000000010000000100000001000000010000000100000001000001111100000000000000000: '1',
- 0b00000000000000000000000000000000001111000100001001000010000000100000110000010000001000000100000001000000011111100000000000000000: '2',
- 0b00000000000000000000000000000000001111000100001001000010000000100001110000000010000000100100001001000010001111000000000000000000: '3',
- 0b00000000000000000000000000000000000001000000110000010100001001000100010001000100011111100000010000000100000001000000000000000000: '4',
- 0b00000000000000000000000000000000011111100100000001000000010000000111110000000010000000100000001001000010001111000000000000000000: '5',
- 0b00000000000000000000000000000000000111000010000001000000010000000111110001000010010000100100001001000010001111000000000000000000: '6',
- 0b00000000000000000000000000000000011111100000001000000010000001000000010000000100000010000000100000001000000010000000000000000000: '7',
- 0b00000000000000000000000000000000001111000100001001000010010000100011110001000010010000100100001001000010001111000000000000000000: '8',
- 0b00000000000000000000000000000000001111000100001001000010010000100011111000000010000000100000001000000100001110000000000000000000: '9',
- 0b00000000000000000000000000000000000000000000000000111100010000100000001000111110010000100100001001000110001110100000000000000000: 'a',
- 0b00000000000000000000000001000000010000000100000001011100011000100100001001000010010000100100001001100010010111000000000000000000: 'b',
- 0b00000000000000000000000000000000000000000000000000111100010000100100000001000000010000000100000001000010001111000000000000000000: 'c',
- 0b00000000000000000000000000000010000000100000001000111010010001100100001001000010010000100100001001000110001110100000000000000000: 'd',
- 0b00000000000000000000000000000000000000000000000000111100010000100100001001111110010000000100000001000010001111000000000000000000: 'e',
- 0b00000000000000000000000000001100000100000001000000010000011111000001000000010000000100000001000000010000000100000000000000000000: 'f',
- 0b00000000000000000000000000000000000000000000001000111010010001000100010001000100001110000010000000111100010000100100001000111100: 'g',
- 0b00000000000000000000000001000000010000000100000001011100011000100100001001000010010000100100001001000010010000100000000000000000: 'h',
- 0b00000000000000000000000000001000000010000000000000011000000010000000100000001000000010000000100000001000001111100000000000000000: 'i',
- 0b00000000000000000000000000000100000001000000000000001100000001000000010000000100000001000000010000000100000001000100100000110000: 'j',
- 0b00000000000000000000000001000000010000000100000001000100010010000101000001100000010100000100100001000100010000100000000000000000: 'k',
- 0b00000000000000000000000000011000000010000000100000001000000010000000100000001000000010000000100000001000001111100000000000000000: 'l',
- 0b00000000000000000000000000000000000000000000000001110110010010010100100101001001010010010100100101001001010010010000000000000000: 'm',
- 0b00000000000000000000000000000000000000000000000001011100011000100100001001000010010000100100001001000010010000100000000000000000: 'n',
- 0b00000000000000000000000000000000000000000000000000111100010000100100001001000010010000100100001001000010001111000000000000000000: 'o',
- 0b00000000000000000000000000000000000000000000000001011100011000100100001001000010010000100100001001100010010111000100000001000000: 'p',
- 0b00000000000000000000000000000000000000000000000000111010010001100100001001000010010000100100001001000110001110100000001000000010: 'q',
- 0b00000000000000000000000000000000000000000000000001011100011000100100001001000000010000000100000001000000010000000000000000000000: 'r',
- 0b00000000000000000000000000000000000000000000000000111100010000100100000000110000000011000000001001000010001111000000000000000000: 's',
- 0b00000000000000000000000000000000000100000001000000010000011111000001000000010000000100000001000000010000000011000000000000000000: 't',
- 0b00000000000000000000000000000000000000000000000001000010010000100100001001000010010000100100001001000110001110100000000000000000: 'u',
- 0b00000000000000000000000000000000000000000000000001000010010000100100001000100100001001000010010000011000000110000000000000000000: 'v',
- 0b00000000000000000000000000000000000000000000000001000001010010010100100101001001010010010100100101001001001101100000000000000000: 'w',
- 0b00000000000000000000000000000000000000000000000001000010010000100010010000011000000110000010010001000010010000100000000000000000: 'x',
- 0b00000000000000000000000000000000000000000000000001000010010000100100001001000010010000100010011000011010000000100000001000111100: 'y',
- 0b00000000000000000000000000000000000000000000000001111110000000100000010000001000000100000010000001000000011111100000000000000000: 'z',
- 0b00000000000000000000000000000000000110000010010000100100010000100100001001111110010000100100001001000010010000100000000000000000: 'A',
- 0b00000000000000000000000000000000011111000100001001000010010000100111110001000010010000100100001001000010011111000000000000000000: 'B',
- 0b00000000000000000000000000000000001111000100001001000010010000000100000001000000010000000100001001000010001111000000000000000000: 'C',
- 0b00000000000000000000000000000000011110000100010001000010010000100100001001000010010000100100001001000100011110000000000000000000: 'D',
- 0b00000000000000000000000000000000011111100100000001000000010000000111110001000000010000000100000001000000011111100000000000000000: 'E',
- 0b00000000000000000000000000000000011111100100000001000000010000000111110001000000010000000100000001000000010000000000000000000000: 'F',
- 0b00000000000000000000000000000000001111000100001001000010010000000100000001001110010000100100001001000110001110100000000000000000: 'G',
- 0b00000000000000000000000000000000010000100100001001000010010000100111111001000010010000100100001001000010010000100000000000000000: 'H',
- 0b00000000000000000000000000000000001111100000100000001000000010000000100000001000000010000000100000001000001111100000000000000000: 'I',
- 0b00000000000000000000000000000000000111110000010000000100000001000000010000000100000001000100010001000100001110000000000000000000: 'J',
- 0b00000000000000000000000000000000010000100100010001001000010100000110000001100000010100000100100001000100010000100000000000000000: 'K',
- 0b00000000000000000000000000000000010000000100000001000000010000000100000001000000010000000100000001000000011111100000000000000000: 'L',
- 0b00000000000000000000000000000000010000100100001001100110011001100101101001011010010000100100001001000010010000100000000000000000: 'M',
- 0b00000000000000000000000000000000010000100110001001100010010100100101001001001010010010100100011001000110010000100000000000000000: 'N',
- 0b00000000000000000000000000000000001111000100001001000010010000100100001001000010010000100100001001000010001111000000000000000000: 'O',
- 0b00000000000000000000000000000000011111000100001001000010010000100111110001000000010000000100000001000000010000000000000000000000: 'P',
- 0b00000000000000000000000000000000001111000100001001000010010000100100001001000010010000100101101001100110001111000000001100000000: 'Q',
- 0b00000000000000000000000000000000011111000100001001000010010000100111110001001000010001000100010001000010010000100000000000000000: 'R',
- 0b00000000000000000000000000000000001111000100001001000010010000000011000000001100000000100100001001000010001111000000000000000000: 'S',
- 0b00000000000000000000000000000000011111110000100000001000000010000000100000001000000010000000100000001000000010000000000000000000: 'T',
- 0b00000000000000000000000000000000010000100100001001000010010000100100001001000010010000100100001001000010001111000000000000000000: 'U',
- 0b00000000000000000000000000000000010000010100000101000001001000100010001000100010000101000001010000001000000010000000000000000000: 'V',
- 0b00000000000000000000000000000000010000100100001000100100001001000001100000011000001001000010010001000010010000100000000000000000: 'X',
- 0b00000000000000000000000000000000010000010100000100100010001000100001010000001000000010000000100000001000000010000000000000000000: 'Y',
- 0b00000000000000000000000000000000011111100000001000000010000001000000100000010000001000000100000001000000011111100000000000000000: 'Z',
- 0b00000000000000000000000000000000000010000000100000001000000010000000100000001000000010000000000000001000000010000000000000000000: '!',
- 0b00000000000000000000000000000000010000000100000000100000000100000001000000001000000010000000010000000010000000100000000000000000: '\\',
- 0b00000000000000000010001000100010001000100010001000000000000000000000000000000000000000000000000000000000000000000000000000000000: '"',
- 0b00000000000000000000000000000000000100100001001000010010011111100010010000100100011111100100100001001000010010000000000000000000: '#',
- 0b00000000000000000000000000000000000010000011111001001001010010000011100000001110000010010100100100111110000010000000000000000000: '$',
- 0b00000000000000000000000000000000001100010100101001001010001101000000100000001000000101100010100100101001010001100000000000000000: '%',
- 0b00000000000000000000000000000000000111000010001000100010000101000001100000101001010001010100001001000110001110010000000000000000: '&',
- 0b00000000000000000000100000001000000010000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000: '\'',
- 0b00000000000000000000000000000100000010000000100000010000000100000001000000010000000100000001000000001000000010000000010000000000: '(',
- 0b00000000000000000000000000100000000100000001000000001000000010000000100000001000000010000000100000010000000100000010000000000000: ')',
- 0b00000000000000000000000000000000000000000000000000001000010010010010101000011100001010100100100100001000000000000000000000000000: '*',
- 0b00000000000000000000000000000000000000000000000000001000000010000000100001111111000010000000100000001000000000000000000000000000: '+',
- 0b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011000000010000000100000010000: ',',
- 0b00000000000000000000000000000000000000000000000000000000000000000000000000111100000000000000000000000000000000000000000000000000: '-',
- 0b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011000000110000000000000000000: '.',
- 0b00000000000000000000000000000000000000100000001000000100000010000000100000010000000100000010000001000000010000000000000000000000: '/',
- 0b00000000000000000000000000000000000000000000000000011000000110000000000000000000000000000001100000011000000000000000000000000000: ':',
- 0b00000000000000000000000000000000000000000000000000011000000110000000000000000000000000000001100000001000000010000001000000000000: ';',
- 0b00000000000000000000000000000000000000000000001000000100000010000001000000100000000100000000100000000100000000100000000000000000: '<',
- 0b00000000000000000000000000000000000000000000000000000000011111100000000000000000000000000111111000000000000000000000000000000000: '=',
- 0b00000000000000000000000000000000000000000100000000100000000100000000100000000100000010000001000000100000010000000000000000000000: '>',
- }
- def charbox_at(x, y):
- startx = offsetx + sizex * x
- starty = offsety + sizey * y
- box = (startx, starty, startx + sizex, starty + sizey)
- return box
- def char_image(image, x, y):
- return image.crop(charbox_at(x, y))
- def char_to_hashint(image, charbox):
- data = [1 if x != 0 else 0 for x in image.crop(charbox).tobytes()[::4]]
- # return ''.join([str(x) for x in data])
- res = 0
- for bit in data:
- res = (res << 1) | bit
- return res
- def decode_char_at(image, x, y):
- chbox = charbox_at(x, y)
- chsign = char_to_hashint(image, chbox)
- if chsign in transbox:
- return transbox[chsign]
- else:
- return '?'
- def decode_image(image):
- resw = image.width // sizex
- resh = image.height // sizey
- res = [0] * (resw * resh)
- for y in range(0, resh):
- for x in range(0, resw):
- res[resw * y + x] = decode_char_at(image, x, y)
- return res
- if __name__ == '__main__':
- image = decode_screen()
- txtimg = decode_image(image)
- image.show()
- print(txtimg)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement