mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-12-02 20:31:49 +00:00
Convert indentation to spaces
The tab war is lost
This commit is contained in:
@@ -11,67 +11,67 @@
|
||||
struct cpio_newc_header;
|
||||
|
||||
struct cpio_entry_base {
|
||||
uint32_t mode = 0;
|
||||
uint32_t uid = 0;
|
||||
uint32_t gid = 0;
|
||||
uint32_t filesize = 0;
|
||||
uint32_t mode = 0;
|
||||
uint32_t uid = 0;
|
||||
uint32_t gid = 0;
|
||||
uint32_t filesize = 0;
|
||||
|
||||
void *data = nullptr;
|
||||
void *data = nullptr;
|
||||
|
||||
cpio_entry_base() : mode(0), uid(0), gid(0), filesize(0) {};
|
||||
explicit cpio_entry_base(const cpio_newc_header *h);
|
||||
virtual ~cpio_entry_base() = default;
|
||||
cpio_entry_base() : mode(0), uid(0), gid(0), filesize(0) {};
|
||||
explicit cpio_entry_base(const cpio_newc_header *h);
|
||||
virtual ~cpio_entry_base() = default;
|
||||
};
|
||||
|
||||
struct cpio_entry : public cpio_entry_base {
|
||||
std::string filename;
|
||||
std::string filename;
|
||||
|
||||
cpio_entry() = default;
|
||||
explicit cpio_entry(const char *name, uint32_t mode) : filename(name) {
|
||||
this->mode = mode;
|
||||
}
|
||||
explicit cpio_entry(const cpio_newc_header *h) : cpio_entry_base(h) {}
|
||||
cpio_entry() = default;
|
||||
explicit cpio_entry(const char *name, uint32_t mode) : filename(name) {
|
||||
this->mode = mode;
|
||||
}
|
||||
explicit cpio_entry(const cpio_newc_header *h) : cpio_entry_base(h) {}
|
||||
|
||||
~cpio_entry() override { free(data); };
|
||||
~cpio_entry() override { free(data); };
|
||||
};
|
||||
|
||||
typedef std::map<std::string_view, std::unique_ptr<cpio_entry_base>> entry_map;
|
||||
|
||||
class cpio {
|
||||
public:
|
||||
void dump(const char *file);
|
||||
void rm(const char *name, bool r = false);
|
||||
void extract();
|
||||
bool extract(const char *name, const char *file);
|
||||
bool exists(const char *name);
|
||||
void dump(const char *file);
|
||||
void rm(const char *name, bool r = false);
|
||||
void extract();
|
||||
bool extract(const char *name, const char *file);
|
||||
bool exists(const char *name);
|
||||
|
||||
protected:
|
||||
entry_map entries;
|
||||
void rm(entry_map::iterator &it);
|
||||
void dump(FILE *out);
|
||||
entry_map entries;
|
||||
void rm(entry_map::iterator &it);
|
||||
void dump(FILE *out);
|
||||
};
|
||||
|
||||
class cpio_rw : public cpio {
|
||||
public:
|
||||
cpio_rw() = default;
|
||||
explicit cpio_rw(const char *file);
|
||||
void load_cpio(const char *file);
|
||||
void add(mode_t mode, const char *name, const char *file);
|
||||
void mkdir(mode_t mode, const char *name);
|
||||
void ln(const char *target, const char *name);
|
||||
bool mv(const char *from, const char *to);
|
||||
cpio_rw() = default;
|
||||
explicit cpio_rw(const char *file);
|
||||
void load_cpio(const char *file);
|
||||
void add(mode_t mode, const char *name, const char *file);
|
||||
void mkdir(mode_t mode, const char *name);
|
||||
void ln(const char *target, const char *name);
|
||||
bool mv(const char *from, const char *to);
|
||||
|
||||
protected:
|
||||
void insert(cpio_entry *e);
|
||||
void mv(entry_map::iterator &it, const char *to);
|
||||
void load_cpio(const char *buf, size_t sz);
|
||||
void insert(cpio_entry *e);
|
||||
void mv(entry_map::iterator &it, const char *to);
|
||||
void load_cpio(const char *buf, size_t sz);
|
||||
};
|
||||
|
||||
class cpio_mmap : public cpio {
|
||||
public:
|
||||
explicit cpio_mmap(const char *file);
|
||||
~cpio_mmap();
|
||||
explicit cpio_mmap(const char *file);
|
||||
~cpio_mmap();
|
||||
private:
|
||||
char *buf;
|
||||
size_t sz;
|
||||
char *buf;
|
||||
size_t sz;
|
||||
};
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
|
||||
class stream {
|
||||
public:
|
||||
virtual int read(void *buf, size_t len);
|
||||
virtual int write(const void *buf, size_t len);
|
||||
virtual off_t seek(off_t off, int whence);
|
||||
virtual ~stream() = default;
|
||||
virtual int read(void *buf, size_t len);
|
||||
virtual int write(const void *buf, size_t len);
|
||||
virtual off_t seek(off_t off, int whence);
|
||||
virtual ~stream() = default;
|
||||
};
|
||||
|
||||
using stream_ptr = std::unique_ptr<stream>;
|
||||
@@ -18,44 +18,44 @@ using stream_ptr = std::unique_ptr<stream>;
|
||||
// Delegates all operations to base stream
|
||||
class filter_stream : public stream {
|
||||
public:
|
||||
filter_stream(stream_ptr &&base) : base(std::move(base)) {}
|
||||
filter_stream(stream_ptr &&base) : base(std::move(base)) {}
|
||||
|
||||
int read(void *buf, size_t len) override;
|
||||
int write(const void *buf, size_t len) override;
|
||||
int read(void *buf, size_t len) override;
|
||||
int write(const void *buf, size_t len) override;
|
||||
|
||||
protected:
|
||||
stream_ptr base;
|
||||
stream_ptr base;
|
||||
};
|
||||
|
||||
// Byte stream that dynamically allocates memory
|
||||
class byte_stream : public stream {
|
||||
public:
|
||||
byte_stream(uint8_t *&buf, size_t &len);
|
||||
template <class byte>
|
||||
byte_stream(byte *&buf, size_t &len) : byte_stream(reinterpret_cast<uint8_t *&>(buf), len) {}
|
||||
int read(void *buf, size_t len) override;
|
||||
int write(const void *buf, size_t len) override;
|
||||
off_t seek(off_t off, int whence) override;
|
||||
byte_stream(uint8_t *&buf, size_t &len);
|
||||
template <class byte>
|
||||
byte_stream(byte *&buf, size_t &len) : byte_stream(reinterpret_cast<uint8_t *&>(buf), len) {}
|
||||
int read(void *buf, size_t len) override;
|
||||
int write(const void *buf, size_t len) override;
|
||||
off_t seek(off_t off, int whence) override;
|
||||
|
||||
private:
|
||||
uint8_t *&_buf;
|
||||
size_t &_len;
|
||||
size_t _pos = 0;
|
||||
size_t _cap = 0;
|
||||
uint8_t *&_buf;
|
||||
size_t &_len;
|
||||
size_t _pos = 0;
|
||||
size_t _cap = 0;
|
||||
|
||||
void resize(size_t new_pos, bool zero = false);
|
||||
void resize(size_t new_pos, bool zero = false);
|
||||
};
|
||||
|
||||
// File stream but does not close the file descriptor at any time
|
||||
class fd_stream : public stream {
|
||||
public:
|
||||
fd_stream(int fd) : fd(fd) {}
|
||||
int read(void *buf, size_t len) override;
|
||||
int write(const void *buf, size_t len) override;
|
||||
off_t seek(off_t off, int whence) override;
|
||||
fd_stream(int fd) : fd(fd) {}
|
||||
int read(void *buf, size_t len) override;
|
||||
int write(const void *buf, size_t len) override;
|
||||
off_t seek(off_t off, int whence) override;
|
||||
|
||||
private:
|
||||
int fd;
|
||||
int fd;
|
||||
};
|
||||
|
||||
/* ****************************************
|
||||
@@ -65,14 +65,14 @@ private:
|
||||
// sFILE -> stream_ptr
|
||||
class fp_stream final : public stream {
|
||||
public:
|
||||
fp_stream(FILE *fp = nullptr) : fp(fp, fclose) {}
|
||||
fp_stream(sFILE &&fp) : fp(std::move(fp)) {}
|
||||
int read(void *buf, size_t len) override;
|
||||
int write(const void *buf, size_t len) override;
|
||||
off_t seek(off_t off, int whence) override;
|
||||
fp_stream(FILE *fp = nullptr) : fp(fp, fclose) {}
|
||||
fp_stream(sFILE &&fp) : fp(std::move(fp)) {}
|
||||
int read(void *buf, size_t len) override;
|
||||
int write(const void *buf, size_t len) override;
|
||||
off_t seek(off_t off, int whence) override;
|
||||
|
||||
private:
|
||||
sFILE fp;
|
||||
sFILE fp;
|
||||
};
|
||||
|
||||
// stream_ptr -> sFILE
|
||||
@@ -80,5 +80,5 @@ sFILE make_stream_fp(stream_ptr &&strm);
|
||||
|
||||
template <class T, class... Args>
|
||||
sFILE make_stream_fp(Args &&... args) {
|
||||
return make_stream_fp(stream_ptr(new T(std::forward<Args>(args)...)));
|
||||
return make_stream_fp(stream_ptr(new T(std::forward<Args>(args)...)));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user