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
fd4aaab1
Commit
fd4aaab1
authored
Jun 15, 2017
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rewrite zip signing
parent
42d14d5c
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
593 additions
and
1079 deletions
+593
-1079
ProcessRepoZip.java
...main/java/com/topjohnwu/magisk/asyncs/ProcessRepoZip.java
+12
-31
ManagerUpdate.java
...in/java/com/topjohnwu/magisk/receivers/ManagerUpdate.java
+0
-1
ZipUtils.java
app/src/main/java/com/topjohnwu/magisk/utils/ZipUtils.java
+426
-864
jni_glue.c
app/src/main/jni/jni_glue.c
+9
-50
zipadjust.c
app/src/main/jni/zipadjust.c
+145
-129
zipadjust.h
app/src/main/jni/zipadjust.h
+1
-4
No files found.
app/src/main/java/com/topjohnwu/magisk/asyncs/ProcessRepoZip.java
View file @
fd4aaab1
...
...
@@ -14,7 +14,6 @@ import com.topjohnwu.magisk.utils.ZipUtils;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.FileOutputStream
;
import
java.io.OutputStream
;
public
class
ProcessRepoZip
extends
ParallelTask
<
Void
,
Void
,
Boolean
>
{
...
...
@@ -38,51 +37,33 @@ public class ProcessRepoZip extends ParallelTask<Void, Void, Boolean> {
@Override
protected
Boolean
doInBackground
(
Void
...
params
)
{
FileInputStream
in
;
FileOutputStream
out
;
try
{
// Create temp file
File
temp1
=
new
File
(
magiskManager
.
getCacheDir
(),
"1.zip"
);
File
temp2
=
new
File
(
magiskManager
.
getCacheDir
(),
"2.zip"
);
if
(
magiskManager
.
getCacheDir
().
mkdirs
())
{
temp1
.
createNewFile
();
temp2
.
createNewFile
();
}
out
=
new
FileOutputStream
(
temp1
);
magiskManager
.
getCacheDir
().
mkdirs
();
temp1
.
createNewFile
();
temp2
.
createNewFile
();
// First remove top folder in Github source zip, Uri -> temp1
ZipUtils
.
removeTopFolder
(
activity
.
getContentResolver
().
openInputStream
(
mUri
),
out
);
out
.
flush
();
out
.
close
();
out
=
new
FileOutputStream
(
temp2
);
ZipUtils
.
removeTopFolder
(
activity
.
getContentResolver
().
openInputStream
(
mUri
),
temp1
);
// Then sign the zip for the first time, temp1 -> temp2
ZipUtils
.
signZip
(
activity
,
temp1
,
out
,
false
);
out
.
flush
();
out
.
close
();
// Adjust the zip to prevent unzip issues, temp2 -> temp2
ZipUtils
.
adjustZip
(
temp2
);
out
=
new
FileOutputStream
(
temp1
);
ZipUtils
.
signZip
(
activity
,
temp1
,
temp2
,
false
);
// Finally, sign the whole zip file again, temp2 -> temp1
ZipUtils
.
signZip
(
activity
,
temp2
,
out
,
true
);
out
.
flush
();
out
.
close
();
// Adjust the zip to prevent unzip issues, temp2 -> temp1
ZipUtils
.
zipAdjust
(
temp2
.
getPath
(),
temp1
.
getPath
());
in
=
new
FileInputStream
(
temp1
);
// Finally, sign the whole zip file again, temp1 -> temp2
ZipUtils
.
signZip
(
activity
,
temp1
,
temp2
,
true
);
// Write it back to the downloaded zip, temp1 -> Uri
// Write it back to the downloaded zip, temp2 -> Uri
FileInputStream
in
=
new
FileInputStream
(
temp2
);
try
(
OutputStream
target
=
activity
.
getContentResolver
().
openOutputStream
(
mUri
))
{
byte
[]
buffer
=
new
byte
[
4096
];
int
length
;
if
(
target
==
null
)
throw
new
FileNotFoundException
();
if
(
target
==
null
)
throw
new
FileNotFoundException
();
while
((
length
=
in
.
read
(
buffer
))
>
0
)
target
.
write
(
buffer
,
0
,
length
);
}
...
...
app/src/main/java/com/topjohnwu/magisk/receivers/ManagerUpdate.java
View file @
fd4aaab1
...
...
@@ -7,7 +7,6 @@ import android.net.Uri;
import
android.os.Build
;
import
android.support.v4.content.FileProvider
;
import
com.topjohnwu.magisk.MagiskManager
;
import
com.topjohnwu.magisk.utils.Utils
;
import
java.io.File
;
...
...
app/src/main/java/com/topjohnwu/magisk/utils/ZipUtils.java
View file @
fd4aaab1
This diff is collapsed.
Click to expand it.
app/src/main/jni/jni_glue.c
View file @
fd4aaab1
...
...
@@ -3,58 +3,17 @@
//
#include <jni.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include "zipadjust.h"
JNIEXPORT
jbyteArray
JNICALL
Java_com_topjohnwu_magisk_utils_ZipUtils_zipAdjust___3BI
(
JNIEnv
*
env
,
jclass
type
,
jbyteArray
jbytes
,
jint
size
)
{
fin
=
(
*
env
)
->
GetPrimitiveArrayCritical
(
env
,
jbytes
,
NULL
);
insize
=
(
size_t
)
size
;
zipadjust
(
0
);
(
*
env
)
->
ReleasePrimitiveArrayCritical
(
env
,
jbytes
,
fin
,
0
);
jbyteArray
ret
=
(
*
env
)
->
NewByteArray
(
env
,
outsize
);
(
*
env
)
->
SetByteArrayRegion
(
env
,
ret
,
0
,
outsize
,
(
const
jbyte
*
)
fout
);
free
(
fout
);
return
ret
;
}
JNIEXPORT
void
JNICALL
Java_com_topjohnwu_magisk_utils_ZipUtils_zipAdjust__Ljava_lang_String_2
(
JNIEnv
*
env
,
jclass
type
,
jstring
name
)
{
const
char
*
filename
=
(
*
env
)
->
GetStringUTFChars
(
env
,
name
,
NULL
);
int
fd
=
open
(
filename
,
O_RDONLY
);
if
(
fd
<
0
)
return
;
// Load the file to memory
insize
=
lseek
(
fd
,
0
,
SEEK_END
);
lseek
(
fd
,
0
,
SEEK_SET
);
fin
=
malloc
(
insize
);
read
(
fd
,
fin
,
insize
);
zipadjust
(
0
);
close
(
fd
);
// Open file for output
fd
=
open
(
filename
,
O_WRONLY
|
O_TRUNC
);
if
(
fd
<
0
)
return
;
(
*
env
)
->
ReleaseStringUTFChars
(
env
,
name
,
filename
);
// Write back to file
lseek
(
fd
,
0
,
SEEK_SET
);
write
(
fd
,
fout
,
outsize
);
Java_com_topjohnwu_magisk_utils_ZipUtils_zipAdjust
(
JNIEnv
*
env
,
jclass
type
,
jstring
filenameIn_
,
jstring
filenameOut_
)
{
const
char
*
filenameIn
=
(
*
env
)
->
GetStringUTFChars
(
env
,
filenameIn_
,
0
);
const
char
*
filenameOut
=
(
*
env
)
->
GetStringUTFChars
(
env
,
filenameOut_
,
0
);
close
(
fd
);
free
(
fin
);
free
(
fout
);
// TODO
zipadjust
(
filenameIn
,
filenameOut
,
0
);
}
(
*
env
)
->
ReleaseStringUTFChars
(
env
,
filenameIn_
,
filenameIn
);
(
*
env
)
->
ReleaseStringUTFChars
(
env
,
filenameOut_
,
filenameOut
);
}
\ No newline at end of file
app/src/main/jni/zipadjust.c
View file @
fd4aaab1
This diff is collapsed.
Click to expand it.
app/src/main/jni/zipadjust.h
View file @
fd4aaab1
...
...
@@ -3,10 +3,7 @@
#include <android/log.h>
int
zipadjust
(
int
decompress
);
extern
size_t
insize
,
outsize
,
alloc
;
extern
unsigned
char
*
fin
,
*
fout
;
int
zipadjust
(
const
char
*
filenameIn
,
const
char
*
filenameOut
,
int
decompress
);
#define LOG_TAG "zipadjust"
...
...
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