1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #pragma once 17 18 #include <android/binder_auto_utils.h> 19 #include <vector> 20 21 #include <android/binder_parcel.h> 22 #include "parcel_fuzzer.h" 23 24 // libbinder_ndk doesn't export this header which breaks down its API for NDK 25 // and APEX users, but we need access to it to fuzz. 26 #include "../../ndk/parcel_internal.h" 27 28 class NdkParcelAdapter { 29 public: NdkParcelAdapter()30 NdkParcelAdapter() : mParcel(new AParcel(nullptr /*binder*/)) {} 31 aParcel()32 const AParcel* aParcel() const { return mParcel.get(); } aParcel()33 AParcel* aParcel() { return mParcel.get(); } 34 parcel()35 android::Parcel* parcel() { return aParcel()->get(); } 36 data()37 const uint8_t* data() const { return aParcel()->get()->data(); } dataSize()38 size_t dataSize() const { return aParcel()->get()->dataSize(); } dataAvail()39 size_t dataAvail() const { return aParcel()->get()->dataAvail(); } dataPosition()40 size_t dataPosition() const { return aParcel()->get()->dataPosition(); } dataCapacity()41 size_t dataCapacity() const { return aParcel()->get()->dataCapacity(); } setData(const uint8_t * buffer,size_t len)42 android::status_t setData(const uint8_t* buffer, size_t len) { 43 return aParcel()->get()->setData(buffer, len); 44 } 45 46 private: 47 ndk::ScopedAParcel mParcel; 48 }; 49 50 extern std::vector<ParcelRead<NdkParcelAdapter>> BINDER_NDK_PARCEL_READ_FUNCTIONS; 51