Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
Magisk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Magisk
Commits
2ab17204
Commit
2ab17204
authored
Feb 23, 2019
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add stream output for CPIO
parent
75939047
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
51 deletions
+63
-51
cpio.cpp
native/jni/utils/cpio.cpp
+59
-35
cpio.h
native/jni/utils/include/cpio.h
+4
-16
No files found.
native/jni/utils/cpio.cpp
View file @
2ab17204
...
...
@@ -10,6 +10,23 @@
using
namespace
std
;
struct
cpio_newc_header
{
char
magic
[
6
];
char
ino
[
8
];
char
mode
[
8
];
char
uid
[
8
];
char
gid
[
8
];
char
nlink
[
8
];
char
mtime
[
8
];
char
filesize
[
8
];
char
devmajor
[
8
];
char
devminor
[
8
];
char
rdevmajor
[
8
];
char
rdevminor
[
8
];
char
namesize
[
8
];
char
check
[
8
];
}
__attribute__
((
packed
));
static
uint32_t
x8u
(
const
char
*
hex
)
{
uint32_t
val
,
inpos
=
8
,
outpos
;
char
pattern
[
6
];
...
...
@@ -47,43 +64,11 @@ cpio_entry::~cpio_entry() {
free
(
data
);
}
#define dump_align() write_zero(fd, align_off(lseek(fd, 0, SEEK_CUR), 4))
void
cpio
::
dump
(
const
char
*
file
)
{
fprintf
(
stderr
,
"Dump cpio: [%s]
\n
"
,
file
);
unsigned
inode
=
300000
;
char
header
[
111
];
int
fd
=
creat
(
file
,
0644
);
for
(
auto
&
e
:
entries
)
{
sprintf
(
header
,
"070701%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x"
,
inode
++
,
// e->ino
e
.
second
->
mode
,
e
.
second
->
uid
,
e
.
second
->
gid
,
1
,
// e->nlink
0
,
// e->mtime
e
.
second
->
filesize
,
0
,
// e->devmajor
0
,
// e->devminor
0
,
// e->rdevmajor
0
,
// e->rdevminor
(
uint32_t
)
e
.
first
.
size
()
+
1
,
0
// e->check
);
xwrite
(
fd
,
header
,
110
);
xwrite
(
fd
,
e
.
first
.
data
(),
e
.
first
.
size
()
+
1
);
dump_align
();
if
(
e
.
second
->
filesize
)
{
xwrite
(
fd
,
e
.
second
->
data
,
e
.
second
->
filesize
);
dump_align
();
}
}
// Write trailer
sprintf
(
header
,
"070701%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x"
,
inode
++
,
0
,
0
,
0
,
1
,
0
,
0
,
0
,
0
,
0
,
0
,
11
,
0
);
xwrite
(
fd
,
header
,
110
);
xwrite
(
fd
,
"TRAILER!!!
\0
"
,
11
);
dump_align
();
close
(
fd
);
int
fd
=
xopen
(
file
,
O_WRONLY
|
O_CREAT
,
0644
);
FDOutStream
fd_out
(
fd
,
true
);
output
(
fd_out
);
}
void
cpio
::
rm
(
entry_map
::
iterator
&
it
)
{
...
...
@@ -143,6 +128,45 @@ bool cpio::exists(const char *name) {
return
entries
.
count
(
name
)
!=
0
;
}
#define do_out(b, l) out.write(b, l); pos += (l)
#define out_align() out.write(zeros, align_off(pos, 4)); pos = do_align(pos, 4)
void
cpio
::
output
(
OutStream
&
out
)
{
size_t
pos
=
0
;
unsigned
inode
=
300000
;
char
header
[
111
];
char
zeros
[
4
]
=
{
0
};
for
(
auto
&
e
:
entries
)
{
sprintf
(
header
,
"070701%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x"
,
inode
++
,
// e->ino
e
.
second
->
mode
,
e
.
second
->
uid
,
e
.
second
->
gid
,
1
,
// e->nlink
0
,
// e->mtime
e
.
second
->
filesize
,
0
,
// e->devmajor
0
,
// e->devminor
0
,
// e->rdevmajor
0
,
// e->rdevminor
(
uint32_t
)
e
.
first
.
size
()
+
1
,
0
// e->check
);
do_out
(
header
,
110
);
do_out
(
e
.
first
.
data
(),
e
.
first
.
size
()
+
1
);
out_align
();
if
(
e
.
second
->
filesize
)
{
do_out
(
e
.
second
->
data
,
e
.
second
->
filesize
);
out_align
();
}
}
// Write trailer
sprintf
(
header
,
"070701%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x%08x"
,
inode
++
,
0
,
0
,
0
,
1
,
0
,
0
,
0
,
0
,
0
,
0
,
11
,
0
);
do_out
(
header
,
110
);
do_out
(
"TRAILER!!!
\0
"
,
11
);
out_align
();
}
cpio_rw
::
cpio_rw
(
const
char
*
filename
)
{
int
fd
=
xopen
(
filename
,
O_RDONLY
);
fprintf
(
stderr
,
"Loading cpio: [%s]
\n
"
,
filename
);
...
...
native/jni/utils/include/cpio.h
View file @
2ab17204
...
...
@@ -6,22 +6,9 @@
#include <map>
#include <string_view>
struct
cpio_newc_header
{
char
magic
[
6
];
char
ino
[
8
];
char
mode
[
8
];
char
uid
[
8
];
char
gid
[
8
];
char
nlink
[
8
];
char
mtime
[
8
];
char
filesize
[
8
];
char
devmajor
[
8
];
char
devminor
[
8
];
char
rdevmajor
[
8
];
char
rdevminor
[
8
];
char
namesize
[
8
];
char
check
[
8
];
}
__attribute__
((
packed
));
#include <OutStream.h>
struct
cpio_newc_header
;
struct
cpio_entry_base
{
uint32_t
mode
=
0
;
...
...
@@ -58,6 +45,7 @@ public:
protected
:
entry_map
entries
;
void
rm
(
entry_map
::
iterator
&
it
);
void
output
(
OutStream
&
out
);
};
class
cpio_rw
:
public
cpio
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment