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
2c69e2c1
Commit
2c69e2c1
authored
Dec 01, 2017
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update SignAPK to use less memory
parent
c1dd23f5
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
57 deletions
+34
-57
build.gradle
app/build.gradle
+1
-1
build.gradle
crypto/build.gradle
+1
-1
JarMap.java
crypto/src/main/java/com/topjohnwu/crypto/JarMap.java
+11
-42
SignAPK.java
crypto/src/main/java/com/topjohnwu/crypto/SignAPK.java
+21
-13
No files found.
app/build.gradle
View file @
2c69e2c1
...
...
@@ -8,7 +8,7 @@ android {
applicationId
"com.topjohnwu.magisk"
minSdkVersion
21
targetSdkVersion
27
versionCode
6
4
versionCode
6
6
versionName
"5.4.3"
ndk
{
moduleName
'zipadjust'
...
...
crypto/build.gradle
View file @
2c69e2c1
...
...
@@ -15,7 +15,7 @@ jar {
shadowJar
{
baseName
=
'zipsigner'
classifier
=
null
version
=
1.
0
version
=
1.
1
}
buildscript
{
...
...
crypto/src/main/java/com/topjohnwu/crypto/JarMap.java
View file @
2c69e2c1
...
...
@@ -2,8 +2,6 @@ package com.topjohnwu.crypto;
import
java.io.Closeable
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
...
...
@@ -28,10 +26,8 @@ import java.util.zip.ZipFile;
public
class
JarMap
implements
Closeable
,
AutoCloseable
{
private
JarFile
jarFile
;
private
JarInputStream
jis
;
private
InputStream
is
;
private
File
file
;
private
boolean
isInputStream
=
false
,
hasLoaded
=
false
,
verify
;
private
LinkedHashMap
<
String
,
JarEntry
>
bufMap
=
new
LinkedHashMap
<>();
private
boolean
isInputStream
=
false
;
private
LinkedHashMap
<
String
,
JarEntry
>
bufMap
;
public
JarMap
(
File
file
)
throws
IOException
{
this
(
file
,
true
);
...
...
@@ -42,7 +38,6 @@ public class JarMap implements Closeable, AutoCloseable {
}
public
JarMap
(
File
file
,
boolean
verify
,
int
mode
)
throws
IOException
{
this
.
file
=
file
;
jarFile
=
new
JarFile
(
file
,
verify
,
mode
);
}
...
...
@@ -60,47 +55,30 @@ public class JarMap implements Closeable, AutoCloseable {
public
JarMap
(
InputStream
is
,
boolean
verify
)
throws
IOException
{
isInputStream
=
true
;
this
.
is
=
is
;
this
.
verify
=
verify
;
}
private
void
loadJarInputStream
()
{
if
(!
isInputStream
||
hasLoaded
)
return
;
hasLoaded
=
true
;
JarEntry
entry
;
try
{
bufMap
=
new
LinkedHashMap
<>();
jis
=
new
JarInputStream
(
is
,
verify
);
JarEntry
entry
;
while
((
entry
=
jis
.
getNextJarEntry
())
!=
null
)
{
bufMap
.
put
(
entry
.
getName
(),
new
JarMapEntry
(
entry
,
jis
));
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
public
InputStream
getInputStream
()
{
try
{
return
isInputStream
?
is
:
new
FileInputStream
(
file
);
}
catch
(
FileNotFoundException
e
)
{
return
null
;
}
public
File
getFile
()
{
return
isInputStream
?
null
:
new
File
(
jarFile
.
getName
());
}
public
Manifest
getManifest
()
throws
IOException
{
loadJarInputStream
();
return
isInputStream
?
jis
.
getManifest
()
:
jarFile
.
getManifest
();
}
public
InputStream
getInputStream
(
ZipEntry
ze
)
throws
IOException
{
loadJarInputStream
();
return
isInputStream
?
((
JarMapEntry
)
bufMap
.
get
(
ze
.
getName
())).
getInputStream
()
:
return
isInputStream
?
((
JarMapEntry
)
bufMap
.
get
(
ze
.
getName
())).
data
.
getInputStream
()
:
jarFile
.
getInputStream
(
ze
);
}
public
OutputStream
getOutputStream
(
ZipEntry
ze
)
{
if
(!
isInputStream
)
// Only support
inputs
tream mode
if
(!
isInputStream
)
// Only support
InputS
tream mode
return
null
;
loadJarInputStream
();
ByteArrayStream
bs
=
((
JarMapEntry
)
bufMap
.
get
(
ze
.
getName
())).
data
;
bs
.
reset
();
return
bs
;
...
...
@@ -108,7 +86,6 @@ public class JarMap implements Closeable, AutoCloseable {
public
byte
[]
getRawData
(
ZipEntry
ze
)
throws
IOException
{
if
(
isInputStream
)
{
loadJarInputStream
();
return
((
JarMapEntry
)
bufMap
.
get
(
ze
.
getName
())).
data
.
toByteArray
();
}
else
{
ByteArrayStream
bytes
=
new
ByteArrayStream
();
...
...
@@ -118,7 +95,6 @@ public class JarMap implements Closeable, AutoCloseable {
}
public
Enumeration
<
JarEntry
>
entries
()
{
loadJarInputStream
();
return
isInputStream
?
Collections
.
enumeration
(
bufMap
.
values
())
:
jarFile
.
entries
();
}
...
...
@@ -127,16 +103,12 @@ public class JarMap implements Closeable, AutoCloseable {
}
public
JarEntry
getJarEntry
(
String
name
)
{
loadJarInputStream
();
return
isInputStream
?
bufMap
.
get
(
name
)
:
jarFile
.
getJarEntry
(
name
);
}
@Override
public
void
close
()
throws
IOException
{
if
(
isInputStream
)
is
.
close
();
else
jarFile
.
close
();
(
isInputStream
?
jis
:
jarFile
).
close
();
}
private
static
class
JarMapEntry
extends
JarEntry
{
...
...
@@ -146,8 +118,5 @@ public class JarMap implements Closeable, AutoCloseable {
data
=
new
ByteArrayStream
();
data
.
readFrom
(
is
);
}
InputStream
getInputStream
()
{
return
data
.
getInputStream
();
}
}
}
crypto/src/main/java/com/topjohnwu/crypto/SignAPK.java
View file @
2c69e2c1
...
...
@@ -21,12 +21,14 @@ import org.bouncycastle.util.encoders.Base64;
import
java.io.BufferedOutputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.FileOutputStream
;
import
java.io.FilterOutputStream
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.io.PrintStream
;
import
java.io.RandomAccessFile
;
import
java.security.DigestOutputStream
;
import
java.security.GeneralSecurityException
;
import
java.security.MessageDigest
;
...
...
@@ -36,7 +38,6 @@ import java.security.Security;
import
java.security.cert.CertificateEncodingException
;
import
java.security.cert.X509Certificate
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Collections
;
import
java.util.Enumeration
;
import
java.util.Locale
;
...
...
@@ -84,7 +85,7 @@ public class SignAPK {
outputFile
=
new
BufferedOutputStream
(
new
FileOutputStream
(
output
));
if
(
minSign
)
{
signWholeFile
(
input
.
get
InputStream
(),
publicKey
,
privateKey
,
outputFile
);
signWholeFile
(
input
.
get
File
(),
publicKey
,
privateKey
,
outputFile
);
}
else
{
JarOutputStream
outputJar
=
new
JarOutputStream
(
outputFile
);
// For signing .apks, use the maximum compression to make
...
...
@@ -373,15 +374,12 @@ public class SignAPK {
// Used for signWholeFile
private
static
class
CMSProcessableFile
implements
CMSTypedData
{
private
InputStream
is
;
private
ASN1ObjectIdentifier
type
;
ByteArrayStream
bos
;
private
RandomAccessFile
file
;
CMSProcessableFile
(
InputStream
is
)
{
this
.
is
=
is
;
CMSProcessableFile
(
File
file
)
throws
FileNotFoundException
{
this
.
file
=
new
RandomAccessFile
(
file
,
"r"
)
;
type
=
new
ASN1ObjectIdentifier
(
CMSObjectIdentifiers
.
data
.
getId
());
bos
=
new
ByteArrayStream
();
bos
.
readFrom
(
is
);
}
@Override
...
...
@@ -391,20 +389,30 @@ public class SignAPK {
@Override
public
void
write
(
OutputStream
out
)
throws
IOException
,
CMSException
{
bos
.
writeTo
(
out
,
0
,
bos
.
size
()
-
2
);
file
.
seek
(
0
);
int
read
;
byte
buffer
[]
=
new
byte
[
4096
];
int
len
=
(
int
)
file
.
length
()
-
2
;
while
((
read
=
file
.
read
(
buffer
,
0
,
len
<
buffer
.
length
?
len
:
buffer
.
length
))
>
0
)
{
out
.
write
(
buffer
,
0
,
read
);
len
-=
read
;
}
}
@Override
public
Object
getContent
()
{
return
is
;
return
file
;
}
byte
[]
getTail
()
{
return
Arrays
.
copyOfRange
(
bos
.
getBuf
(),
bos
.
size
()
-
22
,
bos
.
size
());
byte
[]
getTail
()
throws
IOException
{
byte
tail
[]
=
new
byte
[
22
];
file
.
seek
(
file
.
length
()
-
22
);
file
.
readFully
(
tail
);
return
tail
;
}
}
private
static
void
signWholeFile
(
InputStream
input
,
X509Certificate
publicKey
,
private
static
void
signWholeFile
(
File
input
,
X509Certificate
publicKey
,
PrivateKey
privateKey
,
OutputStream
outputStream
)
throws
Exception
{
ByteArrayOutputStream
temp
=
new
ByteArrayOutputStream
();
...
...
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