1 // Copyright 2023 Code Intelligence GmbH
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 #include <cstddef>
16 #include <cstdint>
17
18 #include "com_code_intelligence_jazzer_runtime_Mutator.h"
19
20 extern "C" size_t LLVMFuzzerMutate(uint8_t *Data, size_t Size, size_t MaxSize);
21
22 [[maybe_unused]] jint
Java_com_code_1intelligence_jazzer_runtime_Mutator_defaultMutateNative(JNIEnv * env,jclass,jbyteArray jni_data,jint size)23 Java_com_code_1intelligence_jazzer_runtime_Mutator_defaultMutateNative(
24 JNIEnv *env, jclass, jbyteArray jni_data, jint size) {
25 jint maxSize = env->GetArrayLength(jni_data);
26 uint8_t *data =
27 static_cast<uint8_t *>(env->GetPrimitiveArrayCritical(jni_data, nullptr));
28 jint res = LLVMFuzzerMutate(data, size, maxSize);
29 env->ReleasePrimitiveArrayCritical(jni_data, data, 0);
30 return res;
31 }
32