Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7d978c90 authored by Pawan Wagh's avatar Pawan Wagh Committed by Gerrit Code Review
Browse files

Merge "Adding rust lib for random parcel"

parents 39627bab 4c8aa332
Loading
Loading
Loading
Loading
+1 −0
Original line number Original line Diff line number Diff line
@@ -148,4 +148,5 @@ pub mod unstable_api {
    pub use crate::binder::AsNative;
    pub use crate::binder::AsNative;
    pub use crate::proxy::unstable_api::new_spibinder;
    pub use crate::proxy::unstable_api::new_spibinder;
    pub use crate::sys::AIBinder;
    pub use crate::sys::AIBinder;
    pub use crate::sys::AParcel;
}
}
+50 −0
Original line number Original line Diff line number Diff line
package {
    // See: http://go/android-license-faq
    default_applicable_licenses: ["frameworks_native_license"],
}

rust_bindgen {
    name: "libbinder_random_parcel_bindgen",
    crate_name: "binder_random_parcel_bindgen",
    host_supported: true,
    wrapper_src: "wrappers/RandomParcelWrapper.hpp",
    source_stem: "bindings",
    visibility: [":__subpackages__"],
    bindgen_flags: [
        "--size_t-is-usize",
        "--allowlist-function",
        "createRandomParcel",
    ],
    shared_libs: [
        "libc++",
        "libbinder_ndk",
    ],
    rustlibs: [
        "libbinder_rs",
    ],
}

rust_library {
    name: "libbinder_random_parcel_rs",
    crate_name: "binder_random_parcel_rs",
    host_supported: true,
    srcs: [
        "src/lib.rs",
    ],
    shared_libs: [
        "libbinder",
        "libutils",
        "libcutils",
        "libc++",
    ],
    static_libs: [
        "libbinder_create_parcel",
        "libbinder_random_parcel",
    ],
    rustlibs: [
        "libbinder_rs",
        "libbinder_random_parcel_bindgen",
    ],
    lints: "none",
    clippy_lints: "none",
}
+33 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

use binder::binder_impl::Parcel;
use binder::unstable_api::{AParcel, AsNative};
use binder_random_parcel_bindgen::createRandomParcel;
use std::os::raw::c_void;

/// This API creates a random parcel to be used by fuzzers
pub fn create_random_parcel(fuzzer_data: &[u8]) -> Parcel {
    let mut parcel = Parcel::new();
    let aparcel_ptr: *mut AParcel = parcel.as_native_mut();
    let ptr = aparcel_ptr as *mut c_void;
    unsafe {
        // Safety: `Parcel::as_native_mut` and `slice::as_ptr` always
        // return valid pointers.
        createRandomParcel(ptr, fuzzer_data.as_ptr(), fuzzer_data.len());
    }
    parcel
}
+22 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#include <cstdint>
#include <cstddef>

extern "C" {
    // This API is used by rust to fill random parcel.
    void createRandomParcel(void* aParcel, const uint8_t* data, size_t len);
}
 No newline at end of file
+24 −0
Original line number Original line Diff line number Diff line
package {
    default_applicable_licenses: ["frameworks_native_license"],
}

cc_library_static {
    name: "libbinder_create_parcel",
    host_supported: true,
    target: {
        darwin: {
            enabled: false,
        },
    },
    srcs: [
        "RandomParcelWrapper.cpp",
    ],
    shared_libs: [
        "libbase",
        "libbinder",
        "libbinder_ndk",
    ],
    static_libs: [
        "libbinder_random_parcel",
    ],
}
Loading