Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
Fix sonext
Browse files Browse the repository at this point in the history
  • Loading branch information
yujincheng08 committed Dec 4, 2021
1 parent f5c3a07 commit 2caac6e
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 36 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.2'
classpath 'com.android.tools.build:gradle:7.0.3'
classpath 'org.eclipse.jgit:org.eclipse.jgit:5.10.0.202012080955-r'
}
}
Expand Down
2 changes: 2 additions & 0 deletions riru/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ android {
defaultConfig {
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
ndkVersion '23.1.7779620'
externalNativeBuild {
cmake {
arguments "-DRIRU_VERSION_NAME:STRING=$versionNameShort",
"-DRIRU_VERSION_CODE:STRING=$versionCode",
"-DRIRU_API_VERSION=$apiVersion",
"-DRIRU_MIN_API_VERSION=$minApiVersion",
"-DANDROID_STL=none"
cppFlags "-std=c++20"
}
}
}
Expand Down
1 change: 0 additions & 1 deletion riru/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ endif ()

message("Build type: ${CMAKE_BUILD_TYPE}")

set(CMAKE_CXX_STANDARD 17)

if (NOT DEFINED RIRU_VERSION_NAME)
message(FATAL_ERROR "RIRU_VERSION_NAME is not set")
Expand Down
26 changes: 5 additions & 21 deletions riru/src/main/cpp/hide_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,6 @@

namespace hide {
namespace {
const char *GetLinkerPath() {
#if __LP64__
if (android_prop::GetApiLevel() >= 29) {
return "/apex/com.android.runtime/bin/linker64";
} else {
return "/system/bin/linker64";
}
#else
if (android_prop::GetApiLevel() >= 29) {
return "/apex/com.android.runtime/bin/linker";
} else {
return "/system/bin/linker";
}
#endif
}

class ProtectedDataGuard {

public:
Expand Down Expand Up @@ -82,7 +66,7 @@ namespace hide {
struct soinfo;

soinfo *solist = nullptr;
soinfo *sonext = nullptr;
soinfo **sonext = nullptr;
soinfo *somain = nullptr;

template<typename T>
Expand Down Expand Up @@ -152,8 +136,8 @@ namespace hide {
// prev will never be null, because the first entry in solist is
// always the static libdl_info.
prev->next(si->next());
if (si == sonext) {
sonext = prev;
if (si == *sonext) {
*sonext = prev;
}

LOGD("removed soinfo: %s", si->get_realpath());
Expand All @@ -162,10 +146,10 @@ namespace hide {
}

const auto initialized = []() {
SandHook::ElfImg linker(GetLinkerPath());
SandHook::ElfImg linker("/linker");
return ProtectedDataGuard::setup(linker) &&
(solist = getStaticVariable<soinfo>(linker, "__dl__ZL6solist")) != nullptr &&
(sonext = getStaticVariable<soinfo>(linker, "__dl__ZL6sonext")) != nullptr &&
(sonext = linker.getSymbAddress<soinfo**>("__dl__ZL6sonext")) != nullptr &&
(somain = getStaticVariable<soinfo>(linker, "__dl__ZL6somain")) != nullptr &&
soinfo::setup(linker);
}();
Expand Down
8 changes: 4 additions & 4 deletions riru/src/main/cpp/include/elf_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
#define SANDHOOK_ELF_UTIL_H

#include <string_view>
#include <string>
#include <unordered_map>
#include <linux/elf.h>
#include <sys/types.h>
#include <link.h>
#include <string>
#include "config.h"

#define SHT_GNU_HASH 0x6ffffff6
Expand All @@ -50,8 +50,8 @@ namespace SandHook {
}

template<typename T>
constexpr std::enable_if_t<std::is_pointer_v<T>, T>
getSymbAddress(std::string_view name) const {
requires(std::is_pointer_v<T>)
constexpr T getSymbAddress(std::string_view name) const {
return reinterpret_cast<T>(getSymbAddress(name));
}

Expand Down Expand Up @@ -116,7 +116,7 @@ namespace SandHook {
};

constexpr uint32_t ElfImg::ElfHash(std::string_view name) {
uint32_t h = 0, g = 0;
uint32_t h = 0, g;
for (unsigned char p: name) {
h = (h << 4) + p;
g = h & 0xf0000000;
Expand Down
16 changes: 7 additions & 9 deletions riru/src/main/cpp/util/elf_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include "logging.h"
#include "elf_util.h"

using SandHook::ElfImg;
using namespace SandHook;

template<typename T>
inline constexpr auto offsetOf(ElfW(Ehdr) *head, ElfW(Off) off) {
Expand Down Expand Up @@ -223,23 +223,21 @@ ElfImg::getSymbOffset(std::string_view name, uint32_t gnu_hash, uint32_t elf_has
bool ElfImg::findModuleBase() {
char buff[256];
off_t load_addr;
int found = 0;
bool found = false;
FILE *maps = fopen("/proc/self/maps", "r");


while (fgets(buff, sizeof(buff), maps)) {
if ((strstr(buff, "r-xp") || strstr(buff, "r--p")) && strstr(buff, elf.data())) {
found = 1;
LOGD("found: %s", buff);
std::string_view b = buff;
if (auto begin = b.find_last_of(' '); begin != std::string_view::npos) {
elf = b.substr(begin + 1);
if (auto begin = b.find_last_of(' '); begin != std::string_view::npos && b[++begin] == '/') {
found = true;
elf = b.substr(begin);
if (elf.back() == '\n') elf.pop_back();
} else {
return false;
LOGD("update path: %s", elf.data());
break;
}
LOGD("update path: %s", elf.data());
break;
}
}

Expand Down

0 comments on commit 2caac6e

Please sign in to comment.