You've already forked Zygisk-Assistant
mirror of
https://github.com/snake-4/Zygisk-Assistant.git
synced 2025-09-06 06:37:02 +00:00
Added FD reopener
This commit is contained in:
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -7,3 +7,6 @@
|
|||||||
[submodule "module/jni/system_properties"]
|
[submodule "module/jni/system_properties"]
|
||||||
path = module/jni/system_properties
|
path = module/jni/system_properties
|
||||||
url = https://github.com/topjohnwu/system_properties
|
url = https://github.com/topjohnwu/system_properties
|
||||||
|
[submodule "module/jni/aosp_fd_utils"]
|
||||||
|
path = module/jni/aosp_fd_utils
|
||||||
|
url = https://github.com/snake-4/aosp_fd_utils.git
|
||||||
|
|||||||
@@ -3,10 +3,11 @@ LOCAL_PATH := $(call my-dir)
|
|||||||
include $(CLEAR_VARS)
|
include $(CLEAR_VARS)
|
||||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include $(LOCAL_PATH)/elfio
|
LOCAL_C_INCLUDES := $(LOCAL_PATH)/include $(LOCAL_PATH)/elfio
|
||||||
LOCAL_MODULE := zygisk
|
LOCAL_MODULE := zygisk
|
||||||
LOCAL_SRC_FILES := utils.cpp map_parser.cpp mountinfo_parser.cpp modules.cpp main.cpp
|
LOCAL_SRC_FILES := fd_reopener.cpp utils.cpp map_parser.cpp mountinfo_parser.cpp modules.cpp main.cpp
|
||||||
LOCAL_STATIC_LIBRARIES := libcxx libsystemproperties
|
LOCAL_STATIC_LIBRARIES := libcxx libsystemproperties libfdutils
|
||||||
LOCAL_LDLIBS := -llog
|
LOCAL_LDLIBS := -llog
|
||||||
include $(BUILD_SHARED_LIBRARY)
|
include $(BUILD_SHARED_LIBRARY)
|
||||||
|
|
||||||
include jni/libcxx/Android.mk
|
include jni/libcxx/Android.mk
|
||||||
include jni/system_properties/Android.mk
|
include jni/system_properties/Android.mk
|
||||||
|
include jni/aosp_fd_utils/Android.mk
|
||||||
|
|||||||
1
module/jni/aosp_fd_utils
Submodule
1
module/jni/aosp_fd_utils
Submodule
Submodule module/jni/aosp_fd_utils added at 303bcb1577
33
module/jni/fd_reopener.cpp
Normal file
33
module/jni/fd_reopener.cpp
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#include "fd_reopener.hpp"
|
||||||
|
#include <fd_utils.h>
|
||||||
|
#include <string>
|
||||||
|
#include <utility>
|
||||||
|
#include "logging.hpp"
|
||||||
|
|
||||||
|
FDReopener::ScopedRegularReopener::ScopedRegularReopener()
|
||||||
|
{
|
||||||
|
auto pFdSet = GetOpenFds([](const std::string &error)
|
||||||
|
{ LOGE("GetOpenFds: %s", error.c_str()); });
|
||||||
|
if (pFdSet)
|
||||||
|
{
|
||||||
|
for (const auto &fd : *pFdSet)
|
||||||
|
{
|
||||||
|
auto pFDI = FileDescriptorInfo::CreateFromFd(fd, [fd](const std::string &error)
|
||||||
|
{ LOGE("CreateFromFd(%d): %s", fd, error.c_str()); });
|
||||||
|
|
||||||
|
// Only process regular files that are not memfds
|
||||||
|
if (pFDI && !pFDI->is_sock && !pFDI->file_path.starts_with("/memfd:"))
|
||||||
|
fdi_vector.emplace_back(std::move(pFDI));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FDReopener::ScopedRegularReopener::~ScopedRegularReopener()
|
||||||
|
{
|
||||||
|
for (const auto &pFDI : fdi_vector)
|
||||||
|
{
|
||||||
|
LOGD("Reopening FD %d with %s", pFDI->fd, pFDI->file_path.c_str());
|
||||||
|
pFDI->ReopenOrDetach([fd = pFDI->fd](const std::string &error)
|
||||||
|
{ LOGE("ReopenOrDetach(%d): %s", fd, error.c_str()); });
|
||||||
|
}
|
||||||
|
}
|
||||||
19
module/jni/include/fd_reopener.hpp
Normal file
19
module/jni/include/fd_reopener.hpp
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "fd_utils.h"
|
||||||
|
#include <vector>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace FDReopener
|
||||||
|
{
|
||||||
|
class ScopedRegularReopener
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ScopedRegularReopener();
|
||||||
|
~ScopedRegularReopener();
|
||||||
|
|
||||||
|
private:
|
||||||
|
ScopedRegularReopener(const ScopedRegularReopener &);
|
||||||
|
void operator=(const ScopedRegularReopener &);
|
||||||
|
std::vector<std::unique_ptr<FileDescriptorInfo>> fdi_vector;
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
#include "logging.hpp"
|
#include "logging.hpp"
|
||||||
#include "utils.hpp"
|
#include "utils.hpp"
|
||||||
#include "modules.hpp"
|
#include "modules.hpp"
|
||||||
|
#include "fd_reopener.hpp"
|
||||||
|
|
||||||
using zygisk::Api;
|
using zygisk::Api;
|
||||||
using zygisk::AppSpecializeArgs;
|
using zygisk::AppSpecializeArgs;
|
||||||
@@ -46,6 +47,8 @@ DCL_HOOK_FUNC(static int, unshare, int flags)
|
|||||||
/*
|
/*
|
||||||
* The reason why we hook setresuid is because so far it has been unconditionally called
|
* The reason why we hook setresuid is because so far it has been unconditionally called
|
||||||
* and we still have CAP_SYS_ADMIN during this call.
|
* and we still have CAP_SYS_ADMIN during this call.
|
||||||
|
* Also, KSU hooks setuid and unmounts some overlays
|
||||||
|
* so we have to run our code before the syscall.
|
||||||
*/
|
*/
|
||||||
DCL_HOOK_FUNC(static int, setresuid, uid_t ruid, uid_t euid, uid_t suid)
|
DCL_HOOK_FUNC(static int, setresuid, uid_t ruid, uid_t euid, uid_t suid)
|
||||||
{
|
{
|
||||||
@@ -97,6 +100,8 @@ public:
|
|||||||
|
|
||||||
callbackFunction = [fd = companionFd]()
|
callbackFunction = [fd = companionFd]()
|
||||||
{
|
{
|
||||||
|
FDReopener::ScopedRegularReopener srr;
|
||||||
|
|
||||||
bool result = false;
|
bool result = false;
|
||||||
if (fd != -1)
|
if (fd != -1)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user