unsigned long int get_ptmx_fops_address(void) { int i; device_id_t device_id; device_id = detect_device(); for (i = 0; i < n_supported_devices; i++) { if (supported_devices[i].device_id == device_id) { return supported_devices[i].ptmx_fops_address; } } if (kallsyms_exist()) { unsigned long int address; address = kallsyms_get_symbol_address("ptmx_fops"); if (address) { return address; } } print_reason_device_not_supported(); return 0; }
static bool setup_variables(void) { device_id_t device_id = detect_device(); int i; for (i = 0; i < n_supported_devices; i++) { if (supported_devices[i].device_id == device_id) { ccsecurity_ops = (void *)supported_devices[i].ccsecurity_ops_address; search_binary_handler = (void *)supported_devices[i].search_binary_handler_address; __ccs_search_binary_handler = (void **)supported_devices[i].__ccs_search_binary_handler_address; break; } } if (!ccsecurity_ops) { ccsecurity_ops = lookup_symbol_name("ccsecurity_ops"); } if (!search_binary_handler) { search_binary_handler = lookup_symbol_name("search_binary_handler"); } return ccsecurity_ops && search_binary_handler; }
unsigned long int device_get_symbol_address(device_symbol_t symbol) { device_id_t device_id; sqlite3_stmt *st; int rc; unsigned long int value; device_id = detect_device(); if (device_id == DEVICE_NOT_SUPPORTED) { return 0; } value = 0; rc = sqlite3_prepare(db, SQL_QUERY_DEVICE_ADDRESS, -1, &st, NULL); if (!IS_SQL_ERROR(rc)) { rc = sqlite3_reset(st); } if (!IS_SQL_ERROR(rc)) { rc = sqlite3_bind_int(st, 1, device_id); } if (!IS_SQL_ERROR(rc)) { rc = sqlite3_bind_text(st, 2, symbol, -1, SQLITE_STATIC); } if (!IS_SQL_ERROR(rc)) { rc = execute_sql(st); } if (!IS_SQL_ERROR(rc)) { sqlite3_value *value_object; int value_type; value_object = sqlite3_column_value(st, 0); value_type = sqlite3_value_type(value_object); if (value_type == SQLITE_INTEGER) { value = sqlite3_value_int(value_object); } else { const unsigned char *value_text; value_text = sqlite3_value_text(value_object); if (value_text) { sscanf(value_text, "%lx", &value); } } } if (IS_SQL_ERROR(rc)) { printf("%s(%d)\n", sqlite3_errmsg(db), sqlite3_errcode(db)); } sqlite3_finalize(st); return value; }
void detect_ps2(void) { // disable ps/2 devices outb(PS2_CMND, 0xAD); outb(PS2_CMND, 0xA7); flush_output(); // disable interrupts and translation chg_config(0x43, 0); // ps/2 controller self test outb(PS2_CMND, 0xAA); do_assert(wait_read()); if (inb(PS2_DATA) != 0x55) { kputs("PS/2 Controller self test failed.\n"); return; } // individual device detection detect_device(0, 0xAE, 0xAB, 0x10); detect_device(1, 0xA8, 0xA9, 0x20); }
static const acdb_param * get_acdb_param(void) { device_id_t device_id = detect_device(); int i; for (i = 0; i < n_supported_devices; i++) { if (supported_devices[i].device_id == device_id) { return &supported_devices[i].param; } } print_reason_device_not_supported(); return NULL; }
unsigned long int device_get_symbol_address(device_symbol_t symbol) { device_id_t device_id; sqlite3_stmt *st; int rc; unsigned long int value; device_id = detect_device(); if (device_id == DEVICE_NOT_SUPPORTED) { return 0; } value = 0; rc = sqlite3_prepare(db, SQL_QUERY_DEVICE_ADDRESS, -1, &st, NULL); if (!IS_SQL_ERROR(rc)) { rc = sqlite3_reset(st); } if (!IS_SQL_ERROR(rc)) { rc = sqlite3_bind_int(st, 1, device_id); } if (!IS_SQL_ERROR(rc)) { rc = sqlite3_bind_text(st, 2, symbol, -1, SQLITE_STATIC); } if (!IS_SQL_ERROR(rc)) { rc = execute_sql(st); } if (!IS_SQL_ERROR(rc)) { value = sqlite3_column_int(st, 0); } if (IS_SQL_ERROR(rc)) { printf("%s(%d)\n", sqlite3_errmsg(db), sqlite3_errcode(db)); } sqlite3_finalize(st); return value; }
int main() { pthread_t listen_thread; pthread_t play_thread; printf("pid:%d\n", getpid()); printf("device enumeration done\n"); pthread_create(&play_thread, NULL, start_play, NULL); detect_device(); pthread_create(&listen_thread, NULL, listen_device, NULL); pthread_join(listen_thread, NULL); pthread_join(play_thread, NULL); return 0; }
static unsigned long int get_perf_swevent_enabled_address(void) { int i; device_id_t device_id; device_id = detect_device(); for (i = 0; i < n_supported_devices; i++) { if (supported_devices[i].device_id == device_id){ return supported_devices[i].perf_swevent_enabled_address; } } print_reason_device_not_supported(); return 0; }
unsigned long int _get_remap_pfn_range_address(void) { int i; device_id_t device_id; device_id = detect_device(); for (i = 0; i < n_supported_devices; i++) { if (supported_devices[i].device_id == device_id){ return supported_devices[i].remap_pfn_range_address; } } print_reason_device_not_supported(); return 0; }
static unsigned long int get_sys_setresuid_address(void) { int i; device_id_t device_id; device_id = detect_device(); for (i = 0; i < n_supported_devices; i++) { if (supported_devices[i].device_id == device_id) { return supported_devices[i].set_sysresuid_address; } } print_reason_device_not_supported(); printf("Attempting to detect from /proc/kallsyms...\n"); return get_sys_setresuid_address_from_kallayms(); }
bool fj_hdcp_write_value_at_address(unsigned long address, int value) { void *mmap_address = NULL; int *write_address; int fd; switch (detect_device()) { case DEVICE_F05D_V08R31C: case DEVICE_F05D_V11R40A: case DEVICE_ISW11F_V25R45A: case DEVICE_ISW11F_V27R47I: break; default: return false; } fd = open("/dev/hdcp", O_RDWR); if (fd < 0) { return false; } mmap_address = mmap((void *)MAPPED_BASE, PHYS_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED|MAP_FIXED, fd, 0); if (mmap_address == MAP_FAILED) { printf("Failed to mmap due to %s\n", strerror(errno)); close(fd); return false; } write_address = convert_to_mmaped_address((void*)address, mmap_address); *write_address = value; munmap(mmap_address, PHYS_SIZE); close(fd); return true; }
static bool get_creds_functions_addresses(void **prepare_kernel_cred_address, void **commit_creds_address) { int i; device_id_t device_id; device_id = detect_device(); for (i = 0; i < n_supported_devices; i++) { if (supported_devices[i].device_id == device_id){ if (prepare_kernel_cred_address) { *prepare_kernel_cred_address = (void*)supported_devices[i].prepare_kernel_cred_address; } if (commit_creds_address) { *commit_creds_address = (void*)supported_devices[i].commit_creds_address; } return true; } } print_reason_device_not_supported(); return false; }
int main(int argc, char *argv[]) { enum { OPT_NO_LOG_FILE = 1000, }; static struct option long_options[] = { { "no-log-file", no_argument, 0, OPT_NO_LOG_FILE }, { "help", no_argument, 0, 'h' }, { 0, 0, 0, 0 } }; int opt; int long_index = 0; bool no_log_file = false; while ((opt = getopt_long(argc, argv, "h", long_options, &long_index)) != -1) { switch (opt) { case OPT_NO_LOG_FILE: no_log_file = true; break; case 'h': usage(stdout); return EXIT_SUCCESS; default: usage(stderr); return EXIT_FAILURE; } } // There should be one other argument if (argc - optind != 1) { usage(stderr); return EXIT_FAILURE; } umask(0); if (!mb::util::mkdir_recursive(MBBOOTUI_BASE_PATH, 0755)) { LOGE("%s: Failed to create directory: %s", MBBOOTUI_BASE_PATH, strerror(errno)); return EXIT_FAILURE; } if (!no_log_file && !redirect_output_to_file(MBBOOTUI_LOG_PATH, 0600)) { return EXIT_FAILURE; } signal(SIGPIPE, SIG_IGN); // Set paths tw_resource_path = MBBOOTUI_THEME_PATH; tw_settings_path = MBBOOTUI_SETTINGS_PATH; tw_screenshots_path = MBBOOTUI_SCREENSHOTS_PATH; // Disallow custom themes, which could manipulate variables in such as way // as to execute malicious code tw_theme_zip_path = ""; if (!detect_device()) { return EXIT_FAILURE; } // Check if device supports the boot UI if (!device->twOptions()->supported) { LOGW("Boot UI is not supported for the device"); return EXIT_FAILURE; } // Load device configuration options load_device_config(); log_startup(); if (!extract_theme(argv[optind], MBBOOTUI_THEME_PATH, device->twOptions()->theme)) { LOGE("Failed to extract theme"); return EXIT_FAILURE; } // Connect to daemon if (!mbtool_connection.connect()) { LOGE("Failed to connect to mbtool"); return EXIT_FAILURE; } mbtool_interface = mbtool_connection.interface(); LOGV("Loading default values..."); DataManager::SetDefaultValues(); // Set daemon version std::string mbtool_version; mbtool_interface->version(&mbtool_version); DataManager::SetValue(TW_MBTOOL_VERSION, mbtool_version); // Set ROM ID std::string rom_id; mbtool_interface->get_booted_rom_id(&rom_id); DataManager::SetValue(TW_ROM_ID, rom_id); LOGV("Loading graphics system..."); if (gui_init() < 0) { LOGE("Failed to load graphics system"); return EXIT_FAILURE; } LOGV("Loading resources..."); gui_loadResources(); LOGV("Loading user settings..."); DataManager::ReadSettingsFile(); LOGV("Loading language..."); PageManager::LoadLanguage(DataManager::GetStrValue(TW_LANGUAGE)); GUIConsole::Translate_Now(); LOGV("Fixing time..."); TWFunc::Fixup_Time_On_Boot(); LOGV("Loading main UI..."); //gui_start(); gui_startPage("autoboot", 1, 0); // Exit action std::string exit_action; DataManager::GetValue(TW_EXIT_ACTION, exit_action); std::vector<std::string> args = mb::util::split(exit_action, ","); // Save settings DataManager::Flush(); if (args.size() > 0) { if (args[0] == "reboot") { std::string reboot_arg; if (args.size() > 1) { reboot_arg = args[1]; } bool result; mbtool_interface->reboot(reboot_arg, &result); wait_forever(); } else if (args[0] == "shutdown") { bool result; mbtool_interface->shutdown(&result); wait_forever(); } } return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { enum { OPT_NO_LOG_FILE = 1000, }; static struct option long_options[] = { { "no-log-file", no_argument, 0, OPT_NO_LOG_FILE }, { "help", no_argument, 0, 'h' }, { 0, 0, 0, 0 } }; int opt; int long_index = 0; bool no_log_file = false; while ((opt = getopt_long(argc, argv, "h", long_options, &long_index)) != -1) { switch (opt) { case OPT_NO_LOG_FILE: no_log_file = true; break; case 'h': usage(stdout); return EXIT_SUCCESS; default: usage(stderr); return EXIT_FAILURE; } } // There should be one other argument if (argc - optind != 1) { usage(stderr); return EXIT_FAILURE; } umask(0); if (!mb::util::mkdir_recursive(MBBOOTUI_BASE_PATH, 0755)) { LOGE("%s: Failed to create directory: %s", MBBOOTUI_BASE_PATH, strerror(errno)); return EXIT_FAILURE; } // Rotate log if it is too large struct stat sb; if (stat(MBBOOTUI_LOG_PATH, &sb) == 0 && sb.st_size > MAX_LOG_SIZE) { rename(MBBOOTUI_LOG_PATH, MBBOOTUI_LOG_PATH ".prev"); } if (!no_log_file && !redirect_output_to_file(MBBOOTUI_LOG_PATH, 0600)) { return EXIT_FAILURE; } signal(SIGPIPE, SIG_IGN); // Set paths tw_resource_path = MBBOOTUI_THEME_PATH; tw_settings_path = MBBOOTUI_SETTINGS_PATH; tw_screenshots_path = MBBOOTUI_SCREENSHOTS_PATH; // Disallow custom themes, which could manipulate variables in such as way // as to execute malicious code tw_theme_zip_path = ""; if (!detect_device()) { return EXIT_FAILURE; } // Check if device supports the boot UI if (!device->twOptions()->supported) { LOGW("Boot UI is not supported for the device"); return EXIT_FAILURE; } // Load device configuration options load_device_config(); load_other_config(); log_startup(); if (!extract_theme(argv[optind], MBBOOTUI_THEME_PATH, device->twOptions()->theme)) { LOGE("Failed to extract theme"); return EXIT_FAILURE; } // Connect to daemon if (!mbtool_connection.connect()) { LOGE("Failed to connect to mbtool"); return EXIT_FAILURE; } mbtool_interface = mbtool_connection.interface(); LOGV("Loading default values..."); DataManager::SetDefaultValues(); // Set daemon version std::string mbtool_version; mbtool_interface->version(&mbtool_version); DataManager::SetValue(TW_MBTOOL_VERSION, mbtool_version); LOGV("Loading graphics system..."); if (gui_init() < 0) { LOGE("Failed to load graphics system"); return EXIT_FAILURE; } LOGV("Loading resources..."); gui_loadResources(); LOGV("Checking for encryption..."); char crypto_state[PROP_VALUE_MAX]; mb::util::property_get(PROP_CRYPTO_STATE, crypto_state, CRYPTO_STATE_DECRYPTED); if (strcmp(crypto_state, CRYPTO_STATE_ENCRYPTED) == 0) { LOGV("Data appears to be encrypted"); int is_encrypted = 1; // Ask mbtool for password type std::string pw_type; if (!mbtool_interface->crypto_get_pw_type(&pw_type)) { LOGE("Failed to ask mbtool for the crypto password type"); return EXIT_FAILURE; } // If password type is unknown, assume "password" if (pw_type.empty()) { LOGW("Crypto password type is unknown. Assuming 'password'"); pw_type = "password"; } // Try default password if (pw_type == "default") { bool ret; if (!mbtool_interface->crypto_decrypt("default_password", &ret)) { LOGE("Failed to ask mbtool to decrypt userdata"); return EXIT_FAILURE; } if (ret) { LOGV("Successfully decrypted device with default password"); is_encrypted = 0; } else { LOGW("Failed to decrypt device with default password despite " "password type being 'default'"); pw_type = "password"; } } DataManager::SetValue(TW_IS_ENCRYPTED, is_encrypted); DataManager::SetValue(TW_CRYPTO_PWTYPE, pw_type); DataManager::SetValue(TW_CRYPTO_PASSWORD, ""); DataManager::SetValue("tw_crypto_display", ""); if (is_encrypted) { LOGV("Showing decrypt page first due to encrypted device"); gui_startPage("decrypt", 1, 1); } if (DataManager::GetIntValue(TW_IS_ENCRYPTED) != 0) { LOGE("Decrypt page exited, but device is still encrypted"); mb::util::property_set(PROP_CRYPTO_STATE, CRYPTO_STATE_ERROR); return EXIT_FAILURE; } else { LOGV("Decrypt page exited and device was successfully decrypted"); mb::util::property_set(PROP_CRYPTO_STATE, CRYPTO_STATE_DECRYPTED); } } // Set ROM ID. This must happen after decryption or else the current ROM // will not be detected if it is a data-slot. mbtool's ROM detection code // doesn't fully trust the "ro.multiboot.romid" property and will do some // additional checks to ensure that the value is correct. std::string rom_id; mbtool_interface->get_booted_rom_id(&rom_id); if (rom_id.empty()) { LOGW("Could not determine ROM ID"); } DataManager::SetValue(TW_ROM_ID, rom_id); LOGV("Loading user settings..."); DataManager::ReadSettingsFile(); LOGV("Loading language..."); PageManager::LoadLanguage(DataManager::GetStrValue(TW_LANGUAGE)); GUIConsole::Translate_Now(); LOGV("Fixing time..."); TWFunc::Fixup_Time_On_Boot(); LOGV("Loading main UI..."); //gui_start(); gui_startPage("autoboot", 1, 0); // Exit action std::string exit_action; DataManager::GetValue(TW_EXIT_ACTION, exit_action); std::vector<std::string> args = mb::util::split(exit_action, ","); // Save settings DataManager::Flush(); if (args.size() > 0) { if (args[0] == "reboot") { std::string reboot_arg; if (args.size() > 1) { reboot_arg = args[1]; } bool result; mbtool_interface->reboot(reboot_arg, &result); wait_forever(); } else if (args[0] == "shutdown") { bool result; mbtool_interface->shutdown(&result); wait_forever(); } } return EXIT_SUCCESS; }
int main(int argc, char **argv) { switch (detect_device()) { case DEVICE_SBM203SH_S0024: mmc_protect_part = mmc_protect_part_sbm203sh_s0024; mmc_protect_part_type = MMC_PROTECT_PART_TYPE1; break; case DEVICE_SH04E_01_00_02: mmc_protect_part = mmc_protect_part_sh04e_01_00_02; mmc_protect_part_type = MMC_PROTECT_PART_TYPE1; break; case DEVICE_SH04E_01_00_03: mmc_protect_part = mmc_protect_part_sh04e_01_00_03; mmc_protect_part_type = MMC_PROTECT_PART_TYPE1; break; case DEVICE_SH04E_01_00_04: mmc_protect_part = mmc_protect_part_sh04e_01_00_04; mmc_protect_part_type = MMC_PROTECT_PART_TYPE1; break; case DEVICE_SH05E_01_00_05: mmc_protect_part = mmc_protect_part_sh05e_01_00_05; mmc_protect_part_type = MMC_PROTECT_PART_TYPE2; break; case DEVICE_SH05E_01_00_06: mmc_protect_part = mmc_protect_part_sh05e_01_00_06; mmc_protect_part_type = MMC_PROTECT_PART_TYPE2; break; case DEVICE_SH06E_01_00_01: mmc_protect_part = mmc_protect_part_sh06e_01_00_01; mmc_protect_part_type = MMC_PROTECT_PART_TYPE1; break; case DEVICE_SH06E_01_00_06: mmc_protect_part = mmc_protect_part_sh06e_01_00_06; mmc_protect_part_type = MMC_PROTECT_PART_TYPE1; break; case DEVICE_SH06E_01_00_07: mmc_protect_part = mmc_protect_part_sh06e_01_00_07; mmc_protect_part_type = MMC_PROTECT_PART_TYPE1; break; case DEVICE_SH07E_01_00_03: mmc_protect_part = mmc_protect_part_sh07e_01_00_03; mmc_protect_part_type = MMC_PROTECT_PART_TYPE1; break; case DEVICE_SH09D_02_00_03: mmc_protect_part = mmc_protect_part_sh09d_02_00_03; mmc_protect_part_type = MMC_PROTECT_PART_TYPE2; break; case DEVICE_SHL21_01_00_09: mmc_protect_part = mmc_protect_part_shl21_01_00_09; mmc_protect_part_type = MMC_PROTECT_PART_TYPE2; break; case DEVICE_SHL21_01_01_02: mmc_protect_part = mmc_protect_part_shl21_01_01_02; mmc_protect_part_type = MMC_PROTECT_PART_TYPE2; break; default: mmc_protect_part = 0; mmc_protect_part_type = MMC_PROTECT_PART_TYPE_UNKNOWN; } if (!do_unlock()) { printf("Failed to unlock MMC protect.\n"); exit(EXIT_FAILURE); } exit(EXIT_SUCCESS); }
/*! * This function is directly exported. * * @param found_device * @param pdev * * @return igd_driver_h * @return NULL on failure */ igd_driver_h igd_driver_init( igd_init_info_t *init_info ) { igd_context_t *context; os_pci_dev_t pdev = (os_pci_dev_t)NULL; os_pci_dev_t vga_disable_dev; iegd_pci_t *found_device; int ret; int i; EMGD_TRACE_ENTER; /* Allocate a context */ context = (void *) OS_ALLOC(sizeof(igd_context_t)); fixme_vbios_context = context; if(!context) { EMGD_ERROR_EXIT("igd_driver_init failed to create context"); return NULL; } OS_MEMSET(context, 0, sizeof(igd_context_t)); /* Search VGA devices for a supported one */ ret = detect_device(&found_device, &pdev); if(ret) { OS_FREE(context); return NULL; } /* * Some platforms (currently only Atom E6xx) use two PCI devices (the * second device being for SDVO) and this causes the VGA arbiter to get * involved. Legacy VGA decoding must be disabled for all PCI devices * except one, otherwise the VGA arbiter will prevent DRI usage in the * X server. */ for (i = 0; i < MAX_LEGACY_VGA_DISABLE; i++) { vga_disable_dev = os_pci_find_device(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_SDVO_TNC, 0xFFFF, 0, 0, NULL); if (vga_disable_dev) { printk(KERN_INFO "VGA arbiter detected; disabling legacy VGA" " decoding on SDVO device\n"); os_pci_disable_legacy_vga_decoding(vga_disable_dev); os_pci_free_device(vga_disable_dev); } } context->device_context.did = found_device->device_id; init_dispatch = (init_dispatch_t *)dispatch_acquire(context, init_dispatch_table); if(!init_dispatch) { EMGD_ERROR_EXIT("No dispatch found for listed device"); return NULL; } ret = init_dispatch->query(context, init_dispatch, pdev, &init_info->bus, &init_info->slot, &init_info->func); if(ret) { OS_FREE(context); EMGD_ERROR_EXIT("Device Dependent Query Failed"); return NULL; } /* init info */ init_info->vendor_id = found_device->vendor_id; init_info->device_id = found_device->device_id; init_info->name = init_dispatch->name; init_info->chipset = init_dispatch->chipset; init_info->default_pd_list = init_dispatch->default_pd_list; EMGD_TRACE_EXIT; return (igd_driver_h)context; }
void MAX_Process(void){ detect_device(); waitframes(200); // Some devices require this enumerate_device(); }