1 /*
2  * Copyright (C) 2022 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 package randomparcel;
17 import android.os.IBinder;
18 import android.os.Parcel;
19 
20 public class FuzzBinder {
21     static {
22         System.loadLibrary("random_parcel_jni");
23     }
24 
25     // DO NOT REUSE: This API should be called from fuzzer to setup JNI dependencies from
26     // libandroid_runtime. THIS IS WORKAROUND. Please file a bug if you need to use this.
init()27     public static void init() {
28         System.loadLibrary("android_runtime");
29         registerNatives();
30     }
31 
32     // This API automatically fuzzes provided service
fuzzService(IBinder binder, byte[] data)33     public static void fuzzService(IBinder binder, byte[] data) {
34         fuzzServiceInternal(binder, data);
35     }
36 
37     // This API fills parcel object
fillRandomParcel(Parcel parcel, byte[] data)38     public static void fillRandomParcel(Parcel parcel, byte[] data) {
39         fillParcelInternal(parcel, data);
40     }
41 
fuzzServiceInternal(IBinder binder, byte[] data)42     private static native void fuzzServiceInternal(IBinder binder, byte[] data);
fillParcelInternal(Parcel parcel, byte[] data)43     private static native void fillParcelInternal(Parcel parcel, byte[] data);
registerNatives()44     private static native int registerNatives();
45 }
46