mirror of
https://github.com/jkcoxson/idevice.git
synced 2026-03-02 06:26:15 +01:00
Add cpp bindings for image mounter
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <idevice++/bindings.hpp>
|
||||
|
||||
87
cpp/include/idevice++/mobile_image_mounter.hpp
Normal file
87
cpp/include/idevice++/mobile_image_mounter.hpp
Normal file
@@ -0,0 +1,87 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <idevice++/bindings.hpp>
|
||||
#include <idevice++/ffi.hpp>
|
||||
#include <idevice++/provider.hpp>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
namespace IdeviceFFI {
|
||||
|
||||
using MobileImageMounterPtr =
|
||||
std::unique_ptr<ImageMounterHandle, FnDeleter<ImageMounterHandle, image_mounter_free>>;
|
||||
|
||||
class MobileImageMounter {
|
||||
public:
|
||||
// Factory: connect via Provider
|
||||
static Result<MobileImageMounter, FfiError> connect(Provider& provider);
|
||||
|
||||
// Factory: wrap an existing Idevice socket (consumes it on success)
|
||||
static Result<MobileImageMounter, FfiError> from_socket(Idevice&& socket);
|
||||
|
||||
// Ops
|
||||
Result<std::vector<plist_t>, FfiError> copy_devices();
|
||||
Result<std::vector<uint8_t>, FfiError> lookup_image(std::string image_type);
|
||||
Result<void, FfiError> upload_image(std::string image_type,
|
||||
const uint8_t* image_data,
|
||||
size_t image_size,
|
||||
const uint8_t* signature_data,
|
||||
size_t signature_size);
|
||||
Result<void, FfiError> mount_image(std::string image_type,
|
||||
const uint8_t* signature_data,
|
||||
size_t signature_size,
|
||||
const uint8_t* trust_cache_data,
|
||||
size_t trust_cache_size,
|
||||
plist_t info_plist);
|
||||
Result<void, FfiError> unmount_image(std::string mount_path);
|
||||
Result<bool, FfiError> query_developer_mode_status();
|
||||
Result<void, FfiError> mount_developer(const uint8_t* image_data,
|
||||
size_t image_size,
|
||||
const uint8_t* signature_data,
|
||||
size_t signature_size);
|
||||
Result<std::vector<uint8_t>, FfiError> query_personalization_manifest(
|
||||
std::string image_type, const uint8_t* signature_data, size_t signature_size);
|
||||
Result<std::vector<uint8_t>, FfiError> query_nonce(std::string personalized_image_type);
|
||||
Result<plist_t, FfiError> query_personalization_identifiers(std::string image_type);
|
||||
Result<void, FfiError> roll_personalization_nonce();
|
||||
Result<void, FfiError> roll_cryptex_nonce();
|
||||
Result<void, FfiError> mount_personalized(Provider& provider,
|
||||
const uint8_t* image_data,
|
||||
size_t image_size,
|
||||
const uint8_t* trust_cache_data,
|
||||
size_t trust_cache_size,
|
||||
const uint8_t* build_manifest_data,
|
||||
size_t build_manifest_size,
|
||||
plist_t info_plist,
|
||||
uint64_t unique_chip_id);
|
||||
Result<void, FfiError>
|
||||
mount_personalized_with_callback(Provider& provider,
|
||||
const uint8_t* image_data,
|
||||
size_t image_size,
|
||||
const uint8_t* trust_cache_data,
|
||||
size_t trust_cache_size,
|
||||
const uint8_t* build_manifest_data,
|
||||
size_t build_manifest_size,
|
||||
plist_t info_plist,
|
||||
uint64_t unique_chip_id,
|
||||
std::function<void(size_t, size_t)>& lambda);
|
||||
|
||||
// RAII / moves
|
||||
~MobileImageMounter() noexcept = default;
|
||||
MobileImageMounter(MobileImageMounter&&) noexcept = default;
|
||||
MobileImageMounter& operator=(MobileImageMounter&&) noexcept = default;
|
||||
MobileImageMounter(const MobileImageMounter&) = delete;
|
||||
MobileImageMounter& operator=(const MobileImageMounter&) = delete;
|
||||
|
||||
ImageMounterHandle* raw() const noexcept { return handle_.get(); }
|
||||
static MobileImageMounter adopt(ImageMounterHandle* h) noexcept {
|
||||
return MobileImageMounter(h);
|
||||
}
|
||||
|
||||
private:
|
||||
explicit MobileImageMounter(ImageMounterHandle* h) noexcept : handle_(h) {}
|
||||
MobileImageMounterPtr handle_{};
|
||||
};
|
||||
|
||||
} // namespace IdeviceFFI
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdio>
|
||||
#include <stdexcept>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
@@ -115,6 +116,34 @@ template <typename T> class Option {
|
||||
return has_ ? std::move(*ptr()) : static_cast<T>(f());
|
||||
}
|
||||
|
||||
T expect(const char* message) && {
|
||||
if (is_none()) {
|
||||
std::fprintf(stderr, "Fatal (expect) error: %s\n", message);
|
||||
std::terminate();
|
||||
}
|
||||
T tmp = std::move(*ptr());
|
||||
reset();
|
||||
return tmp;
|
||||
}
|
||||
|
||||
// Returns a mutable reference from an lvalue Result
|
||||
T& expect(const char* message) & {
|
||||
if (is_none()) {
|
||||
std::fprintf(stderr, "Fatal (expect) error: %s\n", message);
|
||||
std::terminate();
|
||||
}
|
||||
return *ptr();
|
||||
}
|
||||
|
||||
// Returns a const reference from a const lvalue Result
|
||||
const T& expect(const char* message) const& {
|
||||
if (is_none()) {
|
||||
std::fprintf(stderr, "Fatal (expect) error: %s\n", message);
|
||||
std::terminate();
|
||||
}
|
||||
return *ptr();
|
||||
}
|
||||
|
||||
// map
|
||||
template <typename F>
|
||||
auto map(F&& f) const& -> Option<typename std::decay<decltype(f(*ptr()))>::type> {
|
||||
|
||||
Reference in New Issue
Block a user