Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add il2cppString transformation utils #130

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions module/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${LINKER_FLAGS}")
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${LINKER_FLAGS}")

include_directories(xdl/include)
include_directories(utf8-cpp/source)

aux_source_directory(xdl xdl-src)

Expand Down
31 changes: 31 additions & 0 deletions module/src/main/cpp/string_utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// Created by StarHeartHunt on 2023/4/3.
//

#include "string_utils.h"

std::string Utf16ToUtf8(const Il2CppChar *utf16String, int maximumSize) {
const Il2CppChar *ptr = utf16String;
size_t length = 0;
while (*ptr) {
ptr++;
length++;
if (maximumSize != -1 && length == maximumSize)
break;
}

std::string utf8String;
utf8String.reserve(length);
utf8::unchecked::utf16to8(utf16String, ptr, std::back_inserter(utf8String));

return utf8String;
}

std::string Utf16ToUtf8(const Il2CppChar *utf16String) {
return Utf16ToUtf8(utf16String, -1);
}

std::string Il2CppStringToStdString(Il2CppString *str) {
auto chars = il2cpp_string_chars(str);
return Utf16ToUtf8(chars);
}
14 changes: 14 additions & 0 deletions module/src/main/cpp/string_utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// Created by StarHeartHunt on 2023/4/3.
//

#ifndef ZYGISK_IL2CPPDUMPER_STRING_UTILS_H
#define ZYGISK_IL2CPPDUMPER_STRING_UTILS_H

#include "utf8.h"

std::string Utf16ToUtf8(const Il2CppChar *utf16String, int maximumSize);
std::string Utf16ToUtf8(const Il2CppChar *utf16String);
std::string Il2CppStringToStdString(Il2CppString *str);

#endif //ZYGISK_IL2CPPDUMPER_STRING_UTILS_H
34 changes: 34 additions & 0 deletions module/src/main/cpp/utf8-cpp/source/utf8.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright 2006 Nemanja Trifunovic

/*
Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:

The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
*/


#ifndef UTF8_FOR_CPP_2675DCD0_9480_4c0c_B92A_CC14C027B731
#define UTF8_FOR_CPP_2675DCD0_9480_4c0c_B92A_CC14C027B731

#include "utf8/checked.h"
#include "utf8/unchecked.h"

#endif // header guard
Loading