mirror of
https://github.com/siemens-mobile-hacks/elfloader3-linux.git
synced 2026-11-25 23:57:20 +00:00
fs
This commit is contained in:
parent
44e708fbb0
commit
eead4290cb
3 changed files with 39 additions and 9 deletions
|
|
@ -1,22 +1,50 @@
|
|||
#include "SieFs.h"
|
||||
|
||||
#include <regex>
|
||||
#include <filesystem>
|
||||
|
||||
#include "log.h"
|
||||
#include "utils.h"
|
||||
|
||||
static std::map<std::string, std::string> m_drives;
|
||||
|
||||
void SieFs::mount(const std::string &drive, const std::string &path) {
|
||||
m_drives[drive] = path;
|
||||
m_drives[drive] = std::filesystem::canonical(path + "/");
|
||||
if (m_drives[drive] == "/")
|
||||
m_drives[drive] = "";
|
||||
LOGD("mount: %s -> %s\n", drive.c_str(), m_drives[drive].c_str());
|
||||
}
|
||||
|
||||
std::string SieFs::path2sie(const std::string &path) {
|
||||
return "";
|
||||
std::string SieFs::path2sie(const std::string &unix_path) {
|
||||
std::string siemens_path;
|
||||
for (auto [drive, mount_path]: m_drives) {
|
||||
if (unix_path == mount_path) {
|
||||
siemens_path = drive + ":" + unix_path;
|
||||
break;
|
||||
} else if (mount_path.size() > 0 && strStartsWith(unix_path, mount_path + "/")) {
|
||||
siemens_path = drive + ":" + unix_path.substr(mount_path.size());
|
||||
break;
|
||||
} else if (!mount_path.size()) {
|
||||
siemens_path = drive + ":" + unix_path; // fallback
|
||||
}
|
||||
}
|
||||
|
||||
std::replace(siemens_path.begin(), siemens_path.end(), '/', '\\');
|
||||
fprintf(stderr, "path2sie: %s -> %s\n", unix_path.c_str(), siemens_path.c_str());
|
||||
|
||||
if (!siemens_path.size()) {
|
||||
fprintf(stderr, "Invalid unix path: %s\n", unix_path.c_str());
|
||||
abort();
|
||||
}
|
||||
|
||||
return siemens_path;
|
||||
}
|
||||
|
||||
std::string SieFs::sie2path(const std::string &uri) {
|
||||
std::string SieFs::sie2path(const std::string &siemens_path) {
|
||||
std::regex path_re("^([0-9a-f]):\\\\(.*?)$", std::regex_constants::ECMAScript | std::regex_constants::icase);
|
||||
|
||||
std::smatch m;
|
||||
if (std::regex_match(uri, m, path_re)) {
|
||||
if (std::regex_match(siemens_path, m, path_re)) {
|
||||
auto drive = m[1].str();
|
||||
auto path = m[2].str();
|
||||
|
||||
|
|
@ -28,7 +56,7 @@ std::string SieFs::sie2path(const std::string &uri) {
|
|||
return unix_path;
|
||||
}
|
||||
}
|
||||
fprintf(stderr, "Invalid siemens path: %s\n", uri.c_str());
|
||||
fprintf(stderr, "Invalid siemens path: %s\n", siemens_path.c_str());
|
||||
abort();
|
||||
return "";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,9 +76,11 @@ int main(int argc, char **argv) {
|
|||
LOGD("run INIT array\n");
|
||||
loader_run_INIT_Array(ex);
|
||||
|
||||
std::string fname = SieFs::path2sie(filename);
|
||||
|
||||
auto entry = (int (*)(const char *, const char *, const void *)) loader_elf_entry(ex);
|
||||
printf("run entry at %p\n", entry);
|
||||
int ret = entry(filename.c_str(), nullptr, nullptr);
|
||||
printf("run entry at %p (fname=%s)\n", entry, fname.c_str());
|
||||
int ret = entry(fname.c_str(), nullptr, nullptr);
|
||||
LOGD("entry ret = %d\n", ret);
|
||||
|
||||
// loader_elf_close(ex);
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ int SWI_open(const char *path, unsigned int f, unsigned int m, unsigned int *err
|
|||
flags |= O_APPEND;
|
||||
|
||||
int ret;
|
||||
if (strcmp(path, "0:\\Misc\\stdout.txt") == 0) {
|
||||
if (0&&strcmp(path, "0:\\Misc\\stdout.txt") == 0) {
|
||||
ret = dup(STDOUT_FILENO);
|
||||
} else if (strcmp(path, "0:\\Misc\\stderr.txt") == 0) {
|
||||
ret = dup(STDERR_FILENO);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue