-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
V1.0
- Loading branch information
Showing
12 changed files
with
402 additions
and
479 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,19 @@ | ||
from . import encoding, decoding | ||
from .execution import execute_command | ||
|
||
from .gethelpers import string_to_bytes, bytes_to_string | ||
|
||
#Parameterdecrypt --> Parameterdecrypt | ||
|
||
def Parameterdecrypt(selectedlang, path, data): | ||
data2 = encoding.encode_base64(data) | ||
output = execute_command(selectedlang, path, data2) | ||
if output is not False: | ||
return output.decode('utf-8') | ||
else: | ||
return data | ||
|
||
|
||
def Customrequestdecrypt(selectedlang, path, header, body): | ||
body2 = encoding.encode_base64(body) | ||
output = execute_command(selectedlang, path, body2, encoding.encode_base64(header)).decode('utf-8') | ||
if output is not False: | ||
return output.decode('utf-8') | ||
def Parameterdecrypt(selectedlang, path, data,headers_str=None): | ||
body_parameter_byte = list(string_to_bytes(data)) | ||
result = execute_command(selectedlang, path, body_parameter_byte,headers_str) | ||
if result is not False: | ||
body, header = result | ||
string_body = bytes_to_string(body) | ||
return string_body,header | ||
else: | ||
return body | ||
|
||
return data,headers_str | ||
|
||
def Customeditrequestdecrypt(selectedlang, path, header, body): | ||
body2 = encoding.encode_base64(body) | ||
header2 = encoding.encode_base64(header) | ||
|
||
output = execute_command(selectedlang, path, body2, header2) | ||
if output is not False: | ||
lines = output.splitlines() | ||
headerbase64, bodybase64 = lines[0], lines[1] | ||
|
||
header = decoding.decode_base64(headerbase64).decode('utf-8') | ||
body = decoding.decode_base64(bodybase64).decode('utf-8') | ||
|
||
return (header, body) | ||
else: | ||
|
||
return (header, body) | ||
|
||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,16 @@ | ||
from . import encoding, decoding | ||
from .execution import execute_command | ||
|
||
from .gethelpers import string_to_bytes, bytes_to_string | ||
|
||
#Jsonvalueencrypt --> Parameterencrypt | ||
|
||
def Parameterencrypt(selectedlang, path, data): | ||
output = execute_command(selectedlang, path, str(encoding.encode_base64(data))) | ||
|
||
if output is not False: | ||
return output.decode('utf-8') | ||
else: | ||
return data | ||
|
||
def Parameterencrypt(selectedlang, path, data,headers_str=None): | ||
body_parameter_byte = str(list(string_to_bytes(data))) | ||
result = execute_command(selectedlang, path, body_parameter_byte,headers_str) | ||
|
||
def Customrequestencrypt(selectedlang, path, header, body): | ||
output = execute_command(selectedlang, path, encoding.encode_base64(body), encoding.encode_base64(header)) | ||
|
||
if output is not False: | ||
return output.decode('utf-8') | ||
if result is not False: | ||
body, header = result | ||
string_body = bytes_to_string(body) | ||
return string_body,header | ||
else: | ||
return body | ||
|
||
|
||
|
||
def Customeditrequestencrypt(selectedlang, path, header, body): | ||
body2 = encoding.encode_base64(body) | ||
header2 = encoding.encode_base64(header) | ||
|
||
output = execute_command(selectedlang, path, body2, header2) | ||
if output is not False: | ||
lines = output.splitlines() | ||
headerbase64, bodybase64 = lines[0], lines[1] | ||
header = decoding.decode_base64(headerbase64).decode('utf-8') | ||
body = decoding.decode_base64(bodybase64).decode('utf-8') | ||
return (header, body) | ||
else: | ||
return (header, body) | ||
|
||
|
||
return data,headers_str |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from java.util import Arrays; | ||
from java.lang import String | ||
|
||
_helpers = None # Private variable to hold the helpers reference. | ||
|
||
def set_helpers(helpers): | ||
"""Set the helpers instance.""" | ||
global _helpers | ||
_helpers = helpers | ||
|
||
def get_helpers(): | ||
"""Get the helpers instance.""" | ||
if _helpers is None: | ||
raise RuntimeError("Helpers not initialized. Call `set_helpers` first.") | ||
return _helpers | ||
|
||
def string_to_bytes(string): | ||
"""Convert a string to bytes using helpers.""" | ||
return get_helpers().stringToBytes(string) | ||
|
||
def bytes_to_string(byte_data): | ||
"""Convert bytes to string using helpers.""" | ||
byte_data_clean = byte_data.strip('[]') | ||
byte_data2 = [int(code.strip()) for code in byte_data_clean.split(',')] | ||
#return get_helpers().bytesToString(byte_data2) # for some reason helper API gives error or remove some non ascii data from string results in wrong string for non ascii or binary data | ||
return ''.join(chr(code) for code in byte_data2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import os | ||
import tempfile | ||
import random | ||
import string | ||
import shutil | ||
|
||
from .gui import logerrors | ||
|
||
user_home = os.path.expanduser("~") | ||
pycript_dir = os.path.join(user_home, ".pycript") | ||
|
||
def parse_temp_file_output(original_data, original_header, temp_file_path): | ||
with open(temp_file_path, 'rb') as temp_file: | ||
file_content = temp_file.read() | ||
body_end_marker = b'\n--BODY_END--\n' | ||
|
||
logerrors("User Script Created File Output:") | ||
logerrors(file_content) | ||
|
||
# Split the file content using the marker | ||
parts = file_content.split(body_end_marker, 1) | ||
|
||
# Extract body data | ||
body_data = parts[0] | ||
|
||
# Extract header data if present, otherwise use the original header | ||
if len(parts) > 1 and parts[1].strip(): # Check if header exists and is not empty | ||
header_data = parts[1].strip() | ||
else: | ||
header_data = original_header | ||
return body_data, header_data | ||
|
||
|
||
def create_temp_file(data, headervalue=None): | ||
# Get the temp directory path | ||
random_file_name = ''.join([random.choice(string.ascii_letters + string.digits) for _ in range(12)]) | ||
file_path = os.path.join(pycript_dir, random_file_name) | ||
|
||
# Write data to the file | ||
with open(file_path, "wb") as file: | ||
file.write(bytes(data)) # Write the byte array directly to the file | ||
file.write(b'\n--BODY_END--\n') # Write the binary body end marker | ||
if headervalue is not None: | ||
file.write(headervalue.encode('utf-8')) | ||
|
||
return file_path | ||
|
||
|
||
def create_temp_dir(): | ||
|
||
if not os.path.exists(pycript_dir): | ||
os.makedirs(pycript_dir) | ||
temp_dir = tempfile.mkdtemp(dir=pycript_dir) | ||
|
||
|
||
def delete_temp_folder(): | ||
if os.path.exists(pycript_dir): | ||
shutil.rmtree(pycript_dir) # Remove the directory and all its contents | ||
print("Temporary directory and its contents have been deleted.") | ||
else: | ||
print("Directory does not exist.") | ||
|
Oops, something went wrong.