Guest User

Untitled

a guest
Mar 1st, 2022
1,717
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.54 KB | None | 0 0
  1. import json
  2. from pathlib import *
  3. import requests
  4. import zipfile
  5. import os
  6. from random import randint
  7. import shutil
  8.  
  9.  
  10. def search_in_log(PATH, zip_path=None):
  11.     list_result = []
  12.     print('Ищем .log...\n')
  13.     paths = Path(PATH).glob('**/*.log')
  14.     for path in paths:
  15.         try:
  16.             if zip_path is not None:
  17.                 print('.log in ZIP:', zip_path)
  18.             print('.log:', path)
  19.             with open(path, 'r', encoding='utf-8', errors='ignore') as file:
  20.                 str_l = file.read()
  21.                 parse_result = parse_hash_adr(str_l, path, zip_path)
  22.  
  23.                 if parse_result[1] or parse_result[2]:
  24.                     list_result.append(parse_result)
  25.         except Exception as Error:
  26.             print('Ошибка открытия файла', Error)
  27.     return list_result
  28.  
  29. def search_in_zip(PATH):
  30.     table_list = []
  31.     print('Ищем ZIP...\n')
  32.     zip_path = Path(PATH).glob('**/*.zip')
  33.     if not os.path.isdir('temp'):
  34.         os.mkdir('temp')
  35.     for path in zip_path:
  36.         name_dir = os.path.join('temp', str(randint(9999, 999999)))
  37.         os.mkdir(name_dir)
  38.         if zipfile.is_zipfile(path):
  39.             print('ZIP:', str(path))
  40.             try:
  41.                 with zipfile.ZipFile(path, 'r') as zip_f:
  42.                     for file in zip_f.infolist():
  43.                         if '.log' in str(file):
  44.                             zipfile.ZipFile.extract(zip_f, file, name_dir)
  45.                             table_list += search_in_log(name_dir, zip_path=path)
  46.             except Exception as Error:
  47.                 print('Ошибка открытия ZIP', Error)
  48.         else:
  49.             print('Не корректный файл', path)
  50.         shutil.rmtree(name_dir)
  51.     shutil.rmtree('temp')
  52.     return table_list
  53.  
  54.  
  55. def parse_hash_adr(str_fish, path, zip_path):
  56.     hash = None
  57.     addreses = []
  58.  
  59.     try:
  60.         if str_fish.find('"KeyringController":{"vault":"') != -1:
  61.             str_l = str_fish[
  62.                     str_fish.find('"KeyringController":{"vault":"') + 30:str_fish.find(',"MetaMetricsController"') - 2]
  63.             hash = str_l.replace(r'\\', '')
  64.             print('Хэш:', hash)
  65.         else:
  66.             print('Хэш не найден')
  67.     except Exception as Error:
  68.         print('Ошибка поиска хэша', Error)
  69.  
  70.     try:
  71.         if str_fish.find('"cachedBalances":') != -1:
  72.             str_fish_sr = str_fish[str_fish.find('"cachedBalances":') + 17:]
  73.             sym = 0
  74.             sr_end = 0
  75.             for count, s in enumerate(str_fish_sr):
  76.                 if s == '{':
  77.                     sym += 1
  78.                 if s == '}':
  79.                     sym -= 1
  80.                 if sym == 0:
  81.                     sr_end = count
  82.                     break
  83.             json_hash_adr = json.loads(str_fish_sr[:sr_end + 1])
  84.             for value in json_hash_adr.values():
  85.                 if value:
  86.                     for k, v in value.items():
  87.                         if k not in addreses:
  88.                             addreses.append(k)
  89.                             print('Найден адрес:', k)
  90.         else:
  91.             print('Адреса не найдены')
  92.     except Exception as Error:
  93.         print('Ошибка поиска адресов', Error)
  94.     if zip_path:
  95.         list_hash_adr = [str(zip_path)[5:], hash, addreses]
  96.     else:
  97.         list_hash_adr = [str(path)[5:], hash, addreses]
  98.     return list_hash_adr
  99.  
  100.  
  101. def check_balance(adr_l):
  102.     adr_balance_dict = {}
  103.     for adr in adr_l:
  104.         adr_balance_dict.update({adr: None})
  105.         try:
  106.             for i in range(3):
  107.                 response = requests.get('https://openapi.debank.com/v1/user/total_balance?id=' + adr,
  108.                                         params='accept: application/json')
  109.                 if response.status_code == 200:
  110.                     #print(response.json())
  111.                     if 'total_usd_value' in response.json():
  112.                         adr_balance_dict.update({adr: int(response.json()['total_usd_value'])})
  113.                         break
  114.                 elif response.status_code == 400:
  115.                     print('Ошибка проверки баланса, некорректный адрес')
  116.                     break
  117.         except Exception as Err:
  118.             print('Ошибка проверки баланса', Err)
  119.     return adr_balance_dict
  120.  
  121.  
  122. def check(zip_checkbox, folder_checkbox, balance_checkbox, PATH):
  123.     PATH = r'\\?\\' + str(PATH)
  124.     result_list = []
  125.     balance_dict = {}
  126.     if zip_checkbox:
  127.         result_list += search_in_zip(PATH)
  128.  
  129.     if folder_checkbox:
  130.         result_list += search_in_log(PATH)
  131.  
  132.     if balance_checkbox and result_list:
  133.         adress_list = []
  134.         for item in result_list:
  135.             try:
  136.                 if item[2]:
  137.                     for adress in item[2]:
  138.                         if adress not in adress_list:
  139.                             adress_list.append(adress)
  140.             except Exception as Error:
  141.                 print('Ошибка проверки баланса', Error)
  142.  
  143.         balance_dict = check_balance(adress_list)
  144.  
  145.     if not result_list:
  146.         print('Ничего не найдено')
  147.  
  148.     return result_list, balance_dict
  149.  
  150.  
  151. def save_results(list_table, path):
  152.     if list_table:
  153.         try:
  154.             with open(path, 'w') as f:
  155.                 for row in list_table:
  156.                     f.write(str(row) + '\n')
  157.         except Exception as Err:
  158.             print('Ошибка сохранения', Err)
  159.  
Advertisement
Add Comment
Please, Sign In to add comment