#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_CMD 512
#define MAX_OUTPUT 4096
// تنفيذ أمر ADB وإرجاع النتيجة
char* adb_execute(const char* command) {
char full_cmd[MAX_CMD];
static char output[MAX_OUTPUT];
FILE* pipe;
snprintf(full_cmd, sizeof(full_cmd), "adb %s 2>&1", command);
pipe = popen(full_cmd, "r");
if (!pipe) {
return "خطأ في تنفيذ الأمر";
}
output[0] = '\0';
fgets(output, sizeof(output), pipe);
pclose(pipe);
return output;
}
// فحص الأجهزة المتصلة
void list_devices() {
printf("📱 الأجهزة المتصلة:\n");
printf("%s\n", adb_execute("devices"));
}
// الحصول على معلومات الجهاز
void get_device_info() {
printf("📊 معلومات الجهاز:\n");
printf(" النموذج: %s", adb_execute("shell getprop ro.product.model"));
printf(" الإصدار: %s", adb_execute("shell getprop ro.build.version.release"));
printf(" الشركة: %s", adb_execute("shell getprop ro.product.manufacturer"));
printf(" SDK: %s", adb_execute("shell getprop ro.build.version.sdk"));
printf(" الشاشة: %s", adb_execute("shell wm size"));
}
// تثبيت تطبيق
void install_app(const char* apk_path) {
char cmd[MAX_CMD];
snprintf(cmd, sizeof(cmd), "install -r \"%s\"", apk_path);
printf("📦 تثبيت التطبيق...\n");
printf("%s\n", adb_execute(cmd));
}
// إلغاء تثبيت تطبيق
void uninstall_app(const char* package_name) {
char cmd[MAX_CMD];
snprintf(cmd, sizeof(cmd), "uninstall %s", package_name);
printf("🗑️ إزالة التطبيق...\n");
printf("%s\n", adb_execute(cmd));
}
// نسخ ملف من الجهاز
void pull_file(const char* device_path, const char* local_path) {
char cmd[MAX_CMD];
snprintf(cmd, sizeof(cmd), "pull \"%s\" \"%s\"", device_path, local_path);
printf("📥 نسخ الملف...\n");
printf("%s\n", adb_execute(cmd));
}
// إرسال ملف إلى الجهاز
void push_file(const char* local_path, const char* device_path) {
char cmd[MAX_CMD];
snprintf(cmd, sizeof(cmd), "push \"%s\" \"%s\"", local_path, device_path);
printf("📤 إرسال الملف...\n");
printf("%s\n", adb_execute(cmd));
}
// التقاط صورة للشاشة
void take_screenshot(const char* output_path) {
char cmd[MAX_CMD];
adb_execute("shell screencap -p /sdcard/screenshot.png");
snprintf(cmd, sizeof(cmd), "pull /sdcard/screenshot.png \"%s\"", output_path);
adb_execute(cmd);
adb_execute("shell rm /sdcard/screenshot.png");
printf("📸 تم حفظ الصورة: %s\n", output_path);
}
// تسجيل الشاشة
void record_screen(int duration, const char* output_path) {
char cmd[MAX_CMD];
snprintf(cmd, sizeof(cmd),
"shell screenrecord --time-limit %d /sdcard/record.mp4", duration);
printf("🎥 تسجيل الشاشة لمدة %d ثانية...\n", duration);
adb_execute(cmd);
snprintf(cmd, sizeof(cmd), "pull /sdcard/record.mp4 \"%s\"", output_path);
adb_execute(cmd);
adb_execute("shell rm /sdcard/record.mp4");
printf("✅ تم حفظ التسجيل: %s\n", output_path);
}
// إدخال نص
void input_text(const char* text) {
char cmd[MAX_CMD];
snprintf(cmd, sizeof(cmd), "shell input text \"%s\"", text);
printf("