1bc03f14fSopenharmony_ci/*
2bc03f14fSopenharmony_ci * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3bc03f14fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4bc03f14fSopenharmony_ci * you may not use this file except in compliance with the License.
5bc03f14fSopenharmony_ci * You may obtain a copy of the License at
6bc03f14fSopenharmony_ci *
7bc03f14fSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8bc03f14fSopenharmony_ci *
9bc03f14fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10bc03f14fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11bc03f14fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12bc03f14fSopenharmony_ci * See the License for the specific language governing permissions and
13bc03f14fSopenharmony_ci * limitations under the License.
14bc03f14fSopenharmony_ci */
15bc03f14fSopenharmony_ci
16bc03f14fSopenharmony_ci#include <cstddef>
17bc03f14fSopenharmony_ci#include <cstdint>
18bc03f14fSopenharmony_ci#include <map>
19bc03f14fSopenharmony_ci
20bc03f14fSopenharmony_ci#include "pasteboard_client.h"
21bc03f14fSopenharmony_ci#include "pasteboard_observer.h"
22bc03f14fSopenharmony_ci#include "paste_data.h"
23bc03f14fSopenharmony_ci#include "paste_data_record.h"
24bc03f14fSopenharmony_ci
25bc03f14fSopenharmony_ciusing namespace OHOS::MiscServices;
26bc03f14fSopenharmony_ci
27bc03f14fSopenharmony_cinamespace OHOS {
28bc03f14fSopenharmony_ciusing namespace OHOS::Media;
29bc03f14fSopenharmony_ciusing namespace OHOS::AAFwk;
30bc03f14fSopenharmony_ciconstexpr size_t THRESHOLD = 5;
31bc03f14fSopenharmony_ciconstexpr size_t OFFSET = 4;
32bc03f14fSopenharmony_ciconstexpr size_t RANDNUM_ZERO = 0;
33bc03f14fSopenharmony_ciconstexpr size_t LENGTH = 46;
34bc03f14fSopenharmony_ci
35bc03f14fSopenharmony_ciuint32_t ConvertToUint32(const uint8_t *ptr)
36bc03f14fSopenharmony_ci{
37bc03f14fSopenharmony_ci    if (ptr == nullptr) {
38bc03f14fSopenharmony_ci        return 0;
39bc03f14fSopenharmony_ci    }
40bc03f14fSopenharmony_ci    uint32_t bigVar = (ptr[0] << 24) | (ptr[1] << 16) | (ptr[2] << 8) | (ptr[3]);
41bc03f14fSopenharmony_ci    return bigVar;
42bc03f14fSopenharmony_ci}
43bc03f14fSopenharmony_ci
44bc03f14fSopenharmony_civoid FuzzPasteboardclient(const uint8_t *rawData, size_t size)
45bc03f14fSopenharmony_ci{
46bc03f14fSopenharmony_ci    std::shared_ptr<PasteData> pasteData = std::make_shared<PasteData>();
47bc03f14fSopenharmony_ci    std::shared_ptr<PasteDataRecord> pasteDataRecord = std::make_shared<PasteDataRecord>();
48bc03f14fSopenharmony_ci    uint32_t code = ConvertToUint32(rawData);
49bc03f14fSopenharmony_ci    rawData = rawData + OFFSET;
50bc03f14fSopenharmony_ci    size = size - OFFSET;
51bc03f14fSopenharmony_ci    std::string str(reinterpret_cast<const char *>(rawData), size);
52bc03f14fSopenharmony_ci
53bc03f14fSopenharmony_ci    if (code == RANDNUM_ZERO) {
54bc03f14fSopenharmony_ci        pasteData = PasteboardClient::GetInstance()->CreatePlainTextData(str);
55bc03f14fSopenharmony_ci        pasteDataRecord = PasteboardClient::GetInstance()->CreatePlainTextRecord(str);
56bc03f14fSopenharmony_ci    } else {
57bc03f14fSopenharmony_ci        pasteData = PasteboardClient::GetInstance()->CreateUriData(Uri(str));
58bc03f14fSopenharmony_ci        pasteDataRecord = PasteboardClient::GetInstance()->CreateUriRecord(Uri(str));
59bc03f14fSopenharmony_ci    }
60bc03f14fSopenharmony_ci    pasteData->AddRecord(pasteDataRecord);
61bc03f14fSopenharmony_ci    std::vector<uint8_t> buffer;
62bc03f14fSopenharmony_ci    pasteData->Encode(buffer);
63bc03f14fSopenharmony_ci
64bc03f14fSopenharmony_ci    PasteData pasteData2;
65bc03f14fSopenharmony_ci    pasteData2.Decode(buffer);
66bc03f14fSopenharmony_ci    pasteData2.HasMimeType(std::string(reinterpret_cast<const char *>(rawData), size));
67bc03f14fSopenharmony_ci    pasteData2.RemoveRecordAt(code);
68bc03f14fSopenharmony_ci    pasteData2.ReplaceRecordAt(code, pasteDataRecord);
69bc03f14fSopenharmony_ci
70bc03f14fSopenharmony_ci    std::shared_ptr<OHOS::AAFwk::Want> want = std::make_shared<OHOS::AAFwk::Want>();
71bc03f14fSopenharmony_ci    std::shared_ptr<PixelMap> pixelMap = std::make_shared<PixelMap>();
72bc03f14fSopenharmony_ci    const std::vector<uint8_t> arrayBuffer = {rawData, rawData + size};
73bc03f14fSopenharmony_ci    const OHOS::Uri uri = Uri(str);
74bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->CreateHtmlTextRecord(str);
75bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->CreateWantRecord(want);
76bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->CreatePlainTextRecord(str);
77bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->CreateUriRecord(uri);
78bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->CreateKvRecord(str, arrayBuffer);
79bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->CreateHtmlData(str);
80bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->CreateWantData(want);
81bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->CreatePlainTextData(str);
82bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->CreatePixelMapData(pixelMap);
83bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->CreateUriData(uri);
84bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->CreateKvData(str, arrayBuffer);
85bc03f14fSopenharmony_ci}
86bc03f14fSopenharmony_ci
87bc03f14fSopenharmony_civoid FuzzPasteboardclient002(const uint8_t *rawData, size_t size)
88bc03f14fSopenharmony_ci{
89bc03f14fSopenharmony_ci    PasteData pasteData3;
90bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->GetPasteData(pasteData3);
91bc03f14fSopenharmony_ci    UDMF::UnifiedData unifiedData;
92bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->GetUnifiedData(unifiedData);
93bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->HasPasteData();
94bc03f14fSopenharmony_ci    std::shared_ptr<PasteboardDelayGetter> delayGetter;
95bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->SetPasteData(pasteData3, delayGetter);
96bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->SetUnifiedData(unifiedData, delayGetter);
97bc03f14fSopenharmony_ci    PasteboardObserverType type = PasteboardObserverType::OBSERVER_LOCAL;
98bc03f14fSopenharmony_ci    sptr<PasteboardObserver> callback = new PasteboardObserver();
99bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->Subscribe(type, callback);
100bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->AddPasteboardChangedObserver(callback);
101bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->AddPasteboardEventObserver(callback);
102bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->Unsubscribe(type, callback);
103bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->RemovePasteboardChangedObserver(callback);
104bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->RemovePasteboardEventObserver(callback);
105bc03f14fSopenharmony_ci    const std::vector<uint32_t> tokenIds = {1, 2, 3};
106bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->GetGlobalShareOption(tokenIds);
107bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->RemoveGlobalShareOption(tokenIds);
108bc03f14fSopenharmony_ci    const ShareOption shareOptions = ShareOption::LocalDevice;
109bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->SetAppShareOptions(shareOptions);
110bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->Clear();
111bc03f14fSopenharmony_ci}
112bc03f14fSopenharmony_ci
113bc03f14fSopenharmony_civoid FuzzPasteboard(const uint8_t *rawData, size_t size)
114bc03f14fSopenharmony_ci{
115bc03f14fSopenharmony_ci    std::shared_ptr<PasteData> pasteData = std::make_shared<PasteData>();
116bc03f14fSopenharmony_ci    std::shared_ptr<PasteDataRecord> pasteDataRecord = std::make_shared<PasteDataRecord>();
117bc03f14fSopenharmony_ci    uint32_t code = ConvertToUint32(rawData);
118bc03f14fSopenharmony_ci    rawData = rawData + OFFSET;
119bc03f14fSopenharmony_ci    size = size - OFFSET;
120bc03f14fSopenharmony_ci    std::string str(reinterpret_cast<const char *>(rawData), size);
121bc03f14fSopenharmony_ci    uint32_t color[100] = { code };
122bc03f14fSopenharmony_ci    InitializationOptions opts = { { 5, 7}, PixelFormat::ARGB_8888 };
123bc03f14fSopenharmony_ci    std::unique_ptr<PixelMap> pixelMap = PixelMap::Create(color, sizeof(color)/sizeof(color[0]), opts);
124bc03f14fSopenharmony_ci    std::shared_ptr<PixelMap> pixelMapIn = move(pixelMap);
125bc03f14fSopenharmony_ci
126bc03f14fSopenharmony_ci    std::vector<uint8_t> kvData(LENGTH);
127bc03f14fSopenharmony_ci    kvData = { *rawData };
128bc03f14fSopenharmony_ci    std::string mimetype = "image/jpg";
129bc03f14fSopenharmony_ci
130bc03f14fSopenharmony_ci    if (code == RANDNUM_ZERO) {
131bc03f14fSopenharmony_ci        pasteData = PasteboardClient::GetInstance()->CreatePixelMapData(pixelMapIn);
132bc03f14fSopenharmony_ci        pasteDataRecord = PasteboardClient::GetInstance()->CreatePixelMapRecord(pixelMapIn);
133bc03f14fSopenharmony_ci    } else {
134bc03f14fSopenharmony_ci        pasteData = PasteboardClient::GetInstance()->CreateKvData(mimetype, kvData);
135bc03f14fSopenharmony_ci        pasteDataRecord = PasteboardClient::GetInstance()->CreateKvRecord(mimetype, kvData);
136bc03f14fSopenharmony_ci    }
137bc03f14fSopenharmony_ci
138bc03f14fSopenharmony_ci    pasteData->AddRecord(pasteDataRecord);
139bc03f14fSopenharmony_ci    if (PasteboardClient::GetInstance()->HasPasteData()) {
140bc03f14fSopenharmony_ci        PasteboardClient::GetInstance()->RemovePasteboardChangedObserver(nullptr);
141bc03f14fSopenharmony_ci    }
142bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->SetPasteData(*pasteData);
143bc03f14fSopenharmony_ci    std::set<Pattern> patternsToCheck = {Pattern::URL, Pattern::EmailAddress, static_cast<Pattern>(code)};
144bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->DetectPatterns(patternsToCheck);
145bc03f14fSopenharmony_ci}
146bc03f14fSopenharmony_ci
147bc03f14fSopenharmony_civoid FuzzPastedata(const uint8_t *rawData, size_t size)
148bc03f14fSopenharmony_ci{
149bc03f14fSopenharmony_ci    std::string str(reinterpret_cast<const char *>(rawData), size);
150bc03f14fSopenharmony_ci    PasteData pasteData2;
151bc03f14fSopenharmony_ci    pasteData2.SetRemote(static_cast<bool>(*rawData));
152bc03f14fSopenharmony_ci    pasteData2.SetLocalPasteFlag(static_cast<bool>(*rawData));
153bc03f14fSopenharmony_ci    pasteData2.SetDraggedDataFlag(static_cast<bool>(*rawData));
154bc03f14fSopenharmony_ci    pasteData2.SetOrginAuthority(str);
155bc03f14fSopenharmony_ci    pasteData2.SetBundleName(str);
156bc03f14fSopenharmony_ci    pasteData2.SetTag(str);
157bc03f14fSopenharmony_ci    pasteData2.SetTime(str);
158bc03f14fSopenharmony_ci    pasteData2.SetDelayData(false);
159bc03f14fSopenharmony_ci    pasteData2.IsDelayData();
160bc03f14fSopenharmony_ci    pasteData2.IsValid();
161bc03f14fSopenharmony_ci    pasteData2.IsRemote();
162bc03f14fSopenharmony_ci    pasteData2.IsLocalPaste();
163bc03f14fSopenharmony_ci    pasteData2.GetLocalOnly();
164bc03f14fSopenharmony_ci    pasteData2.IsDraggedData();
165bc03f14fSopenharmony_ci    pasteData2.GetDeviceId();
166bc03f14fSopenharmony_ci    pasteData2.ReplaceShareUri(1);
167bc03f14fSopenharmony_ci    pasteData2.SetLocalOnly(false);
168bc03f14fSopenharmony_ci    AAFwk::WantParams additions;
169bc03f14fSopenharmony_ci    pasteData2.SetAdditions(additions);
170bc03f14fSopenharmony_ci    pasteData2.GetTag();
171bc03f14fSopenharmony_ci    ScreenEvent screenStatus = ScreenEvent::ScreenLocked;
172bc03f14fSopenharmony_ci    pasteData2.SetScreenStatus(screenStatus);
173bc03f14fSopenharmony_ci    pasteData2.GetScreenStatus();
174bc03f14fSopenharmony_ci    pasteData2.GetTime();
175bc03f14fSopenharmony_ci    pasteData2.SetOrginAuthority(str);
176bc03f14fSopenharmony_ci    pasteData2.GetOrginAuthority();
177bc03f14fSopenharmony_ci    pasteData2.SetBundleName(str);
178bc03f14fSopenharmony_ci    pasteData2.GetBundleName();
179bc03f14fSopenharmony_ci    pasteData2.GetDeviceId();
180bc03f14fSopenharmony_ci    pasteData2.IsDraggedData();
181bc03f14fSopenharmony_ci    pasteData2.GetLocalOnly();
182bc03f14fSopenharmony_ci    pasteData2.AllRecords();
183bc03f14fSopenharmony_ci    pasteData2.SetTokenId(0);
184bc03f14fSopenharmony_ci    pasteData2.GetTokenId();
185bc03f14fSopenharmony_ci    pasteData2.GetRecordAt(0);
186bc03f14fSopenharmony_ci}
187bc03f14fSopenharmony_ci
188bc03f14fSopenharmony_civoid FuzzPasteData002(const uint8_t *rawData, size_t size)
189bc03f14fSopenharmony_ci{
190bc03f14fSopenharmony_ci    std::string str(reinterpret_cast<const char *>(rawData), size);
191bc03f14fSopenharmony_ci    PasteData pasteData2;
192bc03f14fSopenharmony_ci    pasteData2.GetPrimaryText();
193bc03f14fSopenharmony_ci    pasteData2.GetPrimaryWant();
194bc03f14fSopenharmony_ci    pasteData2.GetPrimaryPixelMap();
195bc03f14fSopenharmony_ci    pasteData2.GetPrimaryHtml();
196bc03f14fSopenharmony_ci    std::shared_ptr<OHOS::AAFwk::Want> wantPtr = std::make_shared<OHOS::AAFwk::Want>();
197bc03f14fSopenharmony_ci    pasteData2.AddWantRecord(wantPtr);
198bc03f14fSopenharmony_ci    std::shared_ptr<PixelMap> pixelMap = std::make_shared<PixelMap>();
199bc03f14fSopenharmony_ci    pasteData2.AddPixelMapRecord(pixelMap);
200bc03f14fSopenharmony_ci    pasteData2.AddHtmlRecord(str);
201bc03f14fSopenharmony_ci    PasteDataProperty property;
202bc03f14fSopenharmony_ci    pasteData2.SetProperty(property);
203bc03f14fSopenharmony_ci    pasteData2.GetProperty();
204bc03f14fSopenharmony_ci    std::shared_ptr<PasteDataRecord> pasteDataRecord = std::make_shared<PasteDataRecord>();
205bc03f14fSopenharmony_ci    pasteData2.AddRecord(pasteDataRecord);
206bc03f14fSopenharmony_ci
207bc03f14fSopenharmony_ci    PasteData pasteData1 = pasteData2;
208bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->SetPasteData(pasteData2);
209bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->HasDataType(std::string(reinterpret_cast<const char *>(rawData), size));
210bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->IsRemoteData();
211bc03f14fSopenharmony_ci    std::string bundlename = pasteData2.GetBundleName();
212bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->GetPasteData(pasteData2);
213bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->GetDataSource(bundlename);
214bc03f14fSopenharmony_ci
215bc03f14fSopenharmony_ci    std::string shareoption1;
216bc03f14fSopenharmony_ci    PasteData::ShareOptionToString(ShareOption::InApp, shareoption1);
217bc03f14fSopenharmony_ci    PasteData::ShareOptionToString(ShareOption::LocalDevice, shareoption1);
218bc03f14fSopenharmony_ci    PasteData::ShareOptionToString(ShareOption::CrossDevice, shareoption1);
219bc03f14fSopenharmony_ci    std::vector<std::uint8_t> buffer = {rawData, rawData + size};
220bc03f14fSopenharmony_ci    pasteData2.Decode(buffer);
221bc03f14fSopenharmony_ci    pasteData2.SetInvalid();
222bc03f14fSopenharmony_ci    sptr<IRemoteObject> remoteObject = nullptr;
223bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->LoadSystemAbilitySuccess(remoteObject);
224bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->LoadSystemAbilityFail();
225bc03f14fSopenharmony_ci    const wptr<IRemoteObject> object;
226bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->OnRemoteSaDied(object);
227bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->Clear();
228bc03f14fSopenharmony_ci}
229bc03f14fSopenharmony_ci
230bc03f14fSopenharmony_civoid FuzzPastedataProperty(const uint8_t *rawData, size_t size)
231bc03f14fSopenharmony_ci{
232bc03f14fSopenharmony_ci    std::string str(reinterpret_cast<const char *>(rawData), size);
233bc03f14fSopenharmony_ci    PasteDataProperty property1;
234bc03f14fSopenharmony_ci    property1.tag ="tag1";
235bc03f14fSopenharmony_ci    PasteDataProperty property2(property1);
236bc03f14fSopenharmony_ci
237bc03f14fSopenharmony_ci    std::vector<std::uint8_t> buffer = {rawData, rawData + size};
238bc03f14fSopenharmony_ci    property1.DecodeTag(buffer);
239bc03f14fSopenharmony_ci    property1.Decode(buffer);
240bc03f14fSopenharmony_ci}
241bc03f14fSopenharmony_ci
242bc03f14fSopenharmony_civoid FuzzPastedataRecord(const uint8_t *rawData, size_t size)
243bc03f14fSopenharmony_ci{
244bc03f14fSopenharmony_ci    std::string str(reinterpret_cast<const char *>(rawData), size);
245bc03f14fSopenharmony_ci    std::vector<std::uint8_t> buffer = {rawData, rawData + size};
246bc03f14fSopenharmony_ci    PasteDataRecord pasteDataRecord;
247bc03f14fSopenharmony_ci
248bc03f14fSopenharmony_ci    std::shared_ptr<std::string> htmlText = std::make_shared<std::string>(str);
249bc03f14fSopenharmony_ci    std::shared_ptr<OHOS::AAFwk::Want> want = std::make_shared<OHOS::AAFwk::Want>();
250bc03f14fSopenharmony_ci    std::shared_ptr<OHOS::Media::PixelMap> pixelMap = std::make_shared<PixelMap>();
251bc03f14fSopenharmony_ci    std::shared_ptr<OHOS::Uri> uri = std::make_shared<Uri>(str);
252bc03f14fSopenharmony_ci    std::shared_ptr<MineCustomData> customData = std::make_shared<MineCustomData>();
253bc03f14fSopenharmony_ci
254bc03f14fSopenharmony_ci    pasteDataRecord.SetUri(uri);
255bc03f14fSopenharmony_ci    const std::string htmlText2(reinterpret_cast<const char *>(rawData), size);
256bc03f14fSopenharmony_ci    pasteDataRecord.NewHtmlRecord(htmlText2);
257bc03f14fSopenharmony_ci    pasteDataRecord.NewWantRecord(want);
258bc03f14fSopenharmony_ci    pasteDataRecord.NewPlaintTextRecord(str);
259bc03f14fSopenharmony_ci    pasteDataRecord.NewPixelMapRecord(pixelMap);
260bc03f14fSopenharmony_ci    pasteDataRecord.GetHtmlText();
261bc03f14fSopenharmony_ci    pasteDataRecord.GetMimeType();
262bc03f14fSopenharmony_ci    pasteDataRecord.GetPlainText();
263bc03f14fSopenharmony_ci    pasteDataRecord.GetPixelMap();
264bc03f14fSopenharmony_ci    pasteDataRecord.GetOrginUri();
265bc03f14fSopenharmony_ci    pasteDataRecord.GetWant();
266bc03f14fSopenharmony_ci    pasteDataRecord.GetCustomData();
267bc03f14fSopenharmony_ci    pasteDataRecord.GetUri();
268bc03f14fSopenharmony_ci    pasteDataRecord.ClearPixelMap();
269bc03f14fSopenharmony_ci    pasteDataRecord.ConvertToText();
270bc03f14fSopenharmony_ci    pasteDataRecord.Encode(buffer);
271bc03f14fSopenharmony_ci    pasteDataRecord.Decode(buffer);
272bc03f14fSopenharmony_ci    pasteDataRecord.Count();
273bc03f14fSopenharmony_ci    pasteDataRecord.ReplaceShareUri(1);
274bc03f14fSopenharmony_ci    pasteDataRecord.SetConvertUri(str),
275bc03f14fSopenharmony_ci    pasteDataRecord.GetConvertUri();
276bc03f14fSopenharmony_ci    pasteDataRecord.SetGrantUriPermission(false);
277bc03f14fSopenharmony_ci    pasteDataRecord.HasGrantUriPermission();
278bc03f14fSopenharmony_ci    pasteDataRecord.SetTextContent(str);
279bc03f14fSopenharmony_ci    pasteDataRecord.GetTextContent();
280bc03f14fSopenharmony_ci}
281bc03f14fSopenharmony_ci
282bc03f14fSopenharmony_civoid FuzzPastedataRecord002(const uint8_t *rawData, size_t size)
283bc03f14fSopenharmony_ci{
284bc03f14fSopenharmony_ci    std::string str(reinterpret_cast<const char *>(rawData), size);
285bc03f14fSopenharmony_ci    std::vector<std::uint8_t> buffer = {rawData, rawData + size};
286bc03f14fSopenharmony_ci    PasteDataRecord pasteDataRecord;
287bc03f14fSopenharmony_ci
288bc03f14fSopenharmony_ci    std::shared_ptr<std::string> htmlText = std::make_shared<std::string>(str);
289bc03f14fSopenharmony_ci    std::shared_ptr<OHOS::AAFwk::Want> want = std::make_shared<OHOS::AAFwk::Want>();
290bc03f14fSopenharmony_ci    std::shared_ptr<OHOS::Media::PixelMap> pixelMap = std::make_shared<PixelMap>();
291bc03f14fSopenharmony_ci    std::shared_ptr<OHOS::Uri> uri = std::make_shared<Uri>(str);
292bc03f14fSopenharmony_ci    std::shared_ptr<MineCustomData> customData = std::make_shared<MineCustomData>();
293bc03f14fSopenharmony_ci
294bc03f14fSopenharmony_ci    Details details;
295bc03f14fSopenharmony_ci    pasteDataRecord.SetDetails(details);
296bc03f14fSopenharmony_ci    pasteDataRecord.GetDetails();
297bc03f14fSopenharmony_ci    pasteDataRecord.SetSystemDefinedContent(details);
298bc03f14fSopenharmony_ci    pasteDataRecord.GetSystemDefinedContent();
299bc03f14fSopenharmony_ci    pasteDataRecord.SetUDType(0);
300bc03f14fSopenharmony_ci    pasteDataRecord.GetUDType();
301bc03f14fSopenharmony_ci
302bc03f14fSopenharmony_ci    std::vector<std::uint8_t> value = {rawData, rawData + size};
303bc03f14fSopenharmony_ci    std::shared_ptr<PixelMap> pixelMap2 = std::make_shared<PixelMap>();
304bc03f14fSopenharmony_ci    pasteDataRecord.Vector2PixelMap(value);
305bc03f14fSopenharmony_ci    pasteDataRecord.PixelMap2Vector(pixelMap2);
306bc03f14fSopenharmony_ci    std::string mimeType(reinterpret_cast<const char *>(rawData), size);
307bc03f14fSopenharmony_ci    std::vector<uint8_t> arrayBuffer;
308bc03f14fSopenharmony_ci    PasteDataRecord::NewKvRecord(mimeType, arrayBuffer);
309bc03f14fSopenharmony_ci
310bc03f14fSopenharmony_ci    PasteDataRecord::Builder builder(MIMETYPE_TEXT_HTML);
311bc03f14fSopenharmony_ci    std::shared_ptr<std::string> htmlText3 = std::make_shared<std::string>(str);
312bc03f14fSopenharmony_ci    builder.SetHtmlText(htmlText3);
313bc03f14fSopenharmony_ci    builder.SetMimeType(str);
314bc03f14fSopenharmony_ci    builder.SetPlainText(htmlText3);
315bc03f14fSopenharmony_ci    builder.SetUri(uri);
316bc03f14fSopenharmony_ci    builder.SetPixelMap(pixelMap);
317bc03f14fSopenharmony_ci    builder.SetWant(want);
318bc03f14fSopenharmony_ci    builder.SetCustomData(customData);
319bc03f14fSopenharmony_ci    builder.Build();
320bc03f14fSopenharmony_ci}
321bc03f14fSopenharmony_ci
322bc03f14fSopenharmony_civoid FuzzMinecustomData(const uint8_t *rawData, size_t size)
323bc03f14fSopenharmony_ci{
324bc03f14fSopenharmony_ci    std::string str(reinterpret_cast<const char *>(rawData), size);
325bc03f14fSopenharmony_ci    std::string mimeType(reinterpret_cast<const char *>(rawData), size);
326bc03f14fSopenharmony_ci    std::vector<uint8_t> arrayBuffer;
327bc03f14fSopenharmony_ci    MineCustomData customData;
328bc03f14fSopenharmony_ci
329bc03f14fSopenharmony_ci    std::vector<std::uint8_t> buffer = {rawData, rawData + size};
330bc03f14fSopenharmony_ci    customData.Encode(buffer);
331bc03f14fSopenharmony_ci    customData.Decode(buffer);
332bc03f14fSopenharmony_ci    customData.Count();
333bc03f14fSopenharmony_ci    customData.GetItemData();
334bc03f14fSopenharmony_ci    customData.AddItemData(mimeType, arrayBuffer);
335bc03f14fSopenharmony_ci}
336bc03f14fSopenharmony_ci
337bc03f14fSopenharmony_civoid FuzzPasteboardclientcreateData(const uint8_t *rawData, size_t size)
338bc03f14fSopenharmony_ci{
339bc03f14fSopenharmony_ci    std::shared_ptr<PasteData> pasteData = std::make_shared<PasteData>();
340bc03f14fSopenharmony_ci    std::shared_ptr<PasteDataRecord> pasteDataRecord = std::make_shared<PasteDataRecord>();
341bc03f14fSopenharmony_ci    uint32_t code = ConvertToUint32(rawData);
342bc03f14fSopenharmony_ci    rawData = rawData + OFFSET;
343bc03f14fSopenharmony_ci    size = size - OFFSET;
344bc03f14fSopenharmony_ci    std::string str(reinterpret_cast<const char *>(rawData), size);
345bc03f14fSopenharmony_ci
346bc03f14fSopenharmony_ci    std::shared_ptr<Want> want = std::make_shared<Want>();
347bc03f14fSopenharmony_ci    std::string key = "id";
348bc03f14fSopenharmony_ci    bool id = static_cast<bool>(*rawData);
349bc03f14fSopenharmony_ci    Want wantIn = want->SetParam(key, id);
350bc03f14fSopenharmony_ci
351bc03f14fSopenharmony_ci    if (code == RANDNUM_ZERO) {
352bc03f14fSopenharmony_ci        pasteData = PasteboardClient::GetInstance()->CreateHtmlData(str);
353bc03f14fSopenharmony_ci        pasteDataRecord = PasteboardClient::GetInstance()->CreateHtmlTextRecord(str);
354bc03f14fSopenharmony_ci    } else {
355bc03f14fSopenharmony_ci        pasteData = PasteboardClient::GetInstance()->CreateWantData(std::make_shared<Want>(wantIn));
356bc03f14fSopenharmony_ci        pasteDataRecord = PasteboardClient::GetInstance()->CreateWantRecord(std::make_shared<Want>(wantIn));
357bc03f14fSopenharmony_ci    }
358bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->SetPasteData(*pasteData);
359bc03f14fSopenharmony_ci    std::set<Pattern> patternsToCheck = {Pattern::URL, Pattern::Number, static_cast<Pattern>(code)};
360bc03f14fSopenharmony_ci    PasteboardClient::GetInstance()->DetectPatterns(patternsToCheck);
361bc03f14fSopenharmony_ci}
362bc03f14fSopenharmony_ci} // namespace OHOS
363bc03f14fSopenharmony_ci/* Fuzzer entry point */
364bc03f14fSopenharmony_ciextern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
365bc03f14fSopenharmony_ci{
366bc03f14fSopenharmony_ci    if (size < OHOS::THRESHOLD) {
367bc03f14fSopenharmony_ci        return 0;
368bc03f14fSopenharmony_ci    }
369bc03f14fSopenharmony_ci    /* Run your code on data */
370bc03f14fSopenharmony_ci    OHOS::FuzzPasteboardclient(data, size);
371bc03f14fSopenharmony_ci    OHOS::FuzzPasteboardclient002(data, size);
372bc03f14fSopenharmony_ci    OHOS::FuzzPasteboard(data, size);
373bc03f14fSopenharmony_ci    OHOS::FuzzPastedata(data, size);
374bc03f14fSopenharmony_ci    OHOS::FuzzPasteData002(data, size);
375bc03f14fSopenharmony_ci    OHOS::FuzzMinecustomData(data, size);
376bc03f14fSopenharmony_ci    OHOS::FuzzPastedataProperty(data, size);
377bc03f14fSopenharmony_ci    OHOS::FuzzPastedataRecord(data, size);
378bc03f14fSopenharmony_ci    OHOS::FuzzPastedataRecord002(data, size);
379bc03f14fSopenharmony_ci    OHOS::FuzzPasteboardclientcreateData(data, size);
380bc03f14fSopenharmony_ci    return 0;
381bc03f14fSopenharmony_ci}