import sys
import random
import os
from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton, QFileDialog, QLabel, QComboBox, QMessageBox, QVBoxLayout, QGroupBox, QWidget
from PyQt5.QtGui import QColor, QPalette
class FileCorrupterApp(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Dosya Bozucu")
self.setGeometry(300, 300, 500, 300)
palette = QPalette()
palette.setColor(QPalette.Window, QColor(30, 30, 30))
palette.setColor(QPalette.WindowText, QColor(61, 142, 185))
palette.setColor(QPalette.Base, QColor(25, 25, 25))
palette.setColor(QPalette.Text, QColor(61, 142, 185))
palette.setColor(QPalette.Button, QColor(53, 53, 53))
palette.setColor(QPalette.ButtonText, QColor(61, 142, 185))
self.setPalette(palette)
main_widget = QWidget()
main_layout = QVBoxLayout(main_widget)
self.setCentralWidget(main_widget)
file_group = QGroupBox("Dosya İşlemleri")
file_layout = QVBoxLayout(file_group)
self.label = QLabel("Bozulacak Dosyayı Seçin")
self.label.setStyleSheet("color: white; font-size: 16px;")
file_layout.addWidget(self.label)
self.select_button = QPushButton("Dosya Seç")
self.select_button.setStyleSheet("background-color: #5c5c5c; color: #ffffff; font-size: 14px; padding: 8px;")
self.select_button.clicked.connect(self.open_file_dialog)
file_layout.addWidget(self.select_button)
main_layout.addWidget(file_group)
options_group = QGroupBox("Bozma Seçenekleri")
options_layout = QVBoxLayout(options_group)
self.level_label = QLabel("Bozma Seviyesi Seçin:")
self.level_label.setStyleSheet("color: white; font-size: 14px;")
options_layout.addWidget(self.level_label)
self.level_combo = QComboBox()
self.level_combo.addItems(["Hafif", "Orta", "Yüksek"])
self.level_combo.setStyleSheet("background-color: #3c3c3c; color: #ffffff; font-size: 14px; padding: 5px;")
options_layout.addWidget(self.level_combo)
self.corrupt_button = QPushButton("Dosyayı Boz")
self.corrupt_button.setStyleSheet("background-color: #ff5733; color: #ffffff; font-size: 14px; padding: 8px;")
self.corrupt_button.clicked.connect(self.corrupt_file)
options_layout.addWidget(self.corrupt_button)
main_layout.addWidget(options_group)
def open_file_dialog(self):
self.file_path, _ = QFileDialog.getOpenFileName(self, "Dosya Seç", "", "All Files (*)")
if self.file_path:
self.label.setText(f"Seçilen Dosya: {self.file_path}")
def corrupt_file(self):
if not hasattr(self, 'file_path') or not self.file_path:
self.show_error("Lütfen önce bir dosya seçin.")
return
corrupt_file_path, _ = QFileDialog.getSaveFileName(self, "Bozulan Dosyayı Kaydet", os.path.splitext(self.file_path)[0] + "_bozuk", "All Files (*)")
if not corrupt_file_path:
return
file_ext = os.path.splitext(self.file_path)[1].lower()
try:
if file_ext == ".pdf":
self.corrupt_generic(corrupt_file_path)
elif file_ext in [".jpg", ".png"]:
self.corrupt_generic(corrupt_file_path)
else:
self.corrupt_generic(corrupt_file_path)
self.show_corrupt_success(corrupt_file_path)
except Exception as e:
self.show_error("Dosya bozulurken bir hata oluştu.")
def corrupt_generic(self, save_path):
with open(self.file_path, "rb") as f:
content = bytearray(f.read())
level = self.level_combo.currentText()
corruption_amount = int(len(content) * (0.01 if level == "Hafif" else 0.05 if level == "Orta" else 0.1))
for _ in range(corruption_amount):
index = random.randint(0, len(content) - 1)
content[index] = random.randint(0, 255)
with open(save_path, "wb") as f:
f.write(content)
def show_corrupt_success(self, path):
msg = QMessageBox()
msg.setWindowTitle("Başarılı!")
msg.setText(f"Dosya başarıyla bozuldu: {path}")
msg.setIcon(QMessageBox.Information)
msg.exec_()
def show_error(self, error_text):
msg = QMessageBox()
msg.setWindowTitle("Hata")
msg.setText(error_text)
msg.setIcon(QMessageBox.Critical)
msg.exec_()
if __name__ == "__main__":
app = QApplication(sys.argv)
window = FileCorrupterApp()
window.show()
sys.exit(app.exec_())