This repository has been archived by the owner on Sep 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
182 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include <map> | ||
#include <vector> | ||
#include <string> | ||
#include <fcntl.h> | ||
#include <unistd.h> | ||
#include <sys/system_properties.h> | ||
#include "config.h" | ||
#include "misc.h" | ||
#include "logging.h" | ||
|
||
using namespace Config; | ||
|
||
#define CONFIG_PATH "/data/adb/riru/modules/" RIRU_MODULE_ID "/config" | ||
#define PROPS_PATH CONFIG_PATH "/properties" | ||
#define PACKAGES_PATH CONFIG_PATH "/packages" | ||
|
||
static std::map<std::string, Property *> props; | ||
static std::vector<std::string> packages; | ||
|
||
Property *Properties::Find(const char *name) { | ||
if (!name) return nullptr; | ||
|
||
auto it = props.find(name); | ||
if (it != props.end()) { | ||
return it->second; | ||
} | ||
return nullptr; | ||
} | ||
|
||
void Properties::Put(const char *name, const char *value) { | ||
if (!name) return; | ||
|
||
auto prop = Find(name); | ||
delete prop; | ||
|
||
props[name] = new Property(name, value ? value : ""); | ||
|
||
LOGD("property: %s %s", name, value); | ||
} | ||
|
||
bool Packages::Find(const char *name) { | ||
if (!name) return false; | ||
return std::find(packages.begin(), packages.end(), name) != packages.end(); | ||
} | ||
|
||
void Packages::Add(const char *name) { | ||
if (!name) return; | ||
packages.emplace_back(name); | ||
|
||
LOGD("package: %s", name); | ||
} | ||
|
||
void Config::Load() { | ||
foreach_dir(PROPS_PATH, [](int dirfd, struct dirent *entry) { | ||
auto name = entry->d_name; | ||
int fd = openat(dirfd, name, O_RDONLY); | ||
if (fd == -1) return; | ||
|
||
char buf[PROP_VALUE_MAX]{0}; | ||
if (read(fd, buf, PROP_VALUE_MAX) >= 0) { | ||
Properties::Put(name, buf); | ||
} | ||
|
||
close(fd); | ||
}); | ||
|
||
foreach_dir(PACKAGES_PATH, [](int, struct dirent *entry) { | ||
auto name = entry->d_name; | ||
Packages::Add(name); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
|
||
namespace Config { | ||
|
||
struct Property { | ||
|
||
std::string name; | ||
std::string value; | ||
|
||
Property(const char *name, const char *value) : name(name), value(value) {} | ||
}; | ||
|
||
void Load(); | ||
|
||
namespace Properties { | ||
|
||
Property *Find(const char *name); | ||
|
||
void Put(const char *name, const char *value); | ||
} | ||
|
||
namespace Packages { | ||
|
||
bool Find(const char *name); | ||
|
||
void Add(const char *name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,5 @@ | ||
#pragma once | ||
|
||
#ifndef HOOK_H | ||
#define HOOK_H | ||
|
||
void install_hook(); | ||
void set_sim_operator_numeric(const char *string); | ||
void set_sim_operator_country(const char* string); | ||
|
||
#endif // HOOK_H | ||
namespace Hook { | ||
void install(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include <dirent.h> | ||
|
||
int foreach_dir(const char *path, void(*callback)(int, struct dirent *)) { | ||
DIR *dir; | ||
struct dirent *entry; | ||
int fd; | ||
|
||
if ((dir = opendir(path)) == nullptr) | ||
return -1; | ||
|
||
fd = dirfd(dir); | ||
|
||
while ((entry = readdir(dir))) { | ||
if (entry->d_name[0] == '.') continue; | ||
callback(fd, entry); | ||
} | ||
|
||
closedir(dir); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#pragma once | ||
|
||
#include <dirent.h> | ||
|
||
int foreach_dir(const char *path, void(*callback)(int dirfd, struct dirent * entry)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters