Пример #1
0
static bool find_paths(struct paths *paths)
{
    std::unordered_map<std::string, std::string> props;
    util::file_get_all_properties(DEFAULT_PROP_PATH, &props);

    std::string userdata;
    std::string header;
    std::string recovery;

    std::vector<unsigned char> contents;
    util::file_read_all(DEVICE_JSON_PATH, &contents);
    contents.push_back('\0');

    MbDeviceJsonError error;
    Device *device = mb_device_new_from_json((char *) contents.data(), &error);
    if (!device) {
        LOGE("%s: Failed to load device definition", DEVICE_JSON_PATH);
        return false;
    } else if (mb_device_validate(device) != 0) {
        LOGE("%s: Device definition validation failed", DEVICE_JSON_PATH);
        mb_device_free(device);
        return false;
    }

    auto userdata_list = mb_device_data_block_devs(device);
    auto recovery_list = mb_device_recovery_block_devs(device);

    if (userdata_list) {
        for (auto it = userdata_list; *it; ++it) {
            if (access(*it, R_OK) == 0) {
                userdata = *it;
                break;
            }
        }
    }

    if (recovery_list) {
        for (auto it = recovery_list; *it; ++it) {
            if (access(*it, R_OK) == 0) {
                recovery = *it;
                break;
            }
        }
    }

    mb_device_free(device);

    header = props[PROP_CRYPTFS_HEADER_PATH];

    if (userdata.empty()) {
        LOGE("Encrypted partition path could not be detected");
        return false;
    }
    if (recovery.empty()) {
        LOGE("Recovery partition path could not be detected");
        return false;
    }
    if (header.empty()) {
        LOGE("Cryptfs header path could not be detected");
        return false;
    }

    paths->userdata.swap(userdata);
    paths->recovery.swap(recovery);
    paths->header.swap(header);

    return true;
}
Пример #2
0
 ScopedDevice(const char *json)
 {
     device = mb_device_new_from_json(json, &error);
 }