Closed rikhtehgaran closed 1 week ago
Also, i repeated the path with the quotation it returned invalid path error:
i have done some changes: in config file I put this:
# Configure colors for printing messages
YELLOW = '\033[93m'
BLUE = '\033[94m'
GREEN = '\033[92m'
RED = '\033[91m'
RESET = '\033[0m'
# Configure YakPro packages path
YAKPRO = "/home/mrg/www/Test/obfuscator/new/php-obfuscator/yakpro-po/yakpro-po.php"
# Log filename
log_filename = 'app.log'
Also, I changed this method:
def obfuscate_php(input_file, obfuscation_options, create_backup, output_directory):
if create_backup:
backup_file = f"{os.path.splitext(input_file)[0]}_backup.php"
shutil.copy2(input_file, backup_file)
logging.info(f"Created backup: {backup_file}")
try:
# Create the directory if it doesn't exist
os.makedirs(output_directory, exist_ok=True)
output_file = os.path.join(output_directory, f"obfuscated_{os.path.basename(input_file)}")
logging.info(f"Obfuscating {input_file}")
command = ["php", YAKPRO] + obfuscation_options + ["-o", output_file, input_file]
call(command)
print(f"{GREEN}Obfuscated file saved as {output_file}{RESET}")
logging.info(f"Obfuscated {input_file} successfully")
except Exception as e:
logging.error(f"Error while obfuscating {input_file}: {e}")
print(f"{RED}Error while obfuscating {input_file}: {e}{RESET}")
And I do this:
$ git clone --branch 4.x https://github.com/nikic/PHP-Parser.git
$ cd /home/mrg/www/Test/obfuscator/new/php-obfuscator/yakpro-po/PHP-Parser
$ git checkout 4.x
Now I get this output:
$ python3 main.py
Welcome to the PHP Obfuscator!
Follow the prompts to obfuscate your PHP files.
Choose the mode for obfuscating your PHP files:
1: Single file
2: Multiple files
3: Entire project directory
Enter the mode number (1/2/3): 1
Enter the output directory path: /home/mrg/www/Test/encode/0
Enter file or directory paths to exclude (separated by a space) (you can skip this step):
Create backups of original PHP files? (y/n): y
Choose the obfuscation options:
Obfuscate variables? (y/n): y
Obfuscate functions? (y/n): y
Obfuscate classes? (y/n): y
Enter the PHP file path: /home/mrg/www/Test/encode/test.php
Info: Using [/mnt/My/Home/www/Test/obfuscator/new/php-obfuscator/yakpro-po/yakpro-po.cnf] Config File...
Info: yakpro-po version = 2.0.14
Error: Too much parameters are specified, I do not know how to deal with that!!!
Obfuscated file saved as /home/mrg/www/Test/encode/0/obfuscated_test.php
But no file was created. It only take a backup
@rikhtehgaran thank you for your feedback. Later today I will check and release a fix.
@rikhtehgaran the errors you are encountering seem to stem from two primary issues:
Invalid command type: we are constructing the YAKPRO command as a list, which is correct. However, when we pass this list to subprocess.call(), the list should contain only strings. If any element of the list is not a string, Python will raise an error similar to expected str, bytes or os.PathLike object, not list.
Improper handling of file paths: The error message regarding invalid file paths may be a result of incorrectly handling quoted file paths or improper input validation. If file paths contain spaces or special characters, they need to be handled appropriately.
I've updated the code, thinking the bugs are fixed. Please, check this commit: ee6d727
i make test.php with this code:
now run this :