added files.
This commit is contained in:
commit
aa6291eb33
155 files changed
+26385
No files matched your search
+12
@@ -0,0 +1,12 @@
|
|||||||
|
.gradle/
|
||||||
|
build/
|
||||||
|
out/
|
||||||
|
.idea/
|
||||||
|
*.iml
|
||||||
|
.classpath
|
||||||
|
.project
|
||||||
|
.settings/
|
||||||
|
*.log
|
||||||
|
*.BACKUP
|
||||||
|
out.jar
|
||||||
|
*-out.jar
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
<p align="center">
|
||||||
|
<img src="assets/ss.png" alt="Skid Solutions Banner" width="350" />
|
||||||
|
<br><br>
|
||||||
|
<a href="https://discord.gg/skidsolutions">
|
||||||
|
<img src="https://img.shields.io/badge/Discord-Skid%20Solutions-18181b?style=for-the-badge&logo=discord&logoColor=ffffff&labelColor=09090b" alt="Discord" />
|
||||||
|
</a>
|
||||||
|
<img src="https://img.shields.io/badge/Version-9.1.15-27272a?style=for-the-badge&labelColor=09090b" alt="Version 9.1.15" />
|
||||||
|
<img src="https://img.shields.io/badge/Java-17-3f3f46?style=for-the-badge&logo=openjdk&logoColor=ffffff&labelColor=09090b" alt="Java 17" />
|
||||||
|
<img src="https://img.shields.io/badge/Gradle-8.14.3-52525b?style=for-the-badge&logo=gradle&logoColor=ffffff&labelColor=09090b" alt="Gradle 8.14.3" />
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<a href="https://discord.gg/skidsolutions">https://discord.gg/skidsolutions</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<img src="assets/divider.svg" alt="" width="720" />
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<img src="assets/jak.jpg" alt="jak" height="150" />
|
||||||
|
<img src="assets/hack.jpg" alt="hack" height="150" />
|
||||||
|
<img src="assets/deobf2.png" alt="deobf2" height="150" />
|
||||||
|
<img src="assets/deobf.jpg" alt="deobf" height="150" />
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<sub>This is not a reconstruction nor a remake.</sub>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p align="center">
|
||||||
|
<img src="assets/divider.svg" alt="" width="720" />
|
||||||
|
</p>
|
||||||
|
|
||||||
|
## How to build
|
||||||
|
|
||||||
|
### Prerequisites
|
||||||
|
- **Java Development Kit**: JDK 17 (the Gradle wrapper 8.14.3 does not run on newer JDKs)
|
||||||
|
|
||||||
|
### Building OpenStringer
|
||||||
|
|
||||||
|
Run from this folder:
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
$env:JAVA_HOME = "C:\Program Files\Java\jdk-17"
|
||||||
|
|
||||||
|
.\gradlew.bat clean build
|
||||||
|
```
|
||||||
|
|
||||||
|
Generated `build/libs/`:
|
||||||
|
- `OpenStringer-9.1.15.jar`
|
||||||
|
- `OpenStringer-9.1.15-sources.jar`
|
||||||
|
|
||||||
|
### Running
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
java -jar build\libs\OpenStringer-9.1.15.jar [options] <src> <dest>
|
||||||
|
```
|
||||||
|
|
||||||
|
No license file, activation code, or online check is required.
|
||||||
|
|
||||||
|
Common options:
|
||||||
|
- `-configFile <file.xml>` — load XML protection configuration
|
||||||
|
- `-verbose` — enable verbose logging
|
||||||
|
- `-optimize` — strip debug info (line numbers, local variables, source file)
|
||||||
|
- `-checkCaller` — enable caller-context string encryption
|
||||||
|
- `-integrityProtection` — enable bytecode and JAR integrity checks
|
||||||
|
- `-resourceEncryption` — enable resource encryption and stream wrappers
|
||||||
|
- `-target <1.5|1.6|1.7|1.8|9>` — force target bytecode version
|
||||||
|
- `-info` — display product information
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 76 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 135 KiB |
@@ -0,0 +1,26 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 820 20" width="820" height="20" role="img" aria-hidden="true">
|
||||||
|
<defs>
|
||||||
|
<linearGradient id="baseLine" x1="0%" y1="0%" x2="100%" y2="0%">
|
||||||
|
<stop offset="0%" stop-color="#000000" stop-opacity="0" />
|
||||||
|
<stop offset="25%" stop-color="#404040" stop-opacity="0.7" />
|
||||||
|
<stop offset="50%" stop-color="#d4d4d4" stop-opacity="0.95" />
|
||||||
|
<stop offset="75%" stop-color="#404040" stop-opacity="0.7" />
|
||||||
|
<stop offset="100%" stop-color="#000000" stop-opacity="0" />
|
||||||
|
</linearGradient>
|
||||||
|
<linearGradient id="pulse" x1="0%" y1="0%" x2="100%" y2="0%">
|
||||||
|
<stop offset="0%" stop-color="#ffffff" stop-opacity="0" />
|
||||||
|
<stop offset="50%" stop-color="#ffffff" stop-opacity="1" />
|
||||||
|
<stop offset="100%" stop-color="#ffffff" stop-opacity="0" />
|
||||||
|
</linearGradient>
|
||||||
|
<clipPath id="lineClip">
|
||||||
|
<rect x="40" y="8" width="740" height="4" rx="2" />
|
||||||
|
</clipPath>
|
||||||
|
</defs>
|
||||||
|
|
||||||
|
<rect x="40" y="9.25" width="740" height="1.5" rx="0.75" fill="url(#baseLine)" />
|
||||||
|
<g clip-path="url(#lineClip)">
|
||||||
|
<rect x="-120" y="8.5" width="140" height="3" rx="1.5" fill="url(#pulse)">
|
||||||
|
<animate attributeName="x" values="-120;820" dur="3.4s" repeatCount="indefinite" />
|
||||||
|
</rect>
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 1.2 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 1.0 MiB |
Binary file not shown.
|
After Width: | Height: | Size: 4.3 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 323 KiB |
@@ -0,0 +1,84 @@
|
|||||||
|
plugins {
|
||||||
|
id 'java'
|
||||||
|
id 'application'
|
||||||
|
id 'idea'
|
||||||
|
id 'eclipse'
|
||||||
|
}
|
||||||
|
|
||||||
|
group = 'com.licel.stringer'
|
||||||
|
version = '9.1.15'
|
||||||
|
|
||||||
|
def javaVersion = 17
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation 'org.ow2.asm:asm:9.11.1'
|
||||||
|
implementation 'org.ow2.asm:asm-commons:9.11.1'
|
||||||
|
implementation 'org.apache.commons:commons-jexl3:3.3'
|
||||||
|
implementation 'commons-io:commons-io:2.18.0'
|
||||||
|
implementation 'org.zeroturnaround:zt-zip:1.17'
|
||||||
|
implementation 'org.slf4j:slf4j-simple:1.7.36'
|
||||||
|
implementation 'org.bouncycastle:bcprov-jdk18on:1.80'
|
||||||
|
implementation 'org.bouncycastle:bcpkix-jdk18on:1.80'
|
||||||
|
compileOnly 'org.apache.ant:ant:1.10.15'
|
||||||
|
}
|
||||||
|
|
||||||
|
java {
|
||||||
|
toolchain {
|
||||||
|
languageVersion = JavaLanguageVersion.of(javaVersion)
|
||||||
|
}
|
||||||
|
withSourcesJar()
|
||||||
|
}
|
||||||
|
|
||||||
|
application {
|
||||||
|
applicationName = 'OpenStringer'
|
||||||
|
mainClass = 'com.licel.stringer.ConsoleTask'
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType(JavaCompile).configureEach {
|
||||||
|
options.release = javaVersion
|
||||||
|
options.encoding = 'UTF-8'
|
||||||
|
options.compilerArgs += ['-parameters', '-Xlint:none', '-Xmaxerrs', '4096']
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType(JavaExec).configureEach {
|
||||||
|
javaLauncher = javaToolchains.launcherFor {
|
||||||
|
languageVersion = JavaLanguageVersion.of(javaVersion)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.withType(AbstractArchiveTask).configureEach {
|
||||||
|
preserveFileTimestamps = false
|
||||||
|
reproducibleFileOrder = true
|
||||||
|
}
|
||||||
|
|
||||||
|
tasks.named('jar', Jar) {
|
||||||
|
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||||
|
manifest {
|
||||||
|
attributes(
|
||||||
|
'Main-Class': 'com.licel.stringer.ConsoleTask',
|
||||||
|
'Implementation-Title': 'OpenStringer',
|
||||||
|
'Implementation-Version': project.version)
|
||||||
|
}
|
||||||
|
exclude 'META-INF/*.SF', 'META-INF/*.DSA', 'META-INF/*.RSA', 'META-INF/versions/**'
|
||||||
|
from {
|
||||||
|
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
idea {
|
||||||
|
module {
|
||||||
|
downloadSources = true
|
||||||
|
downloadJavadoc = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
eclipse {
|
||||||
|
classpath {
|
||||||
|
downloadSources = true
|
||||||
|
downloadJavadoc = true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
org.gradle.jvmargs=-Xmx2g -Dfile.encoding=UTF-8
|
||||||
|
org.gradle.parallel=true
|
||||||
|
org.gradle.caching=true
|
||||||
Vendored
BIN
Binary file not shown.
+8
@@ -0,0 +1,8 @@
|
|||||||
|
distributionBase=GRADLE_USER_HOME
|
||||||
|
distributionPath=wrapper/dists
|
||||||
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
|
||||||
|
networkTimeout=10000
|
||||||
|
validateDistributionUrl=true
|
||||||
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
zipStorePath=wrapper/dists
|
||||||
|
distributionSha256Sum=bd71102213493060956ec229d946beee57158dbd89d0e62b91bca0fa2c5f3531
|
||||||
@@ -0,0 +1,251 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
#
|
||||||
|
# Copyright © 2015-2021 the original authors.
|
||||||
|
#
|
||||||
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
# you may not use this file except in compliance with the License.
|
||||||
|
# You may obtain a copy of the License at
|
||||||
|
#
|
||||||
|
# https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
#
|
||||||
|
# Unless required by applicable law or agreed to in writing, software
|
||||||
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
# See the License for the specific language governing permissions and
|
||||||
|
# limitations under the License.
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
|
#
|
||||||
|
|
||||||
|
##############################################################################
|
||||||
|
#
|
||||||
|
# Gradle start up script for POSIX generated by Gradle.
|
||||||
|
#
|
||||||
|
# Important for running:
|
||||||
|
#
|
||||||
|
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||||
|
# noncompliant, but you have some other compliant shell such as ksh or
|
||||||
|
# bash, then to run this script, type that shell name before the whole
|
||||||
|
# command line, like:
|
||||||
|
#
|
||||||
|
# ksh Gradle
|
||||||
|
#
|
||||||
|
# Busybox and similar reduced shells will NOT work, because this script
|
||||||
|
# requires all of these POSIX shell features:
|
||||||
|
# * functions;
|
||||||
|
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||||
|
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||||
|
# * compound commands having a testable exit status, especially «case»;
|
||||||
|
# * various built-in commands including «command», «set», and «ulimit».
|
||||||
|
#
|
||||||
|
# Important for patching:
|
||||||
|
#
|
||||||
|
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||||
|
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||||
|
#
|
||||||
|
# The "traditional" practice of packing multiple parameters into a
|
||||||
|
# space-separated string is a well documented source of bugs and security
|
||||||
|
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||||
|
# options in "$@", and eventually passing that to Java.
|
||||||
|
#
|
||||||
|
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||||
|
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||||
|
# see the in-line comments for details.
|
||||||
|
#
|
||||||
|
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||||
|
# Darwin, MinGW, and NonStop.
|
||||||
|
#
|
||||||
|
# (3) This script is generated from the Groovy template
|
||||||
|
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||||
|
# within the Gradle project.
|
||||||
|
#
|
||||||
|
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||||
|
#
|
||||||
|
##############################################################################
|
||||||
|
|
||||||
|
# Attempt to set APP_HOME
|
||||||
|
|
||||||
|
# Resolve links: $0 may be a link
|
||||||
|
app_path=$0
|
||||||
|
|
||||||
|
# Need this for daisy-chained symlinks.
|
||||||
|
while
|
||||||
|
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||||
|
[ -h "$app_path" ]
|
||||||
|
do
|
||||||
|
ls=$( ls -ld "$app_path" )
|
||||||
|
link=${ls#*' -> '}
|
||||||
|
case $link in #(
|
||||||
|
/*) app_path=$link ;; #(
|
||||||
|
*) app_path=$APP_HOME$link ;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
# This is normally unused
|
||||||
|
# shellcheck disable=SC2034
|
||||||
|
APP_BASE_NAME=${0##*/}
|
||||||
|
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
|
||||||
|
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit
|
||||||
|
|
||||||
|
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||||
|
MAX_FD=maximum
|
||||||
|
|
||||||
|
warn () {
|
||||||
|
echo "$*"
|
||||||
|
} >&2
|
||||||
|
|
||||||
|
die () {
|
||||||
|
echo
|
||||||
|
echo "$*"
|
||||||
|
echo
|
||||||
|
exit 1
|
||||||
|
} >&2
|
||||||
|
|
||||||
|
# OS specific support (must be 'true' or 'false').
|
||||||
|
cygwin=false
|
||||||
|
msys=false
|
||||||
|
darwin=false
|
||||||
|
nonstop=false
|
||||||
|
case "$( uname )" in #(
|
||||||
|
CYGWIN* ) cygwin=true ;; #(
|
||||||
|
Darwin* ) darwin=true ;; #(
|
||||||
|
MSYS* | MINGW* ) msys=true ;; #(
|
||||||
|
NONSTOP* ) nonstop=true ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
CLASSPATH="\\\"\\\""
|
||||||
|
|
||||||
|
|
||||||
|
# Determine the Java command to use to start the JVM.
|
||||||
|
if [ -n "$JAVA_HOME" ] ; then
|
||||||
|
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||||
|
# IBM's JDK on AIX uses strange locations for the executables
|
||||||
|
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||||
|
else
|
||||||
|
JAVACMD=$JAVA_HOME/bin/java
|
||||||
|
fi
|
||||||
|
if [ ! -x "$JAVACMD" ] ; then
|
||||||
|
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||||
|
|
||||||
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
location of your Java installation."
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
JAVACMD=java
|
||||||
|
if ! command -v java >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||||
|
|
||||||
|
Please set the JAVA_HOME variable in your environment to match the
|
||||||
|
location of your Java installation."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Increase the maximum file descriptors if we can.
|
||||||
|
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||||
|
case $MAX_FD in #(
|
||||||
|
max*)
|
||||||
|
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
|
||||||
|
# shellcheck disable=SC2039,SC3045
|
||||||
|
MAX_FD=$( ulimit -H -n ) ||
|
||||||
|
warn "Could not query maximum file descriptor limit"
|
||||||
|
esac
|
||||||
|
case $MAX_FD in #(
|
||||||
|
'' | soft) :;; #(
|
||||||
|
*)
|
||||||
|
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
|
||||||
|
# shellcheck disable=SC2039,SC3045
|
||||||
|
ulimit -n "$MAX_FD" ||
|
||||||
|
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Collect all arguments for the java command, stacking in reverse order:
|
||||||
|
# * args from the command line
|
||||||
|
# * the main class name
|
||||||
|
# * -classpath
|
||||||
|
# * -D...appname settings
|
||||||
|
# * --module-path (only if needed)
|
||||||
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||||
|
|
||||||
|
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||||
|
if "$cygwin" || "$msys" ; then
|
||||||
|
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||||
|
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||||
|
|
||||||
|
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||||
|
|
||||||
|
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||||
|
for arg do
|
||||||
|
if
|
||||||
|
case $arg in #(
|
||||||
|
-*) false ;; # don't mess with options #(
|
||||||
|
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||||
|
[ -e "$t" ] ;; #(
|
||||||
|
*) false ;;
|
||||||
|
esac
|
||||||
|
then
|
||||||
|
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||||
|
fi
|
||||||
|
# Roll the args list around exactly as many times as the number of
|
||||||
|
# args, so each arg winds up back in the position where it started, but
|
||||||
|
# possibly modified.
|
||||||
|
#
|
||||||
|
# NB: a `for` loop captures its iteration list before it begins, so
|
||||||
|
# changing the positional parameters here affects neither the number of
|
||||||
|
# iterations, nor the values presented in `arg`.
|
||||||
|
shift # remove old arg
|
||||||
|
set -- "$@" "$arg" # push replacement arg
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||||
|
|
||||||
|
# Collect all arguments for the java command:
|
||||||
|
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
|
||||||
|
# and any embedded shellness will be escaped.
|
||||||
|
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
|
||||||
|
# treated as '${Hostname}' itself on the command line.
|
||||||
|
|
||||||
|
set -- \
|
||||||
|
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||||
|
-classpath "$CLASSPATH" \
|
||||||
|
-jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \
|
||||||
|
"$@"
|
||||||
|
|
||||||
|
# Stop when "xargs" is not available.
|
||||||
|
if ! command -v xargs >/dev/null 2>&1
|
||||||
|
then
|
||||||
|
die "xargs is not available"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Use "xargs" to parse quoted args.
|
||||||
|
#
|
||||||
|
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||||
|
#
|
||||||
|
# In Bash we could simply go:
|
||||||
|
#
|
||||||
|
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||||
|
# set -- "${ARGS[@]}" "$@"
|
||||||
|
#
|
||||||
|
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||||
|
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||||
|
# character that might be a shell metacharacter, then use eval to reverse
|
||||||
|
# that process (while maintaining the separation between arguments), and wrap
|
||||||
|
# the whole thing up as a single "set" statement.
|
||||||
|
#
|
||||||
|
# This will of course break if any of these variables contains a newline or
|
||||||
|
# an unmatched quote.
|
||||||
|
#
|
||||||
|
|
||||||
|
eval "set -- $(
|
||||||
|
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||||
|
xargs -n1 |
|
||||||
|
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||||
|
tr '\n' ' '
|
||||||
|
)" '"$@"'
|
||||||
|
|
||||||
|
exec "$JAVACMD" "$@"
|
||||||
Vendored
+94
@@ -0,0 +1,94 @@
|
|||||||
|
@rem
|
||||||
|
@rem Copyright 2015 the original author or authors.
|
||||||
|
@rem
|
||||||
|
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
@rem you may not use this file except in compliance with the License.
|
||||||
|
@rem You may obtain a copy of the License at
|
||||||
|
@rem
|
||||||
|
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
@rem
|
||||||
|
@rem Unless required by applicable law or agreed to in writing, software
|
||||||
|
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
@rem See the License for the specific language governing permissions and
|
||||||
|
@rem limitations under the License.
|
||||||
|
@rem
|
||||||
|
@rem SPDX-License-Identifier: Apache-2.0
|
||||||
|
@rem
|
||||||
|
|
||||||
|
@if "%DEBUG%"=="" @echo off
|
||||||
|
@rem ##########################################################################
|
||||||
|
@rem
|
||||||
|
@rem Gradle startup script for Windows
|
||||||
|
@rem
|
||||||
|
@rem ##########################################################################
|
||||||
|
|
||||||
|
@rem Set local scope for the variables with windows NT shell
|
||||||
|
if "%OS%"=="Windows_NT" setlocal
|
||||||
|
|
||||||
|
set DIRNAME=%~dp0
|
||||||
|
if "%DIRNAME%"=="" set DIRNAME=.
|
||||||
|
@rem This is normally unused
|
||||||
|
set APP_BASE_NAME=%~n0
|
||||||
|
set APP_HOME=%DIRNAME%
|
||||||
|
|
||||||
|
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||||
|
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||||
|
|
||||||
|
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||||
|
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||||
|
|
||||||
|
@rem Find java.exe
|
||||||
|
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||||
|
|
||||||
|
set JAVA_EXE=java.exe
|
||||||
|
%JAVA_EXE% -version >NUL 2>&1
|
||||||
|
if %ERRORLEVEL% equ 0 goto execute
|
||||||
|
|
||||||
|
echo. 1>&2
|
||||||
|
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
|
||||||
|
echo. 1>&2
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||||
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
|
goto fail
|
||||||
|
|
||||||
|
:findJavaFromJavaHome
|
||||||
|
set JAVA_HOME=%JAVA_HOME:"=%
|
||||||
|
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||||
|
|
||||||
|
if exist "%JAVA_EXE%" goto execute
|
||||||
|
|
||||||
|
echo. 1>&2
|
||||||
|
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
|
||||||
|
echo. 1>&2
|
||||||
|
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
|
||||||
|
echo location of your Java installation. 1>&2
|
||||||
|
|
||||||
|
goto fail
|
||||||
|
|
||||||
|
:execute
|
||||||
|
@rem Setup the command line
|
||||||
|
|
||||||
|
set CLASSPATH=
|
||||||
|
|
||||||
|
|
||||||
|
@rem Execute Gradle
|
||||||
|
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %*
|
||||||
|
|
||||||
|
:end
|
||||||
|
@rem End local scope for the variables with windows NT shell
|
||||||
|
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||||
|
|
||||||
|
:fail
|
||||||
|
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||||
|
rem the _cmd.exe /c_ return code!
|
||||||
|
set EXIT_CODE=%ERRORLEVEL%
|
||||||
|
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||||
|
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||||
|
exit /b %EXIT_CODE%
|
||||||
|
|
||||||
|
:mainEnd
|
||||||
|
if "%OS%"=="Windows_NT" endlocal
|
||||||
|
|
||||||
|
:omega
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
pluginManagement {
|
||||||
|
repositories {
|
||||||
|
mavenCentral()
|
||||||
|
gradlePluginPortal()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
rootProject.name = 'OpenStringer'
|
||||||
@@ -0,0 +1,372 @@
|
|||||||
|
package com.licel.stringer;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import org.apache.tools.ant.BuildException;
|
||||||
|
import org.apache.tools.ant.Project;
|
||||||
|
import org.apache.tools.ant.Task;
|
||||||
|
import org.apache.tools.ant.types.PatternSet;
|
||||||
|
import org.apache.tools.ant.types.PatternSet.NameEntry;
|
||||||
|
|
||||||
|
public class AntTask extends Task {
|
||||||
|
private Config config = new Config();
|
||||||
|
private final PatternSet patternSet;
|
||||||
|
|
||||||
|
public AntTask() {
|
||||||
|
this.config.setCheckCaller(true);
|
||||||
|
this.config.setListener(new AntTaskWorkerListener(this, this));
|
||||||
|
this.patternSet = new PatternSet();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute() {
|
||||||
|
this.log("Mode: ANT");
|
||||||
|
this.log(ProductInfo.getConsoleTitle());
|
||||||
|
Project project = this.getProject();
|
||||||
|
|
||||||
|
String[] includes = this.patternSet.getIncludePatterns(project);
|
||||||
|
if (includes != null) {
|
||||||
|
for (String include : includes) {
|
||||||
|
this.config.addInclude(include);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] excludes = this.patternSet.getExcludePatterns(project);
|
||||||
|
if (excludes != null) {
|
||||||
|
for (String exclude : excludes) {
|
||||||
|
this.config.addExclude(exclude);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Worker worker = new Worker(this.config);
|
||||||
|
worker.stringerIt();
|
||||||
|
} catch (Throwable ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
throw new BuildException(ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSrcFile(File srcFile) {
|
||||||
|
this.config.setSrcFile(srcFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSrcDir(File srcDir) {
|
||||||
|
this.config.setSrcDir(srcDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDestFile(File destFile) {
|
||||||
|
this.config.setDestFile(destFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDestDir(File destDir) {
|
||||||
|
this.config.setDestDir(destDir);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVerbose(boolean verbose) {
|
||||||
|
this.config.setVerbose(verbose);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParamsOptions createVerbose() {
|
||||||
|
return new ParamsOptions(this.config, "setVerbose", boolean.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOptimize(boolean optimize) {
|
||||||
|
this.config.setOptimize(optimize);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParamsOptions createOptimize() {
|
||||||
|
return new ParamsOptions(this.config, "setOptimize", boolean.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIntegrityProtection(boolean integrityProtection) {
|
||||||
|
this.config.setIntegrityProtection(integrityProtection);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setResourceEncryption(boolean resourceEncryption) {
|
||||||
|
this.config.setResourceEncryption(resourceEncryption);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOsgiCompatibility(boolean osgiCompatibility) {
|
||||||
|
this.config.setOsgiCompatibility(osgiCompatibility);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setJ2EECompatibility(boolean j2eeCompatibility) {
|
||||||
|
this.config.setOsgiCompatibility(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNameGenMethod(String nameGenMethod) {
|
||||||
|
this.config.setNameGenMethod(nameGenMethod);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProguardMapFile(File proguardMapFile) {
|
||||||
|
this.config.setProguardMapFile(proguardMapFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParamsOptions createProguardMapFile() {
|
||||||
|
return new ParamsOptions(this.config, "setProguardMapFile", String.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTarget(String target) {
|
||||||
|
this.config.setTarget(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParamsOptions createTarget() {
|
||||||
|
return new ParamsOptions(this.config, "setTarget", String.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setForceAndroid(boolean forceAndroid) {
|
||||||
|
this.config.setForceAndroid(forceAndroid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTrialExpirationTimestamp(String trialExpirationTimestamp) {
|
||||||
|
this.config.setTrialExpirationTimestamp(trialExpirationTimestamp);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParamsOptions createTrialExpirationTimestamp() {
|
||||||
|
return new ParamsOptions(this.config, "setTrialExpirationTimestamp", String.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTrialExpirationTimestampPattern(String trialExpirationTimestampPattern) {
|
||||||
|
this.config.setTrialExpirationTimestampPattern(trialExpirationTimestampPattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParamsOptions createTrialExpirationTimestampPattern() {
|
||||||
|
return new ParamsOptions(this.config, "setTrialExpirationTimestampPattern", String.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSignMode(String signMode) {
|
||||||
|
this.config.setSignMode(signMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParamsOptions createSignMode() {
|
||||||
|
return new ParamsOptions(this.config, "setSignMode", String.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setKeystore(String keystore) {
|
||||||
|
this.config.setKeystore(keystore);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParamsOptions createKeystore() {
|
||||||
|
return new ParamsOptions(this.config, "setKeystore", String.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAlias(String alias) {
|
||||||
|
this.config.setAlias(alias);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParamsOptions createAlias() {
|
||||||
|
return new ParamsOptions(this.config, "setAlias", String.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStorepass(String storepass) {
|
||||||
|
this.config.setStorepass(storepass);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParamsOptions createStorepass() {
|
||||||
|
return new ParamsOptions(this.config, "setStorepass", String.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setKeypass(String keypass) {
|
||||||
|
this.config.setKeypass(keypass);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParamsOptions createKeypass() {
|
||||||
|
return new ParamsOptions(this.config, "setKeypass", String.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStoretype(String storetype) {
|
||||||
|
this.config.setKeystoreType(storetype);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParamsOptions createStoretype() {
|
||||||
|
return new ParamsOptions(this.config, "setKeystoreType", String.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConfigFile(File configFile) {
|
||||||
|
try {
|
||||||
|
FileConfig fileConfig = new FileConfig(configFile);
|
||||||
|
if (this.config.getDestFile() != null) {
|
||||||
|
fileConfig.setDestFile(this.config.getDestFile());
|
||||||
|
}
|
||||||
|
if (this.config.getSrcFile() != null) {
|
||||||
|
fileConfig.setSrcFile(this.config.getSrcFile());
|
||||||
|
}
|
||||||
|
this.config = fileConfig;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw new BuildException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public NameEntry createInclude() {
|
||||||
|
return this.patternSet.createInclude();
|
||||||
|
}
|
||||||
|
|
||||||
|
public NameEntry createExclude() {
|
||||||
|
return this.patternSet.createExclude();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCheckCaller(boolean checkCaller) {
|
||||||
|
this.config.setCheckCaller(checkCaller);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCheckJar(boolean checkJar) {
|
||||||
|
this.config.setCheckJar(checkJar);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProtectionElementsOptions createProtectionElements() {
|
||||||
|
return new ProtectionElementsOptions(this.config.getProtectionElements());
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ParamsOptions {
|
||||||
|
protected Params container;
|
||||||
|
protected Method setMethod;
|
||||||
|
protected Method valueOfMethod;
|
||||||
|
|
||||||
|
public ParamsOptions(Params container, String methodName, Class<?> valueType) {
|
||||||
|
this.container = container;
|
||||||
|
try {
|
||||||
|
this.setMethod = container.getClass().getMethod(methodName, valueType);
|
||||||
|
Class<?> boxedType = valueType.equals(boolean.class) ? Boolean.class : valueType;
|
||||||
|
Class<?> valueOfArg = boxedType.equals(String.class) ? Object.class : String.class;
|
||||||
|
this.valueOfMethod = boxedType.getMethod("valueOf", valueOfArg);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw new BuildException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addText(String text) {
|
||||||
|
try {
|
||||||
|
Object parsedValue = this.valueOfMethod.invoke(null, text);
|
||||||
|
this.setMethod.invoke(this.container, parsedValue);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw new BuildException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class FiltersOptions {
|
||||||
|
protected Params container;
|
||||||
|
|
||||||
|
public FiltersOptions(Params container) {
|
||||||
|
this.container = container;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParamsOptions createFilter() {
|
||||||
|
return new ParamsOptions(this.container, "addFilter", String.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class FilteredParamsOptions {
|
||||||
|
protected Params container;
|
||||||
|
|
||||||
|
public FilteredParamsOptions(Params container) {
|
||||||
|
this.container = container;
|
||||||
|
container.setEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public FiltersOptions createFilters() {
|
||||||
|
return new FiltersOptions(this.container);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParamsOptions createMode() {
|
||||||
|
return new ParamsOptions(this.container, "setMode", String.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class StringEncryptonParamsOptions extends FilteredParamsOptions {
|
||||||
|
public StringEncryptonParamsOptions(Params params) {
|
||||||
|
super(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParamsOptions createCheckCaller() {
|
||||||
|
return new ParamsOptions(this.container, "setCheckCaller", boolean.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParamsOptions createEqualsIntrinsicEnabled() {
|
||||||
|
return new ParamsOptions(this.container, "setEqualsIntrinsicEnabled", boolean.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class IntegrityControlParamsOptions extends FilteredParamsOptions {
|
||||||
|
public IntegrityControlParamsOptions(Params params) {
|
||||||
|
super(params);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParamsOptions createCheckBytecode() {
|
||||||
|
return new ParamsOptions(((IntegrityControlParams) this.container).checkBytecode(), "setEnabled", boolean.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParamsOptions createCheckJar() {
|
||||||
|
return new ParamsOptions(((IntegrityControlParams) this.container).checkJar(), "setEnabled", boolean.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParamsOptions createSealJar() {
|
||||||
|
return new ParamsOptions(((IntegrityControlParams) this.container).sealJar(), "setEnabled", boolean.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParamsOptions createOsgiCompatibility() {
|
||||||
|
return new ParamsOptions(((IntegrityControlParams) this.container).osgiCompatibility(), "setEnabled", boolean.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class PathsOptions {
|
||||||
|
protected ProtectionElementParams container;
|
||||||
|
|
||||||
|
public PathsOptions(ProtectionElementParams container) {
|
||||||
|
this.container = container;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParamsOptions createPath() {
|
||||||
|
return new ParamsOptions(this.container, "addPath", String.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ProtectionElementOptions {
|
||||||
|
protected ProtectionElementParams container;
|
||||||
|
|
||||||
|
public ProtectionElementOptions(ProtectionElementParams container) {
|
||||||
|
this.container = container;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTarget(String target) {
|
||||||
|
this.container.setTarget(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ParamsOptions createTarget() {
|
||||||
|
return new ParamsOptions(this.container, "setTarget", String.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PathsOptions createPaths() {
|
||||||
|
return new PathsOptions(this.container);
|
||||||
|
}
|
||||||
|
|
||||||
|
public StringEncryptonParamsOptions createStringEncryption() {
|
||||||
|
return new StringEncryptonParamsOptions(this.container.getStringEncryption());
|
||||||
|
}
|
||||||
|
|
||||||
|
public FilteredParamsOptions createHideAccess() {
|
||||||
|
return new FilteredParamsOptions(this.container.getHideAccess());
|
||||||
|
}
|
||||||
|
|
||||||
|
public FilteredParamsOptions createResourceEncryption() {
|
||||||
|
return new FilteredParamsOptions(this.container.getResourceEncryption());
|
||||||
|
}
|
||||||
|
|
||||||
|
public IntegrityControlParamsOptions createIntegrityControl() {
|
||||||
|
return new IntegrityControlParamsOptions(this.container.getIntegrityControl());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ProtectionElementsOptions {
|
||||||
|
protected ProtectionElementParamsContainer container;
|
||||||
|
|
||||||
|
public ProtectionElementsOptions(ProtectionElementParamsContainer container) {
|
||||||
|
this.container = container;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProtectionElementOptions createProtectionElement() {
|
||||||
|
return new ProtectionElementOptions(this.container.createElement());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.licel.stringer;
|
||||||
|
|
||||||
|
import org.apache.tools.ant.Task;
|
||||||
|
|
||||||
|
class AntTaskWorkerListener implements WorkerListener {
|
||||||
|
private final AntTask antTask;
|
||||||
|
private final Task task;
|
||||||
|
|
||||||
|
AntTaskWorkerListener(AntTask antTask, Task task) {
|
||||||
|
this.antTask = antTask;
|
||||||
|
this.task = task;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void info(String message) {
|
||||||
|
this.task.log(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void verbose(String message) {
|
||||||
|
this.task.log(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,503 @@
|
|||||||
|
package com.licel.stringer;
|
||||||
|
|
||||||
|
import com.licel.stringer.model.ClassInfo;
|
||||||
|
import com.licel.stringer.util.StringerUtils;
|
||||||
|
import java.io.File;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
public class Config extends ProtectionElementParams {
|
||||||
|
public static final String RELEASE_MODE = "release";
|
||||||
|
public static final String DEFAULT_MODE = "default";
|
||||||
|
public static final String NONE_MODE = "none";
|
||||||
|
|
||||||
|
protected boolean verbose = false;
|
||||||
|
protected boolean optimize = false;
|
||||||
|
protected String nameGenMethod = "utf";
|
||||||
|
protected long trialExpirationTimestampSeconds = 0L;
|
||||||
|
protected String trialExpirationTimestamp = null;
|
||||||
|
protected String trialExpirationTimestampPattern = null;
|
||||||
|
protected List<String> injectList;
|
||||||
|
protected File srcFile;
|
||||||
|
protected File destFile;
|
||||||
|
protected File proguardMapFile;
|
||||||
|
protected Properties proguardMap;
|
||||||
|
protected WorkerListener listener;
|
||||||
|
protected String keystore;
|
||||||
|
protected String keystoreType;
|
||||||
|
protected String storepass;
|
||||||
|
protected String alias;
|
||||||
|
protected String keypass;
|
||||||
|
protected String signMode = NONE_MODE;
|
||||||
|
protected File tmpDir;
|
||||||
|
protected ArrayList<String> includeList;
|
||||||
|
protected ArrayList<String> excludeList;
|
||||||
|
public boolean isLegacy = false;
|
||||||
|
protected PersonalizationProfile personalizationProfile = new PersonalizationProfile();
|
||||||
|
protected ProtectionElementParamsContainer protectionElements = new ProtectionElementParamsContainer();
|
||||||
|
protected boolean forceGenerateInternalLibPkg = false;
|
||||||
|
|
||||||
|
public void validate() {
|
||||||
|
if (this.srcFile == null) {
|
||||||
|
throw new RuntimeException("Missing srcFile");
|
||||||
|
}
|
||||||
|
if (!this.srcFile.exists()) {
|
||||||
|
throw new RuntimeException("Could not find srcFile " + this.srcFile.getAbsolutePath());
|
||||||
|
}
|
||||||
|
if (this.destFile == null) {
|
||||||
|
throw new RuntimeException("Missing destFile");
|
||||||
|
}
|
||||||
|
if (this.tmpDir != null && this.tmpDir.isFile()) {
|
||||||
|
throw new RuntimeException("The value of tmpDir must point to a valid and writable directory");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.trialExpirationTimestamp != null) {
|
||||||
|
if (this.trialExpirationTimestampPattern == null) {
|
||||||
|
try {
|
||||||
|
this.trialExpirationTimestampSeconds = Long.parseLong(this.trialExpirationTimestamp);
|
||||||
|
if (this.trialExpirationTimestampSeconds <= 0L) {
|
||||||
|
throw new NumberFormatException();
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException ex) {
|
||||||
|
throw new RuntimeException("Incorrect format of trialExpirationTimestamp (positive integer > 0): " + this.trialExpirationTimestamp);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
SimpleDateFormat format = new SimpleDateFormat(this.trialExpirationTimestampPattern);
|
||||||
|
this.trialExpirationTimestampSeconds = format.parse(this.trialExpirationTimestamp).getTime() / 1000L;
|
||||||
|
} catch (IllegalArgumentException ex) {
|
||||||
|
throw new RuntimeException("Incorrect format of trialExpirationTimestampPattern: " + this.trialExpirationTimestampPattern);
|
||||||
|
} catch (ParseException ex) {
|
||||||
|
throw new RuntimeException("Incorrect format of trialExpirationTimestamp (" + this.trialExpirationTimestampPattern + "): " + this.trialExpirationTimestamp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!RELEASE_MODE.equalsIgnoreCase(this.signMode)
|
||||||
|
&& !DEFAULT_MODE.equalsIgnoreCase(this.signMode)
|
||||||
|
&& !NONE_MODE.equalsIgnoreCase(this.signMode)) {
|
||||||
|
throw new RuntimeException("Incorrect signMode:" + this.signMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.isReleaseMode()) {
|
||||||
|
if (this.keystore == null) {
|
||||||
|
throw new RuntimeException("In case of sign mode release it is necessary to set keystore path");
|
||||||
|
}
|
||||||
|
if (this.alias == null) {
|
||||||
|
throw new RuntimeException("In case of sign mode release it is necessary to set key alias");
|
||||||
|
}
|
||||||
|
if (this.storepass == null) {
|
||||||
|
throw new RuntimeException("In case of sign mode release it is necessary to set storepass");
|
||||||
|
}
|
||||||
|
if (this.keypass == null) {
|
||||||
|
throw new RuntimeException("In case of sign mode release it is necessary to set keypass");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.includeList != null && this.excludeList != null) {
|
||||||
|
this.stringEncryption.addFilter(new ClassInfo("glob:!**/**"));
|
||||||
|
this.integrityControl.addFilter(new ClassInfo("glob:!**/**"));
|
||||||
|
this.hideAccess.addFilter(new ClassInfo("glob:!**/**"));
|
||||||
|
this.resourceEncryption.addFilter(new ClassInfo("glob:!**/**"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.includeList != null) {
|
||||||
|
this.stringEncryption.setFiltered(true);
|
||||||
|
this.stringEncryption.setEnabled(true);
|
||||||
|
this.integrityControl.setFiltered(true);
|
||||||
|
this.integrityControl.setEnabled(true);
|
||||||
|
this.hideAccess.setFiltered(true);
|
||||||
|
this.hideAccess.setEnabled(true);
|
||||||
|
this.resourceEncryption.setFiltered(true);
|
||||||
|
this.resourceEncryption.setEnabled(true);
|
||||||
|
|
||||||
|
for (String include : this.includeList) {
|
||||||
|
this.stringEncryption.addFilter(new ClassInfo(include));
|
||||||
|
this.integrityControl.addFilter(new ClassInfo(include));
|
||||||
|
this.hideAccess.addFilter(new ClassInfo(include));
|
||||||
|
this.resourceEncryption.addFilter(new ClassInfo(include));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.excludeList != null) {
|
||||||
|
this.stringEncryption.setFiltered(true);
|
||||||
|
this.stringEncryption.setEnabled(true);
|
||||||
|
this.integrityControl.setFiltered(true);
|
||||||
|
this.integrityControl.setEnabled(true);
|
||||||
|
this.hideAccess.setFiltered(true);
|
||||||
|
this.hideAccess.setEnabled(true);
|
||||||
|
this.resourceEncryption.setFiltered(true);
|
||||||
|
this.resourceEncryption.setEnabled(true);
|
||||||
|
|
||||||
|
for (String exclude : this.excludeList) {
|
||||||
|
this.stringEncryption.addFilter(new ClassInfo("glob:!" + exclude));
|
||||||
|
this.integrityControl.addFilter(new ClassInfo("glob:!" + exclude));
|
||||||
|
this.hideAccess.addFilter(new ClassInfo("glob:!" + exclude));
|
||||||
|
this.resourceEncryption.addFilter(new ClassInfo("glob:!" + exclude));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.proguardMapFile != null) {
|
||||||
|
if (!this.proguardMapFile.exists()) {
|
||||||
|
throw new RuntimeException("Could not find proguardMapFile: " + this.proguardMapFile.getAbsolutePath());
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
this.proguardMap = StringerUtils.loadProguardMap(this.proguardMapFile);
|
||||||
|
this.stringEncryption.setMap(this.proguardMap);
|
||||||
|
this.hideAccess.setMap(this.proguardMap);
|
||||||
|
this.resourceEncryption.setMap(this.proguardMap);
|
||||||
|
this.integrityControl.setMap(this.proguardMap);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
throw new RuntimeException("Could not load proguardMapFile " + ex.getMessage());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
boolean hasNullPaths = false;
|
||||||
|
for (ProtectionElementParams element : this.protectionElements.getElements()) {
|
||||||
|
if (element.getPaths() == null) {
|
||||||
|
hasNullPaths = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (hasNullPaths && this.protectionElements.getElements().size() > 1) {
|
||||||
|
throw new RuntimeException("Protection elements w/ and w/o path tag cannot be used at the same time");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<Config> generateProtectionElementsConfigs() {
|
||||||
|
ArrayList<Config> configs = new ArrayList<>();
|
||||||
|
if (this.protectionElements.getElements().isEmpty()) {
|
||||||
|
configs.add(this);
|
||||||
|
return configs;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (ProtectionElementParams element : this.protectionElements.getElements()) {
|
||||||
|
Config elementConfig = new Config();
|
||||||
|
elementConfig.setAlias(this.alias);
|
||||||
|
elementConfig.setKeypass(this.keypass);
|
||||||
|
elementConfig.setKeystore(this.keystore);
|
||||||
|
elementConfig.setKeystoreType(this.keystoreType);
|
||||||
|
elementConfig.setOptimize(this.optimize);
|
||||||
|
elementConfig.setSignMode(this.signMode);
|
||||||
|
elementConfig.setStorepass(this.storepass);
|
||||||
|
elementConfig.setTrialExpirationTimestamp(this.trialExpirationTimestamp);
|
||||||
|
elementConfig.setTrialExpirationTimestampPattern(this.trialExpirationTimestampPattern);
|
||||||
|
elementConfig.setTrialExpirationTimestampSeconds(this.trialExpirationTimestampSeconds);
|
||||||
|
elementConfig.setVerbose(this.verbose);
|
||||||
|
elementConfig.setListener(this.listener);
|
||||||
|
elementConfig.setProguardMapFile(this.proguardMapFile);
|
||||||
|
elementConfig.setTarget(element.getTarget() != null ? element.getTarget() : this.target);
|
||||||
|
elementConfig.setPaths(element.getPaths());
|
||||||
|
elementConfig.setStringEncryption(element.getStringEncryption());
|
||||||
|
elementConfig.setHideAccess(element.getHideAccess());
|
||||||
|
elementConfig.setIntegrityControl(element.getIntegrityControl());
|
||||||
|
elementConfig.setResourceEncryption(element.getResourceEncryption());
|
||||||
|
if (this.proguardMap != null) {
|
||||||
|
elementConfig.getStringEncryption().setMap(this.proguardMap);
|
||||||
|
elementConfig.getHideAccess().setMap(this.proguardMap);
|
||||||
|
elementConfig.getResourceEncryption().setMap(this.proguardMap);
|
||||||
|
elementConfig.getIntegrityControl().setMap(this.proguardMap);
|
||||||
|
}
|
||||||
|
elementConfig.setSrcFile(this.srcFile);
|
||||||
|
elementConfig.setDestFile(this.destFile);
|
||||||
|
configs.add(elementConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
return configs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addInclude(String pattern) {
|
||||||
|
if (this.includeList == null) {
|
||||||
|
this.includeList = new ArrayList<>();
|
||||||
|
}
|
||||||
|
this.includeList.add(pattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addExclude(String pattern) {
|
||||||
|
if (this.excludeList == null) {
|
||||||
|
this.excludeList = new ArrayList<>();
|
||||||
|
}
|
||||||
|
this.excludeList.add(pattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addInject(String pattern) {
|
||||||
|
if (this.injectList == null) {
|
||||||
|
this.injectList = new ArrayList<>();
|
||||||
|
}
|
||||||
|
this.injectList.add(pattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getInjectList() {
|
||||||
|
return this.injectList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCheckCaller(boolean checkCaller) {
|
||||||
|
this.stringEncryption.setEnabled(true);
|
||||||
|
this.stringEncryption.setCheckCaller(checkCaller);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isVerbose() {
|
||||||
|
return this.verbose;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVerbose(boolean verbose) {
|
||||||
|
this.verbose = verbose;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIntegrityProtection(boolean integrityProtection) {
|
||||||
|
this.integrityControl.setEnabled(true);
|
||||||
|
this.integrityControl.checkBytecode().setEnabled(integrityProtection);
|
||||||
|
this.integrityControl.checkJar().setEnabled(integrityProtection);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setResourceEncryption(boolean resourceEncryption) {
|
||||||
|
this.resourceEncryption.setEnabled(resourceEncryption);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isOptimize() {
|
||||||
|
return this.optimize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOptimize(boolean optimize) {
|
||||||
|
this.optimize = optimize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isJ2EECompatibility() {
|
||||||
|
return this.isOsgiCompatibility();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setJ2EECompatibility(boolean j2eeCompatibility) {
|
||||||
|
this.setOsgiCompatibility(j2eeCompatibility);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isOsgiCompatibility() {
|
||||||
|
return this.integrityControl.osgiCompatibility().isEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOsgiCompatibility(boolean osgiCompatibility) {
|
||||||
|
this.integrityControl.osgiCompatibility().setEnabled(osgiCompatibility);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNameGenMethod() {
|
||||||
|
return this.nameGenMethod;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNameGenMethod(String nameGenMethod) {
|
||||||
|
this.nameGenMethod = nameGenMethod;
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getDestFile() {
|
||||||
|
return this.destFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDestFile(File destFile) {
|
||||||
|
this.destFile = destFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getSrcFile() {
|
||||||
|
return this.srcFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSrcFile(File srcFile) {
|
||||||
|
this.srcFile = srcFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDestDir(File destDir) {
|
||||||
|
this.destFile = destDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSrcDir(File srcDir) {
|
||||||
|
this.srcFile = srcDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getKeystore() {
|
||||||
|
return this.keystore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setKeystore(String keystore) {
|
||||||
|
this.keystore = keystore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getKeystoreType() {
|
||||||
|
return this.keystoreType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setKeystoreType(String keystoreType) {
|
||||||
|
this.keystoreType = keystoreType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStorepass() {
|
||||||
|
return this.storepass;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStorepass(String storepass) {
|
||||||
|
this.storepass = storepass;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAlias() {
|
||||||
|
return this.alias;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAlias(String alias) {
|
||||||
|
this.alias = alias;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getKeypass() {
|
||||||
|
return this.keypass;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setKeypass(String keypass) {
|
||||||
|
this.keypass = keypass;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSignMode() {
|
||||||
|
return this.signMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSignMode(String signMode) {
|
||||||
|
this.signMode = signMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isReleaseMode() {
|
||||||
|
return RELEASE_MODE.equalsIgnoreCase(this.signMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDefaultMode() {
|
||||||
|
return DEFAULT_MODE.equalsIgnoreCase(this.signMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isNoneMode() {
|
||||||
|
return NONE_MODE.equalsIgnoreCase(this.signMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getProguardMapFile() {
|
||||||
|
return this.proguardMapFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProguardMapFile(File proguardMapFile) {
|
||||||
|
this.proguardMapFile = proguardMapFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProguardMapFile(String proguardMapFile) {
|
||||||
|
this.proguardMapFile = new File(proguardMapFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Properties getProguardMap() {
|
||||||
|
return this.proguardMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public WorkerListener getListener() {
|
||||||
|
return this.listener != null ? this.listener : this.getDefaultListener();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setListener(WorkerListener listener) {
|
||||||
|
this.listener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isForceAndroid() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setForceAndroid(boolean forceAndroid) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTrialExpirationTimestamp() {
|
||||||
|
return this.trialExpirationTimestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTrialExpirationTimestamp(String trialExpirationTimestamp) {
|
||||||
|
this.trialExpirationTimestamp = trialExpirationTimestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getTrialExpirationTimestampSeconds() {
|
||||||
|
return this.trialExpirationTimestampSeconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTrialExpirationTimestampSeconds(long trialExpirationTimestampSeconds) {
|
||||||
|
this.trialExpirationTimestampSeconds = trialExpirationTimestampSeconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTrialExpirationTimestampPattern() {
|
||||||
|
return this.trialExpirationTimestampPattern;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTrialExpirationTimestampPattern(String trialExpirationTimestampPattern) {
|
||||||
|
this.trialExpirationTimestampPattern = trialExpirationTimestampPattern;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCheckJar(boolean checkJar) {
|
||||||
|
this.integrityControl.checkJar().setEnabled(checkJar);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProtectionElementParamsContainer getProtectionElements() {
|
||||||
|
return this.protectionElements;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PersonalizationProfile getPersonalizationProfile() {
|
||||||
|
return this.personalizationProfile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPersonalizationProfile(PersonalizationProfile personalizationProfile) {
|
||||||
|
this.personalizationProfile = personalizationProfile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getTmpDir() {
|
||||||
|
return this.tmpDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTmpDir(File tmpDir) {
|
||||||
|
this.tmpDir = tmpDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
WorkerListener getDefaultListener() {
|
||||||
|
return new ConsoleWorkerListener(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isForceGenerateInternalLibPkg() {
|
||||||
|
return this.forceGenerateInternalLibPkg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setForceGenerateInternalLibPkg(boolean forceGenerateInternalLibPkg) {
|
||||||
|
this.forceGenerateInternalLibPkg = forceGenerateInternalLibPkg;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dump(WorkerListener listener) {
|
||||||
|
if (this.isLegacy) {
|
||||||
|
listener.verbose("A legacy format configuration file is set. See actual protection settings in verbose mode.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.verbose) {
|
||||||
|
listener.verbose("[Configuration]");
|
||||||
|
listener.verbose(" source: " + this.srcFile.getAbsolutePath());
|
||||||
|
listener.verbose(" destination: " + this.destFile.getAbsolutePath());
|
||||||
|
listener.verbose(" sign mode: " + this.signMode);
|
||||||
|
listener.verbose(" verbose: " + this.verbose);
|
||||||
|
listener.verbose(" optimize: " + this.optimize);
|
||||||
|
listener.verbose(" android library: " + this.isForceAndroid());
|
||||||
|
if (this.getProguardMapFile() != null) {
|
||||||
|
listener.verbose(" proguard map file: " + this.getProguardMapFile());
|
||||||
|
}
|
||||||
|
if (this.getTrialExpirationTimestampSeconds() > 0L) {
|
||||||
|
Date expirationDate = new Date(this.getTrialExpirationTimestampSeconds() * 1000L);
|
||||||
|
SimpleDateFormat format = new SimpleDateFormat();
|
||||||
|
listener.verbose(" trialExpirationTimestamp: " + this.getTrialExpirationTimestampSeconds() + "(" + format.format(expirationDate) + ")");
|
||||||
|
}
|
||||||
|
if (this.getTmpDir() != null) {
|
||||||
|
listener.verbose(" tmpDir: " + this.getTmpDir());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.protectionElements.getElements().isEmpty()) {
|
||||||
|
super.dump(listener);
|
||||||
|
} else {
|
||||||
|
for (ProtectionElementParams element : this.protectionElements.getElements()) {
|
||||||
|
element.dump(listener);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,148 @@
|
|||||||
|
package com.licel.stringer;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class ConsoleTask {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Config config = new Config();
|
||||||
|
String configFilePath = null;
|
||||||
|
boolean repairMode = false;
|
||||||
|
int positionalIndex = 0;
|
||||||
|
|
||||||
|
try {
|
||||||
|
for (int i = 0; i < args.length; i++) {
|
||||||
|
if (args[i].equalsIgnoreCase("-verbose")) {
|
||||||
|
config.setVerbose(true);
|
||||||
|
} else if (args[i].equalsIgnoreCase("-checkCaller")) {
|
||||||
|
config.setCheckCaller(true);
|
||||||
|
} else if (args[i].equalsIgnoreCase("-integrityProtection")) {
|
||||||
|
config.setIntegrityProtection(true);
|
||||||
|
} else if (args[i].equalsIgnoreCase("-optimize")) {
|
||||||
|
config.setOptimize(true);
|
||||||
|
} else if (args[i].equalsIgnoreCase("-resourceEncryption")) {
|
||||||
|
config.setResourceEncryption(true);
|
||||||
|
} else if (args[i].equalsIgnoreCase("-osgiCompatibility")) {
|
||||||
|
config.setOsgiCompatibility(true);
|
||||||
|
} else if (args[i].equalsIgnoreCase("-include")) {
|
||||||
|
if (i + 1 < args.length) {
|
||||||
|
config.addInclude(args[++i]);
|
||||||
|
}
|
||||||
|
} else if (args[i].equalsIgnoreCase("-exclude")) {
|
||||||
|
if (i + 1 < args.length) {
|
||||||
|
config.addExclude(args[++i]);
|
||||||
|
}
|
||||||
|
} else if (args[i].equalsIgnoreCase("-inject")) {
|
||||||
|
if (i + 1 < args.length) {
|
||||||
|
config.addInject(args[++i]);
|
||||||
|
}
|
||||||
|
} else if (args[i].equalsIgnoreCase("-configFile")) {
|
||||||
|
if (i + 1 < args.length) {
|
||||||
|
configFilePath = args[++i];
|
||||||
|
}
|
||||||
|
} else if (args[i].equalsIgnoreCase("-proguardMapFile")) {
|
||||||
|
if (i + 1 < args.length) {
|
||||||
|
config.setProguardMapFile(new File(args[++i]));
|
||||||
|
}
|
||||||
|
} else if (args[i].equalsIgnoreCase("-nameGenMethod")) {
|
||||||
|
if (i + 1 < args.length) {
|
||||||
|
String method = args[++i];
|
||||||
|
if ("utf".equalsIgnoreCase(method) || "latin".equalsIgnoreCase(method)) {
|
||||||
|
config.setNameGenMethod(method);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (args[i].equalsIgnoreCase("-target")) {
|
||||||
|
if (i + 1 < args.length) {
|
||||||
|
config.setTarget(args[++i]);
|
||||||
|
}
|
||||||
|
} else if (args[i].equalsIgnoreCase("-outputType")) {
|
||||||
|
if (i + 1 < args.length) {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
} else if (args[i].equalsIgnoreCase("-trialExpirationTimestamp")) {
|
||||||
|
if (i + 1 < args.length) {
|
||||||
|
config.setTrialExpirationTimestamp(args[++i]);
|
||||||
|
}
|
||||||
|
} else if (args[i].equalsIgnoreCase("-trialExpirationTimestampPattern")) {
|
||||||
|
if (i + 1 < args.length) {
|
||||||
|
config.setTrialExpirationTimestampPattern(args[++i]);
|
||||||
|
}
|
||||||
|
} else if (args[i].equalsIgnoreCase("-forceAndroid")) {
|
||||||
|
config.setForceAndroid(true);
|
||||||
|
} else if (args[i].equalsIgnoreCase("-noCheckJar")) {
|
||||||
|
config.setCheckJar(false);
|
||||||
|
} else if (args[i].equalsIgnoreCase("-equalsIntrinsicEnabled")) {
|
||||||
|
config.getStringEncryption().setEqualsIntrinsicEnabled(true);
|
||||||
|
} else if (args[i].equalsIgnoreCase("-repair")) {
|
||||||
|
repairMode = true;
|
||||||
|
} else if (args[i].equalsIgnoreCase("-info")) {
|
||||||
|
printProductInfo();
|
||||||
|
} else {
|
||||||
|
positionalIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception ex) {
|
||||||
|
System.err.println("Error parsing config parameters : " + ex.getMessage());
|
||||||
|
System.exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (configFilePath != null) {
|
||||||
|
try {
|
||||||
|
FileConfig fileConfig = new FileConfig(new File(configFilePath));
|
||||||
|
if (config.getDestFile() != null) {
|
||||||
|
fileConfig.setDestFile(config.getDestFile());
|
||||||
|
}
|
||||||
|
if (config.getSrcFile() != null) {
|
||||||
|
fileConfig.setSrcFile(config.getSrcFile());
|
||||||
|
}
|
||||||
|
if (config.getProguardMapFile() != null) {
|
||||||
|
fileConfig.setProguardMapFile(config.getProguardMapFile());
|
||||||
|
}
|
||||||
|
config = fileConfig;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
System.err.println("Error parsing config file : " + ex.getMessage());
|
||||||
|
System.exit(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.getSrcFile() == null && positionalIndex + 1 > args.length) {
|
||||||
|
System.err.println("Missing src parameter");
|
||||||
|
System.err.println("Usage : java -jar stringer.jar [options] src dest");
|
||||||
|
System.exit(-1);
|
||||||
|
} else if (positionalIndex < args.length) {
|
||||||
|
File src = new File(args[positionalIndex]);
|
||||||
|
if (src.isDirectory()) {
|
||||||
|
config.setSrcDir(src);
|
||||||
|
} else {
|
||||||
|
config.setSrcFile(src);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config.getDestFile() == null && positionalIndex + 2 > args.length) {
|
||||||
|
System.err.println("Missing dest parameter");
|
||||||
|
System.err.println("Usage : java -jar stringer.jar [options] src dest");
|
||||||
|
System.exit(-1);
|
||||||
|
} else if (positionalIndex + 1 < args.length) {
|
||||||
|
config.setDestFile(new File(args[positionalIndex + 1]));
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
config.getListener().info("Mode: CLI");
|
||||||
|
if (!repairMode) {
|
||||||
|
Worker worker = new Worker(config);
|
||||||
|
worker.stringerIt();
|
||||||
|
} else {
|
||||||
|
Worker.repairArchive(config.getSrcFile(), config.getDestFile());
|
||||||
|
}
|
||||||
|
} catch (Throwable ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
System.err.println("Failed to process due to: " + ex.getMessage());
|
||||||
|
System.exit(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void printProductInfo() {
|
||||||
|
System.out.println(ProductInfo.getInfoText());
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.licel.stringer;
|
||||||
|
|
||||||
|
class ConsoleWorkerListener implements WorkerListener {
|
||||||
|
private final Config config;
|
||||||
|
|
||||||
|
ConsoleWorkerListener(Config config) {
|
||||||
|
this.config = config;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void info(String message) {
|
||||||
|
System.out.println(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void verbose(String message) {
|
||||||
|
System.out.println(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,193 @@
|
|||||||
|
package com.licel.stringer;
|
||||||
|
|
||||||
|
import com.licel.stringer.config.PathFilter;
|
||||||
|
import com.licel.stringer.config.ProtectionConfigHandler;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import javax.xml.parsers.DocumentBuilder;
|
||||||
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
import javax.xml.parsers.SAXParser;
|
||||||
|
import javax.xml.parsers.SAXParserFactory;
|
||||||
|
import javax.xml.transform.Transformer;
|
||||||
|
import javax.xml.transform.TransformerException;
|
||||||
|
import javax.xml.transform.TransformerFactory;
|
||||||
|
import javax.xml.transform.dom.DOMSource;
|
||||||
|
import javax.xml.transform.stream.StreamResult;
|
||||||
|
import org.w3c.dom.Document;
|
||||||
|
import org.w3c.dom.Element;
|
||||||
|
import org.xml.sax.InputSource;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
public class FileConfig extends Config {
|
||||||
|
private SAXParserFactory saxParserFactory = null;
|
||||||
|
|
||||||
|
public FileConfig() {
|
||||||
|
this.saxParserFactory = this.createSAXParserFactory();
|
||||||
|
}
|
||||||
|
|
||||||
|
public FileConfig(File file) throws IOException, ParserConfigurationException, SAXException {
|
||||||
|
this.saxParserFactory = this.createSAXParserFactory();
|
||||||
|
this.parseXmlFile(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Document createXmlDoc() throws ParserConfigurationException {
|
||||||
|
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||||
|
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||||
|
Document document = builder.newDocument();
|
||||||
|
Element root = document.createElement("stringer-v3");
|
||||||
|
root.appendChild(this.createTag(document, "signMode", this.signMode));
|
||||||
|
root.appendChild(this.createTag(document, "verbose", Boolean.toString(this.verbose)));
|
||||||
|
root.appendChild(this.createTag(document, "optimize", Boolean.toString(this.optimize)));
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (this.proguardMapFile != null) {
|
||||||
|
root.appendChild(this.createTag(document, "proguardMapFile", this.proguardMapFile.getCanonicalPath()));
|
||||||
|
}
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
|
||||||
|
document.appendChild(root);
|
||||||
|
if (this.isReleaseMode()) {
|
||||||
|
if (this.keystore != null && !this.keystore.trim().isEmpty()) {
|
||||||
|
root.appendChild(this.createTag(document, "keystore", this.keystore));
|
||||||
|
}
|
||||||
|
if (this.alias != null && !this.alias.trim().isEmpty()) {
|
||||||
|
root.appendChild(this.createTag(document, "alias", this.alias));
|
||||||
|
}
|
||||||
|
if (this.storepass != null && !this.storepass.trim().isEmpty()) {
|
||||||
|
root.appendChild(this.createTag(document, "storepass", this.storepass));
|
||||||
|
}
|
||||||
|
if (this.keystoreType != null && !this.keystoreType.trim().isEmpty()) {
|
||||||
|
root.appendChild(this.createTag(document, "storetype", this.keystoreType));
|
||||||
|
}
|
||||||
|
if (this.keypass != null && !this.keypass.trim().isEmpty()) {
|
||||||
|
root.appendChild(this.createTag(document, "keypass", this.keypass));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (this.tmpDir != null) {
|
||||||
|
root.appendChild(this.createTag(document, "tmpDir", this.tmpDir.getCanonicalPath()));
|
||||||
|
}
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayList<Config> elementConfigs = this.generateProtectionElementsConfigs();
|
||||||
|
Element protectionElementsNode = document.createElement("protectionElements");
|
||||||
|
for (Config elementConfig : elementConfigs) {
|
||||||
|
protectionElementsNode.appendChild(this.createProtectionElementParams(document, elementConfig));
|
||||||
|
}
|
||||||
|
|
||||||
|
root.appendChild(protectionElementsNode);
|
||||||
|
return document;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void store(File file) {
|
||||||
|
try {
|
||||||
|
Document document = this.createXmlDoc();
|
||||||
|
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||||
|
Transformer transformer = transformerFactory.newTransformer();
|
||||||
|
DOMSource source = new DOMSource(document);
|
||||||
|
transformer.setOutputProperty("indent", "yes");
|
||||||
|
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
|
||||||
|
StreamResult result = new StreamResult(file);
|
||||||
|
transformer.transform(source, result);
|
||||||
|
} catch (ParserConfigurationException | TransformerException ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Element createTag(Document document, String tagName, String value) {
|
||||||
|
Element element = document.createElement(tagName);
|
||||||
|
element.setTextContent(value);
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Element createParams(Document document, String tagName, FilteredParams params) {
|
||||||
|
Element element = document.createElement(tagName);
|
||||||
|
Element modeElement = document.createElement("mode");
|
||||||
|
modeElement.setTextContent(params.getMode());
|
||||||
|
element.appendChild(modeElement);
|
||||||
|
if (params.filtered && params.filters != null && !params.filters.isEmpty()) {
|
||||||
|
Element filtersElement = document.createElement("filters");
|
||||||
|
for (PathFilter filter : params.filters) {
|
||||||
|
Element filterElement = document.createElement("filter");
|
||||||
|
filterElement.appendChild(document.createCDATASection(filter.toString()));
|
||||||
|
filtersElement.appendChild(filterElement);
|
||||||
|
}
|
||||||
|
element.appendChild(filtersElement);
|
||||||
|
}
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Element createProtectionElementParams(Document document, ProtectionElementParams params) {
|
||||||
|
Element element = document.createElement("protectionElement");
|
||||||
|
if (this.target != null) {
|
||||||
|
element.appendChild(this.createTag(document, "target", this.target));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (params.getPaths() != null) {
|
||||||
|
Element pathsElement = document.createElement("paths");
|
||||||
|
for (String path : params.getPaths()) {
|
||||||
|
Element pathElement = document.createElement("path");
|
||||||
|
pathElement.appendChild(document.createCDATASection(path));
|
||||||
|
pathsElement.appendChild(pathElement);
|
||||||
|
}
|
||||||
|
element.appendChild(pathsElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (params.getStringEncryption().isEnabled()) {
|
||||||
|
Element stringEnc = this.createParams(document, "stringEncryption", params.getStringEncryption());
|
||||||
|
stringEnc.appendChild(this.createTag(document, "checkCaller", Boolean.toString(params.getStringEncryption().isCheckCaller())));
|
||||||
|
stringEnc.appendChild(this.createTag(document, "equalsIntrinsicEnabled", Boolean.toString(params.getStringEncryption().isEqualsIntrinsicEnabled())));
|
||||||
|
element.appendChild(stringEnc);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (params.getHideAccess().isEnabled()) {
|
||||||
|
element.appendChild(this.createParams(document, "hideAccess", params.getHideAccess()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (params.getResourceEncryption().isEnabled()) {
|
||||||
|
element.appendChild(this.createParams(document, "resourceEncryption", params.getResourceEncryption()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (params.getIntegrityControl().isEnabled()) {
|
||||||
|
Element integrity = this.createParams(document, "integrityControl", params.getIntegrityControl());
|
||||||
|
integrity.appendChild(this.createTag(document, "checkBytecode", Boolean.toString(params.getIntegrityControl().checkBytecode().isEnabled())));
|
||||||
|
integrity.appendChild(this.createTag(document, "checkJar", Boolean.toString(params.getIntegrityControl().checkJar().isEnabled())));
|
||||||
|
integrity.appendChild(this.createTag(document, "sealJar", Boolean.toString(params.getIntegrityControl().sealJar().isEnabled())));
|
||||||
|
integrity.appendChild(this.createTag(document, "osgiCompatibility", Boolean.toString(params.getIntegrityControl().osgiCompatibility().isEnabled())));
|
||||||
|
element.appendChild(integrity);
|
||||||
|
}
|
||||||
|
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
|
private SAXParserFactory createSAXParserFactory() {
|
||||||
|
SAXParserFactory factory = SAXParserFactory.newInstance();
|
||||||
|
factory.setValidating(false);
|
||||||
|
try {
|
||||||
|
factory.setFeature("http://xml.org/sax/features/validation", false);
|
||||||
|
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
|
||||||
|
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
|
||||||
|
factory.setFeature("http://xml.org/sax/features/external-general-entities", false);
|
||||||
|
factory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
return factory;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void parseXmlFile(File file) throws IOException, ParserConfigurationException, SAXException {
|
||||||
|
try (InputStreamReader reader = new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8)) {
|
||||||
|
InputSource inputSource = new InputSource();
|
||||||
|
inputSource.setCharacterStream(reader);
|
||||||
|
ProtectionConfigHandler handler = new ProtectionConfigHandler(this, this);
|
||||||
|
SAXParser parser = this.saxParserFactory.newSAXParser();
|
||||||
|
parser.parse(inputSource, handler);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,220 @@
|
|||||||
|
package com.licel.stringer;
|
||||||
|
|
||||||
|
import com.licel.stringer.config.PathFilter;
|
||||||
|
import com.licel.stringer.model.ClassInfo;
|
||||||
|
import java.nio.file.FileSystems;
|
||||||
|
import java.nio.file.PathMatcher;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
public class FilteredParams extends Params {
|
||||||
|
public static final String ANNOTATIONS_MODE = "annotations";
|
||||||
|
public static final String FILTERED_MODE = "filter";
|
||||||
|
public static final String OFF_MODE = "off";
|
||||||
|
|
||||||
|
protected boolean annotations = false;
|
||||||
|
protected boolean filtered = true;
|
||||||
|
protected List<PathFilter> filters = new ArrayList<>();
|
||||||
|
protected Properties map;
|
||||||
|
|
||||||
|
public void setMode(String mode) throws ParseException {
|
||||||
|
if (mode != null) {
|
||||||
|
if (ANNOTATIONS_MODE.equals(mode)) {
|
||||||
|
this.annotations = true;
|
||||||
|
this.filtered = false;
|
||||||
|
this.enabled = true;
|
||||||
|
} else if (FILTERED_MODE.equals(mode)) {
|
||||||
|
this.annotations = false;
|
||||||
|
this.filtered = true;
|
||||||
|
this.enabled = true;
|
||||||
|
} else if (OFF_MODE.equals(mode)) {
|
||||||
|
this.annotations = false;
|
||||||
|
this.filtered = false;
|
||||||
|
this.enabled = false;
|
||||||
|
} else {
|
||||||
|
throw new ParseException("Illegal mode value: " + mode, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMode() {
|
||||||
|
if (this.annotations) {
|
||||||
|
return ANNOTATIONS_MODE;
|
||||||
|
}
|
||||||
|
return this.filtered ? FILTERED_MODE : OFF_MODE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMap(Properties map) {
|
||||||
|
this.map = map;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAnnotations() {
|
||||||
|
return this.annotations;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAnnotations(boolean annotations) {
|
||||||
|
this.annotations = annotations;
|
||||||
|
this.filtered = !annotations;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isFiltered() {
|
||||||
|
return this.filtered;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFiltered(boolean filtered) {
|
||||||
|
this.filtered = filtered;
|
||||||
|
this.annotations = !filtered;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return this.filters.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<PathFilter> getFilters() {
|
||||||
|
return this.filters;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addFilter(ClassInfo classInfo) {
|
||||||
|
this.addFilter(classInfo.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addFilter(String filterPattern) {
|
||||||
|
this.filters.add(this.makeFilter(filterPattern));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected PathFilter makeFilter(String filterPattern) {
|
||||||
|
PathMatcher pathMatcher = null;
|
||||||
|
String syntaxPrefix = "";
|
||||||
|
boolean exclude = false;
|
||||||
|
boolean isRegex = filterPattern.startsWith("regex:");
|
||||||
|
boolean isGlob = filterPattern.startsWith("glob:");
|
||||||
|
if (isRegex) {
|
||||||
|
syntaxPrefix = "regex:";
|
||||||
|
}
|
||||||
|
if (isGlob) {
|
||||||
|
syntaxPrefix = "glob:";
|
||||||
|
}
|
||||||
|
|
||||||
|
String expression = filterPattern;
|
||||||
|
if (isRegex || isGlob) {
|
||||||
|
int colonIndex = expression.indexOf(':');
|
||||||
|
if (colonIndex + 1 >= expression.length()) {
|
||||||
|
throw new RuntimeException("Invalid filter: " + expression);
|
||||||
|
}
|
||||||
|
expression = filterPattern.substring(colonIndex + 1);
|
||||||
|
exclude = expression.charAt(0) == '!';
|
||||||
|
if (exclude) {
|
||||||
|
expression = expression.substring(1);
|
||||||
|
filterPattern = syntaxPrefix.concat(expression);
|
||||||
|
}
|
||||||
|
pathMatcher = FileSystems.getDefault().getPathMatcher(filterPattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new PathFilter(pathMatcher, syntaxPrefix, expression, exclude);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFilterString(String delimiter) {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
for (int i = 0; i < this.filters.size(); i++) {
|
||||||
|
builder.append(this.filters.get(i).toString()).append(delimiter);
|
||||||
|
}
|
||||||
|
if (builder.length() > 0 && builder.charAt(builder.length() - 1) == delimiter.charAt(0)) {
|
||||||
|
builder.deleteCharAt(builder.length() - 1);
|
||||||
|
}
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFilterString(String filterList, String delimiterRegex) {
|
||||||
|
this.filters = new ArrayList<>();
|
||||||
|
String[] entries = filterList.split(delimiterRegex);
|
||||||
|
for (String entry : entries) {
|
||||||
|
if (!entry.trim().isEmpty()) {
|
||||||
|
this.addFilter(new ClassInfo(entry));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean match(ClassInfo classInfo) {
|
||||||
|
return this.match(classInfo.name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean match(String target) {
|
||||||
|
return this.match(target, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean match(String target, boolean resolveProguardName) {
|
||||||
|
if (!this.filtered) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (this.filters.isEmpty()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean defaultResult = false;
|
||||||
|
for (int i = this.filters.size() - 1; i >= 0; i--) {
|
||||||
|
PathFilter filter = this.filters.get(i);
|
||||||
|
if (filter.pathMatcher != null) {
|
||||||
|
boolean matched = filter.pathMatcher.matches(
|
||||||
|
resolveProguardName ? Paths.get(this.resolveClassName(target)) : Paths.get(target));
|
||||||
|
if (filter.exclude) {
|
||||||
|
defaultResult = true;
|
||||||
|
if (matched) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (matched) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else if (filter.pathExpression != null
|
||||||
|
&& (resolveProguardName ? this.resolveClassName(target) : target).matches(this.wildcardToRegex(filter.pathExpression))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return defaultResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String resolveClassName(String className) {
|
||||||
|
String resolved = className;
|
||||||
|
if (this.map != null && this.map.containsKey(resolved)) {
|
||||||
|
resolved = this.map.getProperty(resolved).replace('.', '/');
|
||||||
|
}
|
||||||
|
return resolved;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String wildcardToRegex(String wildcard) {
|
||||||
|
StringBuilder regex = new StringBuilder(wildcard.length());
|
||||||
|
regex.append('^');
|
||||||
|
for (int i = 0; i < wildcard.length(); i++) {
|
||||||
|
char ch = wildcard.charAt(i);
|
||||||
|
switch (ch) {
|
||||||
|
case '$':
|
||||||
|
case '(':
|
||||||
|
case ')':
|
||||||
|
case '.':
|
||||||
|
case '[':
|
||||||
|
case '\\':
|
||||||
|
case ']':
|
||||||
|
case '^':
|
||||||
|
case '{':
|
||||||
|
case '|':
|
||||||
|
case '}':
|
||||||
|
regex.append("\\").append(ch);
|
||||||
|
break;
|
||||||
|
case '*':
|
||||||
|
regex.append(".*");
|
||||||
|
break;
|
||||||
|
case '?':
|
||||||
|
regex.append(".");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
regex.append(ch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
regex.append('$');
|
||||||
|
return regex.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,114 @@
|
|||||||
|
package com.licel.stringer;
|
||||||
|
|
||||||
|
import com.licel.stringer.config.MemberAccessFilter;
|
||||||
|
import com.licel.stringer.config.PathFilter;
|
||||||
|
import com.licel.stringer.util.StringerUtils;
|
||||||
|
import java.nio.file.FileSystems;
|
||||||
|
import java.nio.file.PathMatcher;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
|
public class HideAccessParams extends FilteredParams {
|
||||||
|
public static final String ANNOTATION = "Lcom/stringer/annotations/HideAccess;";
|
||||||
|
|
||||||
|
public HideAccessParams() {
|
||||||
|
this.name = "hideAccess";
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isSameClassElementName(MemberAccessFilter filter, String owner, String memberName, String descriptor) {
|
||||||
|
String dotOwner = owner.replace('/', '.');
|
||||||
|
if (this.map != null && this.map.containsKey(dotOwner)) {
|
||||||
|
this.map.getProperty(dotOwner).replace('.', '/');
|
||||||
|
}
|
||||||
|
|
||||||
|
String argDescriptor = descriptor.substring(0, descriptor.indexOf(')') + 1);
|
||||||
|
String expectedArgs = StringerUtils.toJvmArgumentDescriptor(filter.parameterPattern, this.map);
|
||||||
|
if (!expectedArgs.equals(argDescriptor)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
String resolvedName = memberName;
|
||||||
|
if (this.map != null) {
|
||||||
|
String key = dotOwner + ':' + memberName + StringerUtils.toJvmArgumentDescriptor(filter.parameterPattern, null);
|
||||||
|
resolvedName = this.map.getProperty(key, memberName);
|
||||||
|
}
|
||||||
|
|
||||||
|
return resolvedName.equals(filter.memberName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean matchClassElement(String owner, String memberName, String descriptor) {
|
||||||
|
if (!this.filtered) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (this.filters.isEmpty()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean defaultResult = false;
|
||||||
|
for (int i = this.filters.size() - 1; i >= 0; i--) {
|
||||||
|
MemberAccessFilter filter = (MemberAccessFilter) this.filters.get(i);
|
||||||
|
if (filter.pathMatcher != null) {
|
||||||
|
boolean matched = filter.pathMatcher.matches(Paths.get(this.resolveClassName(owner)))
|
||||||
|
&& (filter.memberSignature == null || this.isSameClassElementName(filter, owner, memberName, descriptor));
|
||||||
|
if (filter.exclude) {
|
||||||
|
defaultResult = true;
|
||||||
|
if (matched) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (matched) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} else if (filter.pathExpression != null
|
||||||
|
&& this.resolveClassName(owner).matches(this.wildcardToRegex(filter.pathExpression))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return defaultResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected PathFilter makeFilter(String filterPattern) {
|
||||||
|
String rawPattern = filterPattern;
|
||||||
|
String memberSignature = null;
|
||||||
|
boolean exclude = false;
|
||||||
|
int hashIndex = filterPattern.indexOf('#');
|
||||||
|
if (hashIndex > 0) {
|
||||||
|
filterPattern = filterPattern.substring(0, hashIndex);
|
||||||
|
memberSignature = rawPattern.substring(hashIndex + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
PathMatcher pathMatcher = null;
|
||||||
|
String syntaxPrefix = "";
|
||||||
|
boolean isRegex = filterPattern.startsWith("regex:");
|
||||||
|
boolean isGlob = filterPattern.startsWith("glob:");
|
||||||
|
if (isRegex) {
|
||||||
|
syntaxPrefix = "regex:";
|
||||||
|
}
|
||||||
|
if (isGlob) {
|
||||||
|
syntaxPrefix = "glob:";
|
||||||
|
}
|
||||||
|
|
||||||
|
String expression = filterPattern;
|
||||||
|
if (isRegex || isGlob) {
|
||||||
|
int colonIndex = expression.indexOf(':');
|
||||||
|
if (colonIndex + 1 >= expression.length()) {
|
||||||
|
throw new RuntimeException("Invalid filter: " + expression);
|
||||||
|
}
|
||||||
|
expression = filterPattern.substring(colonIndex + 1);
|
||||||
|
exclude = expression.charAt(0) == '!';
|
||||||
|
if (exclude) {
|
||||||
|
expression = expression.substring(1);
|
||||||
|
filterPattern = syntaxPrefix.concat(expression);
|
||||||
|
}
|
||||||
|
pathMatcher = FileSystems.getDefault().getPathMatcher(filterPattern);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new MemberAccessFilter(pathMatcher, memberSignature, syntaxPrefix, expression, exclude);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean match(String target, boolean resolveProguardName) {
|
||||||
|
return this.matchClassElement(target, "", "()");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
package com.licel.stringer;
|
||||||
|
|
||||||
|
public class IntegrityControlParams extends FilteredParams {
|
||||||
|
private final CheckByteCodeParams checkBytecode = new CheckByteCodeParams();
|
||||||
|
private final CheckJarParams checkJar = new CheckJarParams();
|
||||||
|
private final SealJarParams sealJar = new SealJarParams();
|
||||||
|
private final OsgiCompatibility osgiCompatibility = new OsgiCompatibility();
|
||||||
|
|
||||||
|
public IntegrityControlParams() {
|
||||||
|
this.name = "integrityControl";
|
||||||
|
}
|
||||||
|
|
||||||
|
public CheckByteCodeParams checkBytecode() {
|
||||||
|
return this.checkBytecode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CheckJarParams checkJar() {
|
||||||
|
return this.checkJar;
|
||||||
|
}
|
||||||
|
|
||||||
|
public SealJarParams sealJar() {
|
||||||
|
return this.sealJar;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OsgiCompatibility osgiCompatibility() {
|
||||||
|
return this.osgiCompatibility;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class CheckByteCodeParams extends Params {
|
||||||
|
CheckByteCodeParams() {
|
||||||
|
this.enabled = false;
|
||||||
|
this.name = "checkBytecode";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class CheckJarParams extends Params {
|
||||||
|
CheckJarParams() {
|
||||||
|
this.enabled = true;
|
||||||
|
this.name = "checkJar";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class SealJarParams extends Params {
|
||||||
|
SealJarParams() {
|
||||||
|
this.enabled = false;
|
||||||
|
this.name = "sealJar";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class OsgiCompatibility extends Params {
|
||||||
|
OsgiCompatibility() {
|
||||||
|
this.enabled = false;
|
||||||
|
this.name = "osgiCompatibility";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.licel.stringer;
|
||||||
|
|
||||||
|
public class Params {
|
||||||
|
protected String name;
|
||||||
|
protected boolean enabled = false;
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return this.enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnabled(boolean enabled) {
|
||||||
|
this.enabled = enabled;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package com.licel.stringer;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import org.apache.commons.jexl3.JexlBuilder;
|
||||||
|
import org.apache.commons.jexl3.JexlEngine;
|
||||||
|
import org.apache.commons.jexl3.JxltEngine;
|
||||||
|
import org.apache.commons.jexl3.JxltEngine.Expression;
|
||||||
|
import org.apache.commons.jexl3.MapContext;
|
||||||
|
|
||||||
|
public class PersonalizationProfile extends FilteredParams {
|
||||||
|
private static final JexlEngine JEXL_ENGINE = new JexlBuilder().silent(true).cache(128).strict(false).create();
|
||||||
|
private static final JxltEngine JXLT_ENGINE = JEXL_ENGINE.createJxltEngine();
|
||||||
|
|
||||||
|
private String noticeTemplate = "AV contact email - [email protected]";
|
||||||
|
private Expression noticeExpression = JXLT_ENGINE.createExpression(this.noticeTemplate);
|
||||||
|
private String protectedByTemplate = "${stringer.version} Stringer (${stringer.buildId})";
|
||||||
|
private Expression protectedByExpression = JXLT_ENGINE.createExpression(this.protectedByTemplate);
|
||||||
|
private final Map<String, Object> variables = new HashMap<>();
|
||||||
|
|
||||||
|
public PersonalizationProfile() {
|
||||||
|
this.variables.put("stringer.version", ProductInfo.getVersion());
|
||||||
|
this.variables.put("stringer.buildId", ProductInfo.getBuildId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void put(String key, Object value) {
|
||||||
|
this.variables.put(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String evaluateNotice() {
|
||||||
|
return String.valueOf(this.noticeExpression.evaluate(new MapContext(this.variables)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNoticeTemplate(String template) {
|
||||||
|
this.noticeTemplate = template;
|
||||||
|
this.noticeExpression = JXLT_ENGINE.createExpression(template);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNoticeTemplate() {
|
||||||
|
return this.noticeTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String evaluateProtectedBy() {
|
||||||
|
return String.valueOf(this.protectedByExpression.evaluate(new MapContext(this.variables)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProtectedByTemplate(String template) {
|
||||||
|
this.protectedByTemplate = template;
|
||||||
|
this.protectedByExpression = JXLT_ENGINE.createExpression(template);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProtectedByTemplate() {
|
||||||
|
return this.protectedByTemplate;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package com.licel.stringer;
|
||||||
|
|
||||||
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
|
public final class ProductInfo {
|
||||||
|
private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle("productInfo");
|
||||||
|
|
||||||
|
private ProductInfo() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getTitle() {
|
||||||
|
return RESOURCE_BUNDLE.getString("title");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getConsoleTitle() {
|
||||||
|
return RESOURCE_BUNDLE.getString("consoleTitle");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getVendor() {
|
||||||
|
return RESOURCE_BUNDLE.getString("vendor");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getVersion() {
|
||||||
|
return RESOURCE_BUNDLE.getString("version");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getBuildId() {
|
||||||
|
return RESOURCE_BUNDLE.getString("buildId");
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getInfoText() {
|
||||||
|
String lineSeparator = System.lineSeparator();
|
||||||
|
return getTitle() + lineSeparator
|
||||||
|
+ "Version: " + getVersion() + lineSeparator
|
||||||
|
+ "Build id: " + getBuildId() + lineSeparator
|
||||||
|
+ "Vendor: " + getVendor();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,137 @@
|
|||||||
|
package com.licel.stringer;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import org.objectweb.asm.Opcodes;
|
||||||
|
|
||||||
|
public class ProtectionElementParams extends FilteredParams {
|
||||||
|
protected ArrayList<String> paths = null;
|
||||||
|
protected StringEncryptionParams stringEncryption = new StringEncryptionParams();
|
||||||
|
protected IntegrityControlParams integrityControl = new IntegrityControlParams();
|
||||||
|
protected HideAccessParams hideAccess = new HideAccessParams();
|
||||||
|
protected ResourceEncryptionParams resourceEncryption = new ResourceEncryptionParams();
|
||||||
|
protected String target;
|
||||||
|
protected int targetInt = 0;
|
||||||
|
|
||||||
|
public ArrayList<String> getPaths() {
|
||||||
|
return this.paths;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPaths(ArrayList<String> paths) {
|
||||||
|
this.paths = paths;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addPath(String path) {
|
||||||
|
if (this.paths == null) {
|
||||||
|
this.paths = new ArrayList<>();
|
||||||
|
}
|
||||||
|
this.paths.add(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPathsString() {
|
||||||
|
if (this.paths == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
for (int i = 0; i < this.paths.size(); i++) {
|
||||||
|
builder.append(this.paths.get(i)).append(';');
|
||||||
|
}
|
||||||
|
if (builder.length() > 0 && builder.charAt(builder.length() - 1) == ';') {
|
||||||
|
builder.deleteCharAt(builder.length() - 1);
|
||||||
|
}
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public StringEncryptionParams getStringEncryption() {
|
||||||
|
return this.stringEncryption;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStringEncryption(StringEncryptionParams stringEncryption) {
|
||||||
|
this.stringEncryption = stringEncryption;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IntegrityControlParams getIntegrityControl() {
|
||||||
|
return this.integrityControl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIntegrityControl(IntegrityControlParams integrityControl) {
|
||||||
|
this.integrityControl = integrityControl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HideAccessParams getHideAccess() {
|
||||||
|
return this.hideAccess;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHideAccess(HideAccessParams hideAccess) {
|
||||||
|
this.hideAccess = hideAccess;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResourceEncryptionParams getResourceEncryption() {
|
||||||
|
return this.resourceEncryption;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setResourceEncryption(ResourceEncryptionParams resourceEncryption) {
|
||||||
|
this.resourceEncryption = resourceEncryption;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTarget() {
|
||||||
|
return this.target;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTargetInt() {
|
||||||
|
return this.targetInt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTarget(String target) {
|
||||||
|
this.target = target;
|
||||||
|
if (target != null) {
|
||||||
|
try {
|
||||||
|
this.targetInt = (Integer) Opcodes.class.getField("V" + target.replace('.', '_')).get(null);
|
||||||
|
} catch (Throwable ex) {
|
||||||
|
throw new RuntimeException("Incorrect value of target bytecode version: " + target + ". Allowed values are 1.5, 1.6, 1.7, 1.8, 9.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dump(WorkerListener listener) {
|
||||||
|
listener.verbose(" protectionElement path: " + this.getPathsString());
|
||||||
|
if (this.getTarget() != null) {
|
||||||
|
listener.verbose(" force bytecode target: " + this.getTarget() + "(" + this.getTargetInt() + ")");
|
||||||
|
}
|
||||||
|
|
||||||
|
listener.verbose(" string encryption: ");
|
||||||
|
listener.verbose(" enabled: " + this.stringEncryption.isEnabled());
|
||||||
|
listener.verbose(" checkCaller: " + this.stringEncryption.isCheckCaller());
|
||||||
|
listener.verbose(" equalsIntrinsicEnabled: " + this.stringEncryption.isEqualsIntrinsicEnabled());
|
||||||
|
listener.verbose(" annotations: " + this.stringEncryption.isAnnotations());
|
||||||
|
listener.verbose(" filtered: " + this.stringEncryption.isFiltered());
|
||||||
|
if (this.stringEncryption.filters != null) {
|
||||||
|
listener.verbose(" filter: " + this.stringEncryption.getFilterString(";"));
|
||||||
|
}
|
||||||
|
|
||||||
|
listener.verbose(" hide access: ");
|
||||||
|
listener.verbose(" enabled: " + this.hideAccess.isEnabled());
|
||||||
|
listener.verbose(" annotations: " + this.hideAccess.isAnnotations());
|
||||||
|
listener.verbose(" filtered: " + this.hideAccess.isFiltered());
|
||||||
|
if (this.hideAccess.filters != null) {
|
||||||
|
listener.verbose(" filter: " + this.hideAccess.getFilterString(";"));
|
||||||
|
}
|
||||||
|
|
||||||
|
listener.verbose(" resource encryption: ");
|
||||||
|
listener.verbose(" enabled: " + this.resourceEncryption.isEnabled());
|
||||||
|
listener.verbose(" filtered: " + this.resourceEncryption.isFiltered());
|
||||||
|
if (this.resourceEncryption.filters != null) {
|
||||||
|
listener.verbose(" filter: " + this.resourceEncryption.getFilterString(";"));
|
||||||
|
}
|
||||||
|
|
||||||
|
listener.verbose(" integrity control: ");
|
||||||
|
listener.verbose(" enabled: " + this.integrityControl.isEnabled());
|
||||||
|
listener.verbose(" checkBytecode: " + this.integrityControl.checkBytecode().isEnabled());
|
||||||
|
listener.verbose(" checkJar: " + this.integrityControl.checkJar().isEnabled());
|
||||||
|
listener.verbose(" sealJar: " + this.integrityControl.sealJar().isEnabled());
|
||||||
|
listener.verbose(" osgiCompatibility: " + this.integrityControl.osgiCompatibility().isEnabled());
|
||||||
|
listener.verbose(" filtered: " + this.integrityControl.isFiltered());
|
||||||
|
if (this.integrityControl.filters != null) {
|
||||||
|
listener.verbose(" filter: " + this.integrityControl.getFilterString(";"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.licel.stringer;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class ProtectionElementParamsContainer extends FilteredParams {
|
||||||
|
protected ArrayList<ProtectionElementParams> elements = new ArrayList<>();
|
||||||
|
|
||||||
|
public ProtectionElementParams createElement() {
|
||||||
|
ProtectionElementParams element = new ProtectionElementParams();
|
||||||
|
this.elements.add(element);
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<ProtectionElementParams> getElements() {
|
||||||
|
return this.elements;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
package com.licel.stringer;
|
||||||
|
|
||||||
|
public class ResourceEncryptionParams extends FilteredParams {
|
||||||
|
private boolean generateStdWrappers = false;
|
||||||
|
private boolean generateWebContaineWrappers = false;
|
||||||
|
|
||||||
|
public ResourceEncryptionParams() {
|
||||||
|
this.name = "resourceEncryption";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean match(String target) {
|
||||||
|
return this.match(target, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setEnabled(boolean enabled) {
|
||||||
|
super.setEnabled(enabled);
|
||||||
|
if (enabled) {
|
||||||
|
this.generateStdWrappers = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isGenerateStdWrappers() {
|
||||||
|
return this.generateStdWrappers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGenerateStdWrappers(boolean generateStdWrappers) {
|
||||||
|
this.generateStdWrappers = generateStdWrappers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isGenerateWebContaineWrappers() {
|
||||||
|
return this.generateWebContaineWrappers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGenerateWebContaineWrappers(boolean generateWebContaineWrappers) {
|
||||||
|
this.generateWebContaineWrappers = generateWebContaineWrappers;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package com.licel.stringer;
|
||||||
|
|
||||||
|
public class StringEncryptionParams extends FilteredParams {
|
||||||
|
public static final String ANNOTATION = "Lcom/stringer/annotations/StringEncryption;";
|
||||||
|
|
||||||
|
private boolean checkCaller = true;
|
||||||
|
private boolean equalsIntrinsicEnabled = false;
|
||||||
|
|
||||||
|
public StringEncryptionParams() {
|
||||||
|
this.name = "stringEncryption";
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCheckCaller() {
|
||||||
|
return this.checkCaller;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCheckCaller(boolean checkCaller) {
|
||||||
|
this.checkCaller = checkCaller;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isEqualsIntrinsicEnabled() {
|
||||||
|
return this.equalsIntrinsicEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEqualsIntrinsicEnabled(boolean equalsIntrinsicEnabled) {
|
||||||
|
this.equalsIntrinsicEnabled = equalsIntrinsicEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isInternStrings() {
|
||||||
|
return this.equalsIntrinsicEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInternStrings(boolean equalsIntrinsicEnabled) {
|
||||||
|
this.equalsIntrinsicEnabled = equalsIntrinsicEnabled;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,198 @@
|
|||||||
|
package com.licel.stringer;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.RandomAccessFile;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
import java.util.jar.Attributes;
|
||||||
|
import java.util.jar.Manifest;
|
||||||
|
import java.util.zip.Adler32;
|
||||||
|
import org.bouncycastle.util.encoders.Base64;
|
||||||
|
import org.zeroturnaround.zip.ZipUtil;
|
||||||
|
import org.zeroturnaround.zip.commons.FileUtilsV2_2;
|
||||||
|
|
||||||
|
public class Watermark {
|
||||||
|
private byte[] identitySha1;
|
||||||
|
private byte[] identityMd5;
|
||||||
|
private int versionNumber;
|
||||||
|
private String version;
|
||||||
|
private String buildId;
|
||||||
|
private byte[] combinedSha1;
|
||||||
|
private byte[] combinedMd5;
|
||||||
|
private Config config;
|
||||||
|
|
||||||
|
public Watermark() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Watermark(Config config, File sourceFile) throws IOException, NoSuchAlgorithmException {
|
||||||
|
this.config = config;
|
||||||
|
MessageDigest sha1 = MessageDigest.getInstance("SHA-1");
|
||||||
|
MessageDigest md5 = MessageDigest.getInstance("MD5");
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
|
||||||
|
byte[] identitySeed = ProductInfo.getVendor().getBytes(StandardCharsets.UTF_8);
|
||||||
|
sha1.update(identitySeed);
|
||||||
|
md5.update(identitySeed);
|
||||||
|
|
||||||
|
this.identitySha1 = sha1.digest();
|
||||||
|
this.identityMd5 = md5.digest();
|
||||||
|
|
||||||
|
File tempZip = null;
|
||||||
|
if (sourceFile.isDirectory() && sourceFile.list().length == 0) {
|
||||||
|
SecureRandom random = Worker.get().secureRandom;
|
||||||
|
random.nextBytes(buffer);
|
||||||
|
sha1.update(buffer, 0, buffer.length);
|
||||||
|
md5.update(buffer, 0, buffer.length);
|
||||||
|
} else {
|
||||||
|
File targetToHash;
|
||||||
|
if (sourceFile.isDirectory()) {
|
||||||
|
tempZip = File.createTempFile(sourceFile.getName(), "zip");
|
||||||
|
ZipUtil.pack(sourceFile, tempZip, 0);
|
||||||
|
targetToHash = tempZip;
|
||||||
|
} else {
|
||||||
|
targetToHash = sourceFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
try (RandomAccessFile raf = new RandomAccessFile(targetToHash, "r")) {
|
||||||
|
int read;
|
||||||
|
while ((read = raf.read(buffer)) > 0) {
|
||||||
|
sha1.update(buffer, 0, read);
|
||||||
|
md5.update(buffer, 0, read);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (tempZip != null) {
|
||||||
|
FileUtilsV2_2.deleteQuietly(tempZip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.combinedSha1 = sha1.digest();
|
||||||
|
this.combinedMd5 = md5.digest();
|
||||||
|
this.version = ProductInfo.getVersion();
|
||||||
|
this.versionNumber = Integer.parseInt(this.version.replace(".", ""));
|
||||||
|
this.buildId = ProductInfo.getBuildId();
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] generateHeader(SecureRandom random) {
|
||||||
|
byte[] header = new byte[]{0, 0, 68, 69, 88, 80, 0, 0};
|
||||||
|
random.nextInt();
|
||||||
|
|
||||||
|
int salt;
|
||||||
|
do {
|
||||||
|
salt = random.nextInt() >>> 16;
|
||||||
|
} while (Integer.bitCount(salt) % 2 != 1);
|
||||||
|
|
||||||
|
byte[] saltBytes = shortToBytes((short) salt, true);
|
||||||
|
System.arraycopy(saltBytes, 0, header, 0, saltBytes.length);
|
||||||
|
byte[] versionBytes = shortToBytes((short) this.versionNumber, true);
|
||||||
|
System.arraycopy(versionBytes, 0, header, header.length - versionBytes.length, versionBytes.length);
|
||||||
|
this.xorWithKey(header, 2, saltBytes);
|
||||||
|
return header;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Manifest createManifest(SecureRandom random) {
|
||||||
|
Manifest manifest = new Manifest();
|
||||||
|
if (!this.config.getPersonalizationProfile().getProtectedByTemplate().trim().isEmpty()) {
|
||||||
|
manifest.getMainAttributes().putValue("Protected-By", this.config.getPersonalizationProfile().evaluateProtectedBy());
|
||||||
|
}
|
||||||
|
if (!this.config.getPersonalizationProfile().getNoticeTemplate().trim().isEmpty()) {
|
||||||
|
manifest.getMainAttributes().putValue("Protected-Notice", this.config.getPersonalizationProfile().evaluateNotice());
|
||||||
|
}
|
||||||
|
|
||||||
|
random.nextInt();
|
||||||
|
int salt;
|
||||||
|
do {
|
||||||
|
salt = random.nextInt();
|
||||||
|
} while (Integer.bitCount(salt) % 2 != 1);
|
||||||
|
|
||||||
|
byte[] saltBytes = intToBytes(salt, true);
|
||||||
|
byte[] signatureData = new byte[saltBytes.length + this.identityMd5.length + this.combinedMd5.length];
|
||||||
|
System.arraycopy(saltBytes, 0, signatureData, 0, saltBytes.length);
|
||||||
|
System.arraycopy(this.identityMd5, 0, signatureData, saltBytes.length, this.identityMd5.length);
|
||||||
|
System.arraycopy(this.combinedMd5, 0, signatureData, saltBytes.length + this.identityMd5.length, this.combinedMd5.length);
|
||||||
|
this.xorWithKey(signatureData, 4, saltBytes);
|
||||||
|
|
||||||
|
Attributes mainAttributes = manifest.getMainAttributes();
|
||||||
|
mainAttributes.putValue("JAR-Signature", new String(Base64.encode(signatureData), StandardCharsets.US_ASCII));
|
||||||
|
return manifest;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] generateExtraField(SecureRandom random) {
|
||||||
|
byte[] header = this.generateHeader(random);
|
||||||
|
byte[] payload = new byte[this.identitySha1.length + this.combinedSha1.length + 4];
|
||||||
|
byte[] mask = new byte[4];
|
||||||
|
random.nextBytes(mask);
|
||||||
|
byte[] result = new byte[header.length + mask.length + payload.length];
|
||||||
|
|
||||||
|
System.arraycopy(this.identitySha1, 0, payload, 0, this.identitySha1.length);
|
||||||
|
System.arraycopy(this.combinedSha1, 0, payload, this.identitySha1.length, this.combinedSha1.length);
|
||||||
|
Adler32 checksum = new Adler32();
|
||||||
|
checksum.update(payload, 0, this.identitySha1.length + this.combinedSha1.length);
|
||||||
|
byte[] checksumBytes = intToBytes((int) checksum.getValue(), true);
|
||||||
|
System.arraycopy(checksumBytes, 0, payload, this.identitySha1.length + this.combinedSha1.length, checksumBytes.length);
|
||||||
|
|
||||||
|
this.xorWithKey(payload, 0, mask);
|
||||||
|
System.arraycopy(header, 0, result, 0, header.length);
|
||||||
|
System.arraycopy(mask, 0, result, header.length, mask.length);
|
||||||
|
System.arraycopy(payload, 0, result, header.length + mask.length, payload.length);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] generateKeyBlock(SecureRandom random) {
|
||||||
|
byte[] header = this.generateHeader(random);
|
||||||
|
byte[] payload = new byte[this.identitySha1.length + this.combinedSha1.length + 4];
|
||||||
|
byte[] mask = new byte[payload.length];
|
||||||
|
random.nextBytes(mask);
|
||||||
|
byte[] result = new byte[header.length + payload.length + mask.length];
|
||||||
|
|
||||||
|
System.arraycopy(this.identitySha1, 0, payload, 0, this.identitySha1.length);
|
||||||
|
System.arraycopy(this.combinedSha1, 0, payload, this.identitySha1.length, this.combinedSha1.length);
|
||||||
|
Adler32 checksum = new Adler32();
|
||||||
|
checksum.update(payload, 0, this.identitySha1.length + this.combinedSha1.length);
|
||||||
|
byte[] checksumBytes = intToBytes((int) checksum.getValue(), true);
|
||||||
|
System.arraycopy(checksumBytes, 0, payload, this.identitySha1.length + this.combinedSha1.length, checksumBytes.length);
|
||||||
|
|
||||||
|
this.xorWithKey(payload, 0, mask);
|
||||||
|
System.arraycopy(header, 0, result, 0, header.length);
|
||||||
|
System.arraycopy(payload, 0, result, header.length, payload.length);
|
||||||
|
System.arraycopy(mask, 0, result, header.length + payload.length, mask.length);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void xorWithKey(byte[] data, int startOffset, byte[] key) {
|
||||||
|
for (int i = 0; i < data.length - startOffset; i++) {
|
||||||
|
data[i + startOffset] = (byte) (data[i + startOffset] ^ (key[i % key.length] & 0xFF));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] intToBytes(int value, boolean littleEndian) {
|
||||||
|
byte[] bytes = new byte[4];
|
||||||
|
if (littleEndian) {
|
||||||
|
bytes[0] = (byte) (value & 0xFF);
|
||||||
|
bytes[1] = (byte) (value >> 8 & 0xFF);
|
||||||
|
bytes[2] = (byte) (value >> 16 & 0xFF);
|
||||||
|
bytes[3] = (byte) (value >> 24 & 0xFF);
|
||||||
|
} else {
|
||||||
|
bytes[3] = (byte) (value & 0xFF);
|
||||||
|
bytes[2] = (byte) (value >> 8 & 0xFF);
|
||||||
|
bytes[1] = (byte) (value >> 16 & 0xFF);
|
||||||
|
bytes[0] = (byte) (value >> 24 & 0xFF);
|
||||||
|
}
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] shortToBytes(short value, boolean littleEndian) {
|
||||||
|
byte[] bytes = new byte[2];
|
||||||
|
if (littleEndian) {
|
||||||
|
bytes[0] = (byte) (value & 0xFF);
|
||||||
|
bytes[1] = (byte) (value >> 8 & 0xFF);
|
||||||
|
} else {
|
||||||
|
bytes[1] = (byte) (value & 0xFF);
|
||||||
|
bytes[0] = (byte) (value >> 8 & 0xFF);
|
||||||
|
}
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,22 @@
|
|||||||
|
package com.licel.stringer;
|
||||||
|
|
||||||
|
import com.licel.stringer.crypto.CryptoContainer;
|
||||||
|
import com.licel.stringer.io.SourceIterator;
|
||||||
|
import com.licel.stringer.model.ClassInfo;
|
||||||
|
import com.licel.stringer.naming.NameGenerator;
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class WorkerContext {
|
||||||
|
public NameGenerator nameGenerator;
|
||||||
|
public NameGenerator internalNameGenerator;
|
||||||
|
public Config config;
|
||||||
|
public SecureRandom secureRandom;
|
||||||
|
public SourceIterator sourceIterator;
|
||||||
|
public int processedStringCount;
|
||||||
|
public CryptoContainer cryptoContainer;
|
||||||
|
public HashMap<String, ClassInfo> jdkClassCache = new HashMap<>();
|
||||||
|
public long integrityKey0;
|
||||||
|
public long integrityKey1;
|
||||||
|
public HashMap<String, Object> attributes = new HashMap<>();
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package com.licel.stringer;
|
||||||
|
|
||||||
|
final class WorkerContextThreadLocal extends ThreadLocal<WorkerContext> {
|
||||||
|
@Override
|
||||||
|
protected WorkerContext initialValue() {
|
||||||
|
return new WorkerContext();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package com.licel.stringer;
|
||||||
|
|
||||||
|
public class WorkerException extends RuntimeException {
|
||||||
|
private final Worker worker;
|
||||||
|
|
||||||
|
public WorkerException(Worker worker, String message) {
|
||||||
|
super(message);
|
||||||
|
this.worker = worker;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Worker getWorker() {
|
||||||
|
return this.worker;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.licel.stringer;
|
||||||
|
|
||||||
|
public interface WorkerListener {
|
||||||
|
void info(String message);
|
||||||
|
|
||||||
|
void verbose(String message);
|
||||||
|
}
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
package com.licel.stringer.analysis;
|
||||||
|
|
||||||
|
import com.licel.stringer.Config;
|
||||||
|
import com.licel.stringer.model.ClassInfo;
|
||||||
|
import com.licel.stringer.model.ClassMemberInfo;
|
||||||
|
import org.objectweb.asm.AnnotationVisitor;
|
||||||
|
import org.objectweb.asm.ClassVisitor;
|
||||||
|
import org.objectweb.asm.FieldVisitor;
|
||||||
|
import org.objectweb.asm.MethodVisitor;
|
||||||
|
import org.objectweb.asm.ModuleVisitor;
|
||||||
|
import org.objectweb.asm.Opcodes;
|
||||||
|
|
||||||
|
public class ClassMetadataCollector extends ClassVisitor implements Opcodes {
|
||||||
|
public ClassInfo classInfo;
|
||||||
|
private boolean hideAccessMatched = false;
|
||||||
|
private boolean hideAccessExcluded = false;
|
||||||
|
private final Config config;
|
||||||
|
|
||||||
|
public ClassMetadataCollector(String className, Config config) {
|
||||||
|
super(Opcodes.ASM9);
|
||||||
|
this.config = config;
|
||||||
|
this.classInfo = new ClassInfo(className);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClassInfo getClassInfo() {
|
||||||
|
return this.classInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AnnotationVisitor visitAnnotation(String descriptor, boolean visible) {
|
||||||
|
this.classInfo.annotatedSecured = "Lcom/licel/stringer/annotations/secured;".equals(descriptor);
|
||||||
|
this.classInfo.hasStringEncryptionAnnotation = this.classInfo.annotatedSecured;
|
||||||
|
this.classInfo.annotatedInsecure = "Lcom/licel/stringer/annotations/insecure;".equals(descriptor);
|
||||||
|
if ("Lcom/stringer/annotations/StringEncryption;".equals(descriptor)) {
|
||||||
|
this.classInfo.annotatedSecured = true;
|
||||||
|
this.classInfo.hasExplicitStringEncryptionAnnotation = true;
|
||||||
|
this.classInfo.hasStringEncryptionAnnotation = true;
|
||||||
|
}
|
||||||
|
if ("Lcom/stringer/annotations/HideAccess;".equals(descriptor)) {
|
||||||
|
this.hideAccessMatched = true;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
|
||||||
|
this.classInfo.classFileVersion = version;
|
||||||
|
this.classInfo.name = name;
|
||||||
|
this.classInfo.isInterface = (access & ACC_INTERFACE) == ACC_INTERFACE;
|
||||||
|
this.classInfo.isEnum = (access & ACC_ENUM) == ACC_ENUM;
|
||||||
|
this.classInfo.isSynthetic = (access & ACC_SYNTHETIC) == ACC_SYNTHETIC;
|
||||||
|
this.classInfo.superName = superName;
|
||||||
|
if (this.config.getHideAccess().isEnabled() && this.config.getHideAccess().isFiltered()) {
|
||||||
|
this.hideAccessMatched = this.config.getHideAccess().match(this.classInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FieldVisitor visitField(int access, String name, String descriptor, String signature, Object value) {
|
||||||
|
this.classInfo.declaredFields.add(new ClassMemberInfo(access, name, descriptor));
|
||||||
|
if (descriptor.equals("Ljava/lang/String;")) {
|
||||||
|
this.classInfo.stringFieldInitialValues.put(name, value);
|
||||||
|
return new FieldEncryptionAnnotationCollector(this.classInfo, name, value);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) {
|
||||||
|
if ((access & ACC_NATIVE) == ACC_NATIVE) {
|
||||||
|
this.classInfo.hasNativeMethods = true;
|
||||||
|
}
|
||||||
|
if (name.equals("<clinit>")) {
|
||||||
|
this.classInfo.hasStaticInitializer = true;
|
||||||
|
}
|
||||||
|
this.classInfo.declaredMethods.add(new ClassMemberInfo(access, name, descriptor));
|
||||||
|
return new MethodMetadataCollector(this.classInfo, name, descriptor, this.hideAccessMatched, this.hideAccessExcluded, this.config);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ModuleVisitor visitModule(String name, int access, String version) {
|
||||||
|
this.classInfo.isModuleInfo = true;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package com.licel.stringer.analysis;
|
||||||
|
|
||||||
|
import com.licel.stringer.model.ClassInfo;
|
||||||
|
import org.objectweb.asm.AnnotationVisitor;
|
||||||
|
import org.objectweb.asm.FieldVisitor;
|
||||||
|
import org.objectweb.asm.Opcodes;
|
||||||
|
|
||||||
|
public class FieldEncryptionAnnotationCollector extends FieldVisitor implements Opcodes {
|
||||||
|
private final ClassInfo classInfo;
|
||||||
|
private final String initialValue;
|
||||||
|
private final String fieldName;
|
||||||
|
|
||||||
|
public FieldEncryptionAnnotationCollector(ClassInfo classInfo, String fieldName, Object value) {
|
||||||
|
super(Opcodes.ASM9);
|
||||||
|
this.classInfo = classInfo;
|
||||||
|
this.fieldName = fieldName;
|
||||||
|
this.initialValue = value != null ? (value instanceof String ? (String) value : null) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AnnotationVisitor visitAnnotation(String descriptor, boolean visible) {
|
||||||
|
if (("Lcom/stringer/annotations/StringEncryption;".equals(descriptor) || this.classInfo.annotatedSecured)
|
||||||
|
&& !"Lcom/licel/stringer/annotations/insecure;".equals(descriptor)) {
|
||||||
|
this.classInfo.hasStringEncryptionAnnotation = true;
|
||||||
|
this.classInfo.hasSecuredField = true;
|
||||||
|
this.classInfo.hasExplicitStringEncryptionAnnotation = true;
|
||||||
|
this.classInfo.securedStringFields.put(this.fieldName, this.initialValue);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,484 @@
|
|||||||
|
package com.licel.stringer.analysis;
|
||||||
|
|
||||||
|
import com.licel.stringer.Config;
|
||||||
|
import com.licel.stringer.WorkerListener;
|
||||||
|
import com.licel.stringer.model.ClassInfo;
|
||||||
|
import com.licel.stringer.model.ClassMemberInfo;
|
||||||
|
import com.licel.stringer.model.FieldInfo;
|
||||||
|
import com.licel.stringer.model.MethodInfo;
|
||||||
|
import com.licel.stringer.model.OperandStackModel;
|
||||||
|
import com.licel.stringer.model.StackValue;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Set;
|
||||||
|
import org.objectweb.asm.AnnotationVisitor;
|
||||||
|
import org.objectweb.asm.Label;
|
||||||
|
import org.objectweb.asm.MethodVisitor;
|
||||||
|
import org.objectweb.asm.Opcodes;
|
||||||
|
import org.objectweb.asm.Type;
|
||||||
|
|
||||||
|
public class MethodMetadataCollector extends MethodVisitor implements Opcodes {
|
||||||
|
protected static final int STATE_IDLE = 0;
|
||||||
|
private static final int STATE_NEW_SEEN = 1;
|
||||||
|
private static final int STATE_NEW_DUP_SEEN = 2;
|
||||||
|
|
||||||
|
private final ClassInfo classInfo;
|
||||||
|
private final String methodName;
|
||||||
|
private final String descriptor;
|
||||||
|
private String lastStringLiteral = null;
|
||||||
|
private boolean lastInsnWasStringLdc = false;
|
||||||
|
private boolean hideAccessEnabled;
|
||||||
|
private final boolean hideAccessExcluded;
|
||||||
|
private final WorkerListener listener;
|
||||||
|
private boolean canTrimTypes = true;
|
||||||
|
private final String formattedMethodSignature;
|
||||||
|
private final String formattedConstructorSignature;
|
||||||
|
private final boolean isConstructor;
|
||||||
|
private boolean beforeSuperInit = true;
|
||||||
|
private boolean hasPreInitMethodCalls = false;
|
||||||
|
private boolean hasPreInitFieldReads = false;
|
||||||
|
private boolean allocatesSelfOrSuperPreInit = false;
|
||||||
|
private final Set<Label> preInitJumpTargets = new HashSet<>();
|
||||||
|
private final Set<MethodInfo> preInitMethodCalls = new HashSet<>();
|
||||||
|
private final ArrayList<MethodInfo> superInitCalls = new ArrayList<>();
|
||||||
|
private final Set<MethodInfo> constructorMethodCalls = new HashSet<>();
|
||||||
|
private final Set<FieldInfo> preInitFieldReads = new HashSet<>();
|
||||||
|
private final Config config;
|
||||||
|
private boolean hasNonStandardNewPattern = false;
|
||||||
|
protected int newPatternState = STATE_IDLE;
|
||||||
|
private final OperandStackModel operandStackModel = new OperandStackModel();
|
||||||
|
private int fieldRefIndex = 0;
|
||||||
|
private int methodReturnIndex = 0;
|
||||||
|
private boolean stackTrackingStopped = false;
|
||||||
|
|
||||||
|
public MethodMetadataCollector(
|
||||||
|
ClassInfo classInfo,
|
||||||
|
String methodName,
|
||||||
|
String descriptor,
|
||||||
|
boolean hideAccessMatched,
|
||||||
|
boolean hideAccessExcluded,
|
||||||
|
Config config) {
|
||||||
|
super(Opcodes.ASM9);
|
||||||
|
this.classInfo = classInfo;
|
||||||
|
this.methodName = methodName;
|
||||||
|
this.descriptor = descriptor;
|
||||||
|
this.hideAccessExcluded = hideAccessExcluded;
|
||||||
|
this.hideAccessEnabled = hideAccessExcluded ? false : hideAccessMatched;
|
||||||
|
this.formattedMethodSignature = formatMethodSignature(classInfo.name, methodName, descriptor);
|
||||||
|
this.formattedConstructorSignature = formatConstructorSignature(classInfo.name, methodName, descriptor);
|
||||||
|
this.listener = config.getListener();
|
||||||
|
this.config = config;
|
||||||
|
this.isConstructor = "<init>".equals(methodName);
|
||||||
|
|
||||||
|
for (int i = 0; i < 1000; i++) {
|
||||||
|
this.operandStackModel.add(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visitEnd() {
|
||||||
|
if (!"<clinit>".equals(this.methodName) || !this.classInfo.isEnum) {
|
||||||
|
if (!this.hideAccessEnabled) {
|
||||||
|
if (!this.config.getHideAccess().matchClassElement(this.classInfo.name, this.methodName, this.descriptor)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.isConstructor) {
|
||||||
|
if (!this.allocatesSelfOrSuperPreInit && this.preInitJumpTargets.isEmpty()) {
|
||||||
|
if (this.hasPreInitMethodCalls || this.hasPreInitFieldReads) {
|
||||||
|
if (this.superInitCalls.isEmpty()) {
|
||||||
|
this.canTrimTypes = false;
|
||||||
|
this.listener.verbose(" Can't trim types in constructor (#2) " + this.formattedConstructorSignature);
|
||||||
|
|
||||||
|
for (MethodInfo call : this.constructorMethodCalls) {
|
||||||
|
this.listener.verbose(" -***-> " + call);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.listener.verbose(" Can't trim types in constructor (#2) " + this.formattedConstructorSignature);
|
||||||
|
} else if (!this.hasOnlyPrimitiveOrObjectArguments(this.superInitCalls.get(0).descriptor)) {
|
||||||
|
int nonObjectReturnCount = 0;
|
||||||
|
if (this.hasPreInitMethodCalls) {
|
||||||
|
for (MethodInfo call : this.preInitMethodCalls) {
|
||||||
|
if (!this.isPrimitiveOrObjectReturnType(call.descriptor)) {
|
||||||
|
nonObjectReturnCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int nonObjectFieldCount = 0;
|
||||||
|
if (this.hasPreInitFieldReads) {
|
||||||
|
for (FieldInfo field : this.preInitFieldReads) {
|
||||||
|
if (!this.isPrimitiveOrObjectType(field.descriptor)) {
|
||||||
|
nonObjectFieldCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (nonObjectReturnCount != 0 || nonObjectFieldCount != 0) {
|
||||||
|
this.listener.verbose(" Can't trim types in constructor (#3) " + this.formattedConstructorSignature);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.canTrimTypes = false;
|
||||||
|
this.listener.verbose(" Can't trim types in constructor (#1) " + this.formattedConstructorSignature);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.classInfo.hasHideAccessTargets = true;
|
||||||
|
String methodKey = this.methodName + this.descriptor;
|
||||||
|
this.classInfo.hideAccessTrimFlags.put(methodKey, this.canTrimTypes);
|
||||||
|
if (this.hasNonStandardNewPattern) {
|
||||||
|
this.listener.verbose(" Can't trim types in method (#4) " + methodKey);
|
||||||
|
this.classInfo.hideAccessMethodFlags.put(methodKey, !this.hasNonStandardNewPattern);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AnnotationVisitor visitAnnotation(String descriptor, boolean visible) {
|
||||||
|
this.lastInsnWasStringLdc = false;
|
||||||
|
if ("Lcom/licel/stringer/annotations/secured;".equals(descriptor)) {
|
||||||
|
this.classInfo.hasStringEncryptionAnnotation = true;
|
||||||
|
this.classInfo.hasSecuredMethod = true;
|
||||||
|
}
|
||||||
|
if ("Lcom/licel/stringer/annotations/insecure;".equals(descriptor)) {
|
||||||
|
this.classInfo.hasInsecureMethod = true;
|
||||||
|
this.classInfo.hasInsecureAnnotation = true;
|
||||||
|
}
|
||||||
|
if ("Lcom/stringer/annotations/StringEncryption;".equals(descriptor)) {
|
||||||
|
this.classInfo.hasStringEncryptionAnnotation = true;
|
||||||
|
this.classInfo.hasSecuredMethod = true;
|
||||||
|
this.classInfo.hasExplicitStringEncryptionAnnotation = true;
|
||||||
|
}
|
||||||
|
if (!this.hideAccessExcluded && "Lcom/stringer/annotations/HideAccess;".equals(descriptor)) {
|
||||||
|
this.classInfo.hasHideAccessTargets = true;
|
||||||
|
this.hideAccessEnabled = true;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visitFieldInsn(int opcode, String owner, String name, String descriptor) {
|
||||||
|
this.lastInsnWasStringLdc = false;
|
||||||
|
this.classInfo.referencedTypes.add(owner);
|
||||||
|
this.classInfo.referencedTypes.add(descriptor);
|
||||||
|
if ((opcode == PUTFIELD || opcode == PUTSTATIC) && descriptor.equals("Ljava/lang/String;") && this.lastStringLiteral != null) {
|
||||||
|
if (this.classInfo.securedStringFields.containsKey(name)) {
|
||||||
|
this.classInfo.securedStringFields.put(name, this.lastStringLiteral);
|
||||||
|
}
|
||||||
|
this.lastStringLiteral = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.hideAccessEnabled && this.isConstructor && this.beforeSuperInit && (opcode == GETFIELD || opcode == GETSTATIC)) {
|
||||||
|
this.hasPreInitFieldReads = true;
|
||||||
|
this.preInitFieldReads.add(new FieldInfo(owner, name, descriptor));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.hideAccessEnabled && this.isConstructor && this.beforeSuperInit && !this.stackTrackingStopped) {
|
||||||
|
if (opcode != GETFIELD && opcode != GETSTATIC) {
|
||||||
|
this.operandStackModel.pop();
|
||||||
|
} else if (this.isPrimitiveOrObjectType(descriptor)) {
|
||||||
|
this.operandStackModel.add(new StackValue(StackValue.KIND_OTHER));
|
||||||
|
} else {
|
||||||
|
this.operandStackModel.add(new StackValue(StackValue.KIND_FIELD_REF, this.fieldRefIndex++));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visitLocalVariable(String name, String descriptor, String signature, Label start, Label end, int index) {
|
||||||
|
this.lastInsnWasStringLdc = false;
|
||||||
|
this.classInfo.referencedTypes.add(descriptor);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visitMethodInsn(int opcode, String owner, String name, String descriptor, boolean isInterface) {
|
||||||
|
this.lastInsnWasStringLdc = false;
|
||||||
|
this.classInfo.referencedTypes.add(owner);
|
||||||
|
this.classInfo.referencedMethods.add(new ClassMemberInfo(opcode, name, descriptor));
|
||||||
|
if (name.equals("getBundle") && owner.equals("java/util/ResourceBundle")) {
|
||||||
|
this.classInfo.usesResourceBundle = true;
|
||||||
|
}
|
||||||
|
if ((name.equals("getResource") || name.equals("getResourceAsStream"))
|
||||||
|
&& (owner.equals("java/lang/Class") || owner.equals("java/lang/ClassLoader"))) {
|
||||||
|
this.classInfo.usesResourceStreams = true;
|
||||||
|
}
|
||||||
|
if ((name.equals("openConnection") || name.equals("openStream")) && owner.equals("java/net/URL")) {
|
||||||
|
this.classInfo.usesResourceStreams = true;
|
||||||
|
}
|
||||||
|
if (name.equals("getResource") && (owner.equals("java/lang/Class") || owner.equals("java/lang/ClassLoader"))) {
|
||||||
|
this.classInfo.usesGetResourceUrl = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.hideAccessEnabled && this.isConstructor && this.beforeSuperInit && !this.stackTrackingStopped) {
|
||||||
|
Type[] argTypes = Type.getArgumentTypes(descriptor);
|
||||||
|
for (Type argType : argTypes) {
|
||||||
|
if (argType.getSort() == Type.LONG || argType.getSort() == Type.DOUBLE) {
|
||||||
|
this.operandStackModel.pop();
|
||||||
|
}
|
||||||
|
this.operandStackModel.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
Type returnType = Type.getReturnType(descriptor);
|
||||||
|
switch (returnType.getSort()) {
|
||||||
|
case Type.BOOLEAN:
|
||||||
|
case Type.CHAR:
|
||||||
|
case Type.BYTE:
|
||||||
|
case Type.SHORT:
|
||||||
|
case Type.INT:
|
||||||
|
case Type.FLOAT:
|
||||||
|
case Type.LONG:
|
||||||
|
case Type.DOUBLE:
|
||||||
|
this.operandStackModel.add(new StackValue(StackValue.KIND_OTHER));
|
||||||
|
break;
|
||||||
|
case Type.ARRAY:
|
||||||
|
Type elementType = returnType.getElementType();
|
||||||
|
if (elementType.getSort() == Type.OBJECT && !"java/lang/Object".equals(elementType.getInternalName())) {
|
||||||
|
this.operandStackModel.add(new StackValue(StackValue.KIND_METHOD_RETURN, this.methodReturnIndex));
|
||||||
|
} else {
|
||||||
|
this.operandStackModel.add(new StackValue(StackValue.KIND_OTHER));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case Type.OBJECT:
|
||||||
|
if ("java/lang/Object".equals(returnType.getInternalName())) {
|
||||||
|
this.operandStackModel.add(new StackValue(StackValue.KIND_OTHER));
|
||||||
|
} else {
|
||||||
|
this.operandStackModel.add(new StackValue(StackValue.KIND_METHOD_RETURN, this.methodReturnIndex));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.methodReturnIndex++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (("java/lang/System".equals(owner) || "java/lang/Runtime".equals(owner))
|
||||||
|
&& ("load".equals(name) || "loadLibrary".equals(name))
|
||||||
|
&& "(Ljava/lang/String;)V".equals(descriptor)) {
|
||||||
|
this.listener.verbose(" Can't hide call " + owner.replace('/', '.') + "." + name + " from " + this.formattedMethodSignature);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.hideAccessEnabled && this.isConstructor) {
|
||||||
|
this.constructorMethodCalls.add(new MethodInfo(owner, name, descriptor));
|
||||||
|
if (this.beforeSuperInit
|
||||||
|
&& (opcode != INVOKESPECIAL || !"<init>".equals(name) || (!this.classInfo.name.equals(owner) && !this.classInfo.superName.equals(owner)))) {
|
||||||
|
this.hasPreInitMethodCalls = true;
|
||||||
|
this.preInitMethodCalls.add(new MethodInfo(owner, name, descriptor));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.hideAccessEnabled && this.canTrimTypes && opcode == INVOKESPECIAL) {
|
||||||
|
if (this.isConstructor) {
|
||||||
|
if (!"<init>".equals(name) || this.classInfo.name.equals(owner) || this.classInfo.superName.equals(owner)) {
|
||||||
|
if ("<init>".equals(name) || (!this.classInfo.name.equals(owner) && !this.classInfo.superName.equals(owner))) {
|
||||||
|
this.beforeSuperInit = false;
|
||||||
|
this.superInitCalls.add(new MethodInfo(owner, name, descriptor));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isPrimitiveOrObjectReturnType(String methodDescriptor) {
|
||||||
|
Type returnType = Type.getReturnType(methodDescriptor);
|
||||||
|
if (returnType.getSort() == Type.OBJECT && !"java/lang/Object".equals(returnType.getInternalName())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (returnType.getSort() == Type.ARRAY) {
|
||||||
|
Type elementType = returnType.getElementType();
|
||||||
|
if (elementType.getSort() == Type.OBJECT && !"java/lang/Object".equals(elementType.getInternalName())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isPrimitiveOrObjectType(String typeDescriptor) {
|
||||||
|
Type type = Type.getType(typeDescriptor);
|
||||||
|
if (type.getSort() == Type.OBJECT && !"java/lang/Object".equals(type.getInternalName())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (type.getSort() == Type.ARRAY) {
|
||||||
|
Type elementType = type.getElementType();
|
||||||
|
if (elementType.getSort() == Type.OBJECT && !"java/lang/Object".equals(elementType.getInternalName())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasOnlyPrimitiveOrObjectArguments(String methodDescriptor) {
|
||||||
|
Type[] argTypes = Type.getArgumentTypes(methodDescriptor);
|
||||||
|
for (Type argType : argTypes) {
|
||||||
|
if (argType.getSort() == Type.OBJECT && !"java/lang/Object".equals(argType.getInternalName())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (argType.getSort() == Type.ARRAY) {
|
||||||
|
Type elementType = argType.getElementType();
|
||||||
|
if (elementType.getSort() == Type.OBJECT && !"java/lang/Object".equals(elementType.getInternalName())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String formatConstructorSignature(String owner, String methodName, String descriptor) {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append(owner.replace('/', '.'));
|
||||||
|
builder.append('(');
|
||||||
|
Type[] argTypes = Type.getArgumentTypes(descriptor);
|
||||||
|
for (int i = 0; i < argTypes.length; i++) {
|
||||||
|
if (i != 0) {
|
||||||
|
builder.append(", ");
|
||||||
|
}
|
||||||
|
builder.append(argTypes[i].getClassName());
|
||||||
|
}
|
||||||
|
builder.append(')');
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String formatMethodSignature(String owner, String methodName, String descriptor) {
|
||||||
|
Type returnType = Type.getReturnType(descriptor);
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
builder.append(returnType.getClassName());
|
||||||
|
builder.append(' ');
|
||||||
|
builder.append(owner.replace('/', '.'));
|
||||||
|
builder.append('.');
|
||||||
|
builder.append(methodName);
|
||||||
|
builder.append('(');
|
||||||
|
Type[] argTypes = Type.getArgumentTypes(descriptor);
|
||||||
|
for (int i = 0; i < argTypes.length; i++) {
|
||||||
|
if (i != 0) {
|
||||||
|
builder.append(", ");
|
||||||
|
}
|
||||||
|
builder.append(argTypes[i].getClassName());
|
||||||
|
}
|
||||||
|
builder.append(')');
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visitInsn(int opcode) {
|
||||||
|
if (this.newPatternState == STATE_NEW_SEEN) {
|
||||||
|
if (opcode != DUP && opcode != DUP_X1) {
|
||||||
|
this.hasNonStandardNewPattern = true;
|
||||||
|
this.newPatternState = STATE_IDLE;
|
||||||
|
} else {
|
||||||
|
this.newPatternState = STATE_NEW_DUP_SEEN;
|
||||||
|
}
|
||||||
|
} else if (this.newPatternState == STATE_NEW_DUP_SEEN && opcode == SWAP) {
|
||||||
|
this.hasNonStandardNewPattern = true;
|
||||||
|
this.newPatternState = STATE_IDLE;
|
||||||
|
} else {
|
||||||
|
this.newPatternState = STATE_IDLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (opcode == MONITORENTER && this.lastInsnWasStringLdc && this.lastStringLiteral != null) {
|
||||||
|
this.classInfo.excludedStrings.add(this.lastStringLiteral);
|
||||||
|
}
|
||||||
|
this.lastInsnWasStringLdc = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visitIntInsn(int opcode, int operand) {
|
||||||
|
this.lastInsnWasStringLdc = false;
|
||||||
|
switch (opcode) {
|
||||||
|
case BIPUSH:
|
||||||
|
case SIPUSH:
|
||||||
|
this.operandStackModel.add(new StackValue(StackValue.KIND_OTHER));
|
||||||
|
break;
|
||||||
|
case NEWARRAY:
|
||||||
|
this.operandStackModel.replaceTop(new StackValue(StackValue.KIND_OTHER));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new RuntimeException("Unexpected opcode: " + opcode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visitVarInsn(int opcode, int varIndex) {
|
||||||
|
this.lastInsnWasStringLdc = false;
|
||||||
|
super.visitVarInsn(opcode, varIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visitIincInsn(int varIndex, int increment) {
|
||||||
|
this.lastInsnWasStringLdc = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visitTableSwitchInsn(int min, int max, Label dflt, Label... labels) {
|
||||||
|
this.lastInsnWasStringLdc = false;
|
||||||
|
this.operandStackModel.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visitLookupSwitchInsn(Label dflt, int[] keys, Label[] labels) {
|
||||||
|
this.lastInsnWasStringLdc = false;
|
||||||
|
this.operandStackModel.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visitJumpInsn(int opcode, Label label) {
|
||||||
|
this.lastInsnWasStringLdc = false;
|
||||||
|
if (this.isConstructor && this.beforeSuperInit) {
|
||||||
|
this.stackTrackingStopped = true;
|
||||||
|
this.preInitJumpTargets.add(label);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visitTypeInsn(int opcode, String type) {
|
||||||
|
this.lastInsnWasStringLdc = false;
|
||||||
|
this.classInfo.referencedTypes.add(type);
|
||||||
|
if (opcode == NEW) {
|
||||||
|
this.newPatternState = STATE_NEW_SEEN;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.isConstructor && this.beforeSuperInit && !this.stackTrackingStopped) {
|
||||||
|
switch (opcode) {
|
||||||
|
case NEW:
|
||||||
|
if (!type.equals(this.classInfo.name) && !type.equals(this.classInfo.superName)) {
|
||||||
|
this.operandStackModel.add(new StackValue(StackValue.KIND_OTHER));
|
||||||
|
} else {
|
||||||
|
this.stackTrackingStopped = true;
|
||||||
|
this.allocatesSelfOrSuperPreInit = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ANEWARRAY:
|
||||||
|
case INSTANCEOF:
|
||||||
|
this.operandStackModel.add(new StackValue(StackValue.KIND_OTHER));
|
||||||
|
break;
|
||||||
|
case CHECKCAST:
|
||||||
|
this.operandStackModel.pop();
|
||||||
|
this.operandStackModel.add(new StackValue(StackValue.KIND_OTHER));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new RuntimeException("Unexpected opcode: " + opcode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visitMultiANewArrayInsn(String descriptor, int numDimensions) {
|
||||||
|
this.lastInsnWasStringLdc = false;
|
||||||
|
this.operandStackModel.add(new StackValue(StackValue.KIND_OTHER));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visitLdcInsn(Object value) {
|
||||||
|
if (value instanceof String) {
|
||||||
|
this.classInfo.stringLiterals.add((String) value);
|
||||||
|
this.lastStringLiteral = (String) value;
|
||||||
|
this.lastInsnWasStringLdc = true;
|
||||||
|
}
|
||||||
|
if (value instanceof Long || value instanceof Double) {
|
||||||
|
this.operandStackModel.add(new StackValue(StackValue.KIND_OTHER));
|
||||||
|
}
|
||||||
|
this.operandStackModel.add(new StackValue(StackValue.KIND_OTHER));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.licel.stringer.analysis;
|
||||||
|
|
||||||
|
import org.objectweb.asm.ClassVisitor;
|
||||||
|
import org.objectweb.asm.MethodVisitor;
|
||||||
|
import org.objectweb.asm.Opcodes;
|
||||||
|
|
||||||
|
public class ResourceUsageClassVisitor extends ClassVisitor implements Opcodes {
|
||||||
|
public boolean usesResourceCalls = false;
|
||||||
|
|
||||||
|
public ResourceUsageClassVisitor(String className) {
|
||||||
|
super(Opcodes.ASM9);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean usesResourceCalls() {
|
||||||
|
return this.usesResourceCalls;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) {
|
||||||
|
return new ResourceUsageMethodVisitor(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package com.licel.stringer.analysis;
|
||||||
|
|
||||||
|
import org.objectweb.asm.MethodVisitor;
|
||||||
|
import org.objectweb.asm.Opcodes;
|
||||||
|
|
||||||
|
public class ResourceUsageMethodVisitor extends MethodVisitor implements Opcodes {
|
||||||
|
private final ResourceUsageClassVisitor classVisitor;
|
||||||
|
|
||||||
|
public ResourceUsageMethodVisitor(ResourceUsageClassVisitor classVisitor) {
|
||||||
|
super(Opcodes.ASM9);
|
||||||
|
this.classVisitor = classVisitor;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visitMethodInsn(int opcode, String owner, String name, String descriptor, boolean isInterface) {
|
||||||
|
if ((name.equals("getResource") || name.equals("getResourceAsStream"))
|
||||||
|
&& (owner.equals("java/lang/Class") || owner.equals("java/lang/ClassLoader") || owner.equals("javax/servlet/ServletContext"))) {
|
||||||
|
this.classVisitor.usesResourceCalls = true;
|
||||||
|
}
|
||||||
|
if ((name.equals("openConnection") || name.equals("openStream")) && owner.equals("java/net/URL")) {
|
||||||
|
this.classVisitor.usesResourceCalls = true;
|
||||||
|
}
|
||||||
|
if (name.equals("getResource") && (owner.equals("java/lang/Class") || owner.equals("java/lang/ClassLoader"))) {
|
||||||
|
this.classVisitor.usesResourceCalls = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
package com.licel.stringer.config;
|
||||||
|
|
||||||
|
import com.licel.stringer.Config;
|
||||||
|
import com.licel.stringer.FileConfig;
|
||||||
|
import java.io.File;
|
||||||
|
import org.xml.sax.Attributes;
|
||||||
|
import org.xml.sax.helpers.DefaultHandler;
|
||||||
|
|
||||||
|
public class LegacyConfigHandler extends DefaultHandler {
|
||||||
|
protected final FileConfig fileConfig;
|
||||||
|
protected final Config config;
|
||||||
|
|
||||||
|
public LegacyConfigHandler(FileConfig fileConfig, Config config) {
|
||||||
|
this.fileConfig = fileConfig;
|
||||||
|
this.config = config;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void startElement(String uri, String localName, String qName, Attributes attributes) {
|
||||||
|
if (qName.equalsIgnoreCase("stringer")) {
|
||||||
|
if (attributes.getValue("srcFile") != null) {
|
||||||
|
this.config.setSrcFile(new File(attributes.getValue("srcFile")));
|
||||||
|
}
|
||||||
|
if (attributes.getValue("srcDir") != null) {
|
||||||
|
this.config.setSrcDir(new File(attributes.getValue("srcDir")));
|
||||||
|
}
|
||||||
|
if (attributes.getValue("destFile") != null) {
|
||||||
|
this.config.setDestFile(new File(attributes.getValue("destFile")));
|
||||||
|
}
|
||||||
|
if (attributes.getValue("destDir") != null) {
|
||||||
|
this.config.setDestDir(new File(attributes.getValue("destDir")));
|
||||||
|
}
|
||||||
|
if (attributes.getValue("verbose") != null) {
|
||||||
|
this.config.setVerbose(Boolean.parseBoolean(attributes.getValue("verbose")));
|
||||||
|
}
|
||||||
|
if (attributes.getValue("integrityProtection") != null) {
|
||||||
|
this.config.setIntegrityProtection(Boolean.parseBoolean(attributes.getValue("integrityProtection")));
|
||||||
|
}
|
||||||
|
if (attributes.getValue("resourceEncryption") != null) {
|
||||||
|
this.config.setResourceEncryption(Boolean.parseBoolean(attributes.getValue("resourceEncryption")));
|
||||||
|
}
|
||||||
|
if (attributes.getValue("optimize") != null) {
|
||||||
|
this.config.setOptimize(Boolean.parseBoolean(attributes.getValue("optimize")));
|
||||||
|
}
|
||||||
|
if (attributes.getValue("osgiCompatibility") != null) {
|
||||||
|
this.config.setOsgiCompatibility(Boolean.parseBoolean(attributes.getValue("osgiCompatibility")));
|
||||||
|
}
|
||||||
|
if (attributes.getValue("nameGenMethod") != null) {
|
||||||
|
this.config.setNameGenMethod(attributes.getValue("nameGenMethod"));
|
||||||
|
}
|
||||||
|
if (attributes.getValue("checkCaller") != null) {
|
||||||
|
this.config.setCheckCaller(Boolean.parseBoolean(attributes.getValue("checkCaller")));
|
||||||
|
}
|
||||||
|
if (attributes.getValue("proguardMapFile") != null) {
|
||||||
|
this.config.setProguardMapFile(new File(attributes.getValue("proguardMapFile")));
|
||||||
|
}
|
||||||
|
if (attributes.getValue("target") != null) {
|
||||||
|
this.config.setTarget(attributes.getValue("target"));
|
||||||
|
}
|
||||||
|
if (attributes.getValue("trialExpirationTimestamp") != null) {
|
||||||
|
this.config.setTrialExpirationTimestamp(attributes.getValue("trialExpirationTimestamp"));
|
||||||
|
}
|
||||||
|
if (attributes.getValue("trialExpirationTimestampPattern") != null) {
|
||||||
|
this.config.setTrialExpirationTimestampPattern(attributes.getValue("trialExpirationTimestampPattern"));
|
||||||
|
}
|
||||||
|
if (attributes.getValue("checkJar") != null) {
|
||||||
|
this.config.setCheckJar(Boolean.parseBoolean(attributes.getValue("checkJar")));
|
||||||
|
}
|
||||||
|
} else if (qName.equalsIgnoreCase("include")) {
|
||||||
|
this.config.addInclude(attributes.getValue("name"));
|
||||||
|
} else if (qName.equalsIgnoreCase("exclude")) {
|
||||||
|
this.config.addExclude(attributes.getValue("name"));
|
||||||
|
} else if (qName.equalsIgnoreCase("inject")) {
|
||||||
|
this.config.addInject(attributes.getValue("name"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package com.licel.stringer.config;
|
||||||
|
|
||||||
|
import java.nio.file.PathMatcher;
|
||||||
|
|
||||||
|
public class MemberAccessFilter extends PathFilter {
|
||||||
|
public String memberSignature;
|
||||||
|
public String memberName;
|
||||||
|
public String parameterPattern;
|
||||||
|
|
||||||
|
public MemberAccessFilter(PathMatcher pathMatcher, String memberSignature, String pattern, String pathExpression, boolean exclude) {
|
||||||
|
super(pathMatcher, pattern, pathExpression, exclude);
|
||||||
|
this.memberSignature = memberSignature;
|
||||||
|
if (memberSignature != null) {
|
||||||
|
int openParen = memberSignature.indexOf('(');
|
||||||
|
int closeParen = memberSignature.indexOf(')');
|
||||||
|
if (openParen < 1 || memberSignature.length() < 2 || closeParen != memberSignature.length() - 1) {
|
||||||
|
throw new RuntimeException("The value of " + memberSignature + " has incorrect format");
|
||||||
|
}
|
||||||
|
this.memberName = memberSignature.substring(0, openParen);
|
||||||
|
this.parameterPattern = memberSignature.substring(openParen + 1, closeParen);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return super.toString() + (this.memberSignature != null ? "#" + this.memberSignature : "");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.licel.stringer.config;
|
||||||
|
|
||||||
|
import java.nio.file.PathMatcher;
|
||||||
|
|
||||||
|
public class PathFilter {
|
||||||
|
public PathMatcher pathMatcher;
|
||||||
|
public boolean exclude;
|
||||||
|
public String pattern;
|
||||||
|
public String pathExpression;
|
||||||
|
|
||||||
|
public PathFilter(PathMatcher pathMatcher, String pattern, String pathExpression, boolean exclude) {
|
||||||
|
this.pathMatcher = pathMatcher;
|
||||||
|
this.pattern = pattern;
|
||||||
|
this.pathExpression = pathExpression;
|
||||||
|
this.exclude = exclude;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return this.pattern + (this.exclude ? "!" : "") + this.pathExpression;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,248 @@
|
|||||||
|
package com.licel.stringer.config;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class PatternMatchUtils {
|
||||||
|
public static final String DEEP_TREE_MATCH = "**";
|
||||||
|
|
||||||
|
public static boolean matchPath(String[] tokenizedPattern, String[] tokenizedPath, boolean caseSensitive) {
|
||||||
|
int patIdxStart = 0;
|
||||||
|
int patIdxEnd = tokenizedPattern.length - 1;
|
||||||
|
int strIdxStart = 0;
|
||||||
|
int strIdxEnd = tokenizedPath.length - 1;
|
||||||
|
|
||||||
|
while (patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd) {
|
||||||
|
String patDir = tokenizedPattern[patIdxStart];
|
||||||
|
if (patDir.equals(DEEP_TREE_MATCH)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!match(patDir, tokenizedPath[strIdxStart], caseSensitive)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
patIdxStart++;
|
||||||
|
strIdxStart++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strIdxStart > strIdxEnd) {
|
||||||
|
for (int i = patIdxStart; i <= patIdxEnd; i++) {
|
||||||
|
if (!tokenizedPattern[i].equals(DEEP_TREE_MATCH)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (patIdxStart > patIdxEnd) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (patIdxStart <= patIdxEnd && strIdxStart <= strIdxEnd) {
|
||||||
|
String patDir = tokenizedPattern[patIdxEnd];
|
||||||
|
if (patDir.equals(DEEP_TREE_MATCH)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!match(patDir, tokenizedPath[strIdxEnd], caseSensitive)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
patIdxEnd--;
|
||||||
|
strIdxEnd--;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strIdxStart > strIdxEnd) {
|
||||||
|
for (int i = patIdxStart; i <= patIdxEnd; i++) {
|
||||||
|
if (!tokenizedPattern[i].equals(DEEP_TREE_MATCH)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (patIdxStart != patIdxEnd && strIdxStart <= strIdxEnd) {
|
||||||
|
int patIdxTmp = -1;
|
||||||
|
for (int i = patIdxStart + 1; i <= patIdxEnd; i++) {
|
||||||
|
if (tokenizedPattern[i].equals(DEEP_TREE_MATCH)) {
|
||||||
|
patIdxTmp = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (patIdxTmp == patIdxStart + 1) {
|
||||||
|
patIdxStart++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int patLength = patIdxTmp - patIdxStart - 1;
|
||||||
|
int strLength = strIdxEnd - strIdxStart + 1;
|
||||||
|
int foundIdx = -1;
|
||||||
|
|
||||||
|
strLoop:
|
||||||
|
for (int i = 0; i <= strLength - patLength; i++) {
|
||||||
|
for (int j = 0; j < patLength; j++) {
|
||||||
|
String subPat = tokenizedPattern[patIdxStart + j + 1];
|
||||||
|
String subStr = tokenizedPath[strIdxStart + i + j];
|
||||||
|
if (!match(subPat, subStr, caseSensitive)) {
|
||||||
|
continue strLoop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foundIdx = strIdxStart + i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (foundIdx == -1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
patIdxStart = patIdxTmp;
|
||||||
|
strIdxStart = foundIdx + patLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = patIdxStart; i <= patIdxEnd; i++) {
|
||||||
|
if (!tokenizedPattern[i].equals(DEEP_TREE_MATCH)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean match(String pattern, String value, boolean caseSensitive) {
|
||||||
|
char[] patArr = pattern.toCharArray();
|
||||||
|
char[] strArr = value.toCharArray();
|
||||||
|
int patIdxStart = 0;
|
||||||
|
int patIdxEnd = patArr.length - 1;
|
||||||
|
int strIdxStart = 0;
|
||||||
|
int strIdxEnd = strArr.length - 1;
|
||||||
|
boolean containsStar = false;
|
||||||
|
|
||||||
|
for (int i = 0; i < patArr.length; i++) {
|
||||||
|
if (patArr[i] == '*') {
|
||||||
|
containsStar = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!containsStar) {
|
||||||
|
if (patIdxEnd != strIdxEnd) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (int i = 0; i <= patIdxEnd; i++) {
|
||||||
|
char ch = patArr[i];
|
||||||
|
if (ch != '?' && different(caseSensitive, ch, strArr[i])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (patIdxEnd == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
char ch;
|
||||||
|
while ((ch = patArr[patIdxStart]) != '*' && strIdxStart <= strIdxEnd) {
|
||||||
|
if (ch != '?' && different(caseSensitive, ch, strArr[strIdxStart])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
patIdxStart++;
|
||||||
|
strIdxStart++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strIdxStart > strIdxEnd) {
|
||||||
|
return allStars(patArr, patIdxStart, patIdxEnd);
|
||||||
|
}
|
||||||
|
|
||||||
|
while ((ch = patArr[patIdxEnd]) != '*' && strIdxStart <= strIdxEnd) {
|
||||||
|
if (ch != '?' && different(caseSensitive, ch, strArr[strIdxEnd])) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
patIdxEnd--;
|
||||||
|
strIdxEnd--;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (strIdxStart > strIdxEnd) {
|
||||||
|
return allStars(patArr, patIdxStart, patIdxEnd);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (patIdxStart != patIdxEnd && strIdxStart <= strIdxEnd) {
|
||||||
|
int patIdxTmp = -1;
|
||||||
|
for (int i = patIdxStart + 1; i <= patIdxEnd; i++) {
|
||||||
|
if (patArr[i] == '*') {
|
||||||
|
patIdxTmp = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (patIdxTmp == patIdxStart + 1) {
|
||||||
|
patIdxStart++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
int patLength = patIdxTmp - patIdxStart - 1;
|
||||||
|
int strLength = strIdxEnd - strIdxStart + 1;
|
||||||
|
int foundIdx = -1;
|
||||||
|
|
||||||
|
strLoop:
|
||||||
|
for (int i = 0; i <= strLength - patLength; i++) {
|
||||||
|
for (int j = 0; j < patLength; j++) {
|
||||||
|
ch = patArr[patIdxStart + j + 1];
|
||||||
|
if (ch != '?' && different(caseSensitive, ch, strArr[strIdxStart + i + j])) {
|
||||||
|
continue strLoop;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foundIdx = strIdxStart + i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (foundIdx == -1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
patIdxStart = patIdxTmp;
|
||||||
|
strIdxStart = foundIdx + patLength;
|
||||||
|
}
|
||||||
|
|
||||||
|
return allStars(patArr, patIdxStart, patIdxEnd);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean allStars(char[] chars, int start, int end) {
|
||||||
|
for (int i = start; i <= end; i++) {
|
||||||
|
if (chars[i] != '*') {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean different(boolean caseSensitive, char ch, char other) {
|
||||||
|
return caseSensitive ? ch != other : Character.toUpperCase(ch) != Character.toUpperCase(other);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String[] tokenizePath(String path) {
|
||||||
|
char sep = File.separatorChar;
|
||||||
|
int start = 0;
|
||||||
|
int len = path.length();
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
if (path.charAt(i) == sep) {
|
||||||
|
if (i != start) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
start = i + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (len != start) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
|
||||||
|
String[] tokens = new String[count];
|
||||||
|
int index = 0;
|
||||||
|
start = 0;
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
if (path.charAt(i) == sep) {
|
||||||
|
if (i != start) {
|
||||||
|
tokens[index++] = path.substring(start, i);
|
||||||
|
}
|
||||||
|
start = i + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (len != start) {
|
||||||
|
tokens[index] = path.substring(start);
|
||||||
|
}
|
||||||
|
return tokens;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,161 @@
|
|||||||
|
package com.licel.stringer.config;
|
||||||
|
|
||||||
|
import com.licel.stringer.Config;
|
||||||
|
import com.licel.stringer.FileConfig;
|
||||||
|
import com.licel.stringer.FilteredParams;
|
||||||
|
import com.licel.stringer.IntegrityControlParams;
|
||||||
|
import com.licel.stringer.ProtectionElementParams;
|
||||||
|
import com.licel.stringer.ProtectionElementParamsContainer;
|
||||||
|
import com.licel.stringer.StringEncryptionParams;
|
||||||
|
import com.licel.stringer.model.ClassInfo;
|
||||||
|
import java.io.File;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import org.xml.sax.Attributes;
|
||||||
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
public class ProtectionConfigHandler extends LegacyConfigHandler {
|
||||||
|
private StringBuilder elementText;
|
||||||
|
private FilteredParams currentSection;
|
||||||
|
private FilteredParams currentFeature;
|
||||||
|
private ClassInfo pendingFilterClass;
|
||||||
|
|
||||||
|
public ProtectionConfigHandler(FileConfig fileConfig, Config config) {
|
||||||
|
super(fileConfig, config);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void startElement(String uri, String localName, String qName, Attributes attributes) {
|
||||||
|
this.elementText = new StringBuilder();
|
||||||
|
if (qName.equalsIgnoreCase("stringer")) {
|
||||||
|
this.config.isLegacy = true;
|
||||||
|
this.config.getStringEncryption().setEnabled(true);
|
||||||
|
this.config.getHideAccess().setEnabled(true);
|
||||||
|
this.config.getIntegrityControl().setEnabled(true);
|
||||||
|
this.config.getResourceEncryption().setEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (qName.equals("protectionElements")) {
|
||||||
|
this.currentSection = this.config.getProtectionElements();
|
||||||
|
this.currentSection.setEnabled(true);
|
||||||
|
} else if (qName.equals("protectionElement") && this.currentSection instanceof ProtectionElementParamsContainer) {
|
||||||
|
this.currentSection = this.config.getProtectionElements().createElement();
|
||||||
|
this.currentSection.setEnabled(true);
|
||||||
|
} else if (qName.equalsIgnoreCase("stringEncryption") && this.currentSection instanceof ProtectionElementParams) {
|
||||||
|
this.currentFeature = ((ProtectionElementParams) this.currentSection).getStringEncryption();
|
||||||
|
this.currentFeature.setEnabled(true);
|
||||||
|
} else if (qName.equalsIgnoreCase("hideAccess") && this.currentSection instanceof ProtectionElementParams) {
|
||||||
|
this.currentFeature = ((ProtectionElementParams) this.currentSection).getHideAccess();
|
||||||
|
this.currentFeature.setEnabled(true);
|
||||||
|
} else if (qName.equalsIgnoreCase("resourceEncryption") && this.currentSection instanceof ProtectionElementParams) {
|
||||||
|
this.currentFeature = ((ProtectionElementParams) this.currentSection).getResourceEncryption();
|
||||||
|
this.currentFeature.setEnabled(true);
|
||||||
|
} else if (qName.equalsIgnoreCase("integrityControl") && this.currentSection instanceof ProtectionElementParams) {
|
||||||
|
this.currentFeature = ((ProtectionElementParams) this.currentSection).getIntegrityControl();
|
||||||
|
this.currentFeature.setEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.config.isLegacy) {
|
||||||
|
super.startElement(uri, localName, qName, attributes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void endElement(String uri, String localName, String qName) throws SAXException {
|
||||||
|
String text = this.elementText.toString();
|
||||||
|
if (qName.equalsIgnoreCase("filter")) {
|
||||||
|
if (this.currentSection != null && this.currentFeature == null && !text.trim().isEmpty()) {
|
||||||
|
this.pendingFilterClass = new ClassInfo(text);
|
||||||
|
this.currentSection.addFilter(this.pendingFilterClass);
|
||||||
|
}
|
||||||
|
if (this.currentFeature != null && !text.trim().isEmpty()) {
|
||||||
|
this.pendingFilterClass = new ClassInfo(text);
|
||||||
|
this.currentFeature.addFilter(this.pendingFilterClass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (qName.equals("mode") && this.currentFeature != null) {
|
||||||
|
try {
|
||||||
|
this.currentFeature.setMode(text);
|
||||||
|
} catch (ParseException ex) {
|
||||||
|
throw new SAXException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (qName.equals("verbose")) {
|
||||||
|
this.config.setVerbose(Boolean.parseBoolean(text));
|
||||||
|
}
|
||||||
|
if (qName.equals("optimize")) {
|
||||||
|
this.config.setOptimize(Boolean.parseBoolean(text));
|
||||||
|
}
|
||||||
|
if (qName.equals("proguardMapFile")) {
|
||||||
|
this.config.setProguardMapFile(new File(text));
|
||||||
|
}
|
||||||
|
if (qName.equals("signMode")) {
|
||||||
|
this.config.setSignMode(text);
|
||||||
|
}
|
||||||
|
if (qName.equals("keystore") && this.fileConfig.isReleaseMode() && !text.isEmpty()) {
|
||||||
|
this.config.setKeystore(text);
|
||||||
|
}
|
||||||
|
if (qName.equals("alias") && this.fileConfig.isReleaseMode() && !text.isEmpty()) {
|
||||||
|
this.config.setAlias(text);
|
||||||
|
}
|
||||||
|
if (qName.equals("storepass") && this.fileConfig.isReleaseMode() && !text.isEmpty()) {
|
||||||
|
this.config.setStorepass(text);
|
||||||
|
}
|
||||||
|
if (qName.equals("storetype") && this.fileConfig.isReleaseMode() && !text.isEmpty()) {
|
||||||
|
this.config.setKeystoreType(text);
|
||||||
|
}
|
||||||
|
if (qName.equals("keypass") && this.fileConfig.isReleaseMode() && !text.isEmpty()) {
|
||||||
|
this.config.setKeypass(text);
|
||||||
|
}
|
||||||
|
if (qName.equals("trialExpirationTimestamp") && !text.isEmpty()) {
|
||||||
|
this.config.setTrialExpirationTimestamp(text);
|
||||||
|
}
|
||||||
|
if (qName.equals("trialExpirationTimestampPattern") && !text.isEmpty()) {
|
||||||
|
this.config.setTrialExpirationTimestampPattern(text);
|
||||||
|
}
|
||||||
|
if (qName.equals("target") && !text.isEmpty()) {
|
||||||
|
this.config.setTarget(text);
|
||||||
|
}
|
||||||
|
if (qName.equals("tmpDir")) {
|
||||||
|
this.config.setTmpDir(new File(text));
|
||||||
|
}
|
||||||
|
if (qName.equals("path") && this.currentSection instanceof ProtectionElementParams) {
|
||||||
|
((ProtectionElementParams) this.currentSection).addPath(text);
|
||||||
|
}
|
||||||
|
if (qName.equals("target") && this.currentSection instanceof ProtectionElementParams) {
|
||||||
|
((ProtectionElementParams) this.currentSection).setTarget(text);
|
||||||
|
}
|
||||||
|
if (qName.equals("checkCaller") && this.currentFeature instanceof StringEncryptionParams) {
|
||||||
|
((StringEncryptionParams) this.currentFeature).setCheckCaller(Boolean.parseBoolean(text));
|
||||||
|
}
|
||||||
|
if (qName.equals("internStrings") && this.currentFeature instanceof StringEncryptionParams) {
|
||||||
|
((StringEncryptionParams) this.currentFeature).setEqualsIntrinsicEnabled(Boolean.parseBoolean(text));
|
||||||
|
}
|
||||||
|
if (qName.equals("equalsIntrinsicEnabled") && this.currentFeature instanceof StringEncryptionParams) {
|
||||||
|
((StringEncryptionParams) this.currentFeature).setEqualsIntrinsicEnabled(Boolean.parseBoolean(text));
|
||||||
|
}
|
||||||
|
if (qName.equals("checkBytecode") && this.currentFeature instanceof IntegrityControlParams) {
|
||||||
|
((IntegrityControlParams) this.currentFeature).checkBytecode().setEnabled(Boolean.parseBoolean(text));
|
||||||
|
}
|
||||||
|
if (qName.equals("checkJar") && this.currentFeature instanceof IntegrityControlParams) {
|
||||||
|
((IntegrityControlParams) this.currentFeature).checkJar().setEnabled(Boolean.parseBoolean(text));
|
||||||
|
}
|
||||||
|
if (qName.equals("osgiCompatibility") && this.currentFeature instanceof IntegrityControlParams) {
|
||||||
|
((IntegrityControlParams) this.currentFeature).osgiCompatibility().setEnabled(Boolean.parseBoolean(text));
|
||||||
|
}
|
||||||
|
if (qName.equals("protectionElement")) {
|
||||||
|
this.currentSection = this.config.getProtectionElements();
|
||||||
|
}
|
||||||
|
if (qName.equals("protectionElements")) {
|
||||||
|
this.currentSection = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.elementText = new StringBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void characters(char[] ch, int start, int length) {
|
||||||
|
this.elementText.append(ch, start, length);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,338 @@
|
|||||||
|
package com.licel.stringer.crypto;
|
||||||
|
|
||||||
|
import com.licel.stringer.Config;
|
||||||
|
import com.licel.stringer.io.ResourcesOutput;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.zip.Deflater;
|
||||||
|
import java.util.zip.DeflaterOutputStream;
|
||||||
|
|
||||||
|
public class AESFast {
|
||||||
|
static final byte[] S_BOX = {
|
||||||
|
99, 124, 119, 123, -14, 107, 111, -59, 48, 1, 103, 43, -2, -41, -85, 118,
|
||||||
|
-54, -126, -55, 125, -6, 89, 71, -16, -83, -44, -94, -81, -100, -92, 114, -64,
|
||||||
|
-73, -3, -109, 38, 54, 63, -9, -52, 52, -91, -27, -15, 113, -40, 49, 21,
|
||||||
|
4, -57, 35, -61, 24, -106, 5, -102, 7, 18, -128, -30, -21, 39, -78, 117,
|
||||||
|
9, -125, 44, 26, 27, 110, 90, -96, 82, 59, -42, -77, 41, -29, 47, -124,
|
||||||
|
83, -47, 0, -19, 32, -4, -79, 91, 106, -53, -66, 57, 74, 76, 88, -49,
|
||||||
|
-48, -17, -86, -5, 67, 77, 51, -123, 69, -7, 2, 127, 80, 60, -97, -88,
|
||||||
|
81, -93, 64, -113, -110, -99, 56, -11, -68, -74, -38, 33, 16, -1, -13, -46,
|
||||||
|
-51, 12, 19, -20, 95, -105, 68, 23, -60, -89, 126, 61, 100, 93, 25, 115,
|
||||||
|
96, -127, 79, -36, 34, 42, -112, -120, 70, -18, -72, 20, -34, 94, 11, -37,
|
||||||
|
-32, 50, 58, 10, 73, 6, 36, 92, -62, -45, -84, 98, -111, -107, -28, 121,
|
||||||
|
-25, -56, 55, 109, -115, -43, 78, -87, 108, 86, -12, -22, 101, 122, -82, 8,
|
||||||
|
-70, 120, 37, 46, 28, -90, -76, -58, -24, -35, 116, 31, 75, -67, -117, -118,
|
||||||
|
112, 62, -75, 102, 72, 3, -10, 14, 97, 53, 87, -71, -122, -63, 29, -98,
|
||||||
|
-31, -8, -104, 17, 105, -39, -114, -108, -101, 30, -121, -23, -50, 85, 40, -33,
|
||||||
|
-116, -95, -119, 13, -65, -26, 66, 104, 65, -103, 45, 15, -80, 84, -69, 22
|
||||||
|
};
|
||||||
|
|
||||||
|
static final int[] RCON = {
|
||||||
|
1, 2, 4, 8, 16, 32, 64, 128,
|
||||||
|
27, 54, 108, 216, 171, 77, 154, 47,
|
||||||
|
94, 188, 99, 198, 151, 53, 106, 212,
|
||||||
|
179, 125, 250, 239, 197, 145
|
||||||
|
};
|
||||||
|
|
||||||
|
static final int[] T0 = {
|
||||||
|
-1520213050, -2072216328, -1720223762, -1921287178, 234025727, -1117033514, -1318096930, 1422247313,
|
||||||
|
1345335392, 50397442, -1452841010, 2099981142, 436141799, 1658312629, -424957107, -1703512340,
|
||||||
|
1170918031, -1652391393, 1086966153, -2021818886, 368769775, -346465870, -918075506, 200339707,
|
||||||
|
-324162239, 1742001331, -39673249, -357585083, -1080255453, -140204973, -1770884380, 1539358875,
|
||||||
|
-1028147339, 486407649, -1366060227, 1780885068, 1513502316, 1094664062, 49805301, 1338821763,
|
||||||
|
1546925160, -190470831, 887481809, 150073849, -1821281822, 1943591083, 1395732834, 1058346282,
|
||||||
|
201589768, 1388824469, 1696801606, 1589887901, 672667696, -1583966665, 251987210, -1248159185,
|
||||||
|
151455502, 907153956, -1686077413, 1038279391, 652995533, 1764173646, -843926913, -1619692054,
|
||||||
|
453576978, -1635548387, 1949051992, 773462580, 756751158, -1301385508, -296068428, -73359269,
|
||||||
|
-162377052, 1295727478, 1641469623, -827083907, 2066295122, 1055122397, 1898917726, -1752923117,
|
||||||
|
-179088474, 1758581177, 0, 753790401, 1612718144, 536673507, -927878791, -312779850,
|
||||||
|
-1100322092, 1187761037, -641810841, 1262041458, -565556588, -733197160, -396863312, 1255133061,
|
||||||
|
1808847035, 720367557, -441800113, 385612781, -985447546, -682799718, 1429418854, -1803188975,
|
||||||
|
-817543798, 284817897, 100794884, -2122350594, -263171936, 1144798328, -1163944155, -475486133,
|
||||||
|
-212774494, -22830243, -1069531008, -1970303227, -1382903233, -1130521311, 1211644016, 83228145,
|
||||||
|
-541279133, -1044990345, 1977277103, 1663115586, 806359072, 452984805, 250868733, 1842533055,
|
||||||
|
1288555905, 336333848, 890442534, 804056259, -513843266, -1567123659, -867941240, 957814574,
|
||||||
|
1472513171, -223893675, -2105639172, 1195195770, -1402706744, -413311558, 723065138, -1787595802,
|
||||||
|
-1604296512, -1736343271, -783331426, 2145180835, 1713513028, 2116692564, -1416589253, -2088204277,
|
||||||
|
-901364084, 703524551, -742868885, 1007948840, 2044649127, -497131844, 487262998, 1994120109,
|
||||||
|
1004593371, 1446130276, 1312438900, 503974420, -615954030, 168166924, 1814307912, -463709000,
|
||||||
|
1573044895, 1859376061, -273896381, -1503501628, -1466855111, -1533700815, 937747667, -1954973198,
|
||||||
|
854058965, 1137232011, 1496790894, -1217565222, -1936880383, 1691735473, -766620004, -525751991,
|
||||||
|
-1267962664, -95005012, 133494003, 636152527, -1352309302, -1904575756, -374428089, 403179536,
|
||||||
|
-709182865, -2005370640, 1864705354, 1915629148, 605822008, -240736681, -944458637, 1371981463,
|
||||||
|
602466507, 2094914977, -1670089496, 555687742, -582268010, -591544991, -2037675251, -2054518257,
|
||||||
|
-1871679264, 1111375484, -994724495, -1436129588, -666351472, 84083462, 32962295, 302911004,
|
||||||
|
-1553899070, 1597322602, -111716434, -793134743, -1853454825, 1489093017, 656219450, -1180787161,
|
||||||
|
954327513, 335083755, -1281845205, 856756514, -1150719534, 1893325225, -1987146233, -1483434957,
|
||||||
|
-1231316179, 572399164, -1836611819, 552200649, 1238290055, -11184726, 2015897680, 2061492133,
|
||||||
|
-1886614525, -123625127, -2138470135, 386731290, -624967835, 837215959, -968736124, -1201116976,
|
||||||
|
-1019133566, -1332111063, 1999449434, 286199582, -877612933, -61582168, -692339859, 974525996
|
||||||
|
};
|
||||||
|
|
||||||
|
static final int[] T1 = {
|
||||||
|
1667483301, 2088564868, 2004348569, 2071721613, -218956019, 1802229437, 1869602481, -976907948,
|
||||||
|
808476752, 16843267, 1734856361, 724260477, -16849127, -673729182, -1414836762, 1987505306,
|
||||||
|
-892694715, -2105401443, -909539008, 2105408135, -84218091, 1499050731, 1195871945, -252642549,
|
||||||
|
-1381154324, -724257945, -1566416899, -1347467798, -1667488833, -1532734473, 1920132246, -1061119141,
|
||||||
|
-1212713534, -33693412, -1819066962, 640044138, 909536346, 1061125697, -134744830, -859012273,
|
||||||
|
875849820, -1515892236, -437923532, -235800312, 1903288979, -656888973, 825320019, 353708607,
|
||||||
|
67373068, -943221422, 589514341, -1010590370, 404238376, -1768540255, 84216335, -1701171275,
|
||||||
|
117902857, 303178806, -2139087973, -488448195, -336868058, 656887401, -1296924723, 1970662047,
|
||||||
|
151589403, -2088559202, 741103732, 437924910, 454768173, 1852759218, 1515893998, -1600103429,
|
||||||
|
1381147894, 993752653, -690571423, -1280082482, 690573947, -471605954, 791633521, -2071719017,
|
||||||
|
1397991157, -774784664, 0, -303185620, 538984544, -50535649, -1313769016, 1532737261,
|
||||||
|
1785386174, -875852474, -1094817831, 960066123, 1246401758, 1280088276, 1482207464, -808483510,
|
||||||
|
-791626901, -269499094, -1431679003, -67375850, 1128498885, 1296931543, 859006549, -2054876780,
|
||||||
|
1162185423, -101062384, 33686534, 2139094657, 1347461360, 1010595908, -1616960070, -1465365533,
|
||||||
|
1364304627, -1549574658, 1077969088, -1886452342, -1835909203, -1650646596, 943222856, -168431356,
|
||||||
|
-1128504353, -1229555775, -623202443, 555827811, 269492272, -6886, -202113778, -757940371,
|
||||||
|
-842170036, 202119188, 320022069, -320027857, 1600110305, -1751698014, 1145342156, 387395129,
|
||||||
|
-993750185, -1482205710, 2122251394, 1027439175, 1684326572, 1566423783, 421081643, 1936975509,
|
||||||
|
1616953504, -2122245736, 1330618065, -589520001, 572671078, 707417214, -1869595733, -2004350077,
|
||||||
|
1179028682, -286341335, -1195873325, 336865340, -555833479, 1583267042, 185275933, -606360202,
|
||||||
|
-522134725, 842163286, 976909390, 168432670, 1229558491, 101059594, 606357612, 1549580516,
|
||||||
|
-1027432611, -741098130, -1397996561, 1650640038, -1852753496, -1785384540, -454765769, 2038035083,
|
||||||
|
-404237006, -926381245, 926379609, 1835915959, -1920138868, -707415708, 1313774802, -1448523296,
|
||||||
|
1819072692, 1448520954, -185273593, -353710299, 1701169839, 2054878350, -1364310039, 134746136,
|
||||||
|
-1162186795, 2021191816, 623200879, 774790258, 471611428, -1499047951, -1263242297, -960063663,
|
||||||
|
-387396829, -572677764, 1953818780, 522141217, 1263245021, -1111662116, -1953821306, -1970663547,
|
||||||
|
1886445712, 1044282434, -1246400060, 1718013098, 1212715224, 50529797, -151587071, 235805714,
|
||||||
|
1633796771, 892693087, 1465364217, -1179031088, -2038032495, -1044276904, 488454695, -1633802311,
|
||||||
|
-505292488, -117904621, -1734857805, 286335539, 1768542907, -640046736, -1903294583, -1802226777,
|
||||||
|
-1684329034, 505297954, -2021190254, -370554592, -825325751, 1431677695, 673730680, -538991238,
|
||||||
|
-1936981105, -1583261192, -1987507840, 218962455, -1077975590, -421079247, 1111655622, 1751699640,
|
||||||
|
1094812355, -1718015568, 757946999, 252648977, -1330611253, 1414834428, -1145344554, 370551866
|
||||||
|
};
|
||||||
|
|
||||||
|
static final int[] T2 = {
|
||||||
|
1673962851, 2096661628, 2012125559, 2079755643, -218165774, 1809235307, 1876865391, -980331323,
|
||||||
|
811618352, 16909057, 1741597031, 727088427, -18408962, -675978537, -1420958037, 1995217526,
|
||||||
|
-896580150, -2111857278, -913751863, 2113570685, -84994566, 1504897881, 1200539975, -251982864,
|
||||||
|
-1388188499, -726439980, -1570767454, -1354372433, -1675378788, -1538000988, 1927583346, -1063560256,
|
||||||
|
-1217019209, -35578627, -1824674157, 642542118, 913070646, 1065238847, -134937865, -863809588,
|
||||||
|
879254580, -1521355611, -439274267, -235337487, 1910674289, -659852328, 828527409, 355090197,
|
||||||
|
67636228, -946515257, 591815971, -1013096765, 405809176, -1774739050, 84545285, -1708149350,
|
||||||
|
118360327, 304363026, -2145674368, -488686110, -338876693, 659450151, -1300247118, 1978310517,
|
||||||
|
152181513, -2095210877, 743994412, 439627290, 456535323, 1859957358, 1521806938, -1604584544,
|
||||||
|
1386542674, 997608763, -692624938, -1283600717, 693271337, -472039709, 794718511, -2079090812,
|
||||||
|
1403450707, -776378159, 0, -306107155, 541089824, -52224004, -1317418831, 1538714971,
|
||||||
|
1792327274, -879933749, -1100490306, 963791673, 1251270218, 1285084236, 1487988824, -813348145,
|
||||||
|
-793023536, -272291089, -1437604438, -68348165, 1132905795, 1301993293, 862344499, -2062445435,
|
||||||
|
1166724933, -102166279, 33818114, 2147385727, 1352724560, 1014514748, -1624917345, -1471421528,
|
||||||
|
1369633617, -1554121053, 1082179648, -1895462257, -1841320558, -1658733411, 946882616, -168753931,
|
||||||
|
-1134305348, -1233665610, -626035238, 557998881, 270544912, -1762561, -201519373, -759206446,
|
||||||
|
-847164211, 202904588, 321271059, -322752532, 1606345055, -1758092649, 1149815876, 388905239,
|
||||||
|
-996976700, -1487539545, 2130477694, 1031423805, 1690872932, 1572530013, 422718233, 1944491379,
|
||||||
|
1623236704, -2129028991, 1335808335, -593264676, 574907938, 710180394, -1875137648, -2012511352,
|
||||||
|
1183631942, -288937490, -1200893000, 338181140, -559449634, 1589437022, 185998603, -609388837,
|
||||||
|
-522503200, 845436466, 980700730, 169090570, 1234361161, 101452294, 608726052, 1555620956,
|
||||||
|
-1029743166, -742560045, -1404833876, 1657054818, -1858492271, -1791908715, -455919644, 2045938553,
|
||||||
|
-405458201, -930397240, 929978679, 1843050349, -1929278323, -709794603, 1318900302, -1454776151,
|
||||||
|
1826141292, 1454176854, -185399308, -355523094, 1707781989, 2062847610, -1371018834, 135272456,
|
||||||
|
-1167075910, 2029029496, 625635109, 777810478, 473441308, -1504185946, -1267480652, -963161658,
|
||||||
|
-389340184, -576619299, 1961401460, 524165407, 1268178251, -1117659971, -1962047861, -1978694262,
|
||||||
|
1893765232, 1048330814, -1250835275, 1724688998, 1217452104, 50726147, -151584266, 236720654,
|
||||||
|
1640145761, 896163637, 1471084887, -1184247623, -2045275770, -1046914879, 490350365, -1641563746,
|
||||||
|
-505857823, -118811656, -1741966440, 287453969, 1775418217, -643206951, -1912108658, -1808554092,
|
||||||
|
-1691502949, 507257374, -2028629369, -372694807, -829994546, 1437269845, 676362280, -542803233,
|
||||||
|
-1945923700, -1587939167, -1995865975, 219813645, -1083843905, -422104602, 1115997762, 1758509160,
|
||||||
|
1099088705, -1725321063, 760903469, 253628687, -1334064208, 1420360788, -1150429509, 371997206
|
||||||
|
};
|
||||||
|
|
||||||
|
static final int[] T3 = {
|
||||||
|
-962239645, -125535108, -291932297, -158499973, -15863054, -692229269, -558796945, -1856715323,
|
||||||
|
1615867952, 33751297, -827758745, 1451043627, -417726722, -1251813417, 1306962859, -325421450,
|
||||||
|
-1891251510, 530416258, -1992242743, -91783811, -283772166, -1293199015, -1899411641, -83103504,
|
||||||
|
1106029997, -1285040940, 1610457762, 1173008303, 599760028, 1408738468, -459902350, -1688485696,
|
||||||
|
1975695287, -518193667, 1034851219, 1282024998, 1817851446, 2118205247, -184354825, -2091922228,
|
||||||
|
1750873140, 1374987685, -785062427, -116854287, -493653647, -1418471208, 1649619249, 708777237,
|
||||||
|
135005188, -1789737017, 1181033251, -1654733885, 807933976, 933336726, 168756485, 800430746,
|
||||||
|
235472647, 607523346, 463175808, -549592350, -853087253, 1315514151, 2144187058, -358648459,
|
||||||
|
303761673, 496927619, 1484008492, 875436570, 908925723, -592286098, -1259447718, 1543217312,
|
||||||
|
-1527360942, 1984772923, -1218324778, 2110698419, 1383803177, -583080989, 1584475951, 328696964,
|
||||||
|
-1493871789, -1184312879, 0, -1054020115, 1080041504, -484442884, 2043195825, -1225958565,
|
||||||
|
-725718422, -1924740149, 1742323390, 1917532473, -1797371318, -1730917300, -1326950312, -2058694705,
|
||||||
|
-1150562096, -987041809, 1340451498, -317260805, -2033892541, -1697166003, 1716859699, 294946181,
|
||||||
|
-1966127803, -384763399, 67502594, -25067649, -1594863536, 2017737788, 632987551, 1273211048,
|
||||||
|
-1561112239, 1576969123, -2134884288, 92966799, 1068339858, 566009245, 1883781176, -251333131,
|
||||||
|
1675607228, 2009183926, -1351230758, 1113792801, 540020752, -451215361, -49351693, -1083321646,
|
||||||
|
-2125673011, 403966988, 641012499, -1020269332, -1092526241, 899848087, -1999879100, 775493399,
|
||||||
|
-1822964540, 1441965991, -58556802, 2051489085, -928226204, -1159242403, 841685273, -426413197,
|
||||||
|
-1063231392, 429425025, -1630449841, -1551901476, 1147544098, 1417554474, 1001099408, 193169544,
|
||||||
|
-1932900794, -953553170, 1809037496, 675025940, -1485185314, -1126015394, 371002123, -1384719397,
|
||||||
|
-616832800, 1683370546, 1951283770, 337512970, -1831122615, 201983494, 1215046692, -1192993700,
|
||||||
|
-1621245246, -1116810285, 1139780780, -995728798, 967348625, 832869781, -751311644, -225740423,
|
||||||
|
-718084121, -1958491960, 1851340599, -625513107, 25988493, -1318791723, -1663938994, 1239460265,
|
||||||
|
-659264404, -1392880042, -217582348, -819598614, -894474907, -191989126, 1206496942, 270010376,
|
||||||
|
1876277946, -259491720, 1248797989, 1550986798, 941890588, 1475454630, 1942467764, -1756248378,
|
||||||
|
-886839064, -1585652259, -392399756, 1042358047, -1763882165, 1641856445, 226921355, 260409994,
|
||||||
|
-527404944, 2084716094, 1908716981, -861247898, -1864873912, 100991747, -150866186, 470945294,
|
||||||
|
-1029480095, 1784624437, -1359390889, 1775286713, 395413126, -1722236479, 975641885, 666476190,
|
||||||
|
-650583583, -351012616, 733190296, 573772049, -759469719, -1452221991, 126455438, 866620564,
|
||||||
|
766942107, 1008868894, 361924487, -920589847, -2025206066, -1426107051, 1350051880, -1518673953,
|
||||||
|
59739276, 1509466529, 159418761, 437718285, 1708834751, -684595482, -2067381694, -793221016,
|
||||||
|
-2101132991, 699439513, 1517759789, 504434447, 2076946608, -1459858348, 1842789307, 742004246
|
||||||
|
};
|
||||||
|
|
||||||
|
private static int rotateRight(int value, int shift) {
|
||||||
|
return value >>> shift | value << -shift;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int subWord(int value) {
|
||||||
|
return (S_BOX[value & 0xFF] & 0xFF)
|
||||||
|
| (S_BOX[value >> 8 & 0xFF] & 0xFF) << 8
|
||||||
|
| (S_BOX[value >> 16 & 0xFF] & 0xFF) << 16
|
||||||
|
| S_BOX[value >> 24 & 0xFF] << 24;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int[][] expandKey(byte[] key) {
|
||||||
|
int keyWords = key.length / 4;
|
||||||
|
int rounds = keyWords + 6;
|
||||||
|
int[][] roundKeys = new int[rounds + 1][4];
|
||||||
|
int wordIndex = 0;
|
||||||
|
|
||||||
|
for (int byteIndex = 0; byteIndex < key.length; wordIndex++, byteIndex += 4) {
|
||||||
|
roundKeys[wordIndex >> 2][wordIndex & 3] = (key[byteIndex] & 0xFF)
|
||||||
|
| (key[byteIndex + 1] & 0xFF) << 8
|
||||||
|
| (key[byteIndex + 2] & 0xFF) << 16
|
||||||
|
| key[byteIndex + 3] << 24;
|
||||||
|
}
|
||||||
|
|
||||||
|
int totalWords = (rounds + 1) << 2;
|
||||||
|
for (int i = keyWords; i < totalWords; i++) {
|
||||||
|
int temp = roundKeys[(i - 1) >> 2][(i - 1) & 3];
|
||||||
|
if (i % keyWords == 0) {
|
||||||
|
temp = subWord(rotateRight(temp, 8)) ^ RCON[i / keyWords - 1];
|
||||||
|
} else if (keyWords > 6 && i % keyWords == 4) {
|
||||||
|
temp = subWord(temp);
|
||||||
|
}
|
||||||
|
roundKeys[i >> 2][i & 3] = roundKeys[(i - keyWords) >> 2][(i - keyWords) & 3] ^ temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
return roundKeys;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void encryptBlock(int[] state, int[][] roundKeys) {
|
||||||
|
state[0] ^= roundKeys[0][0];
|
||||||
|
state[1] ^= roundKeys[0][1];
|
||||||
|
state[2] ^= roundKeys[0][2];
|
||||||
|
state[3] ^= roundKeys[0][3];
|
||||||
|
int round = 1;
|
||||||
|
|
||||||
|
while (round < roundKeys.length - 2) {
|
||||||
|
int t0 = T0[state[0] & 0xFF] ^ T1[state[1] >> 8 & 0xFF] ^ T2[state[2] >> 16 & 0xFF] ^ T3[state[3] >> 24 & 0xFF] ^ roundKeys[round][0];
|
||||||
|
int t1 = T0[state[1] & 0xFF] ^ T1[state[2] >> 8 & 0xFF] ^ T2[state[3] >> 16 & 0xFF] ^ T3[state[0] >> 24 & 0xFF] ^ roundKeys[round][1];
|
||||||
|
int t2 = T0[state[2] & 0xFF] ^ T1[state[3] >> 8 & 0xFF] ^ T2[state[0] >> 16 & 0xFF] ^ T3[state[1] >> 24 & 0xFF] ^ roundKeys[round][2];
|
||||||
|
int t3 = T0[state[3] & 0xFF] ^ T1[state[0] >> 8 & 0xFF] ^ T2[state[1] >> 16 & 0xFF] ^ T3[state[2] >> 24 & 0xFF] ^ roundKeys[round++][3];
|
||||||
|
state[0] = T0[t0 & 0xFF] ^ T1[t1 >> 8 & 0xFF] ^ T2[t2 >> 16 & 0xFF] ^ T3[t3 >> 24 & 0xFF] ^ roundKeys[round][0];
|
||||||
|
state[1] = T0[t1 & 0xFF] ^ T1[t2 >> 8 & 0xFF] ^ T2[t3 >> 16 & 0xFF] ^ T3[t0 >> 24 & 0xFF] ^ roundKeys[round][1];
|
||||||
|
state[2] = T0[t2 & 0xFF] ^ T1[t3 >> 8 & 0xFF] ^ T2[t0 >> 16 & 0xFF] ^ T3[t1 >> 24 & 0xFF] ^ roundKeys[round][2];
|
||||||
|
state[3] = T0[t3 & 0xFF] ^ T1[t0 >> 8 & 0xFF] ^ T2[t1 >> 16 & 0xFF] ^ T3[t2 >> 24 & 0xFF] ^ roundKeys[round++][3];
|
||||||
|
}
|
||||||
|
|
||||||
|
int r0 = T0[state[0] & 0xFF] ^ T1[state[1] >> 8 & 0xFF] ^ T2[state[2] >> 16 & 0xFF] ^ T3[state[3] >> 24 & 0xFF] ^ roundKeys[round][0];
|
||||||
|
int r1 = T0[state[1] & 0xFF] ^ T1[state[2] >> 8 & 0xFF] ^ T2[state[3] >> 16 & 0xFF] ^ T3[state[0] >> 24 & 0xFF] ^ roundKeys[round][1];
|
||||||
|
int r2 = T0[state[2] & 0xFF] ^ T1[state[3] >> 8 & 0xFF] ^ T2[state[0] >> 16 & 0xFF] ^ T3[state[1] >> 24 & 0xFF] ^ roundKeys[round][2];
|
||||||
|
int r3 = T0[state[3] & 0xFF] ^ T1[state[0] >> 8 & 0xFF] ^ T2[state[1] >> 16 & 0xFF] ^ T3[state[2] >> 24 & 0xFF] ^ roundKeys[round++][3];
|
||||||
|
|
||||||
|
state[0] = (S_BOX[r0 & 0xFF] & 0xFF) ^ (S_BOX[r1 >> 8 & 0xFF] & 0xFF) << 8 ^ (S_BOX[r2 >> 16 & 0xFF] & 0xFF) << 16 ^ S_BOX[r3 >> 24 & 0xFF] << 24 ^ roundKeys[round][0];
|
||||||
|
state[1] = (S_BOX[r1 & 0xFF] & 0xFF) ^ (S_BOX[r2 >> 8 & 0xFF] & 0xFF) << 8 ^ (S_BOX[r3 >> 16 & 0xFF] & 0xFF) << 16 ^ S_BOX[r0 >> 24 & 0xFF] << 24 ^ roundKeys[round][1];
|
||||||
|
state[2] = (S_BOX[r2 & 0xFF] & 0xFF) ^ (S_BOX[r3 >> 8 & 0xFF] & 0xFF) << 8 ^ (S_BOX[r0 >> 16 & 0xFF] & 0xFF) << 16 ^ S_BOX[r1 >> 24 & 0xFF] << 24 ^ roundKeys[round][2];
|
||||||
|
state[3] = (S_BOX[r3 & 0xFF] & 0xFF) ^ (S_BOX[r0 >> 8 & 0xFF] & 0xFF) << 8 ^ (S_BOX[r1 >> 16 & 0xFF] & 0xFF) << 16 ^ S_BOX[r2 >> 24 & 0xFF] << 24 ^ roundKeys[round][3];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String encryptString(String plaintext, int[][] roundKeys, int[] ivWords) {
|
||||||
|
int[] state = new int[4];
|
||||||
|
System.arraycopy(ivWords, 0, state, 0, 4);
|
||||||
|
StringBuilder buffer = new StringBuilder(plaintext);
|
||||||
|
int length = buffer.length();
|
||||||
|
|
||||||
|
for (int i = 0; i < length; i++) {
|
||||||
|
if (i % 8 == 0) {
|
||||||
|
encryptBlock(state, roundKeys);
|
||||||
|
}
|
||||||
|
char keystreamChar = (char) (i % 8 % 2 == 1 ? state[i % 8 / 2] : (state[i % 8 / 2] & 0xFFFF0000) >> 16);
|
||||||
|
buffer.setCharAt(i, (char) (keystreamChar ^ buffer.charAt(i)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return buffer.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String encryptString(String plaintext, int[][] roundKeys, int[] ivWords, int charIndex, char saltChar, int extraKeyWord) {
|
||||||
|
int[] state = new int[4];
|
||||||
|
System.arraycopy(ivWords, 0, state, 0, 4);
|
||||||
|
state[2] ^= extraKeyWord;
|
||||||
|
StringBuilder buffer = new StringBuilder(plaintext);
|
||||||
|
int length = buffer.length();
|
||||||
|
|
||||||
|
for (int i = 0; i < length; i++) {
|
||||||
|
if (i % 8 == 0) {
|
||||||
|
encryptBlock(state, roundKeys);
|
||||||
|
}
|
||||||
|
char keystreamChar = (char) (i % 8 % 2 == 1 ? state[i % 8 / 2] : (state[i % 8 / 2] & 0xFFFF0000) >> 16);
|
||||||
|
buffer.setCharAt(i, (char) (keystreamChar ^ buffer.charAt(i) ^ (i == charIndex ? saltChar : 0)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return buffer.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void writeIntBigEndian(int value, byte[] target, int offset) {
|
||||||
|
target[offset + 3] = (byte) (value & 0xFF);
|
||||||
|
target[offset + 2] = (byte) (value >> 8 & 0xFF);
|
||||||
|
target[offset + 1] = (byte) (value >> 16 & 0xFF);
|
||||||
|
target[offset] = (byte) (value >> 24 & 0xFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int encryptResource(InputStream input, ResourcesOutput output, int[][] roundKeys, int[] ivWords, Config config) throws IOException {
|
||||||
|
byte[] header = new byte[16];
|
||||||
|
for (int i = 0; i < ivWords.length; i++) {
|
||||||
|
writeIntBigEndian(ivWords[i], header, i * 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
ByteArrayOutputStream rawBuffer = new ByteArrayOutputStream();
|
||||||
|
ByteArrayOutputStream compressedBuffer = new ByteArrayOutputStream();
|
||||||
|
Deflater deflater = new Deflater(9, false);
|
||||||
|
DeflaterOutputStream deflaterStream = new DeflaterOutputStream(compressedBuffer, deflater);
|
||||||
|
byte[] chunk = new byte[1024];
|
||||||
|
|
||||||
|
int read;
|
||||||
|
while ((read = input.read(chunk)) > 0) {
|
||||||
|
rawBuffer.write(chunk, 0, read);
|
||||||
|
deflaterStream.write(chunk, 0, read);
|
||||||
|
}
|
||||||
|
|
||||||
|
deflaterStream.flush();
|
||||||
|
rawBuffer.close();
|
||||||
|
deflaterStream.close();
|
||||||
|
|
||||||
|
byte[] payload;
|
||||||
|
if (compressedBuffer.size() > 0 && (double) rawBuffer.size() / compressedBuffer.size() > 1.2) {
|
||||||
|
payload = compressedBuffer.toByteArray();
|
||||||
|
header[3]++;
|
||||||
|
if (config.isVerbose()) {
|
||||||
|
config.getListener().verbose(" compress, ratio " + ((double) rawBuffer.size() / compressedBuffer.size()));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
payload = rawBuffer.toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
output.write(header);
|
||||||
|
int[] state = new int[4];
|
||||||
|
for (int i = 0; i < 16; i++) {
|
||||||
|
state[i / 4] = state[i / 4] << 8 | header[i] & 0xFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < payload.length; i++) {
|
||||||
|
int wordIdx = i % 16 / 4;
|
||||||
|
int byteIdx = i % 16 % 4;
|
||||||
|
if (i % 16 == 0) {
|
||||||
|
encryptBlock(state, roundKeys);
|
||||||
|
}
|
||||||
|
payload[i] ^= (byte) (state[wordIdx] >> 8 * byteIdx);
|
||||||
|
}
|
||||||
|
|
||||||
|
output.write(payload);
|
||||||
|
return payload.length;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,226 @@
|
|||||||
|
package com.licel.stringer.crypto;
|
||||||
|
|
||||||
|
import com.licel.stringer.Watermark;
|
||||||
|
import com.licel.stringer.util.StringerUtils;
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class CryptoContainer {
|
||||||
|
private long primaryKeyHigh;
|
||||||
|
private long currentKeyHigh;
|
||||||
|
private long keyLow;
|
||||||
|
private int[] ivWords = new int[4];
|
||||||
|
private int[][] roundKeys;
|
||||||
|
private int callerHash = 0;
|
||||||
|
private int resourceMagicHeader;
|
||||||
|
private byte[] keyTable;
|
||||||
|
private byte[] keyIndexTable;
|
||||||
|
private List<Integer> keyIndices;
|
||||||
|
private int[] idObfuscationKeys = new int[5];
|
||||||
|
private int[] idObfuscationSigns = new int[3];
|
||||||
|
private long integrityHash = 0L;
|
||||||
|
public SecureRandom secureRandom;
|
||||||
|
|
||||||
|
public CryptoContainer(SecureRandom secureRandom, Watermark watermark, boolean generateRandomKey) {
|
||||||
|
this.secureRandom = secureRandom;
|
||||||
|
if (!generateRandomKey) {
|
||||||
|
this.initWatermarkKey(watermark);
|
||||||
|
for (int i = 0; i < this.ivWords.length; i++) {
|
||||||
|
this.ivWords[i] = secureRandom.nextInt();
|
||||||
|
}
|
||||||
|
this.roundKeys = AESFast.expandKey(this.getKeyBytes());
|
||||||
|
for (int i = 0; i < this.idObfuscationKeys.length; i++) {
|
||||||
|
this.idObfuscationKeys[i] = secureRandom.nextInt();
|
||||||
|
}
|
||||||
|
for (int i = 0; i < this.idObfuscationSigns.length; i++) {
|
||||||
|
this.idObfuscationSigns[i] = secureRandom.nextInt() & 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.primaryKeyHigh = (long) (secureRandom.nextInt(Integer.MAX_VALUE) << 32) + secureRandom.nextInt(Integer.MAX_VALUE);
|
||||||
|
this.currentKeyHigh = this.primaryKeyHigh;
|
||||||
|
this.keyLow = (long) (secureRandom.nextInt(Integer.MAX_VALUE) << 32) + secureRandom.nextInt(Integer.MAX_VALUE);
|
||||||
|
for (int i = 0; i < this.ivWords.length; i++) {
|
||||||
|
this.ivWords[i] = secureRandom.nextInt(Integer.MAX_VALUE);
|
||||||
|
}
|
||||||
|
this.resourceMagicHeader = secureRandom.nextInt(Integer.MAX_VALUE);
|
||||||
|
this.roundKeys = AESFast.expandKey(this.getKeyBytes());
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < this.idObfuscationKeys.length; i++) {
|
||||||
|
this.idObfuscationKeys[i] = secureRandom.nextInt();
|
||||||
|
}
|
||||||
|
for (int i = 0; i < this.idObfuscationSigns.length; i++) {
|
||||||
|
this.idObfuscationSigns[i] = secureRandom.nextInt() & 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initWatermarkKey(Watermark watermark) {
|
||||||
|
this.keyTable = new byte[256];
|
||||||
|
this.secureRandom.nextBytes(this.keyTable);
|
||||||
|
byte[] watermarkBytes = watermark.generateKeyBlock(this.secureRandom);
|
||||||
|
if (watermarkBytes.length != 96) {
|
||||||
|
throw new IllegalArgumentException("");
|
||||||
|
}
|
||||||
|
|
||||||
|
System.arraycopy(watermarkBytes, 0, this.keyTable, 0, watermarkBytes.length);
|
||||||
|
this.keyIndexTable = new byte[256];
|
||||||
|
this.secureRandom.nextBytes(this.keyIndexTable);
|
||||||
|
|
||||||
|
HashSet<Byte> selectedOffsets = new HashSet<>();
|
||||||
|
while (selectedOffsets.size() < 16) {
|
||||||
|
int offset = this.secureRandom.nextInt() & 0xFF;
|
||||||
|
if (offset >= 8) {
|
||||||
|
if (offset < 96) {
|
||||||
|
if (selectedOffsets.contains((byte) offset)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
Byte pairedOffset = (byte) (offset < 56 ? offset + 44 : offset - 44);
|
||||||
|
if (selectedOffsets.contains(pairedOffset)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
selectedOffsets.add((byte) offset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Byte[] offsets = selectedOffsets.toArray(new Byte[16]);
|
||||||
|
HashSet<Integer> lookupSlots = new HashSet<>();
|
||||||
|
while (lookupSlots.size() < 16) {
|
||||||
|
lookupSlots.add(this.secureRandom.nextInt() & 0xFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.keyIndices = Arrays.asList(lookupSlots.toArray(new Integer[16]));
|
||||||
|
Collections.shuffle(this.keyIndices, this.secureRandom);
|
||||||
|
|
||||||
|
for (int i = 0; i < 16; i++) {
|
||||||
|
this.keyIndexTable[this.keyIndices.get(i)] = offsets[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] highBytes = new byte[8];
|
||||||
|
byte[] lowBytes = new byte[8];
|
||||||
|
for (int i = 0; i < 8; i++) {
|
||||||
|
highBytes[i] = this.keyTable[this.keyIndexTable[this.keyIndices.get(i)] & 0xFF];
|
||||||
|
lowBytes[i] = this.keyTable[this.keyIndexTable[this.keyIndices.get(i + 8)] & 0xFF];
|
||||||
|
}
|
||||||
|
|
||||||
|
this.primaryKeyHigh = StringerUtils.bytesToLong(highBytes);
|
||||||
|
this.currentKeyHigh = this.primaryKeyHigh;
|
||||||
|
this.keyLow = StringerUtils.bytesToLong(lowBytes);
|
||||||
|
Arrays.fill(highBytes, (byte) 0);
|
||||||
|
Arrays.fill(lowBytes, (byte) 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getCurrentKeyHigh() {
|
||||||
|
return this.currentKeyHigh;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getPrimaryKeyHigh() {
|
||||||
|
return this.primaryKeyHigh;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getKeyLow() {
|
||||||
|
return this.keyLow;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final byte[] getKeyBytes() {
|
||||||
|
return this.combineKeyBytes(this.currentKeyHigh, this.keyLow);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] getIvWords() {
|
||||||
|
return this.ivWords;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] getIntegrityIvWords() {
|
||||||
|
return this.integrityHash != 0L
|
||||||
|
? new int[]{
|
||||||
|
this.ivWords[0] ^ (int) this.integrityHash,
|
||||||
|
this.ivWords[1] ^ (int) (this.integrityHash >> 32),
|
||||||
|
this.ivWords[2] ^ (int) this.integrityHash,
|
||||||
|
this.ivWords[3] ^ (int) (this.integrityHash >> 32)
|
||||||
|
}
|
||||||
|
: this.ivWords;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void setIntegrityHash(long integrityHash) {
|
||||||
|
this.integrityHash = integrityHash;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] getCallerIvWords() {
|
||||||
|
if (this.callerHash == 0) {
|
||||||
|
return this.ivWords;
|
||||||
|
}
|
||||||
|
int[] result = new int[4];
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
result[i] = this.callerHash ^ this.ivWords[i];
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private byte[] combineKeyBytes(long high, long low) {
|
||||||
|
byte[] result = new byte[16];
|
||||||
|
System.arraycopy(StringerUtils.longToBytes(high), 0, result, 0, 8);
|
||||||
|
System.arraycopy(StringerUtils.longToBytes(low), 0, result, 8, 8);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[][] getRoundKeys() {
|
||||||
|
return this.roundKeys;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getResourceMagicHeader() {
|
||||||
|
return this.resourceMagicHeader;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] createResourceIvWords() {
|
||||||
|
int[] words = new int[4];
|
||||||
|
words[0] = this.resourceMagicHeader;
|
||||||
|
for (int i = 1; i < words.length; i++) {
|
||||||
|
words[i] = this.secureRandom.nextInt();
|
||||||
|
}
|
||||||
|
return words;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCallerHash(int callerHash) {
|
||||||
|
this.callerHash = callerHash;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int encodeMemberId(int memberIndex, int mask) {
|
||||||
|
int value = mask << 16 | memberIndex;
|
||||||
|
value += this.idObfuscationSigns[0] == 0 ? this.idObfuscationKeys[0] : -this.idObfuscationKeys[0];
|
||||||
|
value ^= this.idObfuscationKeys[1];
|
||||||
|
value += this.idObfuscationSigns[1] == 0 ? this.idObfuscationKeys[2] : -this.idObfuscationKeys[2];
|
||||||
|
value ^= this.idObfuscationKeys[3];
|
||||||
|
return value + (this.idObfuscationSigns[2] == 0 ? this.idObfuscationKeys[4] : -this.idObfuscationKeys[4]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] getIdObfuscationKeys() {
|
||||||
|
return this.idObfuscationKeys;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getKeyTable() {
|
||||||
|
return this.keyTable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getKeyIndexTable() {
|
||||||
|
return this.keyIndexTable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Integer> getKeyIndices() {
|
||||||
|
return this.keyIndices;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int[] getIdObfuscationSigns() {
|
||||||
|
return this.idObfuscationSigns;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int nextInt(int bound) {
|
||||||
|
return this.secureRandom.nextInt(bound);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SecureRandom getSecureRandom() {
|
||||||
|
return this.secureRandom;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
package com.licel.stringer.crypto;
|
||||||
|
|
||||||
|
public class SipHash {
|
||||||
|
public static long hash(long k0, long k1, byte[] data) {
|
||||||
|
long v0 = 0x736F6D6570736575L ^ k0;
|
||||||
|
long v1 = 0x646F72616E646F6DL ^ k1;
|
||||||
|
long v2 = 0x6C7967656E657261L ^ k0;
|
||||||
|
long v3 = 0x7465646279746573L ^ k1;
|
||||||
|
int fullBlocksLength = data.length / 8 * 8;
|
||||||
|
int offset = 0;
|
||||||
|
|
||||||
|
while (offset < fullBlocksLength) {
|
||||||
|
long word = (data[offset++] & 0xFFL)
|
||||||
|
| (data[offset++] & 0xFFL) << 8
|
||||||
|
| (data[offset++] & 0xFFL) << 16
|
||||||
|
| (data[offset++] & 0xFFL) << 24
|
||||||
|
| (data[offset++] & 0xFFL) << 32
|
||||||
|
| (data[offset++] & 0xFFL) << 40
|
||||||
|
| (data[offset++] & 0xFFL) << 48
|
||||||
|
| (data[offset++] & 0xFFL) << 56;
|
||||||
|
v3 ^= word;
|
||||||
|
for (int i = 0; i < 2; i++) {
|
||||||
|
v0 += v1;
|
||||||
|
v2 += v3;
|
||||||
|
v1 = v1 << 13 | v1 >>> 51;
|
||||||
|
v3 = v3 << 16 | v3 >>> 48;
|
||||||
|
v1 ^= v0;
|
||||||
|
v3 ^= v2;
|
||||||
|
v0 = v0 << 32 | v0 >>> 32;
|
||||||
|
v2 += v1;
|
||||||
|
v0 += v3;
|
||||||
|
v1 = v1 << 17 | v1 >>> 47;
|
||||||
|
v3 = v3 << 21 | v3 >>> 43;
|
||||||
|
v1 ^= v2;
|
||||||
|
v3 ^= v0;
|
||||||
|
v2 = v2 << 32 | v2 >>> 32;
|
||||||
|
}
|
||||||
|
v0 ^= word;
|
||||||
|
}
|
||||||
|
|
||||||
|
long lastBlock = 0L;
|
||||||
|
for (int i = data.length - 1; i >= fullBlocksLength; i--) {
|
||||||
|
lastBlock <<= 8;
|
||||||
|
lastBlock |= data[i] & 0xFFL;
|
||||||
|
}
|
||||||
|
lastBlock |= (long) data.length << 56;
|
||||||
|
|
||||||
|
v3 ^= lastBlock;
|
||||||
|
for (int i = 0; i < 2; i++) {
|
||||||
|
v0 += v1;
|
||||||
|
v2 += v3;
|
||||||
|
v1 = v1 << 13 | v1 >>> 51;
|
||||||
|
v3 = v3 << 16 | v3 >>> 48;
|
||||||
|
v1 ^= v0;
|
||||||
|
v3 ^= v2;
|
||||||
|
v0 = v0 << 32 | v0 >>> 32;
|
||||||
|
v2 += v1;
|
||||||
|
v0 += v3;
|
||||||
|
v1 = v1 << 17 | v1 >>> 47;
|
||||||
|
v3 = v3 << 21 | v3 >>> 43;
|
||||||
|
v1 ^= v2;
|
||||||
|
v3 ^= v0;
|
||||||
|
v2 = v2 << 32 | v2 >>> 32;
|
||||||
|
}
|
||||||
|
v0 ^= lastBlock;
|
||||||
|
v2 ^= 0xFFL;
|
||||||
|
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
v0 += v1;
|
||||||
|
v2 += v3;
|
||||||
|
v1 = v1 << 13 | v1 >>> 51;
|
||||||
|
v3 = v3 << 16 | v3 >>> 48;
|
||||||
|
v1 ^= v0;
|
||||||
|
v3 ^= v2;
|
||||||
|
v0 = v0 << 32 | v0 >>> 32;
|
||||||
|
v2 += v1;
|
||||||
|
v0 += v3;
|
||||||
|
v1 = v1 << 17 | v1 >>> 47;
|
||||||
|
v3 = v3 << 21 | v3 >>> 43;
|
||||||
|
v1 ^= v2;
|
||||||
|
v3 ^= v0;
|
||||||
|
v2 = v2 << 32 | v2 >>> 32;
|
||||||
|
}
|
||||||
|
|
||||||
|
return v0 ^ v1 ^ v2 ^ v3;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
package com.licel.stringer.io;
|
||||||
|
|
||||||
|
import java.io.FilterOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
|
||||||
|
public class CountingOutputStream extends FilterOutputStream {
|
||||||
|
private long bytesWritten = 0L;
|
||||||
|
|
||||||
|
public CountingOutputStream(OutputStream out) {
|
||||||
|
super(out);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getBytesWritten() {
|
||||||
|
return this.bytesWritten;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(byte[] data) throws IOException {
|
||||||
|
this.out.write(data);
|
||||||
|
this.bytesWritten += data.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(byte[] data, int offset, int length) throws IOException {
|
||||||
|
this.out.write(data, offset, length);
|
||||||
|
this.bytesWritten += length;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(int b) throws IOException {
|
||||||
|
this.out.write(b);
|
||||||
|
this.bytesWritten++;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws IOException {
|
||||||
|
super.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeUInt32(long value) throws IOException {
|
||||||
|
this.write((int) ((value >>> 0) & 0xFFL));
|
||||||
|
this.write((int) ((value >>> 8) & 0xFFL));
|
||||||
|
this.write((int) ((value >>> 16) & 0xFFL));
|
||||||
|
this.write((int) ((value >>> 24) & 0xFFL));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writeUInt16(int value) throws IOException {
|
||||||
|
this.write((value >>> 0) & 0xFF);
|
||||||
|
this.write((value >>> 8) & 0xFF);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
package com.licel.stringer.io;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class DirectoryResourcesOutput extends ResourcesOutput {
|
||||||
|
private final File outputDirectory;
|
||||||
|
private File currentOutputFile;
|
||||||
|
private FileOutputStream outputStream;
|
||||||
|
public final boolean overwriteSource;
|
||||||
|
|
||||||
|
public DirectoryResourcesOutput(File sourceDirectory, File outputDirectory) {
|
||||||
|
this.outputDirectory = outputDirectory;
|
||||||
|
this.overwriteSource = outputDirectory.equals(sourceDirectory);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isOverwriteSource() {
|
||||||
|
return this.overwriteSource;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void openEntry(ResourceEntry entry) throws IOException {
|
||||||
|
String outputPath = this.resolveEntryPath(entry.getName());
|
||||||
|
this.closeCurrentStream();
|
||||||
|
this.currentOutputFile = new File(outputPath);
|
||||||
|
if (entry.isDirectory()) {
|
||||||
|
this.currentOutputFile.mkdirs();
|
||||||
|
} else {
|
||||||
|
File parentDir = this.currentOutputFile.getParentFile();
|
||||||
|
if (parentDir != null) {
|
||||||
|
parentDir.mkdirs();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void closeCurrentStream() throws IOException {
|
||||||
|
if (this.outputStream != null) {
|
||||||
|
this.outputStream.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.outputStream = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(byte[] data) throws IOException {
|
||||||
|
if (this.outputStream == null) {
|
||||||
|
this.outputStream = new FileOutputStream(this.currentOutputFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.outputStream.write(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(byte[] data, int offset, int length) throws IOException {
|
||||||
|
if (this.outputStream == null) {
|
||||||
|
this.outputStream = new FileOutputStream(this.currentOutputFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.outputStream.write(data, offset, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void open() throws IOException {
|
||||||
|
if (!this.outputDirectory.exists()) {
|
||||||
|
this.outputDirectory.mkdirs();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws IOException {
|
||||||
|
this.closeCurrentStream();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String resolveEntryPath(String entryName) {
|
||||||
|
return this.outputDirectory.getAbsolutePath() + File.separator + entryName;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,57 @@
|
|||||||
|
package com.licel.stringer.io;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DirectorySourceIterator extends SourceIterator {
|
||||||
|
private final File rootDirectory;
|
||||||
|
private final int rootPathLength;
|
||||||
|
|
||||||
|
public DirectorySourceIterator(File rootDirectory) {
|
||||||
|
this.rootDirectory = rootDirectory;
|
||||||
|
this.rootPathLength = this.rootDirectory.getAbsolutePath().length() + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterator<ResourceEntry> entries() {
|
||||||
|
List<ResourceEntry> entries = new ArrayList<>();
|
||||||
|
this.collectEntries(this.rootDirectory, entries);
|
||||||
|
return entries.iterator();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InputStream openStream(ResourceEntry entry) throws IOException {
|
||||||
|
return new FileInputStream(this.rootDirectory + File.separator + entry.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void collectEntries(File directory, List<ResourceEntry> entries) {
|
||||||
|
File[] children = directory.listFiles();
|
||||||
|
if (children == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (File child : children) {
|
||||||
|
String relativeName = child.getAbsolutePath().substring(this.rootPathLength);
|
||||||
|
entries.add(new ResourceEntry(relativeName, child.isDirectory(), child.length()));
|
||||||
|
if (child.isDirectory()) {
|
||||||
|
this.collectEntries(child, entries);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws IOException {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public URL getSourceUrl() throws MalformedURLException {
|
||||||
|
return this.rootDirectory.toURI().toURL();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,184 @@
|
|||||||
|
package com.licel.stringer.io;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.BufferedWriter;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Vector;
|
||||||
|
import java.util.jar.JarEntry;
|
||||||
|
import java.util.jar.JarFile;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipFile;
|
||||||
|
|
||||||
|
public class JarIndex {
|
||||||
|
public static final String INDEX_NAME = "META-INF/INDEX.LIST";
|
||||||
|
|
||||||
|
private static final boolean META_INF_FILENAMES =
|
||||||
|
"true".equals(System.getProperty("sun.misc.JarIndex.metaInfFilenames"));
|
||||||
|
|
||||||
|
private final HashMap<String, LinkedList<String>> indexMap = new HashMap<>();
|
||||||
|
private final HashMap<String, LinkedList<String>> jarMap = new HashMap<>();
|
||||||
|
private String[] jarFiles;
|
||||||
|
|
||||||
|
public JarIndex() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public JarIndex(InputStream in) throws IOException {
|
||||||
|
this();
|
||||||
|
this.read(in);
|
||||||
|
}
|
||||||
|
|
||||||
|
public JarIndex(String[] jarFiles) throws IOException {
|
||||||
|
this();
|
||||||
|
this.jarFiles = jarFiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JarIndex getJarIndex(JarFile jar) throws IOException {
|
||||||
|
JarIndex index = null;
|
||||||
|
JarEntry entry = jar.getJarEntry(INDEX_NAME);
|
||||||
|
if (entry != null) {
|
||||||
|
index = new JarIndex(jar.getInputStream(entry));
|
||||||
|
}
|
||||||
|
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getJarFiles() {
|
||||||
|
return this.jarFiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addToList(String key, String value, HashMap<String, LinkedList<String>> map) {
|
||||||
|
LinkedList<String> list = map.get(key);
|
||||||
|
if (list == null) {
|
||||||
|
list = new LinkedList<>();
|
||||||
|
list.add(value);
|
||||||
|
map.put(key, list);
|
||||||
|
} else if (!list.contains(value)) {
|
||||||
|
list.add(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public LinkedList<String> get(String fileName) {
|
||||||
|
LinkedList<String> jars = this.indexMap.get(fileName);
|
||||||
|
int pos;
|
||||||
|
if (jars == null && (pos = fileName.lastIndexOf("/")) != -1) {
|
||||||
|
jars = this.indexMap.get(fileName.substring(0, pos));
|
||||||
|
}
|
||||||
|
|
||||||
|
return jars;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(String fileName, String jarName) {
|
||||||
|
String packageName;
|
||||||
|
int pos = fileName.lastIndexOf("/");
|
||||||
|
if (pos != -1) {
|
||||||
|
packageName = fileName.substring(0, pos);
|
||||||
|
} else {
|
||||||
|
packageName = fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.addMapping(packageName, jarName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addResource(String resourceName, String jarName) {
|
||||||
|
this.addMapping(resourceName, jarName);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addMapping(String jarItem, String jarName) {
|
||||||
|
this.addToList(jarItem, jarName, this.indexMap);
|
||||||
|
this.addToList(jarName, jarItem, this.jarMap);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
private void parseJars(String[] files) throws IOException {
|
||||||
|
if (files == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String currentJar : files) {
|
||||||
|
ZipFile zrf = new ZipFile(currentJar.replace('/', File.separatorChar));
|
||||||
|
Enumeration<? extends ZipEntry> entries = zrf.entries();
|
||||||
|
|
||||||
|
while (entries.hasMoreElements()) {
|
||||||
|
ZipEntry entry = entries.nextElement();
|
||||||
|
String fileName = entry.getName();
|
||||||
|
if (!fileName.equals("META-INF/")
|
||||||
|
&& !fileName.equals(INDEX_NAME)
|
||||||
|
&& !fileName.equals("META-INF/MANIFEST.MF")) {
|
||||||
|
if (!META_INF_FILENAMES || !fileName.startsWith("META-INF/")) {
|
||||||
|
this.addMapping(fileName, currentJar);
|
||||||
|
} else if (!entry.isDirectory()) {
|
||||||
|
this.addMapping(fileName, currentJar);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
zrf.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void write(OutputStream out) throws IOException {
|
||||||
|
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out, StandardCharsets.UTF_8));
|
||||||
|
writer.write("JarIndex-Version: 1.0\n\n");
|
||||||
|
if (this.jarFiles != null) {
|
||||||
|
for (String jar : this.jarFiles) {
|
||||||
|
LinkedList<String> jarList = this.jarMap.get(jar);
|
||||||
|
if (jarList != null) {
|
||||||
|
for (String item : jarList) {
|
||||||
|
writer.write(item + "\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
writer.write("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
writer.flush();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void read(InputStream in) throws IOException {
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8));
|
||||||
|
String currentJar = null;
|
||||||
|
Vector<String> jars = new Vector<>();
|
||||||
|
|
||||||
|
String line;
|
||||||
|
while ((line = reader.readLine()) != null && !line.endsWith(".jar")) {
|
||||||
|
}
|
||||||
|
|
||||||
|
for (; line != null; line = reader.readLine()) {
|
||||||
|
if (line.length() != 0) {
|
||||||
|
if (line.endsWith(".jar")) {
|
||||||
|
currentJar = line;
|
||||||
|
jars.add(currentJar);
|
||||||
|
} else {
|
||||||
|
this.addMapping(line, currentJar);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.jarFiles = jars.toArray(new String[jars.size()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void merge(JarIndex toIndex, String path) {
|
||||||
|
for (Map.Entry<String, LinkedList<String>> entry : this.indexMap.entrySet()) {
|
||||||
|
String packageName = entry.getKey();
|
||||||
|
|
||||||
|
for (String jarName : entry.getValue()) {
|
||||||
|
if (path != null) {
|
||||||
|
jarName = path.concat(jarName);
|
||||||
|
}
|
||||||
|
|
||||||
|
toIndex.addMapping(packageName, jarName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package com.licel.stringer.io;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.FileVisitResult;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.PathMatcher;
|
||||||
|
import java.nio.file.SimpleFileVisitor;
|
||||||
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public final class MatchingFileCollector extends SimpleFileVisitor<Path> {
|
||||||
|
private final Path rootPath;
|
||||||
|
private final PathMatcher pathMatcher;
|
||||||
|
private final List<Path> matchedFiles;
|
||||||
|
|
||||||
|
public MatchingFileCollector(Path rootPath, PathMatcher pathMatcher) {
|
||||||
|
this(rootPath, pathMatcher, new ArrayList<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
public MatchingFileCollector(Path rootPath, PathMatcher pathMatcher, List<Path> matchedFiles) {
|
||||||
|
this.rootPath = rootPath;
|
||||||
|
this.pathMatcher = pathMatcher;
|
||||||
|
this.matchedFiles = matchedFiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Path> getMatchedFiles() {
|
||||||
|
return this.matchedFiles;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void matchPath(Path path) {
|
||||||
|
Path relativePath = this.rootPath.relativize(path);
|
||||||
|
if (relativePath != null && this.pathMatcher.matches(relativePath)) {
|
||||||
|
this.matchedFiles.add(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
|
||||||
|
this.matchPath(file);
|
||||||
|
return FileVisitResult.CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
|
||||||
|
this.matchPath(dir);
|
||||||
|
return FileVisitResult.CONTINUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FileVisitResult visitFileFailed(Path file, IOException exc) {
|
||||||
|
return FileVisitResult.CONTINUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package com.licel.stringer.io;
|
||||||
|
|
||||||
|
public class ResourceEntry {
|
||||||
|
private final String name;
|
||||||
|
private final boolean directory;
|
||||||
|
private final long size;
|
||||||
|
private byte[] extra;
|
||||||
|
|
||||||
|
public ResourceEntry(String name) {
|
||||||
|
this(name, false, -1L);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResourceEntry(String name, boolean directory) {
|
||||||
|
this(name, directory, -1L);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResourceEntry(String name, boolean directory, long size) {
|
||||||
|
this.name = name;
|
||||||
|
this.directory = directory;
|
||||||
|
this.size = directory ? 0L : size;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNormalizedName() {
|
||||||
|
return this.name.replace('\\', '/') + (this.directory && !this.name.endsWith("/") ? "/" : "");
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDirectory() {
|
||||||
|
return this.directory;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getSize() {
|
||||||
|
return this.size;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExtra(byte[] extra) {
|
||||||
|
this.extra = extra;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getExtra() {
|
||||||
|
return this.extra;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.licel.stringer.io;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public abstract class ResourcesOutput {
|
||||||
|
public abstract void open() throws IOException;
|
||||||
|
|
||||||
|
public abstract void openEntry(ResourceEntry entry) throws IOException;
|
||||||
|
|
||||||
|
public abstract void close() throws IOException;
|
||||||
|
|
||||||
|
public abstract void write(byte[] data) throws IOException;
|
||||||
|
|
||||||
|
public abstract void write(byte[] data, int offset, int length) throws IOException;
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.licel.stringer.io;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
public abstract class SourceIterator {
|
||||||
|
public abstract Iterator<ResourceEntry> entries();
|
||||||
|
|
||||||
|
public abstract InputStream openStream(ResourceEntry entry) throws IOException;
|
||||||
|
|
||||||
|
public abstract void close() throws IOException;
|
||||||
|
|
||||||
|
public abstract URL getSourceUrl() throws MalformedURLException;
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.licel.stringer.io;
|
||||||
|
|
||||||
|
public class ZipAlignmentConstants {
|
||||||
|
public static final int LOCAL_FILE_HEADER_SIZE = 30;
|
||||||
|
public static final int VERSION_NEEDED = 20;
|
||||||
|
public static final int EXTRA_FIELD_LENGTH_OFFSET = 28;
|
||||||
|
public static final int EXTRA_FIELD_LENGTH_SIZE = 2;
|
||||||
|
public static final int DATA_DESCRIPTOR_FLAG = 8;
|
||||||
|
public static final int DATA_DESCRIPTOR_SIZE = 16;
|
||||||
|
public static final int DEFAULT_ALIGNMENT = 8;
|
||||||
|
public static final int PAGE_ALIGNMENT = 4096;
|
||||||
|
public static final String ALIGNED_LABEL = "ALIGNED";
|
||||||
|
public static final String CHARSET_UTF8 = "UTF-8";
|
||||||
|
public static final int BUFFER_SIZE = 32768;
|
||||||
|
}
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
package com.licel.stringer.io;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.RandomAccessFile;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipFile;
|
||||||
|
|
||||||
|
public class ZipAlignmentVerifier {
|
||||||
|
private static final int UTF8_ENCODING_FLAG = 2048;
|
||||||
|
|
||||||
|
private final File archiveFile;
|
||||||
|
private final int alignment;
|
||||||
|
private ZipFile zipFile;
|
||||||
|
private RandomAccessFile input;
|
||||||
|
private boolean failed = false;
|
||||||
|
|
||||||
|
public ZipAlignmentVerifier(File archiveFile) {
|
||||||
|
this(archiveFile, ZipAlignmentConstants.DEFAULT_ALIGNMENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ZipAlignmentVerifier(File archiveFile, int alignment) {
|
||||||
|
this.archiveFile = archiveFile;
|
||||||
|
this.alignment = alignment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isFailed() {
|
||||||
|
return this.failed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void verify() throws IOException {
|
||||||
|
try {
|
||||||
|
this.openFiles();
|
||||||
|
this.verifyEntries();
|
||||||
|
} catch (Exception e) {
|
||||||
|
this.failed = true;
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
this.closeFiles();
|
||||||
|
} catch (Exception e) {
|
||||||
|
this.failed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void openFiles() throws IOException {
|
||||||
|
this.zipFile = new ZipFile(this.archiveFile);
|
||||||
|
this.input = new RandomAccessFile(this.archiveFile, "r");
|
||||||
|
}
|
||||||
|
|
||||||
|
private void verifyEntries() throws IOException {
|
||||||
|
int entryCount = this.zipFile.size();
|
||||||
|
if (entryCount == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Enumeration<? extends ZipEntry> entries = this.zipFile.entries();
|
||||||
|
long offset = 0L;
|
||||||
|
|
||||||
|
while (entries.hasMoreElements()) {
|
||||||
|
ZipEntry entry = entries.nextElement();
|
||||||
|
this.input.seek(offset + ZipAlignmentConstants.EXTRA_FIELD_LENGTH_OFFSET);
|
||||||
|
byte[] extraLengthBytes = new byte[ZipAlignmentConstants.EXTRA_FIELD_LENGTH_SIZE];
|
||||||
|
if (this.input.read(extraLengthBytes) != extraLengthBytes.length) {
|
||||||
|
this.failed = true;
|
||||||
|
throw new IOException("Reading extra field length failed");
|
||||||
|
}
|
||||||
|
|
||||||
|
int extraLength = (extraLengthBytes[0] & 0xFF) | ((extraLengthBytes[1] & 0xFF) << 8);
|
||||||
|
int headerLength = ZipAlignmentConstants.LOCAL_FILE_HEADER_SIZE
|
||||||
|
+ extraLength
|
||||||
|
+ entry.getName().getBytes(ZipAlignmentConstants.CHARSET_UTF8).length;
|
||||||
|
|
||||||
|
if (entry.getMethod() == ZipEntry.STORED && (offset + headerLength) % this.alignment != 0L) {
|
||||||
|
this.failed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
int flags = entry.getMethod() == ZipEntry.STORED ? 0 : ZipAlignmentConstants.DATA_DESCRIPTOR_FLAG;
|
||||||
|
flags |= UTF8_ENCODING_FLAG;
|
||||||
|
|
||||||
|
long dataLength;
|
||||||
|
if ((flags & ZipAlignmentConstants.DATA_DESCRIPTOR_FLAG) != 0) {
|
||||||
|
dataLength = (entry.isDirectory() ? 0L : entry.getCompressedSize())
|
||||||
|
+ ZipAlignmentConstants.DATA_DESCRIPTOR_SIZE;
|
||||||
|
} else {
|
||||||
|
dataLength = entry.isDirectory() ? 0L : entry.getCompressedSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
offset += headerLength + dataLength;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void closeFiles() throws IOException {
|
||||||
|
try {
|
||||||
|
if (this.zipFile != null) {
|
||||||
|
this.zipFile.close();
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (this.input != null) {
|
||||||
|
this.input.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,296 @@
|
|||||||
|
package com.licel.stringer.io;
|
||||||
|
|
||||||
|
import java.io.BufferedOutputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.RandomAccessFile;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
import java.util.GregorianCalendar;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipFile;
|
||||||
|
|
||||||
|
public class ZipAlignmentWriter {
|
||||||
|
private static final long LOCAL_FILE_HEADER_SIGNATURE = 0x04034B50L;
|
||||||
|
private static final long CENTRAL_DIRECTORY_HEADER_SIGNATURE = 0x02014B50L;
|
||||||
|
private static final long END_OF_CENTRAL_DIRECTORY_SIGNATURE = 0x06054B50L;
|
||||||
|
private static final int UTF8_ENCODING_FLAG = 2048;
|
||||||
|
private static final int MAX_COMMENT_LENGTH = 65535;
|
||||||
|
private static final byte MANIFEST_EXTRA_HEADER_BYTE = 85;
|
||||||
|
|
||||||
|
private final File inputFile;
|
||||||
|
private final int alignment;
|
||||||
|
private final File outputFile;
|
||||||
|
private final byte[] manifestExtraData;
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
private final byte[] extraMetadata;
|
||||||
|
private ZipFile zipFile;
|
||||||
|
private RandomAccessFile input;
|
||||||
|
private CountingOutputStream output;
|
||||||
|
private final List<ZipEntryRecord> entries = new ArrayList<>();
|
||||||
|
private long inputOffset = 0L;
|
||||||
|
private int totalPadding = 0;
|
||||||
|
|
||||||
|
public ZipAlignmentWriter(File inputFile, File outputFile, byte[] manifestExtraData, byte[] extraMetadata) {
|
||||||
|
this(inputFile, ZipAlignmentConstants.DEFAULT_ALIGNMENT, outputFile, manifestExtraData, extraMetadata);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ZipAlignmentWriter(
|
||||||
|
File inputFile,
|
||||||
|
int alignment,
|
||||||
|
File outputFile,
|
||||||
|
byte[] manifestExtraData,
|
||||||
|
byte[] extraMetadata) {
|
||||||
|
this.inputFile = inputFile;
|
||||||
|
this.alignment = alignment;
|
||||||
|
this.outputFile = outputFile;
|
||||||
|
this.manifestExtraData = manifestExtraData;
|
||||||
|
this.extraMetadata = extraMetadata;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void align() throws IOException {
|
||||||
|
try {
|
||||||
|
this.openFiles();
|
||||||
|
this.writeLocalEntries();
|
||||||
|
this.writeCentralDirectory();
|
||||||
|
} catch (Exception e) {
|
||||||
|
this.outputFile.delete();
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
this.closeFiles();
|
||||||
|
} catch (Exception e) {
|
||||||
|
this.outputFile.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void openFiles() throws IOException {
|
||||||
|
this.zipFile = new ZipFile(this.inputFile);
|
||||||
|
this.input = new RandomAccessFile(this.inputFile, "r");
|
||||||
|
this.output = new CountingOutputStream(
|
||||||
|
new BufferedOutputStream(new FileOutputStream(this.outputFile), ZipAlignmentConstants.BUFFER_SIZE));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writeLocalEntries() throws IOException {
|
||||||
|
int entryCount = this.zipFile.size();
|
||||||
|
if (entryCount == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Enumeration<? extends ZipEntry> zipEntries = this.zipFile.entries();
|
||||||
|
|
||||||
|
while (zipEntries.hasMoreElements()) {
|
||||||
|
ZipEntry entry = zipEntries.nextElement();
|
||||||
|
int flags = entry.getMethod() == ZipEntry.STORED ? 0 : ZipAlignmentConstants.DATA_DESCRIPTOR_FLAG;
|
||||||
|
flags |= UTF8_ENCODING_FLAG;
|
||||||
|
|
||||||
|
long localHeaderOffset = this.output.getBytesWritten();
|
||||||
|
byte[] nameBytes = entry.getName().getBytes(ZipAlignmentConstants.CHARSET_UTF8);
|
||||||
|
int originalHeaderLength = ZipAlignmentConstants.LOCAL_FILE_HEADER_SIZE
|
||||||
|
+ (entry.getExtra() != null ? entry.getExtra().length : 0)
|
||||||
|
+ nameBytes.length;
|
||||||
|
|
||||||
|
int padding;
|
||||||
|
if (entry.getMethod() != ZipEntry.STORED) {
|
||||||
|
padding = 0;
|
||||||
|
} else {
|
||||||
|
long dataOffset = this.output.getBytesWritten() + originalHeaderLength;
|
||||||
|
if (!entry.getName().endsWith(".so")) {
|
||||||
|
padding = (int) ((this.alignment - dataOffset % this.alignment) % this.alignment);
|
||||||
|
} else {
|
||||||
|
padding = (int) ((ZipAlignmentConstants.PAGE_ALIGNMENT
|
||||||
|
- dataOffset % ZipAlignmentConstants.PAGE_ALIGNMENT)
|
||||||
|
% ZipAlignmentConstants.PAGE_ALIGNMENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.totalPadding += padding;
|
||||||
|
}
|
||||||
|
|
||||||
|
ZipEntryRecord record = new ZipEntryRecord(entry, localHeaderOffset, flags, padding);
|
||||||
|
this.entries.add(record);
|
||||||
|
|
||||||
|
byte[] extra = entry.getExtra();
|
||||||
|
if (entry.getName().equals("META-INF/MANIFEST.MF") && this.manifestExtraData != null) {
|
||||||
|
extra = new byte[this.manifestExtraData.length + 4];
|
||||||
|
extra[0] = MANIFEST_EXTRA_HEADER_BYTE;
|
||||||
|
extra[1] = MANIFEST_EXTRA_HEADER_BYTE;
|
||||||
|
extra[2] = (byte) ((this.manifestExtraData.length >>> 0) & 0xFF);
|
||||||
|
extra[3] = (byte) ((this.manifestExtraData.length >>> 8) & 0xFF);
|
||||||
|
System.arraycopy(this.manifestExtraData, 0, extra, 4, this.manifestExtraData.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (extra == null) {
|
||||||
|
extra = new byte[padding];
|
||||||
|
Arrays.fill(extra, (byte) 0);
|
||||||
|
} else {
|
||||||
|
byte[] paddedExtra = new byte[extra.length + padding];
|
||||||
|
System.arraycopy(extra, 0, paddedExtra, 0, extra.length);
|
||||||
|
Arrays.fill(paddedExtra, extra.length, paddedExtra.length, (byte) 0);
|
||||||
|
extra = paddedExtra;
|
||||||
|
}
|
||||||
|
|
||||||
|
entry.setExtra(extra);
|
||||||
|
|
||||||
|
this.output.writeUInt32(LOCAL_FILE_HEADER_SIGNATURE);
|
||||||
|
this.output.writeUInt16(ZipAlignmentConstants.VERSION_NEEDED);
|
||||||
|
this.output.writeUInt16(flags);
|
||||||
|
this.output.writeUInt16(entry.getMethod());
|
||||||
|
|
||||||
|
int[] dosDateTime = encodeDosDateTime(entry.getTime());
|
||||||
|
this.output.writeUInt16(dosDateTime[0]);
|
||||||
|
this.output.writeUInt16(dosDateTime[1]);
|
||||||
|
|
||||||
|
this.output.writeUInt32(entry.getCrc());
|
||||||
|
this.output.writeUInt32(entry.getCompressedSize());
|
||||||
|
this.output.writeUInt32(entry.getSize());
|
||||||
|
this.output.writeUInt16(nameBytes.length);
|
||||||
|
this.output.writeUInt16(extra.length);
|
||||||
|
this.output.write(nameBytes);
|
||||||
|
this.output.write(extra, 0, extra.length);
|
||||||
|
|
||||||
|
this.inputOffset += originalHeaderLength;
|
||||||
|
|
||||||
|
long dataLength;
|
||||||
|
if ((flags & ZipAlignmentConstants.DATA_DESCRIPTOR_FLAG) != 0) {
|
||||||
|
dataLength = (entry.isDirectory() ? 0L : entry.getCompressedSize())
|
||||||
|
+ ZipAlignmentConstants.DATA_DESCRIPTOR_SIZE;
|
||||||
|
} else {
|
||||||
|
dataLength = entry.isDirectory() ? 0L : entry.getCompressedSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dataLength > 0L) {
|
||||||
|
this.input.seek(this.inputOffset);
|
||||||
|
long copied = 0L;
|
||||||
|
byte[] copyBuffer = new byte[ZipAlignmentConstants.BUFFER_SIZE];
|
||||||
|
|
||||||
|
while (copied < dataLength) {
|
||||||
|
int chunkSize = (int) Math.min(ZipAlignmentConstants.BUFFER_SIZE, dataLength - copied);
|
||||||
|
int read = this.input.read(copyBuffer, 0, chunkSize);
|
||||||
|
if (read <= 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.output.write(copyBuffer, 0, read);
|
||||||
|
copied += read;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.inputOffset += dataLength;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void writeCentralDirectory() throws IOException {
|
||||||
|
long centralDirectoryOffset = this.output.getBytesWritten();
|
||||||
|
|
||||||
|
for (ZipEntryRecord record : this.entries) {
|
||||||
|
ZipEntry entry = record.entry;
|
||||||
|
int[] dosDateTime = encodeDosDateTime(entry.getTime());
|
||||||
|
|
||||||
|
this.output.writeUInt32(CENTRAL_DIRECTORY_HEADER_SIGNATURE);
|
||||||
|
this.output.writeUInt16(ZipAlignmentConstants.VERSION_NEEDED);
|
||||||
|
this.output.writeUInt16(ZipAlignmentConstants.VERSION_NEEDED);
|
||||||
|
this.output.writeUInt16(record.flags);
|
||||||
|
this.output.writeUInt16(entry.getMethod());
|
||||||
|
this.output.writeUInt16(dosDateTime[0]);
|
||||||
|
this.output.writeUInt16(dosDateTime[1]);
|
||||||
|
this.output.writeUInt32(entry.getCrc());
|
||||||
|
this.output.writeUInt32(entry.getCompressedSize());
|
||||||
|
this.output.writeUInt32(entry.getSize());
|
||||||
|
|
||||||
|
byte[] nameBytes = entry.getName().getBytes(ZipAlignmentConstants.CHARSET_UTF8);
|
||||||
|
this.output.writeUInt16(nameBytes.length);
|
||||||
|
|
||||||
|
byte[] extra = entry.getExtra();
|
||||||
|
int centralExtraLength = extra != null ? extra.length - record.padding : 0;
|
||||||
|
this.output.writeUInt16(centralExtraLength);
|
||||||
|
|
||||||
|
byte[] commentBytes;
|
||||||
|
if (entry.getComment() != null) {
|
||||||
|
commentBytes = entry.getComment().getBytes(ZipAlignmentConstants.CHARSET_UTF8);
|
||||||
|
this.output.writeUInt16(Math.min(commentBytes.length, MAX_COMMENT_LENGTH));
|
||||||
|
} else {
|
||||||
|
commentBytes = null;
|
||||||
|
this.output.writeUInt16(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.output.writeUInt16(0);
|
||||||
|
this.output.writeUInt16(0);
|
||||||
|
this.output.writeUInt32(0L);
|
||||||
|
this.output.writeUInt32(record.localHeaderOffset);
|
||||||
|
this.output.write(nameBytes);
|
||||||
|
|
||||||
|
if (extra != null) {
|
||||||
|
this.output.write(extra, 0, centralExtraLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (commentBytes != null) {
|
||||||
|
this.output.write(commentBytes, 0, Math.min(commentBytes.length, MAX_COMMENT_LENGTH));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
long centralDirectorySize = this.output.getBytesWritten() - centralDirectoryOffset;
|
||||||
|
int entryCount = this.entries.size();
|
||||||
|
|
||||||
|
this.output.writeUInt32(END_OF_CENTRAL_DIRECTORY_SIGNATURE);
|
||||||
|
this.output.writeUInt16(0);
|
||||||
|
this.output.writeUInt16(0);
|
||||||
|
this.output.writeUInt16(entryCount);
|
||||||
|
this.output.writeUInt16(entryCount);
|
||||||
|
this.output.writeUInt32(centralDirectorySize);
|
||||||
|
this.output.writeUInt32(centralDirectoryOffset);
|
||||||
|
|
||||||
|
if (this.zipFile.getComment() != null) {
|
||||||
|
byte[] zipCommentBytes = this.zipFile.getComment().getBytes(ZipAlignmentConstants.CHARSET_UTF8);
|
||||||
|
this.output.writeUInt16(zipCommentBytes.length);
|
||||||
|
this.output.write(zipCommentBytes);
|
||||||
|
} else {
|
||||||
|
this.output.writeUInt16(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.output.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int[] encodeDosDateTime(long timeMillis) {
|
||||||
|
GregorianCalendar calendar = new GregorianCalendar();
|
||||||
|
calendar.setTime(new Date(timeMillis));
|
||||||
|
int year = calendar.get(Calendar.YEAR);
|
||||||
|
int dosDate;
|
||||||
|
int dosTime;
|
||||||
|
if (year < 1980) {
|
||||||
|
dosDate = 33;
|
||||||
|
dosTime = 0;
|
||||||
|
} else {
|
||||||
|
dosDate = calendar.get(Calendar.DAY_OF_MONTH);
|
||||||
|
dosDate = ((calendar.get(Calendar.MONTH) + 1) << 5) | dosDate;
|
||||||
|
dosDate = ((calendar.get(Calendar.YEAR) - 1980) << 9) | dosDate;
|
||||||
|
dosTime = calendar.get(Calendar.SECOND) >> 1;
|
||||||
|
dosTime = (calendar.get(Calendar.MINUTE) << 5) | dosTime;
|
||||||
|
dosTime = (calendar.get(Calendar.HOUR_OF_DAY) << 11) | dosTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new int[]{dosTime, dosDate};
|
||||||
|
}
|
||||||
|
|
||||||
|
private void closeFiles() throws IOException {
|
||||||
|
try {
|
||||||
|
if (this.zipFile != null) {
|
||||||
|
this.zipFile.close();
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
if (this.input != null) {
|
||||||
|
this.input.close();
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (this.output != null) {
|
||||||
|
this.output.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
package com.licel.stringer.io;
|
||||||
|
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
|
||||||
|
public class ZipEntryRecord {
|
||||||
|
public final ZipEntry entry;
|
||||||
|
public final long localHeaderOffset;
|
||||||
|
public final int flags;
|
||||||
|
public final int padding;
|
||||||
|
|
||||||
|
public ZipEntryRecord(ZipEntry entry, long localHeaderOffset, int flags, int padding) {
|
||||||
|
this.entry = entry;
|
||||||
|
this.localHeaderOffset = localHeaderOffset;
|
||||||
|
this.flags = flags;
|
||||||
|
this.padding = padding;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
package com.licel.stringer.io;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.zip.Deflater;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
|
public class ZipResourcesOutput extends ResourcesOutput {
|
||||||
|
private static final int DEFAULT_BUFFER_SIZE = 16 * 1024 * 1024;
|
||||||
|
|
||||||
|
private final File outputFile;
|
||||||
|
private final boolean optimize;
|
||||||
|
private ByteArrayOutputStream buffer;
|
||||||
|
private ZipOutputStream zipOutputStream;
|
||||||
|
|
||||||
|
public ZipResourcesOutput(File outputFile, boolean optimize) {
|
||||||
|
this.outputFile = outputFile;
|
||||||
|
this.optimize = optimize;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void openEntry(ResourceEntry entry) throws IOException {
|
||||||
|
ZipEntry zipEntry = new ZipEntry(entry.getName());
|
||||||
|
zipEntry.setExtra(entry.getExtra());
|
||||||
|
this.zipOutputStream.putNextEntry(zipEntry);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void closeArchiveStream() throws IOException {
|
||||||
|
this.zipOutputStream.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(byte[] data) throws IOException {
|
||||||
|
this.zipOutputStream.write(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void write(byte[] data, int offset, int length) throws IOException {
|
||||||
|
this.zipOutputStream.write(data, offset, length);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void open() throws IOException {
|
||||||
|
if (this.outputFile.exists()) {
|
||||||
|
this.buffer = new ByteArrayOutputStream((int) this.outputFile.length());
|
||||||
|
} else {
|
||||||
|
this.buffer = new ByteArrayOutputStream(DEFAULT_BUFFER_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.zipOutputStream = new ZipOutputStream(this.buffer);
|
||||||
|
if (this.optimize) {
|
||||||
|
this.zipOutputStream.setLevel(Deflater.BEST_COMPRESSION);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws IOException {
|
||||||
|
this.zipOutputStream.close();
|
||||||
|
if (!this.outputFile.exists()) {
|
||||||
|
this.outputFile.createNewFile();
|
||||||
|
}
|
||||||
|
|
||||||
|
try (FileOutputStream fileOut = new FileOutputStream(this.outputFile)) {
|
||||||
|
this.buffer.writeTo(fileOut);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
package com.licel.stringer.io;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipFile;
|
||||||
|
|
||||||
|
public class ZipSourceIterator extends SourceIterator {
|
||||||
|
private final File archiveFile;
|
||||||
|
private final ZipFile zipFile;
|
||||||
|
|
||||||
|
public ZipSourceIterator(File archiveFile) throws IOException {
|
||||||
|
this.archiveFile = archiveFile;
|
||||||
|
this.zipFile = new ZipFile(archiveFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterator<ResourceEntry> entries() {
|
||||||
|
List<ResourceEntry> entries = new ArrayList<>();
|
||||||
|
Enumeration<? extends ZipEntry> zipEntries = this.zipFile.entries();
|
||||||
|
|
||||||
|
while (zipEntries.hasMoreElements()) {
|
||||||
|
ZipEntry entry = zipEntries.nextElement();
|
||||||
|
boolean isDirectory = entry.isDirectory()
|
||||||
|
|| entry.getName().endsWith("/")
|
||||||
|
|| entry.getName().endsWith("\\");
|
||||||
|
entries.add(new ResourceEntry(entry.getName(), isDirectory, entry.getSize()));
|
||||||
|
}
|
||||||
|
|
||||||
|
return entries.iterator();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InputStream openStream(ResourceEntry entry) throws IOException {
|
||||||
|
return this.zipFile.getInputStream(this.zipFile.getEntry(entry.getName()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws IOException {
|
||||||
|
this.zipFile.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public URL getSourceUrl() throws MalformedURLException {
|
||||||
|
return this.archiveFile.toURI().toURL();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
package com.licel.stringer.model;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class ClassInfo {
|
||||||
|
public String name;
|
||||||
|
public String superName;
|
||||||
|
public HashMap<String, Object> stringFieldInitialValues;
|
||||||
|
public HashMap<String, Object> securedStringFields;
|
||||||
|
public HashSet<String> excludedStrings;
|
||||||
|
public HashSet<String> stringLiterals;
|
||||||
|
public List<ClassMemberInfo> declaredMethods;
|
||||||
|
public List<ClassMemberInfo> declaredFields;
|
||||||
|
public List<ClassMemberInfo> inheritedMethods;
|
||||||
|
public List<ClassMemberInfo> inheritedFields;
|
||||||
|
public boolean isInterface;
|
||||||
|
public boolean hasNativeMethods = false;
|
||||||
|
public boolean hasStaticInitializer = false;
|
||||||
|
public List<String> referencedTypes;
|
||||||
|
public boolean isEnum = false;
|
||||||
|
public boolean hasLegacySecuredAnnotation = false;
|
||||||
|
public boolean isSynthetic = false;
|
||||||
|
public boolean annotatedSecured = false;
|
||||||
|
public boolean hasStringEncryptionAnnotation = false;
|
||||||
|
public boolean hasSecuredMethod = false;
|
||||||
|
public boolean hasSecuredField = false;
|
||||||
|
public boolean hasInsecureMethod = false;
|
||||||
|
public boolean hasInsecureAnnotation = false;
|
||||||
|
public boolean hasHideAccessTargets = false;
|
||||||
|
public boolean unusedFlag = false;
|
||||||
|
public boolean hasCorruptedFrames = false;
|
||||||
|
public boolean usesResourceBundle = false;
|
||||||
|
public boolean usesResourceStreams = false;
|
||||||
|
public boolean usesGetResourceUrl = false;
|
||||||
|
public int classFileVersion = 49;
|
||||||
|
public List<ClassMemberInfo> referencedMethods;
|
||||||
|
public boolean isGeneratedClass = false;
|
||||||
|
public boolean hideAccessEnabled = false;
|
||||||
|
public boolean stringEncryptionEnabled = false;
|
||||||
|
public boolean moveStringFields = false;
|
||||||
|
public boolean canHostDecoder = true;
|
||||||
|
public boolean annotatedInsecure = false;
|
||||||
|
public boolean inInjectList = false;
|
||||||
|
public HashMap<String, Object> extraMetadata = new HashMap<>();
|
||||||
|
public boolean isDecoderHost = false;
|
||||||
|
public ClassInfo parentClassInfo;
|
||||||
|
public int reservedIndex = 0;
|
||||||
|
public HashMap<String, Object> extraAttributes;
|
||||||
|
public HashMap<String, Boolean> hideAccessTrimFlags = new HashMap<>();
|
||||||
|
public HashMap<String, Boolean> hideAccessMethodFlags = new HashMap<>();
|
||||||
|
public int nextMemberReferenceIndex;
|
||||||
|
public HashMap<String, MemberInfo> hiddenMembers;
|
||||||
|
public int nextClassReferenceIndex = 0;
|
||||||
|
public Map<String, Integer> hiddenClassIndices;
|
||||||
|
public boolean hasExplicitStringEncryptionAnnotation = false;
|
||||||
|
public boolean isModuleInfo = false;
|
||||||
|
|
||||||
|
public ClassInfo(String name) {
|
||||||
|
this.name = name;
|
||||||
|
this.stringFieldInitialValues = new HashMap<>();
|
||||||
|
this.securedStringFields = new HashMap<>();
|
||||||
|
this.stringLiterals = new HashSet<>();
|
||||||
|
this.excludedStrings = new HashSet<>();
|
||||||
|
this.declaredMethods = new ArrayList<>();
|
||||||
|
this.declaredFields = new ArrayList<>();
|
||||||
|
this.inheritedMethods = new ArrayList<>();
|
||||||
|
this.inheritedFields = new ArrayList<>();
|
||||||
|
this.referencedTypes = new ArrayList<>();
|
||||||
|
this.referencedMethods = new ArrayList<>();
|
||||||
|
this.superName = "java/lang/Object";
|
||||||
|
this.extraAttributes = new HashMap<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.licel.stringer.model;
|
||||||
|
|
||||||
|
public class ClassMemberInfo {
|
||||||
|
public int access;
|
||||||
|
public String name;
|
||||||
|
public String descriptor;
|
||||||
|
public String owner;
|
||||||
|
|
||||||
|
public ClassMemberInfo(int access, String owner, String name, String descriptor) {
|
||||||
|
this.access = access;
|
||||||
|
this.name = name;
|
||||||
|
this.descriptor = descriptor;
|
||||||
|
this.owner = owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ClassMemberInfo(int access, String name, String descriptor) {
|
||||||
|
this(access, null, name, descriptor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package com.licel.stringer.model;
|
||||||
|
|
||||||
|
public class FieldInfo {
|
||||||
|
public String name;
|
||||||
|
public String descriptor;
|
||||||
|
public String owner;
|
||||||
|
|
||||||
|
public FieldInfo() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public FieldInfo(String owner, String name, String descriptor) {
|
||||||
|
this.name = name;
|
||||||
|
this.descriptor = descriptor;
|
||||||
|
this.owner = owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object other) {
|
||||||
|
if (this == other) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (other != null && this.getClass() == other.getClass()) {
|
||||||
|
FieldInfo that = (FieldInfo) other;
|
||||||
|
if (!this.descriptor.equals(that.descriptor)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return this.name.equals(that.name) && this.owner.equals(that.owner);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result = this.name.hashCode();
|
||||||
|
result = 31 * result + this.descriptor.hashCode();
|
||||||
|
return 31 * result + this.owner.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "FieldInfo{name='" + this.name + '\'' + ", desc='" + this.descriptor + '\'' + ", owner='" + this.owner + '\'' + '}';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.licel.stringer.model;
|
||||||
|
|
||||||
|
public class Job {
|
||||||
|
public static final int TRANSFORM_CLASS = 0;
|
||||||
|
public static final int COPY_ENTRY = 1;
|
||||||
|
public static final int ENCRYPT_RESOURCE = 2;
|
||||||
|
public static final int REMOVE_ENTRY = 3;
|
||||||
|
public static final int COMPILE_BUNDLE = 4;
|
||||||
|
public static final int PATCH_MANIFEST = 5;
|
||||||
|
public static final int TRANSFORM_WEB_XML = 6;
|
||||||
|
|
||||||
|
public int type;
|
||||||
|
public Object payload;
|
||||||
|
|
||||||
|
public Job(int type, Object payload) {
|
||||||
|
this.type = type;
|
||||||
|
this.payload = payload;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
package com.licel.stringer.model;
|
||||||
|
|
||||||
|
import java.util.Formatter;
|
||||||
|
import org.objectweb.asm.Opcodes;
|
||||||
|
|
||||||
|
public class MemberInfo {
|
||||||
|
public static final int KIND_INVOKESTATIC = 0;
|
||||||
|
public static final int KIND_INVOKESPECIAL = 1;
|
||||||
|
public static final int KIND_INVOKEVIRTUAL = 2;
|
||||||
|
public static final int KIND_NEW = 3;
|
||||||
|
public static final int KIND_GETFIELD = 4;
|
||||||
|
public static final int KIND_PUTFIELD = 5;
|
||||||
|
public static final int KIND_GETSTATIC = 6;
|
||||||
|
public static final int KIND_PUTSTATIC = 7;
|
||||||
|
|
||||||
|
private int referenceIndex;
|
||||||
|
private int accessKind;
|
||||||
|
public int ownerClassIndex;
|
||||||
|
public String name;
|
||||||
|
public String descriptor;
|
||||||
|
public String owner;
|
||||||
|
public int encodedId;
|
||||||
|
public int referenceMask;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return this.referenceIndex + " => " + (this.accessKind < 4 ? "method " : "field ") + this.owner + "->" + this.name + ":" + this.descriptor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getEncodedReference() {
|
||||||
|
return this.referenceMask << 16 | this.referenceIndex ^ this.referenceMask & 65535;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getReferenceIndex() {
|
||||||
|
return this.referenceIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReferenceIndex(int index) {
|
||||||
|
if (index >= 0 && index <= 65535) {
|
||||||
|
this.referenceIndex = index;
|
||||||
|
} else {
|
||||||
|
Formatter formatter = new Formatter();
|
||||||
|
throw new RuntimeException(
|
||||||
|
formatter.format(
|
||||||
|
"The number of method references is more than 65536 that exceeds the limitation for Hide Access.%n Please adjust your Hide Access filter by excluding insensitive classes."
|
||||||
|
).toString()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReferenceMask(int mask) {
|
||||||
|
if (mask >= 0 && mask <= 65535) {
|
||||||
|
this.referenceMask = mask;
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException("" + mask);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAccessKind() {
|
||||||
|
return this.accessKind;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAccessKindFromOpcode(int opcode) {
|
||||||
|
switch (opcode) {
|
||||||
|
case Opcodes.GETSTATIC:
|
||||||
|
this.accessKind = KIND_GETSTATIC;
|
||||||
|
break;
|
||||||
|
case Opcodes.PUTSTATIC:
|
||||||
|
this.accessKind = KIND_PUTSTATIC;
|
||||||
|
break;
|
||||||
|
case Opcodes.GETFIELD:
|
||||||
|
this.accessKind = KIND_GETFIELD;
|
||||||
|
break;
|
||||||
|
case Opcodes.PUTFIELD:
|
||||||
|
this.accessKind = KIND_PUTFIELD;
|
||||||
|
break;
|
||||||
|
case Opcodes.INVOKEVIRTUAL:
|
||||||
|
case Opcodes.INVOKEINTERFACE:
|
||||||
|
this.accessKind = KIND_INVOKEVIRTUAL;
|
||||||
|
break;
|
||||||
|
case Opcodes.INVOKESPECIAL:
|
||||||
|
this.accessKind = KIND_INVOKESPECIAL;
|
||||||
|
break;
|
||||||
|
case Opcodes.INVOKESTATIC:
|
||||||
|
this.accessKind = KIND_INVOKESTATIC;
|
||||||
|
break;
|
||||||
|
case Opcodes.NEW:
|
||||||
|
this.accessKind = KIND_NEW;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new RuntimeException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package com.licel.stringer.model;
|
||||||
|
|
||||||
|
import java.util.Comparator;
|
||||||
|
|
||||||
|
public class MemberInfoComparator implements Comparator<MemberInfo> {
|
||||||
|
@Override
|
||||||
|
public int compare(MemberInfo first, MemberInfo second) {
|
||||||
|
return first.getReferenceIndex() - second.getReferenceIndex();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
package com.licel.stringer.model;
|
||||||
|
|
||||||
|
public class MethodInfo {
|
||||||
|
public String owner;
|
||||||
|
public String name;
|
||||||
|
public String descriptor;
|
||||||
|
public String proxyOwner;
|
||||||
|
public String proxyName;
|
||||||
|
public String proxyDescriptor;
|
||||||
|
public boolean isStatic;
|
||||||
|
public boolean isInterface;
|
||||||
|
public boolean isConstructor;
|
||||||
|
public String targetName;
|
||||||
|
public int opcode;
|
||||||
|
|
||||||
|
public MethodInfo() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public MethodInfo(String owner, String name, String descriptor) {
|
||||||
|
this.name = name;
|
||||||
|
this.descriptor = descriptor;
|
||||||
|
this.owner = owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MethodInfo(
|
||||||
|
boolean isConstructor,
|
||||||
|
boolean isStatic,
|
||||||
|
String proxyOwner,
|
||||||
|
String proxyName,
|
||||||
|
String proxyDescriptor,
|
||||||
|
String name,
|
||||||
|
String descriptor,
|
||||||
|
boolean isInterface) {
|
||||||
|
this.isStatic = isStatic;
|
||||||
|
this.proxyOwner = proxyOwner;
|
||||||
|
this.proxyName = proxyName;
|
||||||
|
this.name = name;
|
||||||
|
this.descriptor = descriptor;
|
||||||
|
this.proxyDescriptor = proxyDescriptor;
|
||||||
|
this.isInterface = isInterface;
|
||||||
|
this.isConstructor = isConstructor;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object other) {
|
||||||
|
if (this == other) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (other != null && this.getClass() == other.getClass()) {
|
||||||
|
MethodInfo that = (MethodInfo) other;
|
||||||
|
if (!this.descriptor.equals(that.descriptor)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return this.name.equals(that.name) && this.owner.equals(that.owner);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result = this.name.hashCode();
|
||||||
|
result = 31 * result + this.descriptor.hashCode();
|
||||||
|
return 31 * result + this.owner.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "MethodInfo{owner='" + this.owner + '\'' + ", name='" + this.name + '\'' + ", desc='" + this.descriptor + '\'' + '}';
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.licel.stringer.model;
|
||||||
|
|
||||||
|
public class MovedFieldInfo {
|
||||||
|
public int access;
|
||||||
|
public String name;
|
||||||
|
public String descriptor;
|
||||||
|
public String initialValue;
|
||||||
|
|
||||||
|
public MovedFieldInfo(int access, String name, String descriptor, String signature, String initialValue) {
|
||||||
|
this.access = access;
|
||||||
|
this.name = name;
|
||||||
|
this.descriptor = descriptor;
|
||||||
|
this.initialValue = initialValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.licel.stringer.model;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class OperandStackModel extends ArrayList<StackValue> {
|
||||||
|
public OperandStackModel() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void pop() {
|
||||||
|
this.remove(this.size() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void replaceTop(StackValue value) {
|
||||||
|
this.set(this.size() - 1, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,288 @@
|
|||||||
|
package com.licel.stringer.model;
|
||||||
|
|
||||||
|
import com.licel.stringer.Config;
|
||||||
|
import com.licel.stringer.Worker;
|
||||||
|
import com.licel.stringer.crypto.CryptoContainer;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import org.objectweb.asm.Type;
|
||||||
|
|
||||||
|
public class PackageProtectionInfo {
|
||||||
|
private final String packagePath;
|
||||||
|
private final HashMap<String, ClassInfo> classes;
|
||||||
|
private int protectedClassCount;
|
||||||
|
private final HashMap<String, ResourceBundleInfo> resourceBundles;
|
||||||
|
private long totalStringCount;
|
||||||
|
private boolean noProtectedClasses = true;
|
||||||
|
private boolean hasInjectCandidates = false;
|
||||||
|
private boolean allInterfaces = true;
|
||||||
|
private CryptoContainer[] cryptoContainers;
|
||||||
|
|
||||||
|
public PackageProtectionInfo(String packagePath) {
|
||||||
|
this.packagePath = packagePath;
|
||||||
|
this.classes = new HashMap<>();
|
||||||
|
this.protectedClassCount = 0;
|
||||||
|
this.resourceBundles = new HashMap<>();
|
||||||
|
this.totalStringCount = 0L;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPackagePath() {
|
||||||
|
return this.packagePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashMap<String, ClassInfo> getClasses() {
|
||||||
|
return this.classes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashMap<String, ResourceBundleInfo> getResourceBundles() {
|
||||||
|
return this.resourceBundles;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getProtectedClassCount() {
|
||||||
|
return this.protectedClassCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public CryptoContainer[] getCryptoContainers() {
|
||||||
|
return this.cryptoContainers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCryptoContainers(CryptoContainer[] cryptoContainers) {
|
||||||
|
this.cryptoContainers = cryptoContainers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addClass(ClassInfo classInfo) {
|
||||||
|
this.classes.put(classInfo.name, classInfo);
|
||||||
|
this.totalStringCount += classInfo.stringLiterals.size() + classInfo.stringFieldInitialValues.values().size();
|
||||||
|
if (classInfo.inInjectList) {
|
||||||
|
this.hasInjectCandidates = true;
|
||||||
|
}
|
||||||
|
if (!classInfo.isInterface) {
|
||||||
|
this.allInterfaces = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addResourceBundle(ResourceBundleInfo bundleInfo) {
|
||||||
|
this.resourceBundles.put(bundleInfo.name, bundleInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getTotalStringCount() {
|
||||||
|
return this.totalStringCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int countNonGeneratedClasses() {
|
||||||
|
int count = 0;
|
||||||
|
for (ClassInfo info : this.classes.values()) {
|
||||||
|
if (!info.isGeneratedClass) {
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<String> getDecoderHostCandidates() {
|
||||||
|
ArrayList<String> candidates = new ArrayList<>();
|
||||||
|
for (String className : this.classes.keySet()) {
|
||||||
|
ClassInfo info = this.classes.get(className);
|
||||||
|
if (className.indexOf('$') < 0
|
||||||
|
&& !info.hasNativeMethods
|
||||||
|
&& !info.isInterface
|
||||||
|
&& !info.isSynthetic
|
||||||
|
&& !className.endsWith("/R")
|
||||||
|
&& !className.endsWith("/BuildConfig")
|
||||||
|
&& !className.endsWith("/Manifest")
|
||||||
|
&& this.hasSafeStaticInit(info)
|
||||||
|
&& !info.isDecoderHost
|
||||||
|
&& !info.isGeneratedClass
|
||||||
|
&& info.canHostDecoder
|
||||||
|
&& !className.endsWith("package-info")) {
|
||||||
|
if (this.hasInjectCandidates) {
|
||||||
|
if (info.inInjectList) {
|
||||||
|
candidates.add(className);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
candidates.add(className);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return candidates;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean hasSafeStaticInit(ClassInfo classInfo) {
|
||||||
|
if (!classInfo.hasStaticInitializer) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < classInfo.referencedTypes.size(); i++) {
|
||||||
|
String typeName = classInfo.referencedTypes.get(i);
|
||||||
|
while (typeName.startsWith("[")) {
|
||||||
|
typeName = typeName.substring(1);
|
||||||
|
}
|
||||||
|
if (typeName.startsWith("L")) {
|
||||||
|
typeName = typeName.substring(1);
|
||||||
|
}
|
||||||
|
if (typeName.endsWith(";")) {
|
||||||
|
typeName = typeName.substring(0, typeName.length() - 1);
|
||||||
|
}
|
||||||
|
ClassInfo referenced = this.classes.get(typeName);
|
||||||
|
if (referenced != null
|
||||||
|
&& !referenced.name.equals(classInfo.name)
|
||||||
|
&& referenced.stringLiterals.size() + referenced.stringFieldInitialValues.values().size() > 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<ClassMemberInfo> getMethodNameCandidates(String excludeClassName) {
|
||||||
|
ArrayList<ClassMemberInfo> result = new ArrayList<>();
|
||||||
|
for (String className : this.classes.keySet()) {
|
||||||
|
if (!className.equalsIgnoreCase(excludeClassName)) {
|
||||||
|
ClassInfo info = this.classes.get(className);
|
||||||
|
for (ClassMemberInfo member : info.declaredMethods) {
|
||||||
|
if (member.name.indexOf('<') < 0) {
|
||||||
|
result.add(member);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<ClassMemberInfo> getFieldNameCandidates(String excludeClassName) {
|
||||||
|
ArrayList<ClassMemberInfo> result = new ArrayList<>();
|
||||||
|
for (String className : this.classes.keySet()) {
|
||||||
|
if (!className.equalsIgnoreCase(excludeClassName)) {
|
||||||
|
ClassInfo info = this.classes.get(className);
|
||||||
|
for (ClassMemberInfo member : info.declaredFields) {
|
||||||
|
if (member.name.indexOf('$') < 0 && !member.name.equalsIgnoreCase("serialVersionUID")) {
|
||||||
|
result.add(member);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int computeWeight() {
|
||||||
|
int depth = this.packagePath.split("\\/").length - 1;
|
||||||
|
return depth * 3 + this.classes.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void evaluateProtection(Config config, ProtectionRegistry registry) {
|
||||||
|
for (ClassInfo classInfo : this.classes.values()) {
|
||||||
|
classInfo.hideAccessEnabled = this.shouldApplyHideAccess(config, registry, classInfo);
|
||||||
|
classInfo.stringEncryptionEnabled = this.shouldApplyStringEncryption(config, registry, classInfo);
|
||||||
|
classInfo.moveStringFields = this.shouldMoveStringFields(registry, classInfo);
|
||||||
|
if (classInfo.isModuleInfo) {
|
||||||
|
classInfo.canHostDecoder = false;
|
||||||
|
this.noProtectedClasses = true;
|
||||||
|
} else {
|
||||||
|
this.resolveHierarchy(classInfo, registry);
|
||||||
|
if (classInfo.isInterface || classInfo.isEnum) {
|
||||||
|
classInfo.canHostDecoder = false;
|
||||||
|
}
|
||||||
|
if (classInfo.annotatedInsecure) {
|
||||||
|
classInfo.canHostDecoder = false;
|
||||||
|
}
|
||||||
|
if (classInfo.hideAccessEnabled || classInfo.stringEncryptionEnabled) {
|
||||||
|
this.protectedClassCount++;
|
||||||
|
this.noProtectedClasses = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void resolveHierarchy(ClassInfo classInfo, ProtectionRegistry registry) {
|
||||||
|
HashMap<String, ClassInfo> jdkCache = Worker.get().jdkClassCache;
|
||||||
|
ClassInfo current = classInfo;
|
||||||
|
|
||||||
|
while (!"java/lang/Object".equals(current.superName)) {
|
||||||
|
if (current.superName == null) {
|
||||||
|
classInfo.canHostDecoder = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (registry.classes.containsKey(current.superName)) {
|
||||||
|
current = registry.classes.get(current.superName);
|
||||||
|
} else if (jdkCache.containsKey(current.superName)) {
|
||||||
|
current = jdkCache.get(current.superName);
|
||||||
|
} else if (!current.name.startsWith("java/") && !current.name.startsWith("javax/")) {
|
||||||
|
current = null;
|
||||||
|
} else {
|
||||||
|
if (current.name.startsWith("java/lang/annotation/Annotation")) {
|
||||||
|
classInfo.canHostDecoder = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
current = this.loadJdkClassInfo(current.superName);
|
||||||
|
if (current != null) {
|
||||||
|
jdkCache.put(current.name, current);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (current == null) {
|
||||||
|
classInfo.canHostDecoder = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
classInfo.inheritedFields.addAll(current.declaredFields);
|
||||||
|
classInfo.inheritedMethods.addAll(current.declaredMethods);
|
||||||
|
}
|
||||||
|
|
||||||
|
ClassInfo loadJdkClassInfo(String internalName) {
|
||||||
|
ClassInfo info = new ClassInfo(internalName);
|
||||||
|
try {
|
||||||
|
Class<?> clazz = Class.forName(internalName.replace("/", "."));
|
||||||
|
info.superName = Type.getType(clazz.getSuperclass()).getInternalName();
|
||||||
|
|
||||||
|
for (Method method : clazz.getDeclaredMethods()) {
|
||||||
|
Type methodType = Type.getType(method);
|
||||||
|
info.declaredMethods.add(new ClassMemberInfo(0, internalName, method.getName(), methodType.getDescriptor()));
|
||||||
|
}
|
||||||
|
for (Field field : clazz.getDeclaredFields()) {
|
||||||
|
Type fieldType = Type.getType(field.getType());
|
||||||
|
info.declaredFields.add(new ClassMemberInfo(0, internalName, field.getName(), fieldType.getDescriptor()));
|
||||||
|
}
|
||||||
|
return info;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSkipped() {
|
||||||
|
return this.noProtectedClasses || this.allInterfaces;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean shouldMoveStringFields(ProtectionRegistry registry, ClassInfo classInfo) {
|
||||||
|
if (classInfo.annotatedInsecure) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return classInfo.hasSecuredField || !classInfo.stringFieldInitialValues.isEmpty();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean shouldApplyHideAccess(Config config, ProtectionRegistry registry, ClassInfo classInfo) {
|
||||||
|
if (!config.getHideAccess().isEnabled()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
boolean matched = false;
|
||||||
|
if (config.getHideAccess().isAnnotations()) {
|
||||||
|
if (registry.hasHideAccessTargets) {
|
||||||
|
matched = classInfo.hasHideAccessTargets;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
matched = classInfo.hasHideAccessTargets;
|
||||||
|
}
|
||||||
|
return matched && !classInfo.referencedMethods.isEmpty() && !classInfo.isInterface;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean shouldApplyStringEncryption(Config config, ProtectionRegistry registry, ClassInfo classInfo) {
|
||||||
|
if (!config.getStringEncryption().isEnabled()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (config.getStringEncryption().isAnnotations()) {
|
||||||
|
return classInfo.hasStringEncryptionAnnotation;
|
||||||
|
}
|
||||||
|
return config.getStringEncryption().match(classInfo)
|
||||||
|
&& classInfo.stringLiterals.size() + classInfo.stringFieldInitialValues.values().size() > 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
package com.licel.stringer.model;
|
||||||
|
|
||||||
|
import com.licel.stringer.Worker;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class ProtectionRegistry {
|
||||||
|
public HashMap<String, PackageProtectionInfo> packages;
|
||||||
|
public HashMap<String, ClassInfo> classes;
|
||||||
|
public boolean javaFxApplication = false;
|
||||||
|
public int classesWithMethodRefs = 0;
|
||||||
|
public int classesWithoutMethodRefs = 0;
|
||||||
|
public boolean usesResourceBundle = false;
|
||||||
|
public boolean usesResourceStreams = false;
|
||||||
|
public boolean usesGetResourceUrl = false;
|
||||||
|
public boolean hasStringEncryptionAnnotations = false;
|
||||||
|
public boolean hasLegacyAnnotations = false;
|
||||||
|
public boolean hasHideAccessTargets = false;
|
||||||
|
public int otherResourceCount = 0;
|
||||||
|
public int propertyBundleCount = 0;
|
||||||
|
public boolean containsSignature = false;
|
||||||
|
|
||||||
|
public ProtectionRegistry() {
|
||||||
|
this.packages = new HashMap<>();
|
||||||
|
this.classes = new HashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerClass(ClassInfo classInfo) {
|
||||||
|
if (!classInfo.isInterface) {
|
||||||
|
if (!classInfo.referencedMethods.isEmpty()) {
|
||||||
|
this.classesWithMethodRefs++;
|
||||||
|
} else {
|
||||||
|
this.classesWithoutMethodRefs++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (classInfo.usesResourceBundle) {
|
||||||
|
this.usesResourceBundle = true;
|
||||||
|
}
|
||||||
|
if (classInfo.usesResourceStreams) {
|
||||||
|
this.usesResourceStreams = true;
|
||||||
|
}
|
||||||
|
if (classInfo.usesGetResourceUrl) {
|
||||||
|
this.usesGetResourceUrl = true;
|
||||||
|
}
|
||||||
|
if (classInfo.hasHideAccessTargets) {
|
||||||
|
this.hasHideAccessTargets = true;
|
||||||
|
}
|
||||||
|
if (!classInfo.isInterface) {
|
||||||
|
if (!classInfo.referencedMethods.isEmpty()) {
|
||||||
|
this.classesWithMethodRefs++;
|
||||||
|
} else {
|
||||||
|
this.classesWithoutMethodRefs++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.classes.put(classInfo.name, classInfo);
|
||||||
|
String packagePath = classInfo.name.substring(0, classInfo.name.lastIndexOf('/') + 1);
|
||||||
|
this.getOrCreatePackage(packagePath).addClass(classInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void registerResourceBundle(ResourceBundleInfo bundleInfo) {
|
||||||
|
if (bundleInfo.resourceBundle != null) {
|
||||||
|
this.propertyBundleCount++;
|
||||||
|
} else {
|
||||||
|
this.otherResourceCount++;
|
||||||
|
}
|
||||||
|
String packagePath = bundleInfo.name.substring(0, bundleInfo.name.lastIndexOf('/') + 1);
|
||||||
|
this.getOrCreatePackage(packagePath).addResourceBundle(bundleInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PackageProtectionInfo getOrCreatePackage(String packagePath) {
|
||||||
|
if (this.packages.containsKey(packagePath)) {
|
||||||
|
return this.packages.get(packagePath);
|
||||||
|
}
|
||||||
|
PackageProtectionInfo info = new PackageProtectionInfo(packagePath);
|
||||||
|
this.packages.put(packagePath, info);
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PackageProtectionInfo selectPreferredRuntimePackage() {
|
||||||
|
PackageProtectionInfo selected = null;
|
||||||
|
for (PackageProtectionInfo candidate : this.packages.values()) {
|
||||||
|
int depth = candidate.getPackagePath().split("/").length;
|
||||||
|
if (depth >= 1
|
||||||
|
&& !candidate.getClasses().isEmpty()
|
||||||
|
&& !candidate.getClasses().containsKey(candidate.getPackagePath() + "Handler")) {
|
||||||
|
if (selected == null) {
|
||||||
|
selected = candidate;
|
||||||
|
} else {
|
||||||
|
int nonGenCount = candidate.countNonGeneratedClasses();
|
||||||
|
if (nonGenCount > 0 && candidate.computeWeight() > selected.computeWeight() + Worker.get().secureRandom.nextInt(nonGenCount)) {
|
||||||
|
selected = candidate;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return selected;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.licel.stringer.model;
|
||||||
|
|
||||||
|
import java.util.ResourceBundle;
|
||||||
|
|
||||||
|
public class ResourceBundleInfo {
|
||||||
|
public String name;
|
||||||
|
public ResourceBundle resourceBundle;
|
||||||
|
|
||||||
|
public ResourceBundleInfo(String name, ResourceBundle resourceBundle) {
|
||||||
|
this.name = name;
|
||||||
|
this.resourceBundle = resourceBundle;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package com.licel.stringer.model;
|
||||||
|
|
||||||
|
import java.security.PrivateKey;
|
||||||
|
import java.security.cert.X509Certificate;
|
||||||
|
|
||||||
|
public class SigningIdentity {
|
||||||
|
public PrivateKey privateKey;
|
||||||
|
public X509Certificate certificate;
|
||||||
|
|
||||||
|
public SigningIdentity(X509Certificate certificate, PrivateKey privateKey) {
|
||||||
|
this.certificate = certificate;
|
||||||
|
this.privateKey = privateKey;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package com.licel.stringer.model;
|
||||||
|
|
||||||
|
public class StackValue {
|
||||||
|
public static final int KIND_OTHER = 0;
|
||||||
|
public static final int KIND_FIELD_REF = 1;
|
||||||
|
public static final int KIND_METHOD_RETURN = 2;
|
||||||
|
|
||||||
|
public int kind;
|
||||||
|
public int index;
|
||||||
|
|
||||||
|
public StackValue() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public StackValue(int kind) {
|
||||||
|
this.kind = kind;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StackValue(int kind, int index) {
|
||||||
|
this.kind = kind;
|
||||||
|
this.index = index;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
package com.licel.stringer.naming;
|
||||||
|
|
||||||
|
import com.licel.stringer.model.ClassInfo;
|
||||||
|
import com.licel.stringer.model.ClassMemberInfo;
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class AlphabeticNameGenerator extends NameGenerator {
|
||||||
|
private final String alphabet = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM";
|
||||||
|
|
||||||
|
public AlphabeticNameGenerator(SecureRandom secureRandom) {
|
||||||
|
super(secureRandom);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String generateMethodName(ClassInfo classInfo, String descriptor, String prefix) {
|
||||||
|
return this.generateMethodName(classInfo, descriptor, prefix, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String generateMethodName(ClassInfo classInfo, String descriptor, String prefix, int minLength) {
|
||||||
|
ArrayList<ClassMemberInfo> usedMembers = new ArrayList<>();
|
||||||
|
usedMembers.addAll(classInfo.declaredMethods);
|
||||||
|
usedMembers.addAll(classInfo.referencedMethods);
|
||||||
|
|
||||||
|
StringBuilder name = new StringBuilder();
|
||||||
|
if (prefix != null) {
|
||||||
|
name.append(prefix.replace("<", "$").replace(">", "$")).append("_");
|
||||||
|
}
|
||||||
|
|
||||||
|
while (name.length() < minLength) {
|
||||||
|
name.append(this.alphabet.charAt(this.random.nextInt(this.alphabet.length())));
|
||||||
|
}
|
||||||
|
|
||||||
|
while (containsMember(usedMembers, name.toString(), descriptor)) {
|
||||||
|
name.append(this.alphabet.charAt(this.random.nextInt(this.alphabet.length())));
|
||||||
|
}
|
||||||
|
|
||||||
|
return name.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String generateFieldName(ClassInfo classInfo, String descriptor) {
|
||||||
|
StringBuilder name = new StringBuilder();
|
||||||
|
name.append(this.alphabet.charAt(this.random.nextInt(this.alphabet.length())));
|
||||||
|
|
||||||
|
while (containsMember(classInfo.declaredFields, name.toString(), null)) {
|
||||||
|
name.append(this.alphabet.charAt(this.random.nextInt(this.alphabet.length())));
|
||||||
|
}
|
||||||
|
|
||||||
|
return name.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMethodNameCandidates(ArrayList<ClassMemberInfo> methodNameCandidates) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setFieldNameCandidates(ArrayList<ClassMemberInfo> fieldNameCandidates) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
package com.licel.stringer.naming;
|
||||||
|
|
||||||
|
import com.licel.stringer.model.ClassInfo;
|
||||||
|
import com.licel.stringer.model.ClassMemberInfo;
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
public class ExistingNameGenerator extends NameGenerator {
|
||||||
|
private ArrayList<ClassMemberInfo> methodNameCandidates = new ArrayList<>();
|
||||||
|
private ArrayList<ClassMemberInfo> fieldNameCandidates = new ArrayList<>();
|
||||||
|
|
||||||
|
public ExistingNameGenerator(SecureRandom secureRandom) {
|
||||||
|
super(secureRandom);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String generateMethodName(ClassInfo classInfo, String descriptor, String prefix) {
|
||||||
|
ArrayList<ClassMemberInfo> existing = new ArrayList<>();
|
||||||
|
existing.addAll(classInfo.declaredMethods);
|
||||||
|
existing.addAll(classInfo.inheritedMethods);
|
||||||
|
ArrayList<ClassMemberInfo> filteredExisting = this.filterMembers(existing, "!<");
|
||||||
|
ArrayList<ClassMemberInfo> filteredCandidates = this.filterMembers(this.methodNameCandidates, "!<");
|
||||||
|
return this.selectAvailableName(descriptor, 5, filteredExisting, filteredCandidates);
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayList<ClassMemberInfo> filterMembers(ArrayList<ClassMemberInfo> members, String filterExpr) {
|
||||||
|
String[] tokens = filterExpr.split(" ");
|
||||||
|
ArrayList<ClassMemberInfo> result = new ArrayList<>();
|
||||||
|
|
||||||
|
for (int i = 0; i < members.size(); i++) {
|
||||||
|
ClassMemberInfo member = members.get(i);
|
||||||
|
boolean matched = false;
|
||||||
|
|
||||||
|
for (int j = 0; j < tokens.length; j++) {
|
||||||
|
boolean negated = tokens[j].startsWith("!");
|
||||||
|
String pattern = negated ? tokens[j].substring(1) : tokens[j];
|
||||||
|
if (!(negated & member.getName().indexOf(pattern) < 0)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
matched = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (matched) {
|
||||||
|
result.add(member);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String generateFieldName(ClassInfo classInfo, String descriptor) {
|
||||||
|
ArrayList<ClassMemberInfo> existing = new ArrayList<>();
|
||||||
|
existing.addAll(classInfo.declaredFields);
|
||||||
|
existing.addAll(classInfo.inheritedFields);
|
||||||
|
ArrayList<ClassMemberInfo> filteredExisting = this.filterMembers(existing, "!serialVersionUID");
|
||||||
|
ArrayList<ClassMemberInfo> filteredCandidates = this.filterMembers(this.fieldNameCandidates, "!serialVersionUID");
|
||||||
|
return this.selectAvailableName(descriptor, 5, filteredExisting, filteredCandidates);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setMethodNameCandidates(ArrayList<ClassMemberInfo> methodNameCandidates) {
|
||||||
|
this.methodNameCandidates = methodNameCandidates;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setFieldNameCandidates(ArrayList<ClassMemberInfo> fieldNameCandidates) {
|
||||||
|
this.fieldNameCandidates = fieldNameCandidates;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String generateMethodName(ClassInfo classInfo, String descriptor, String prefix, int minLength) {
|
||||||
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,124 @@
|
|||||||
|
package com.licel.stringer.naming;
|
||||||
|
|
||||||
|
import com.licel.stringer.model.ClassInfo;
|
||||||
|
import com.licel.stringer.model.ClassMemberInfo;
|
||||||
|
import java.security.SecureRandom;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public abstract class NameGenerator {
|
||||||
|
protected char[] characters = new char[]{
|
||||||
|
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
|
||||||
|
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'x', 'y', 'z'
|
||||||
|
};
|
||||||
|
protected SecureRandom random;
|
||||||
|
|
||||||
|
public NameGenerator(SecureRandom random) {
|
||||||
|
this.random = random;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean containsMember(List<ClassMemberInfo> members, String name, String descriptor) {
|
||||||
|
for (int i = 0; i < members.size(); i++) {
|
||||||
|
ClassMemberInfo member = members.get(i);
|
||||||
|
if (member.name.equals(name)) {
|
||||||
|
if (descriptor == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (descriptor.equals(member.descriptor)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract String generateMethodName(ClassInfo classInfo, String descriptor, String prefix);
|
||||||
|
|
||||||
|
public abstract String generateMethodName(ClassInfo classInfo, String descriptor, String prefix, int minLength);
|
||||||
|
|
||||||
|
public abstract String generateFieldName(ClassInfo classInfo, String descriptor);
|
||||||
|
|
||||||
|
public abstract void setMethodNameCandidates(ArrayList<ClassMemberInfo> methodNameCandidates);
|
||||||
|
|
||||||
|
public abstract void setFieldNameCandidates(ArrayList<ClassMemberInfo> fieldNameCandidates);
|
||||||
|
|
||||||
|
protected String selectAvailableName(
|
||||||
|
String descriptor,
|
||||||
|
int fallbackLength,
|
||||||
|
ArrayList<ClassMemberInfo> existingMembers,
|
||||||
|
ArrayList<ClassMemberInfo> candidateMembers) {
|
||||||
|
String selected = null;
|
||||||
|
if (!existingMembers.isEmpty()) {
|
||||||
|
for (int i = 0; i < existingMembers.size(); i++) {
|
||||||
|
selected = this.pickRandom(existingMembers).name;
|
||||||
|
if (!containsMember(existingMembers, selected, descriptor)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
selected = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selected == null && !candidateMembers.isEmpty()) {
|
||||||
|
for (int i = 0; i < candidateMembers.size(); i++) {
|
||||||
|
selected = this.pickRandom(candidateMembers).name;
|
||||||
|
if (!containsMember(existingMembers, selected, descriptor)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
selected = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (selected == null) {
|
||||||
|
selected = this.generateRandomIdentifier(fallbackLength);
|
||||||
|
while (containsMember(existingMembers, selected, descriptor)) {
|
||||||
|
selected = this.generateRandomIdentifier(10);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return selected;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String generateRandomIdentifier(int maxLength) {
|
||||||
|
return this.generateRandomIdentifier(maxLength, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String generateRandomIdentifier(int length, boolean exactLength) {
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
int targetLength = length;
|
||||||
|
if (!exactLength) {
|
||||||
|
targetLength = this.random.nextInt(length);
|
||||||
|
while (targetLength == 0) {
|
||||||
|
targetLength = this.random.nextInt(length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < targetLength; i++) {
|
||||||
|
builder.append(this.pickRandomChar(this.characters));
|
||||||
|
}
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private char pickRandomChar(char[] pool) {
|
||||||
|
if (pool.length == 1) {
|
||||||
|
return pool[0];
|
||||||
|
}
|
||||||
|
int index = Math.round((pool.length - 1) * this.random.nextFloat());
|
||||||
|
return pool[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> T pickRandom(List<T> list) {
|
||||||
|
if (list.size() == 1) {
|
||||||
|
return list.get(0);
|
||||||
|
}
|
||||||
|
int index = Math.round((list.size() - 1) * this.random.nextFloat());
|
||||||
|
return list.get(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> T pickRandom(T[] array) {
|
||||||
|
if (array.length == 1) {
|
||||||
|
return array[0];
|
||||||
|
}
|
||||||
|
int index = Math.round((array.length - 1) * this.random.nextFloat());
|
||||||
|
return array[index];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package com.licel.stringer.naming;
|
||||||
|
|
||||||
|
import java.util.Properties;
|
||||||
|
import org.objectweb.asm.commons.Remapper;
|
||||||
|
|
||||||
|
public class PropertiesRemapper extends Remapper {
|
||||||
|
private final Properties mappings;
|
||||||
|
|
||||||
|
public PropertiesRemapper(Properties mappings) {
|
||||||
|
this.mappings = mappings;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String mapMethodName(String owner, String name, String descriptor) {
|
||||||
|
return this.mappings.getProperty(owner + "." + name + "." + descriptor, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String map(String internalName) {
|
||||||
|
return this.mappings.getProperty(internalName, internalName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String mapFieldName(String owner, String name, String descriptor) {
|
||||||
|
return this.mappings.getProperty(owner + "." + name + "." + descriptor, name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object mapValue(Object value) {
|
||||||
|
if (value != null) {
|
||||||
|
if (value instanceof String) {
|
||||||
|
String text = (String) value;
|
||||||
|
if (this.mappings.containsKey(text)) {
|
||||||
|
return this.mappings.getProperty(text);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (value instanceof Long) {
|
||||||
|
String key = value.toString();
|
||||||
|
if (this.mappings.containsKey(key)) {
|
||||||
|
return Long.parseLong(this.mappings.getProperty(key));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return super.mapValue(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.licel.stringer.prototype;
|
||||||
|
|
||||||
|
import java.lang.invoke.ConstantCallSite;
|
||||||
|
import java.lang.invoke.MethodHandles.Lookup;
|
||||||
|
import java.lang.invoke.MethodType;
|
||||||
|
|
||||||
|
public class BootstrapMethodPrototype {
|
||||||
|
private static Object bootstrap(Object lookup, Object name, Object methodType) {
|
||||||
|
try {
|
||||||
|
return new ConstantCallSite(
|
||||||
|
((Lookup) lookup)
|
||||||
|
.unreflect(ReflectionClassPrototype.findMethod(Integer.valueOf((String) name, 32)))
|
||||||
|
.asType((MethodType) methodType)
|
||||||
|
);
|
||||||
|
} catch (ClassNotFoundException | IllegalAccessException e) {
|
||||||
|
throw new BootstrapMethodError(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package com.licel.stringer.prototype;
|
||||||
|
|
||||||
|
public class IntrinsicsPrototype {
|
||||||
|
public static final boolean equalsIntrinsics(Object left, Object right) {
|
||||||
|
return left == right || left instanceof String && right instanceof String && left.equals(right);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,165 @@
|
|||||||
|
package com.licel.stringer.prototype;
|
||||||
|
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
|
public class LruCachePrototype<K, V> {
|
||||||
|
private final LinkedHashMap<K, V> map;
|
||||||
|
private int size;
|
||||||
|
private int maxSize;
|
||||||
|
private int putCount;
|
||||||
|
private int createCount;
|
||||||
|
private int evictionCount;
|
||||||
|
private int hitCount;
|
||||||
|
private int missCount;
|
||||||
|
private static LruCachePrototype<Object, Object> lruCache = new LruCachePrototype<>(10);
|
||||||
|
|
||||||
|
public static Object getCachedValue(Object key) {
|
||||||
|
if (lruCache.get(key) != null) {
|
||||||
|
System.out.println(555);
|
||||||
|
return lruCache.get(key);
|
||||||
|
} else {
|
||||||
|
char[] chars = new char[0];
|
||||||
|
String value = new String(chars);
|
||||||
|
lruCache.put(key, value);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public LruCachePrototype(int maxSize) {
|
||||||
|
if (maxSize <= 0) {
|
||||||
|
throw new IllegalArgumentException("maxSize <= 0");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.maxSize = maxSize;
|
||||||
|
this.map = new LinkedHashMap<>(0, 0.75F, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public final synchronized V get(K key) {
|
||||||
|
if (key == null) {
|
||||||
|
throw new NullPointerException("key == null");
|
||||||
|
}
|
||||||
|
|
||||||
|
V mapValue = this.map.get(key);
|
||||||
|
if (mapValue != null) {
|
||||||
|
this.hitCount++;
|
||||||
|
return mapValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.missCount++;
|
||||||
|
mapValue = this.create(key);
|
||||||
|
if (mapValue != null) {
|
||||||
|
this.createCount++;
|
||||||
|
this.size += this.safeSizeOf(key, mapValue);
|
||||||
|
this.map.put(key, mapValue);
|
||||||
|
this.trimToSize(this.maxSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
return mapValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final synchronized void put(K key, V value) {
|
||||||
|
if (key == null || value == null) {
|
||||||
|
throw new NullPointerException("key == null || value == null");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.putCount++;
|
||||||
|
this.size += this.safeSizeOf(key, value);
|
||||||
|
V previous = this.map.put(key, value);
|
||||||
|
if (previous != null) {
|
||||||
|
this.size -= this.safeSizeOf(key, previous);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.trimToSize(this.maxSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void trimToSize(int maxSize) {
|
||||||
|
while (this.size > maxSize && !this.map.isEmpty()) {
|
||||||
|
Entry<K, V> toEvict = this.map.entrySet().iterator().next();
|
||||||
|
if (toEvict == null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
K key = toEvict.getKey();
|
||||||
|
V value = toEvict.getValue();
|
||||||
|
this.map.remove(key);
|
||||||
|
this.size -= this.safeSizeOf(key, value);
|
||||||
|
this.evictionCount++;
|
||||||
|
this.entryEvicted(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.size < 0 || this.map.isEmpty() && this.size != 0) {
|
||||||
|
throw new IllegalStateException(this.getClass().getName() + ".sizeOf() is reporting inconsistent results!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public final synchronized V remove(K key) {
|
||||||
|
if (key == null) {
|
||||||
|
throw new NullPointerException("key == null");
|
||||||
|
}
|
||||||
|
|
||||||
|
V previous = this.map.remove(key);
|
||||||
|
if (previous != null) {
|
||||||
|
this.size -= this.safeSizeOf(key, previous);
|
||||||
|
}
|
||||||
|
|
||||||
|
return previous;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void entryEvicted(K key, V value) {
|
||||||
|
}
|
||||||
|
|
||||||
|
protected V create(K key) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int safeSizeOf(K key, V value) {
|
||||||
|
int result = this.sizeOf(key, value);
|
||||||
|
if (result < 0) {
|
||||||
|
throw new IllegalStateException("Negative size: " + key + "=" + value);
|
||||||
|
} else {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected int sizeOf(K key, V value) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final synchronized void evictAll() {
|
||||||
|
this.trimToSize(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public final synchronized int size() {
|
||||||
|
return this.size;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final synchronized int maxSize() {
|
||||||
|
return this.maxSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final synchronized int hitCount() {
|
||||||
|
return this.hitCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final synchronized int missCount() {
|
||||||
|
return this.missCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final synchronized int createCount() {
|
||||||
|
return this.createCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final synchronized int putCount() {
|
||||||
|
return this.putCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final synchronized int evictionCount() {
|
||||||
|
return this.evictionCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final synchronized Map<K, V> snapshot() {
|
||||||
|
return new LinkedHashMap<>(this.map);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,278 @@
|
|||||||
|
package com.licel.stringer.prototype;
|
||||||
|
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
|
|
||||||
|
public class ReflectionClassPrototype {
|
||||||
|
private static final Object[] memberCache = new Object[123456];
|
||||||
|
private static final Class<?>[] classCache = new Class<?>[98765];
|
||||||
|
private static final int[] memberHash = new int[123456];
|
||||||
|
private static final short[] classIds = new short[123456];
|
||||||
|
private static final int keyX = Integer.parseInt("4444444");
|
||||||
|
private static final int keyA = Integer.parseInt("1111111");
|
||||||
|
|
||||||
|
private static Class<?> findClass(int memberIndex, int salt) throws ClassNotFoundException {
|
||||||
|
int classIndex = classIds[memberIndex] & 0xFFFF;
|
||||||
|
classIndex = (classIndex + salt) % 77777;
|
||||||
|
Class<?> clazz = classCache[classIndex];
|
||||||
|
if (clazz != null) {
|
||||||
|
return clazz;
|
||||||
|
}
|
||||||
|
|
||||||
|
clazz = resolveClass(classIndex);
|
||||||
|
classCache[classIndex] = clazz;
|
||||||
|
return clazz;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Class<?> resolveClass(int classIndex) throws ClassNotFoundException {
|
||||||
|
String className;
|
||||||
|
switch (classIndex) {
|
||||||
|
case 100:
|
||||||
|
className = "aaaa";
|
||||||
|
break;
|
||||||
|
case 101:
|
||||||
|
className = "bbbb";
|
||||||
|
break;
|
||||||
|
case 102:
|
||||||
|
className = "cccc";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new NoClassDefFoundError(Integer.toString(classIndex));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Class.forName(className);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Method findMethod(int encodedId) throws ClassNotFoundException {
|
||||||
|
int decoded = ((encodedId - 55555555 ^ keyX) + 33333333 ^ 22222222) - keyA;
|
||||||
|
int salt = decoded >>> 16;
|
||||||
|
int memberIndex = decoded & 65535;
|
||||||
|
Method cached = (Method) memberCache[memberIndex];
|
||||||
|
if (cached != null) {
|
||||||
|
return cached;
|
||||||
|
}
|
||||||
|
|
||||||
|
Class<?> targetClass = findClass(memberIndex, salt);
|
||||||
|
Class<?> currentClass = targetClass;
|
||||||
|
int expectedHash = memberHash[memberIndex];
|
||||||
|
|
||||||
|
while (currentClass != null) {
|
||||||
|
Method[] methods = currentClass.isInterface()
|
||||||
|
? currentClass.getMethods()
|
||||||
|
: currentClass.getDeclaredMethods();
|
||||||
|
|
||||||
|
for (Method method : methods) {
|
||||||
|
int hash = salt * 31 + method.getName().hashCode();
|
||||||
|
hash = 31 * hash + 40;
|
||||||
|
Class<?>[] parameterTypes = method.getParameterTypes();
|
||||||
|
|
||||||
|
for (int i = 0; i < parameterTypes.length; i++) {
|
||||||
|
if (i != 0) {
|
||||||
|
hash = 31 * hash + 44;
|
||||||
|
}
|
||||||
|
hash = 31 * hash + parameterTypes[i].getName().hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
hash = 31 * hash + 41;
|
||||||
|
hash = 31 * hash + method.getReturnType().getName().hashCode();
|
||||||
|
hash = 31 * hash + salt;
|
||||||
|
if (expectedHash == hash) {
|
||||||
|
method.setAccessible(true);
|
||||||
|
memberCache[memberIndex] = method;
|
||||||
|
return method;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
currentClass = currentClass.getSuperclass();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Class<?> cls = targetClass; cls != null; cls = cls.getSuperclass()) {
|
||||||
|
for (Class<?> iface : cls.getInterfaces()) {
|
||||||
|
for (Method method : iface.getMethods()) {
|
||||||
|
int hash = salt * 31 + method.getName().hashCode();
|
||||||
|
hash = 31 * hash + 40;
|
||||||
|
Class<?>[] parameterTypes = method.getParameterTypes();
|
||||||
|
|
||||||
|
for (int i = 0; i < parameterTypes.length; i++) {
|
||||||
|
if (i != 0) {
|
||||||
|
hash = 31 * hash + 44;
|
||||||
|
}
|
||||||
|
hash = 31 * hash + parameterTypes[i].getName().hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
hash = 31 * hash + 41;
|
||||||
|
hash = 31 * hash + method.getReturnType().getName().hashCode();
|
||||||
|
hash = 31 * hash + salt;
|
||||||
|
if (expectedHash == hash) {
|
||||||
|
method.setAccessible(true);
|
||||||
|
memberCache[memberIndex] = method;
|
||||||
|
return method;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object invokeStatic(int encodedId, Object[] args) throws Throwable {
|
||||||
|
try {
|
||||||
|
Method method = findMethod(encodedId);
|
||||||
|
if (method == null) {
|
||||||
|
throw new NoSuchMethodError(Integer.toString(encodedId));
|
||||||
|
}
|
||||||
|
return method.invoke(null, args);
|
||||||
|
} catch (InvocationTargetException e) {
|
||||||
|
throw e.getTargetException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object invokeVirtual(Object target, int encodedId, Object[] args) throws Throwable {
|
||||||
|
try {
|
||||||
|
Method method = findMethod(encodedId);
|
||||||
|
if (method == null) {
|
||||||
|
throw new NoSuchMethodError(Integer.toString(encodedId));
|
||||||
|
}
|
||||||
|
return method.invoke(target, args);
|
||||||
|
} catch (InvocationTargetException e) {
|
||||||
|
throw e.getTargetException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object construct(int encodedId, Object[] args) throws Throwable {
|
||||||
|
try {
|
||||||
|
int decoded = ((encodedId - 55555555 ^ keyX) + 33333333 ^ 22222222) - keyA;
|
||||||
|
int salt = decoded >>> 16;
|
||||||
|
int memberIndex = decoded & 65535;
|
||||||
|
Class<?> targetClass = findClass(memberIndex, salt);
|
||||||
|
Constructor<?> constructor = (Constructor<?>) memberCache[memberIndex];
|
||||||
|
if (constructor == null) {
|
||||||
|
int expectedHash = memberHash[memberIndex];
|
||||||
|
for (Constructor<?> candidate : targetClass.getDeclaredConstructors()) {
|
||||||
|
int hash = salt * 31 + 40;
|
||||||
|
Class<?>[] parameterTypes = candidate.getParameterTypes();
|
||||||
|
|
||||||
|
for (int i = 0; i < parameterTypes.length; i++) {
|
||||||
|
if (i != 0) {
|
||||||
|
hash = 31 * hash + 44;
|
||||||
|
}
|
||||||
|
hash = 31 * hash + parameterTypes[i].getName().hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
hash = 31 * hash + 41;
|
||||||
|
hash = 31 * hash + salt;
|
||||||
|
if (expectedHash == hash) {
|
||||||
|
candidate.setAccessible(true);
|
||||||
|
memberCache[memberIndex] = candidate;
|
||||||
|
constructor = candidate;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (constructor == null) {
|
||||||
|
throw new NoSuchMethodError(Integer.toString(memberIndex));
|
||||||
|
}
|
||||||
|
return constructor.newInstance(args);
|
||||||
|
} catch (InvocationTargetException e) {
|
||||||
|
throw e.getTargetException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Field findField(int encodedId) throws ReflectiveOperationException {
|
||||||
|
int decoded = ((encodedId - 55555555 ^ keyX) + 33333333 ^ 22222222) - keyA;
|
||||||
|
int salt = decoded >>> 16;
|
||||||
|
int memberIndex = decoded & 65535;
|
||||||
|
Class<?> targetClass = findClass(memberIndex, salt);
|
||||||
|
Class<?> currentClass = targetClass;
|
||||||
|
Field cached = (Field) memberCache[memberIndex];
|
||||||
|
if (cached != null) {
|
||||||
|
return cached;
|
||||||
|
}
|
||||||
|
|
||||||
|
int expectedHash = memberHash[memberIndex];
|
||||||
|
|
||||||
|
while (currentClass != null) {
|
||||||
|
for (Field field : currentClass.getDeclaredFields()) {
|
||||||
|
int hash = 31 * salt + field.getName().hashCode();
|
||||||
|
hash = 31 * hash + 58;
|
||||||
|
hash = 31 * hash + field.getType().getName().hashCode();
|
||||||
|
hash = 31 * hash + salt;
|
||||||
|
if (expectedHash == hash) {
|
||||||
|
field.setAccessible(true);
|
||||||
|
if (Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers())) {
|
||||||
|
Field modifiersField = Field.class.getDeclaredField("modifiers");
|
||||||
|
modifiersField.setAccessible(true);
|
||||||
|
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
|
||||||
|
}
|
||||||
|
memberCache[memberIndex] = field;
|
||||||
|
return field;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
currentClass = currentClass.getSuperclass();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Class<?> cls = targetClass; cls != null; cls = cls.getSuperclass()) {
|
||||||
|
for (Class<?> iface : cls.getInterfaces()) {
|
||||||
|
for (Field field : iface.getFields()) {
|
||||||
|
int hash = 31 * salt + field.getName().hashCode();
|
||||||
|
hash = 31 * hash + 58;
|
||||||
|
hash = 31 * hash + field.getType().getName().hashCode();
|
||||||
|
hash = 31 * hash + salt;
|
||||||
|
if (expectedHash == hash) {
|
||||||
|
field.setAccessible(true);
|
||||||
|
if (Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers())) {
|
||||||
|
Field modifiersField = Field.class.getDeclaredField("modifiers");
|
||||||
|
modifiersField.setAccessible(true);
|
||||||
|
modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
|
||||||
|
}
|
||||||
|
memberCache[memberIndex] = field;
|
||||||
|
return field;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cls = cls.getSuperclass();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object getFieldValue(Object target, int encodedId) throws ReflectiveOperationException {
|
||||||
|
Field field = findField(encodedId);
|
||||||
|
if (field == null) {
|
||||||
|
throw new NoSuchFieldError(Integer.toString(encodedId));
|
||||||
|
}
|
||||||
|
return field.get(target);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Object getStaticFieldValue(int encodedId) throws ReflectiveOperationException {
|
||||||
|
return getFieldValue(null, encodedId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setFieldValue(Object target, int encodedId, Object value) throws ReflectiveOperationException {
|
||||||
|
Field field = findField(encodedId);
|
||||||
|
if (field == null) {
|
||||||
|
throw new NoSuchFieldError(Integer.toString(encodedId));
|
||||||
|
}
|
||||||
|
field.set(target, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setStaticFieldValue(int encodedId, Object value) throws ReflectiveOperationException {
|
||||||
|
setFieldValue(null, encodedId, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
static {
|
||||||
|
memberHash[0] = 9999999;
|
||||||
|
memberHash[10] = 9999999;
|
||||||
|
memberHash[32767] = 9999999;
|
||||||
|
memberHash[65535] = 9999999;
|
||||||
|
classIds[0] = -1;
|
||||||
|
classIds[1] = 32767;
|
||||||
|
classIds[2] = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,40 @@
|
|||||||
|
package com.licel.stringer.prototype;
|
||||||
|
|
||||||
|
import java.io.FilterInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
public class StringerFilterInputStreamPrototype extends FilterInputStream {
|
||||||
|
StringerInputStreamPrototype parent;
|
||||||
|
private byte[] singleByteBuf = new byte[1];
|
||||||
|
|
||||||
|
public StringerFilterInputStreamPrototype(InputStream in, StringerInputStreamPrototype parent) {
|
||||||
|
super(in);
|
||||||
|
this.parent = parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized int read() throws IOException {
|
||||||
|
return this.read(this.singleByteBuf, 0, 1) == -1 ? -1 : this.singleByteBuf[0] & 0xFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean markSupported() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int read(byte[] b) throws IOException {
|
||||||
|
return this.read(b, 0, b.length);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int read(byte[] b, int off, int len) throws IOException {
|
||||||
|
int bytesRead = super.read(b, off, len);
|
||||||
|
if (bytesRead > 0) {
|
||||||
|
this.parent.decrypt(b, off, bytesRead);
|
||||||
|
}
|
||||||
|
|
||||||
|
return bytesRead;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.licel.stringer.prototype;
|
||||||
|
|
||||||
|
import java.util.zip.Inflater;
|
||||||
|
|
||||||
|
public class StringerInflaterPrototype extends Inflater {
|
||||||
|
StringerInputStreamPrototype parent;
|
||||||
|
|
||||||
|
public StringerInflaterPrototype(StringerInputStreamPrototype parent) {
|
||||||
|
super(false);
|
||||||
|
this.parent = parent;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setInput(byte[] b, int off, int len) {
|
||||||
|
this.parent.decrypt(b, off, len);
|
||||||
|
super.setInput(b, off, len);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,366 @@
|
|||||||
|
package com.licel.stringer.prototype;
|
||||||
|
|
||||||
|
import java.io.FilterInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.PushbackInputStream;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.zip.InflaterInputStream;
|
||||||
|
|
||||||
|
public class StringerInputStreamPrototype extends FilterInputStream {
|
||||||
|
private static Object[] storage;
|
||||||
|
int bytesCounter;
|
||||||
|
int[] cfbV;
|
||||||
|
|
||||||
|
public StringerInputStreamPrototype(InputStream in) throws IOException {
|
||||||
|
super(new PushbackInputStream(in, 4));
|
||||||
|
|
||||||
|
try {
|
||||||
|
init();
|
||||||
|
this.cfbV = new int[4];
|
||||||
|
this.bytesCounter = 0;
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] magic = (byte[]) storage[7];
|
||||||
|
byte[] header = new byte[16];
|
||||||
|
int bytesRead = this.in.read(header, 0, 4);
|
||||||
|
if (bytesRead > 0) {
|
||||||
|
if (bytesRead == 4
|
||||||
|
&& header[0] == magic[0]
|
||||||
|
&& header[1] == magic[1]
|
||||||
|
&& header[2] == magic[2]
|
||||||
|
&& header[3] == magic[3] + 1) {
|
||||||
|
this.in.read(header, 4, 12);
|
||||||
|
|
||||||
|
for (int i = 0; i < 16; i++) {
|
||||||
|
this.cfbV[i / 4] = (this.cfbV[i / 4] << 8) | (header[i] & 0xFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.in = new InflaterInputStream(this.in, new StringerInflaterPrototype(this));
|
||||||
|
} else if (bytesRead == 4
|
||||||
|
&& header[0] == magic[0]
|
||||||
|
&& header[1] == magic[1]
|
||||||
|
&& header[2] == magic[2]
|
||||||
|
&& header[3] == magic[3]) {
|
||||||
|
this.in.read(header, 4, 12);
|
||||||
|
|
||||||
|
for (int i = 0; i < 16; i++) {
|
||||||
|
this.cfbV[i / 4] = (this.cfbV[i / 4] << 8) | (header[i] & 0xFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.in = new StringerFilterInputStreamPrototype(this.in, this);
|
||||||
|
} else {
|
||||||
|
((PushbackInputStream) this.in).unread(header, 0, 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static InputStream openStream(URL url) throws IOException {
|
||||||
|
return url.getProtocol().startsWith("jar")
|
||||||
|
? new StringerInputStreamPrototype(url.openStream())
|
||||||
|
: url.openStream();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final void init() {
|
||||||
|
int[] gfExp = new int[256];
|
||||||
|
byte[] sbox = new byte[256];
|
||||||
|
int[] te0 = new int[256];
|
||||||
|
int[] te1 = new int[256];
|
||||||
|
int[] te2 = new int[256];
|
||||||
|
int[] te3 = new int[256];
|
||||||
|
int[] rcon = new int[30];
|
||||||
|
|
||||||
|
try {
|
||||||
|
int val = 1;
|
||||||
|
for (int i = 0; i < 256; i++) {
|
||||||
|
gfExp[i] = val;
|
||||||
|
val ^= (val << 1) ^ ((val >>> 7) * 283);
|
||||||
|
}
|
||||||
|
|
||||||
|
sbox[0] = 99;
|
||||||
|
|
||||||
|
for (int i = 0; i < 255; i++) {
|
||||||
|
int x = gfExp[255 - i];
|
||||||
|
x |= x << 8;
|
||||||
|
x ^= (x >> 4) ^ (x >> 5) ^ (x >> 6) ^ (x >> 7);
|
||||||
|
sbox[gfExp[i]] = (byte) (x ^ 99);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < 256; i++) {
|
||||||
|
int s = sbox[i] & 0xFF;
|
||||||
|
int s2 = (s << 1) ^ ((s >>> 7) * 283);
|
||||||
|
int t = ((s ^ s2) << 24) ^ (s << 16) ^ (s << 8) ^ s2;
|
||||||
|
t &= -1;
|
||||||
|
te0[i] = t;
|
||||||
|
te1[i] = (t << 8) | (t >>> -8);
|
||||||
|
te2[i] = (t << 16) | (t >>> -16);
|
||||||
|
te3[i] = (t << 24) | (t >>> -24);
|
||||||
|
}
|
||||||
|
|
||||||
|
val = 1;
|
||||||
|
for (int i = 0; i < 30; i++) {
|
||||||
|
rcon[i] = val;
|
||||||
|
val = (val << 1) ^ ((val >>> 7) * 283);
|
||||||
|
}
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] keyBytes = null;
|
||||||
|
|
||||||
|
try {
|
||||||
|
long keyHigh = Long.parseLong("123456789") ^ (((Long.MAX_VALUE - System.currentTimeMillis()) >> 63) & 1L);
|
||||||
|
long keyLow = Long.parseLong("987654321");
|
||||||
|
keyBytes = new byte[16];
|
||||||
|
|
||||||
|
for (int i = 0; i < keyBytes.length; i++) {
|
||||||
|
keyBytes[i] = (byte) (((i > 7 ? keyLow : keyHigh) >> (8 * (7 - i % 8))) & 255L);
|
||||||
|
}
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
|
||||||
|
int nk = keyBytes.length / 4;
|
||||||
|
int rounds = nk + 6;
|
||||||
|
int[][] roundKeys = new int[rounds + 1][4];
|
||||||
|
int wordIndex = 0;
|
||||||
|
|
||||||
|
for (int byteOffset = 0; byteOffset < keyBytes.length; wordIndex++) {
|
||||||
|
roundKeys[wordIndex >> 2][wordIndex & 3] = (keyBytes[byteOffset] & 0xFF)
|
||||||
|
| (keyBytes[byteOffset + 1] & 0xFF) << 8
|
||||||
|
| (keyBytes[byteOffset + 2] & 0xFF) << 16
|
||||||
|
| keyBytes[byteOffset + 3] << 24;
|
||||||
|
byteOffset += 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
int totalWords = (rounds + 1) << 2;
|
||||||
|
|
||||||
|
for (int i = nk; i < totalWords; i++) {
|
||||||
|
int temp = roundKeys[(i - 1) >> 2][(i - 1) & 3];
|
||||||
|
if (i % nk == 0) {
|
||||||
|
temp = subWord(sbox, shift(temp, 8)) ^ rcon[i / nk - 1];
|
||||||
|
} else if (nk > 6 && i % nk == 4) {
|
||||||
|
temp = subWord(sbox, temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
roundKeys[i >> 2][i & 3] = roundKeys[(i - nk) >> 2][(i - nk) & 3] ^ temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
byte[] magic = new byte[4];
|
||||||
|
|
||||||
|
try {
|
||||||
|
int magicInt = Integer.parseInt("999999999");
|
||||||
|
|
||||||
|
for (int i = 0; i < magic.length; i++) {
|
||||||
|
magic[i] = (byte) ((magicInt >> (8 * (3 - i % 8))) & 0xFF);
|
||||||
|
}
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
|
||||||
|
int[] iv = new int[]{
|
||||||
|
Integer.parseInt("1"),
|
||||||
|
Integer.parseInt("2"),
|
||||||
|
Integer.parseInt("3"),
|
||||||
|
Integer.parseInt("4")
|
||||||
|
};
|
||||||
|
storage = new Object[]{sbox, te0, te1, te2, te3, roundKeys, iv, magic};
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int shift(int value, int bits) {
|
||||||
|
return value >>> bits | value << -bits;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int subWord(byte[] sbox, int word) {
|
||||||
|
int result = sbox[14] << 16;
|
||||||
|
|
||||||
|
try {
|
||||||
|
result = (sbox[word & 0xFF] & 0xFF)
|
||||||
|
| (sbox[(word >> 8) & 0xFF] & 0xFF) << 8
|
||||||
|
| (sbox[(word >> 16) & 0xFF] & 0xFF) << 16
|
||||||
|
| sbox[(word >> 24) & 0xFF] << 24;
|
||||||
|
} catch (Exception e) {
|
||||||
|
try {
|
||||||
|
result = sbox[word & 127] >> 8;
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
final void decrypt(byte[] buf, int off, int len) {
|
||||||
|
int[][] roundKeys = (int[][]) storage[5];
|
||||||
|
int[] te0 = (int[]) storage[1];
|
||||||
|
int[] te1 = (int[]) storage[2];
|
||||||
|
int[] te2 = (int[]) storage[3];
|
||||||
|
int[] te3 = (int[]) storage[4];
|
||||||
|
byte[] sbox = (byte[]) storage[0];
|
||||||
|
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
int wordIndex = this.bytesCounter % 16 / 4;
|
||||||
|
int byteIndex = this.bytesCounter % 16 % 4;
|
||||||
|
if (this.bytesCounter % 16 == 0) {
|
||||||
|
try {
|
||||||
|
this.cfbV[0] ^= roundKeys[0][0];
|
||||||
|
this.cfbV[1] ^= roundKeys[0][1];
|
||||||
|
this.cfbV[2] ^= roundKeys[0][2];
|
||||||
|
this.cfbV[3] ^= roundKeys[0][3];
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
|
||||||
|
int round = 1;
|
||||||
|
|
||||||
|
while (round < roundKeys.length - 2) {
|
||||||
|
int t0 = te0[this.cfbV[0] & 0xFF]
|
||||||
|
^ te1[(this.cfbV[1] >> 8) & 0xFF]
|
||||||
|
^ te2[(this.cfbV[2] >> 16) & 0xFF]
|
||||||
|
^ te3[(this.cfbV[3] >> 24) & 0xFF]
|
||||||
|
^ roundKeys[round][0];
|
||||||
|
int t1 = te0[this.cfbV[1] & 0xFF]
|
||||||
|
^ te1[(this.cfbV[2] >> 8) & 0xFF]
|
||||||
|
^ te2[(this.cfbV[3] >> 16) & 0xFF]
|
||||||
|
^ te3[(this.cfbV[0] >> 24) & 0xFF]
|
||||||
|
^ roundKeys[round][1];
|
||||||
|
int t2 = te0[this.cfbV[2] & 0xFF]
|
||||||
|
^ te1[(this.cfbV[3] >> 8) & 0xFF]
|
||||||
|
^ te2[(this.cfbV[0] >> 16) & 0xFF]
|
||||||
|
^ te3[(this.cfbV[1] >> 24) & 0xFF]
|
||||||
|
^ roundKeys[round][2];
|
||||||
|
int t3 = te0[this.cfbV[3] & 0xFF]
|
||||||
|
^ te1[(this.cfbV[0] >> 8) & 0xFF]
|
||||||
|
^ te2[(this.cfbV[1] >> 16) & 0xFF]
|
||||||
|
^ te3[(this.cfbV[2] >> 24) & 0xFF]
|
||||||
|
^ roundKeys[round++][3];
|
||||||
|
this.cfbV[0] = te0[t0 & 0xFF] ^ te1[(t1 >> 8) & 0xFF] ^ te2[(t2 >> 16) & 0xFF] ^ te3[(t3 >> 24) & 0xFF] ^ roundKeys[round][0];
|
||||||
|
this.cfbV[1] = te0[t1 & 0xFF] ^ te1[(t2 >> 8) & 0xFF] ^ te2[(t3 >> 16) & 0xFF] ^ te3[(t0 >> 24) & 0xFF] ^ roundKeys[round][1];
|
||||||
|
this.cfbV[2] = te0[t2 & 0xFF] ^ te1[(t3 >> 8) & 0xFF] ^ te2[(t0 >> 16) & 0xFF] ^ te3[(t1 >> 24) & 0xFF] ^ roundKeys[round][2];
|
||||||
|
this.cfbV[3] = te0[t3 & 0xFF] ^ te1[(t0 >> 8) & 0xFF] ^ te2[(t1 >> 16) & 0xFF] ^ te3[(t2 >> 24) & 0xFF] ^ roundKeys[round++][3];
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
int t0 = te0[this.cfbV[0] & 0xFF]
|
||||||
|
^ te1[(this.cfbV[1] >> 8) & 0xFF]
|
||||||
|
^ te2[(this.cfbV[2] >> 16) & 0xFF]
|
||||||
|
^ te3[(this.cfbV[3] >> 24) & 0xFF]
|
||||||
|
^ roundKeys[round][0];
|
||||||
|
int t1 = te0[this.cfbV[1] & 0xFF]
|
||||||
|
^ te1[(this.cfbV[2] >> 8) & 0xFF]
|
||||||
|
^ te2[(this.cfbV[3] >> 16) & 0xFF]
|
||||||
|
^ te3[(this.cfbV[0] >> 24) & 0xFF]
|
||||||
|
^ roundKeys[round][1];
|
||||||
|
int t2 = te0[this.cfbV[2] & 0xFF]
|
||||||
|
^ te1[(this.cfbV[3] >> 8) & 0xFF]
|
||||||
|
^ te2[(this.cfbV[0] >> 16) & 0xFF]
|
||||||
|
^ te3[(this.cfbV[1] >> 24) & 0xFF]
|
||||||
|
^ roundKeys[round][2];
|
||||||
|
int t3 = te0[this.cfbV[3] & 0xFF]
|
||||||
|
^ te1[(this.cfbV[0] >> 8) & 0xFF]
|
||||||
|
^ te2[(this.cfbV[1] >> 16) & 0xFF]
|
||||||
|
^ te3[(this.cfbV[2] >> 24) & 0xFF]
|
||||||
|
^ roundKeys[round++][3];
|
||||||
|
this.cfbV[0] = (sbox[t0 & 0xFF] & 0xFF)
|
||||||
|
^ (sbox[(t1 >> 8) & 0xFF] & 0xFF) << 8
|
||||||
|
^ (sbox[(t2 >> 16) & 0xFF] & 0xFF) << 16
|
||||||
|
^ sbox[(t3 >> 24) & 0xFF] << 24
|
||||||
|
^ roundKeys[round][0];
|
||||||
|
this.cfbV[1] = (sbox[t1 & 0xFF] & 0xFF)
|
||||||
|
^ (sbox[(t2 >> 8) & 0xFF] & 0xFF) << 8
|
||||||
|
^ (sbox[(t3 >> 16) & 0xFF] & 0xFF) << 16
|
||||||
|
^ sbox[(t0 >> 24) & 0xFF] << 24
|
||||||
|
^ roundKeys[round][1];
|
||||||
|
this.cfbV[2] = (sbox[t2 & 0xFF] & 0xFF)
|
||||||
|
^ (sbox[(t3 >> 8) & 0xFF] & 0xFF) << 8
|
||||||
|
^ (sbox[(t0 >> 16) & 0xFF] & 0xFF) << 16
|
||||||
|
^ sbox[(t1 >> 24) & 0xFF] << 24
|
||||||
|
^ roundKeys[round][2];
|
||||||
|
this.cfbV[3] = (sbox[t3 & 0xFF] & 0xFF)
|
||||||
|
^ (sbox[(t0 >> 8) & 0xFF] & 0xFF) << 8
|
||||||
|
^ (sbox[(t1 >> 16) & 0xFF] & 0xFF) << 16
|
||||||
|
^ sbox[(t2 >> 24) & 0xFF] << 24
|
||||||
|
^ roundKeys[round][3];
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
buf[off + i] = (byte) ((byte) (this.cfbV[wordIndex] >> (8 * byteIndex)) ^ buf[off + i]);
|
||||||
|
this.bytesCounter++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final String decryptStringWithoutCheckCallCtx(String encrypted) {
|
||||||
|
try {
|
||||||
|
if (storage == null) {
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
|
||||||
|
int[] iv = (int[]) storage[6];
|
||||||
|
int[][] roundKeys = (int[][]) storage[5];
|
||||||
|
int[] te0 = (int[]) storage[1];
|
||||||
|
int[] te1 = (int[]) storage[2];
|
||||||
|
int[] te2 = (int[]) storage[3];
|
||||||
|
int[] te3 = (int[]) storage[4];
|
||||||
|
byte[] sbox = (byte[]) storage[0];
|
||||||
|
int[] state = new int[4];
|
||||||
|
System.arraycopy(iv, 0, state, 0, 4);
|
||||||
|
StringBuilder result = new StringBuilder(encrypted);
|
||||||
|
int length = result.length();
|
||||||
|
|
||||||
|
for (int i = 0; i < length; i++) {
|
||||||
|
if (i % 8 == 0) {
|
||||||
|
try {
|
||||||
|
state[0] ^= roundKeys[0][0];
|
||||||
|
state[1] ^= roundKeys[0][1];
|
||||||
|
state[2] ^= roundKeys[0][2];
|
||||||
|
state[3] ^= roundKeys[0][3];
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
}
|
||||||
|
|
||||||
|
int round = 1;
|
||||||
|
|
||||||
|
while (round < roundKeys.length - 2) {
|
||||||
|
int t0 = te0[state[0] & 0xFF] ^ te1[(state[1] >> 8) & 0xFF] ^ te2[(state[2] >> 16) & 0xFF] ^ te3[(state[3] >> 24) & 0xFF] ^ roundKeys[round][0];
|
||||||
|
int t1 = te0[state[1] & 0xFF] ^ te1[(state[2] >> 8) & 0xFF] ^ te2[(state[3] >> 16) & 0xFF] ^ te3[(state[0] >> 24) & 0xFF] ^ roundKeys[round][1];
|
||||||
|
int t2 = te0[state[2] & 0xFF] ^ te1[(state[3] >> 8) & 0xFF] ^ te2[(state[0] >> 16) & 0xFF] ^ te3[(state[1] >> 24) & 0xFF] ^ roundKeys[round][2];
|
||||||
|
int t3 = te0[state[3] & 0xFF] ^ te1[(state[0] >> 8) & 0xFF] ^ te2[(state[1] >> 16) & 0xFF] ^ te3[(state[2] >> 24) & 0xFF] ^ roundKeys[round++][3];
|
||||||
|
state[0] = te0[t0 & 0xFF] ^ te1[(t1 >> 8) & 0xFF] ^ te2[(t2 >> 16) & 0xFF] ^ te3[(t3 >> 24) & 0xFF] ^ roundKeys[round][0];
|
||||||
|
state[1] = te0[t1 & 0xFF] ^ te1[(t2 >> 8) & 0xFF] ^ te2[(t3 >> 16) & 0xFF] ^ te3[(t0 >> 24) & 0xFF] ^ roundKeys[round][1];
|
||||||
|
state[2] = te0[t2 & 0xFF] ^ te1[(t3 >> 8) & 0xFF] ^ te2[(t0 >> 16) & 0xFF] ^ te3[(t1 >> 24) & 0xFF] ^ roundKeys[round][2];
|
||||||
|
state[3] = te0[t3 & 0xFF] ^ te1[(t0 >> 8) & 0xFF] ^ te2[(t1 >> 16) & 0xFF] ^ te3[(t2 >> 24) & 0xFF] ^ roundKeys[round++][3];
|
||||||
|
}
|
||||||
|
|
||||||
|
int t0 = te0[state[0] & 0xFF] ^ te1[(state[1] >> 8) & 0xFF] ^ te2[(state[2] >> 16) & 0xFF] ^ te3[(state[3] >> 24) & 0xFF] ^ roundKeys[round][0];
|
||||||
|
int t1 = te0[state[1] & 0xFF] ^ te1[(state[2] >> 8) & 0xFF] ^ te2[(state[3] >> 16) & 0xFF] ^ te3[(state[0] >> 24) & 0xFF] ^ roundKeys[round][1];
|
||||||
|
int t2 = te0[state[2] & 0xFF] ^ te1[(state[3] >> 8) & 0xFF] ^ te2[(state[0] >> 16) & 0xFF] ^ te3[(state[1] >> 24) & 0xFF] ^ roundKeys[round][2];
|
||||||
|
int t3 = te0[state[3] & 0xFF] ^ te1[(state[0] >> 8) & 0xFF] ^ te2[(state[1] >> 16) & 0xFF] ^ te3[(state[2] >> 24) & 0xFF] ^ roundKeys[round++][3];
|
||||||
|
state[0] = (sbox[t0 & 0xFF] & 0xFF)
|
||||||
|
^ (sbox[(t1 >> 8) & 0xFF] & 0xFF) << 8
|
||||||
|
^ (sbox[(t2 >> 16) & 0xFF] & 0xFF) << 16
|
||||||
|
^ sbox[(t3 >> 24) & 0xFF] << 24
|
||||||
|
^ roundKeys[round][0];
|
||||||
|
state[1] = (sbox[t1 & 0xFF] & 0xFF)
|
||||||
|
^ (sbox[(t2 >> 8) & 0xFF] & 0xFF) << 8
|
||||||
|
^ (sbox[(t3 >> 16) & 0xFF] & 0xFF) << 16
|
||||||
|
^ sbox[(t0 >> 24) & 0xFF] << 24
|
||||||
|
^ roundKeys[round][1];
|
||||||
|
state[2] = (sbox[t2 & 0xFF] & 0xFF)
|
||||||
|
^ (sbox[(t3 >> 8) & 0xFF] & 0xFF) << 8
|
||||||
|
^ (sbox[(t0 >> 16) & 0xFF] & 0xFF) << 16
|
||||||
|
^ sbox[(t1 >> 24) & 0xFF] << 24
|
||||||
|
^ roundKeys[round][2];
|
||||||
|
state[3] = (sbox[t3 & 0xFF] & 0xFF)
|
||||||
|
^ (sbox[(t0 >> 8) & 0xFF] & 0xFF) << 8
|
||||||
|
^ (sbox[(t1 >> 16) & 0xFF] & 0xFF) << 16
|
||||||
|
^ sbox[(t2 >> 24) & 0xFF] << 24
|
||||||
|
^ roundKeys[round][3];
|
||||||
|
}
|
||||||
|
|
||||||
|
int keyWord = i % 8 % 2 == 1
|
||||||
|
? state[i % 8 / 2] & -1
|
||||||
|
: (state[i % 8 / 2] & -65536) >> 16;
|
||||||
|
result.setCharAt(i, (char) ((char) keyWord ^ result.charAt(i)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package com.licel.stringer.prototype;
|
||||||
|
|
||||||
|
import java.net.URLStreamHandler;
|
||||||
|
import java.net.URLStreamHandlerFactory;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class StringerStreamHandlerFactoryPrototype implements URLStreamHandlerFactory {
|
||||||
|
private final Map<String, URLStreamHandler> protocolHandlers = new HashMap<>();
|
||||||
|
|
||||||
|
public StringerStreamHandlerFactoryPrototype(String protocol, URLStreamHandler urlHandler) {
|
||||||
|
this.protocolHandlers.put(protocol, urlHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
public StringerStreamHandlerFactoryPrototype() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addHandler(String protocol, URLStreamHandler urlHandler) {
|
||||||
|
this.protocolHandlers.put(protocol, urlHandler);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public URLStreamHandler createURLStreamHandler(String protocol) {
|
||||||
|
return this.protocolHandlers.get(protocol);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package com.licel.stringer.prototype;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
|
||||||
|
public class StringerURLConnectionPrototype extends URLConnection {
|
||||||
|
URLConnection parentConnection;
|
||||||
|
|
||||||
|
public StringerURLConnectionPrototype(URL url) throws IOException {
|
||||||
|
super(url);
|
||||||
|
this.parentConnection = url.openConnection();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void connect() throws IOException {
|
||||||
|
this.parentConnection.connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InputStream getInputStream() throws IOException {
|
||||||
|
return new StringerInputStreamPrototype(this.parentConnection.getInputStream());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
package com.licel.stringer.prototype;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
import java.net.URLStreamHandler;
|
||||||
|
|
||||||
|
public class StringerURLHandlerPrototype extends URLStreamHandler {
|
||||||
|
@Override
|
||||||
|
protected URLConnection openConnection(URL url) throws IOException {
|
||||||
|
if (url.getProtocol().equals("stringer")) {
|
||||||
|
URL wrappedUrl = new URL(url.toString().substring(9));
|
||||||
|
return new StringerURLConnectionPrototype(wrappedUrl);
|
||||||
|
} else {
|
||||||
|
return url.openConnection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.licel.stringer.runtime;
|
||||||
|
|
||||||
|
import com.licel.stringer.model.ClassInfo;
|
||||||
|
import org.objectweb.asm.ClassVisitor;
|
||||||
|
import org.objectweb.asm.Opcodes;
|
||||||
|
|
||||||
|
public class EmptyClassCreator extends ClassVisitor implements Opcodes {
|
||||||
|
public EmptyClassCreator(ClassVisitor classVisitor, ClassInfo classInfo) {
|
||||||
|
super(Opcodes.ASM9, classVisitor);
|
||||||
|
classVisitor.visit(
|
||||||
|
classInfo.classFileVersion,
|
||||||
|
ACC_PUBLIC | ACC_SUPER,
|
||||||
|
classInfo.name,
|
||||||
|
null,
|
||||||
|
classInfo.superName,
|
||||||
|
null);
|
||||||
|
classVisitor.visitEnd();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
package com.licel.stringer.runtime;
|
||||||
|
|
||||||
|
import com.licel.stringer.model.ClassInfo;
|
||||||
|
import java.util.Properties;
|
||||||
|
import org.objectweb.asm.ClassVisitor;
|
||||||
|
import org.objectweb.asm.Label;
|
||||||
|
import org.objectweb.asm.MethodVisitor;
|
||||||
|
import org.objectweb.asm.Opcodes;
|
||||||
|
|
||||||
|
public class IntrinsicsCreator extends ClassVisitor implements Opcodes {
|
||||||
|
public static final Properties METHOD_MAPPINGS = new Properties();
|
||||||
|
public static final Properties FIELD_MAPPINGS = new Properties();
|
||||||
|
private final ClassInfo classInfo;
|
||||||
|
|
||||||
|
public IntrinsicsCreator(ClassVisitor classVisitor, ClassInfo classInfo) {
|
||||||
|
super(Opcodes.ASM9, classVisitor);
|
||||||
|
this.classInfo = classInfo;
|
||||||
|
this.generate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void generate() {
|
||||||
|
this.cv.visit(
|
||||||
|
this.classInfo.classFileVersion,
|
||||||
|
ACC_PUBLIC | ACC_SUPER,
|
||||||
|
"com/licel/stringer/IntrinsicsPrototype",
|
||||||
|
null,
|
||||||
|
"java/lang/Object",
|
||||||
|
null);
|
||||||
|
|
||||||
|
MethodVisitor mv = this.cv.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
|
||||||
|
mv.visitCode();
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
|
||||||
|
mv.visitInsn(RETURN);
|
||||||
|
mv.visitMaxs(1, 1);
|
||||||
|
mv.visitEnd();
|
||||||
|
|
||||||
|
mv = this.cv.visitMethod(
|
||||||
|
ACC_PUBLIC | ACC_STATIC | ACC_FINAL,
|
||||||
|
"equalsIntrinsics",
|
||||||
|
"(Ljava/lang/Object;Ljava/lang/Object;)Z",
|
||||||
|
null,
|
||||||
|
null);
|
||||||
|
mv.visitCode();
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitVarInsn(ALOAD, 1);
|
||||||
|
Label label0 = new Label();
|
||||||
|
mv.visitJumpInsn(IF_ACMPEQ, label0);
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitTypeInsn(INSTANCEOF, "java/lang/String");
|
||||||
|
Label label1 = new Label();
|
||||||
|
mv.visitJumpInsn(IFEQ, label1);
|
||||||
|
mv.visitVarInsn(ALOAD, 1);
|
||||||
|
mv.visitTypeInsn(INSTANCEOF, "java/lang/String");
|
||||||
|
mv.visitJumpInsn(IFEQ, label1);
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitVarInsn(ALOAD, 1);
|
||||||
|
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "equals", "(Ljava/lang/Object;)Z", false);
|
||||||
|
mv.visitJumpInsn(IFEQ, label1);
|
||||||
|
mv.visitLabel(label0);
|
||||||
|
mv.visitInsn(ICONST_1);
|
||||||
|
Label label2 = new Label();
|
||||||
|
mv.visitJumpInsn(GOTO, label2);
|
||||||
|
mv.visitLabel(label1);
|
||||||
|
mv.visitInsn(ICONST_0);
|
||||||
|
mv.visitLabel(label2);
|
||||||
|
mv.visitInsn(IRETURN);
|
||||||
|
mv.visitMaxs(2, 2);
|
||||||
|
mv.visitEnd();
|
||||||
|
|
||||||
|
this.cv.visitEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
static {
|
||||||
|
METHOD_MAPPINGS.put("equalsIntrinsics", "(Ljava/lang/Object;Ljava/lang/Object;)Z");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,494 @@
|
|||||||
|
package com.licel.stringer.runtime;
|
||||||
|
|
||||||
|
import com.licel.stringer.model.ClassInfo;
|
||||||
|
import java.util.Properties;
|
||||||
|
import org.objectweb.asm.ClassVisitor;
|
||||||
|
import org.objectweb.asm.FieldVisitor;
|
||||||
|
import org.objectweb.asm.Label;
|
||||||
|
import org.objectweb.asm.MethodVisitor;
|
||||||
|
import org.objectweb.asm.Opcodes;
|
||||||
|
|
||||||
|
public class LruCacheCreator extends ClassVisitor implements Opcodes {
|
||||||
|
public static final Properties METHOD_MAPPINGS = new Properties();
|
||||||
|
public static final Properties FIELD_MAPPINGS = new Properties();
|
||||||
|
private final ClassInfo classInfo;
|
||||||
|
|
||||||
|
public LruCacheCreator(ClassVisitor classVisitor, ClassInfo classInfo) {
|
||||||
|
super(Opcodes.ASM9, classVisitor);
|
||||||
|
this.classInfo = classInfo;
|
||||||
|
this.generate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void generate() {
|
||||||
|
this.cv.visit(
|
||||||
|
this.classInfo.classFileVersion,
|
||||||
|
ACC_PUBLIC | ACC_SUPER,
|
||||||
|
"com/licel/stringer/LruCachePrototype",
|
||||||
|
"<K:Ljava/lang/Object;V:Ljava/lang/Object;>Ljava/lang/Object;",
|
||||||
|
"java/lang/Object",
|
||||||
|
null);
|
||||||
|
this.cv.visitInnerClass("java/util/Map$Entry", "java/util/Map", "Entry", ACC_PUBLIC | ACC_STATIC | ACC_INTERFACE | ACC_ABSTRACT);
|
||||||
|
FieldVisitor fv = this.cv.visitField(ACC_PRIVATE | ACC_FINAL, "map", "Ljava/util/LinkedHashMap;", "Ljava/util/LinkedHashMap<TK;TV;>;", null);
|
||||||
|
fv.visitEnd();
|
||||||
|
fv = this.cv.visitField(ACC_PRIVATE, "size", "I", null, null);
|
||||||
|
fv.visitEnd();
|
||||||
|
fv = this.cv.visitField(ACC_PRIVATE, "maxSize", "I", null, null);
|
||||||
|
fv.visitEnd();
|
||||||
|
fv = this.cv.visitField(ACC_PRIVATE, "putCount", "I", null, null);
|
||||||
|
fv.visitEnd();
|
||||||
|
fv = this.cv.visitField(ACC_PRIVATE, "createCount", "I", null, null);
|
||||||
|
fv.visitEnd();
|
||||||
|
fv = this.cv.visitField(ACC_PRIVATE, "evictionCount", "I", null, null);
|
||||||
|
fv.visitEnd();
|
||||||
|
fv = this.cv.visitField(ACC_PRIVATE, "hitCount", "I", null, null);
|
||||||
|
fv.visitEnd();
|
||||||
|
fv = this.cv.visitField(ACC_PRIVATE, "missCount", "I", null, null);
|
||||||
|
fv.visitEnd();
|
||||||
|
|
||||||
|
{
|
||||||
|
MethodVisitor mv = this.cv.visitMethod(ACC_PUBLIC, "<init>", "(I)V", null, null);
|
||||||
|
mv.visitCode();
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
|
||||||
|
mv.visitVarInsn(ILOAD, 1);
|
||||||
|
Label label0 = new Label();
|
||||||
|
mv.visitJumpInsn(IFGT, label0);
|
||||||
|
mv.visitTypeInsn(NEW, "java/lang/IllegalArgumentException");
|
||||||
|
mv.visitInsn(DUP);
|
||||||
|
mv.visitLdcInsn("maxSize <= 0");
|
||||||
|
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/IllegalArgumentException", "<init>", "(Ljava/lang/String;)V", false);
|
||||||
|
mv.visitInsn(ATHROW);
|
||||||
|
mv.visitLabel(label0);
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitVarInsn(ILOAD, 1);
|
||||||
|
mv.visitFieldInsn(PUTFIELD, "com/licel/stringer/LruCachePrototype", "maxSize", "I");
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitTypeInsn(NEW, "java/util/LinkedHashMap");
|
||||||
|
mv.visitInsn(DUP);
|
||||||
|
mv.visitInsn(ICONST_0);
|
||||||
|
mv.visitLdcInsn(0.75F);
|
||||||
|
mv.visitInsn(ICONST_1);
|
||||||
|
mv.visitMethodInsn(INVOKESPECIAL, "java/util/LinkedHashMap", "<init>", "(IFZ)V", false);
|
||||||
|
mv.visitFieldInsn(PUTFIELD, "com/licel/stringer/LruCachePrototype", "map", "Ljava/util/LinkedHashMap;");
|
||||||
|
mv.visitInsn(RETURN);
|
||||||
|
mv.visitMaxs(6, 2);
|
||||||
|
mv.visitEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
MethodVisitor mv = this.cv.visitMethod(ACC_PUBLIC | ACC_FINAL | ACC_SYNCHRONIZED, "get", "(Ljava/lang/Object;)Ljava/lang/Object;", "(TK;)TV;", null);
|
||||||
|
mv.visitCode();
|
||||||
|
mv.visitVarInsn(ALOAD, 1);
|
||||||
|
Label label0 = new Label();
|
||||||
|
mv.visitJumpInsn(IFNONNULL, label0);
|
||||||
|
mv.visitTypeInsn(NEW, "java/lang/NullPointerException");
|
||||||
|
mv.visitInsn(DUP);
|
||||||
|
mv.visitLdcInsn("key == null");
|
||||||
|
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/NullPointerException", "<init>", "(Ljava/lang/String;)V", false);
|
||||||
|
mv.visitInsn(ATHROW);
|
||||||
|
mv.visitLabel(label0);
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitFieldInsn(GETFIELD, "com/licel/stringer/LruCachePrototype", "map", "Ljava/util/LinkedHashMap;");
|
||||||
|
mv.visitVarInsn(ALOAD, 1);
|
||||||
|
mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/LinkedHashMap", "get", "(Ljava/lang/Object;)Ljava/lang/Object;", false);
|
||||||
|
mv.visitVarInsn(ASTORE, 2);
|
||||||
|
mv.visitVarInsn(ALOAD, 2);
|
||||||
|
Label label1 = new Label();
|
||||||
|
mv.visitJumpInsn(IFNULL, label1);
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitInsn(DUP);
|
||||||
|
mv.visitFieldInsn(GETFIELD, "com/licel/stringer/LruCachePrototype", "hitCount", "I");
|
||||||
|
mv.visitInsn(ICONST_1);
|
||||||
|
mv.visitInsn(IADD);
|
||||||
|
mv.visitFieldInsn(PUTFIELD, "com/licel/stringer/LruCachePrototype", "hitCount", "I");
|
||||||
|
mv.visitVarInsn(ALOAD, 2);
|
||||||
|
mv.visitInsn(ARETURN);
|
||||||
|
mv.visitLabel(label1);
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitInsn(DUP);
|
||||||
|
mv.visitFieldInsn(GETFIELD, "com/licel/stringer/LruCachePrototype", "missCount", "I");
|
||||||
|
mv.visitInsn(ICONST_1);
|
||||||
|
mv.visitInsn(IADD);
|
||||||
|
mv.visitFieldInsn(PUTFIELD, "com/licel/stringer/LruCachePrototype", "missCount", "I");
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitVarInsn(ALOAD, 1);
|
||||||
|
mv.visitMethodInsn(INVOKEVIRTUAL, "com/licel/stringer/LruCachePrototype", "create", "(Ljava/lang/Object;)Ljava/lang/Object;", false);
|
||||||
|
mv.visitVarInsn(ASTORE, 2);
|
||||||
|
mv.visitVarInsn(ALOAD, 2);
|
||||||
|
Label label2 = new Label();
|
||||||
|
mv.visitJumpInsn(IFNULL, label2);
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitInsn(DUP);
|
||||||
|
mv.visitFieldInsn(GETFIELD, "com/licel/stringer/LruCachePrototype", "createCount", "I");
|
||||||
|
mv.visitInsn(ICONST_1);
|
||||||
|
mv.visitInsn(IADD);
|
||||||
|
mv.visitFieldInsn(PUTFIELD, "com/licel/stringer/LruCachePrototype", "createCount", "I");
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitInsn(DUP);
|
||||||
|
mv.visitFieldInsn(GETFIELD, "com/licel/stringer/LruCachePrototype", "size", "I");
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitVarInsn(ALOAD, 1);
|
||||||
|
mv.visitVarInsn(ALOAD, 2);
|
||||||
|
mv.visitMethodInsn(INVOKESPECIAL, "com/licel/stringer/LruCachePrototype", "safeSizeOf", "(Ljava/lang/Object;Ljava/lang/Object;)I", false);
|
||||||
|
mv.visitInsn(IADD);
|
||||||
|
mv.visitFieldInsn(PUTFIELD, "com/licel/stringer/LruCachePrototype", "size", "I");
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitFieldInsn(GETFIELD, "com/licel/stringer/LruCachePrototype", "map", "Ljava/util/LinkedHashMap;");
|
||||||
|
mv.visitVarInsn(ALOAD, 1);
|
||||||
|
mv.visitVarInsn(ALOAD, 2);
|
||||||
|
mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/LinkedHashMap", "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", false);
|
||||||
|
mv.visitInsn(POP);
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitFieldInsn(GETFIELD, "com/licel/stringer/LruCachePrototype", "maxSize", "I");
|
||||||
|
mv.visitMethodInsn(INVOKESPECIAL, "com/licel/stringer/LruCachePrototype", "trimToSize", "(I)V", false);
|
||||||
|
mv.visitLabel(label2);
|
||||||
|
mv.visitVarInsn(ALOAD, 2);
|
||||||
|
mv.visitInsn(ARETURN);
|
||||||
|
mv.visitMaxs(5, 3);
|
||||||
|
mv.visitEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
MethodVisitor mv = this.cv.visitMethod(ACC_PUBLIC | ACC_FINAL | ACC_SYNCHRONIZED, "put", "(Ljava/lang/Object;Ljava/lang/Object;)V", "(TK;TV;)V", null);
|
||||||
|
mv.visitCode();
|
||||||
|
mv.visitVarInsn(ALOAD, 1);
|
||||||
|
Label label0 = new Label();
|
||||||
|
mv.visitJumpInsn(IFNULL, label0);
|
||||||
|
mv.visitVarInsn(ALOAD, 2);
|
||||||
|
Label label1 = new Label();
|
||||||
|
mv.visitJumpInsn(IFNONNULL, label1);
|
||||||
|
mv.visitLabel(label0);
|
||||||
|
mv.visitTypeInsn(NEW, "java/lang/NullPointerException");
|
||||||
|
mv.visitInsn(DUP);
|
||||||
|
mv.visitLdcInsn("key == null || value == null");
|
||||||
|
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/NullPointerException", "<init>", "(Ljava/lang/String;)V", false);
|
||||||
|
mv.visitInsn(ATHROW);
|
||||||
|
mv.visitLabel(label1);
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitInsn(DUP);
|
||||||
|
mv.visitFieldInsn(GETFIELD, "com/licel/stringer/LruCachePrototype", "putCount", "I");
|
||||||
|
mv.visitInsn(ICONST_1);
|
||||||
|
mv.visitInsn(IADD);
|
||||||
|
mv.visitFieldInsn(PUTFIELD, "com/licel/stringer/LruCachePrototype", "putCount", "I");
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitInsn(DUP);
|
||||||
|
mv.visitFieldInsn(GETFIELD, "com/licel/stringer/LruCachePrototype", "size", "I");
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitVarInsn(ALOAD, 1);
|
||||||
|
mv.visitVarInsn(ALOAD, 2);
|
||||||
|
mv.visitMethodInsn(INVOKESPECIAL, "com/licel/stringer/LruCachePrototype", "safeSizeOf", "(Ljava/lang/Object;Ljava/lang/Object;)I", false);
|
||||||
|
mv.visitInsn(IADD);
|
||||||
|
mv.visitFieldInsn(PUTFIELD, "com/licel/stringer/LruCachePrototype", "size", "I");
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitFieldInsn(GETFIELD, "com/licel/stringer/LruCachePrototype", "map", "Ljava/util/LinkedHashMap;");
|
||||||
|
mv.visitVarInsn(ALOAD, 1);
|
||||||
|
mv.visitVarInsn(ALOAD, 2);
|
||||||
|
mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/LinkedHashMap", "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", false);
|
||||||
|
mv.visitVarInsn(ASTORE, 3);
|
||||||
|
mv.visitVarInsn(ALOAD, 3);
|
||||||
|
Label label2 = new Label();
|
||||||
|
mv.visitJumpInsn(IFNULL, label2);
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitInsn(DUP);
|
||||||
|
mv.visitFieldInsn(GETFIELD, "com/licel/stringer/LruCachePrototype", "size", "I");
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitVarInsn(ALOAD, 1);
|
||||||
|
mv.visitVarInsn(ALOAD, 3);
|
||||||
|
mv.visitMethodInsn(INVOKESPECIAL, "com/licel/stringer/LruCachePrototype", "safeSizeOf", "(Ljava/lang/Object;Ljava/lang/Object;)I", false);
|
||||||
|
mv.visitInsn(ISUB);
|
||||||
|
mv.visitFieldInsn(PUTFIELD, "com/licel/stringer/LruCachePrototype", "size", "I");
|
||||||
|
mv.visitLabel(label2);
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitFieldInsn(GETFIELD, "com/licel/stringer/LruCachePrototype", "maxSize", "I");
|
||||||
|
mv.visitMethodInsn(INVOKESPECIAL, "com/licel/stringer/LruCachePrototype", "trimToSize", "(I)V", false);
|
||||||
|
mv.visitInsn(RETURN);
|
||||||
|
mv.visitMaxs(5, 4);
|
||||||
|
mv.visitEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
MethodVisitor mv = this.cv.visitMethod(ACC_PRIVATE, "trimToSize", "(I)V", null, null);
|
||||||
|
mv.visitCode();
|
||||||
|
Label label0 = new Label();
|
||||||
|
mv.visitLabel(label0);
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitFieldInsn(GETFIELD, "com/licel/stringer/LruCachePrototype", "size", "I");
|
||||||
|
mv.visitVarInsn(ILOAD, 1);
|
||||||
|
Label label1 = new Label();
|
||||||
|
mv.visitJumpInsn(IF_ICMPLE, label1);
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitFieldInsn(GETFIELD, "com/licel/stringer/LruCachePrototype", "map", "Ljava/util/LinkedHashMap;");
|
||||||
|
mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/LinkedHashMap", "isEmpty", "()Z", false);
|
||||||
|
mv.visitJumpInsn(IFNE, label1);
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitFieldInsn(GETFIELD, "com/licel/stringer/LruCachePrototype", "map", "Ljava/util/LinkedHashMap;");
|
||||||
|
mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/LinkedHashMap", "entrySet", "()Ljava/util/Set;", false);
|
||||||
|
mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Set", "iterator", "()Ljava/util/Iterator;", true);
|
||||||
|
mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Iterator", "next", "()Ljava/lang/Object;", true);
|
||||||
|
mv.visitTypeInsn(CHECKCAST, "java/util/Map$Entry");
|
||||||
|
mv.visitVarInsn(ASTORE, 2);
|
||||||
|
mv.visitVarInsn(ALOAD, 2);
|
||||||
|
Label label2 = new Label();
|
||||||
|
mv.visitJumpInsn(IFNONNULL, label2);
|
||||||
|
mv.visitJumpInsn(GOTO, label1);
|
||||||
|
mv.visitLabel(label2);
|
||||||
|
mv.visitVarInsn(ALOAD, 2);
|
||||||
|
mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Map$Entry", "getKey", "()Ljava/lang/Object;", true);
|
||||||
|
mv.visitVarInsn(ASTORE, 3);
|
||||||
|
mv.visitVarInsn(ALOAD, 2);
|
||||||
|
mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Map$Entry", "getValue", "()Ljava/lang/Object;", true);
|
||||||
|
mv.visitVarInsn(ASTORE, 4);
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitFieldInsn(GETFIELD, "com/licel/stringer/LruCachePrototype", "map", "Ljava/util/LinkedHashMap;");
|
||||||
|
mv.visitVarInsn(ALOAD, 3);
|
||||||
|
mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/LinkedHashMap", "remove", "(Ljava/lang/Object;)Ljava/lang/Object;", false);
|
||||||
|
mv.visitInsn(POP);
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitInsn(DUP);
|
||||||
|
mv.visitFieldInsn(GETFIELD, "com/licel/stringer/LruCachePrototype", "size", "I");
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitVarInsn(ALOAD, 3);
|
||||||
|
mv.visitVarInsn(ALOAD, 4);
|
||||||
|
mv.visitMethodInsn(INVOKESPECIAL, "com/licel/stringer/LruCachePrototype", "safeSizeOf", "(Ljava/lang/Object;Ljava/lang/Object;)I", false);
|
||||||
|
mv.visitInsn(ISUB);
|
||||||
|
mv.visitFieldInsn(PUTFIELD, "com/licel/stringer/LruCachePrototype", "size", "I");
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitInsn(DUP);
|
||||||
|
mv.visitFieldInsn(GETFIELD, "com/licel/stringer/LruCachePrototype", "evictionCount", "I");
|
||||||
|
mv.visitInsn(ICONST_1);
|
||||||
|
mv.visitInsn(IADD);
|
||||||
|
mv.visitFieldInsn(PUTFIELD, "com/licel/stringer/LruCachePrototype", "evictionCount", "I");
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitVarInsn(ALOAD, 3);
|
||||||
|
mv.visitVarInsn(ALOAD, 4);
|
||||||
|
mv.visitMethodInsn(INVOKEVIRTUAL, "com/licel/stringer/LruCachePrototype", "entryEvicted", "(Ljava/lang/Object;Ljava/lang/Object;)V", false);
|
||||||
|
mv.visitJumpInsn(GOTO, label0);
|
||||||
|
mv.visitLabel(label1);
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitFieldInsn(GETFIELD, "com/licel/stringer/LruCachePrototype", "size", "I");
|
||||||
|
Label label3 = new Label();
|
||||||
|
mv.visitJumpInsn(IFLT, label3);
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitFieldInsn(GETFIELD, "com/licel/stringer/LruCachePrototype", "map", "Ljava/util/LinkedHashMap;");
|
||||||
|
mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/LinkedHashMap", "isEmpty", "()Z", false);
|
||||||
|
Label label4 = new Label();
|
||||||
|
mv.visitJumpInsn(IFEQ, label4);
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitFieldInsn(GETFIELD, "com/licel/stringer/LruCachePrototype", "size", "I");
|
||||||
|
mv.visitJumpInsn(IFEQ, label4);
|
||||||
|
mv.visitLabel(label3);
|
||||||
|
mv.visitTypeInsn(NEW, "java/lang/IllegalStateException");
|
||||||
|
mv.visitInsn(DUP);
|
||||||
|
mv.visitTypeInsn(NEW, "java/lang/StringBuilder");
|
||||||
|
mv.visitInsn(DUP);
|
||||||
|
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "()V", false);
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Object", "getClass", "()Ljava/lang/Class;", false);
|
||||||
|
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/Class", "getName", "()Ljava/lang/String;", false);
|
||||||
|
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
|
||||||
|
mv.visitLdcInsn(".sizeOf() is reporting inconsistent results!");
|
||||||
|
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
|
||||||
|
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false);
|
||||||
|
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/IllegalStateException", "<init>", "(Ljava/lang/String;)V", false);
|
||||||
|
mv.visitInsn(ATHROW);
|
||||||
|
mv.visitLabel(label4);
|
||||||
|
mv.visitInsn(RETURN);
|
||||||
|
mv.visitMaxs(5, 5);
|
||||||
|
mv.visitEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
MethodVisitor mv = this.cv.visitMethod(ACC_PUBLIC | ACC_FINAL | ACC_SYNCHRONIZED, "remove", "(Ljava/lang/Object;)Ljava/lang/Object;", "(TK;)TV;", null);
|
||||||
|
mv.visitCode();
|
||||||
|
mv.visitVarInsn(ALOAD, 1);
|
||||||
|
Label label0 = new Label();
|
||||||
|
mv.visitJumpInsn(IFNONNULL, label0);
|
||||||
|
mv.visitTypeInsn(NEW, "java/lang/NullPointerException");
|
||||||
|
mv.visitInsn(DUP);
|
||||||
|
mv.visitLdcInsn("key == null");
|
||||||
|
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/NullPointerException", "<init>", "(Ljava/lang/String;)V", false);
|
||||||
|
mv.visitInsn(ATHROW);
|
||||||
|
mv.visitLabel(label0);
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitFieldInsn(GETFIELD, "com/licel/stringer/LruCachePrototype", "map", "Ljava/util/LinkedHashMap;");
|
||||||
|
mv.visitVarInsn(ALOAD, 1);
|
||||||
|
mv.visitMethodInsn(INVOKEVIRTUAL, "java/util/LinkedHashMap", "remove", "(Ljava/lang/Object;)Ljava/lang/Object;", false);
|
||||||
|
mv.visitVarInsn(ASTORE, 2);
|
||||||
|
mv.visitVarInsn(ALOAD, 2);
|
||||||
|
Label label1 = new Label();
|
||||||
|
mv.visitJumpInsn(IFNULL, label1);
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitInsn(DUP);
|
||||||
|
mv.visitFieldInsn(GETFIELD, "com/licel/stringer/LruCachePrototype", "size", "I");
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitVarInsn(ALOAD, 1);
|
||||||
|
mv.visitVarInsn(ALOAD, 2);
|
||||||
|
mv.visitMethodInsn(INVOKESPECIAL, "com/licel/stringer/LruCachePrototype", "safeSizeOf", "(Ljava/lang/Object;Ljava/lang/Object;)I", false);
|
||||||
|
mv.visitInsn(ISUB);
|
||||||
|
mv.visitFieldInsn(PUTFIELD, "com/licel/stringer/LruCachePrototype", "size", "I");
|
||||||
|
mv.visitLabel(label1);
|
||||||
|
mv.visitVarInsn(ALOAD, 2);
|
||||||
|
mv.visitInsn(ARETURN);
|
||||||
|
mv.visitMaxs(5, 3);
|
||||||
|
mv.visitEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
MethodVisitor mv = this.cv.visitMethod(ACC_PROTECTED, "entryEvicted", "(Ljava/lang/Object;Ljava/lang/Object;)V", "(TK;TV;)V", null);
|
||||||
|
mv.visitCode();
|
||||||
|
mv.visitInsn(RETURN);
|
||||||
|
mv.visitMaxs(0, 3);
|
||||||
|
mv.visitEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
MethodVisitor mv = this.cv.visitMethod(ACC_PROTECTED, "create", "(Ljava/lang/Object;)Ljava/lang/Object;", "(TK;)TV;", null);
|
||||||
|
mv.visitCode();
|
||||||
|
mv.visitInsn(ACONST_NULL);
|
||||||
|
mv.visitInsn(ARETURN);
|
||||||
|
mv.visitMaxs(1, 2);
|
||||||
|
mv.visitEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
MethodVisitor mv = this.cv.visitMethod(ACC_PRIVATE, "safeSizeOf", "(Ljava/lang/Object;Ljava/lang/Object;)I", "(TK;TV;)I", null);
|
||||||
|
mv.visitCode();
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitVarInsn(ALOAD, 1);
|
||||||
|
mv.visitVarInsn(ALOAD, 2);
|
||||||
|
mv.visitMethodInsn(INVOKEVIRTUAL, "com/licel/stringer/LruCachePrototype", "sizeOf", "(Ljava/lang/Object;Ljava/lang/Object;)I", false);
|
||||||
|
mv.visitVarInsn(ISTORE, 3);
|
||||||
|
mv.visitVarInsn(ILOAD, 3);
|
||||||
|
Label label0 = new Label();
|
||||||
|
mv.visitJumpInsn(IFGE, label0);
|
||||||
|
mv.visitTypeInsn(NEW, "java/lang/IllegalStateException");
|
||||||
|
mv.visitInsn(DUP);
|
||||||
|
mv.visitTypeInsn(NEW, "java/lang/StringBuilder");
|
||||||
|
mv.visitInsn(DUP);
|
||||||
|
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/StringBuilder", "<init>", "()V", false);
|
||||||
|
mv.visitLdcInsn("Negative size: ");
|
||||||
|
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
|
||||||
|
mv.visitVarInsn(ALOAD, 1);
|
||||||
|
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/Object;)Ljava/lang/StringBuilder;", false);
|
||||||
|
mv.visitLdcInsn("=");
|
||||||
|
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/String;)Ljava/lang/StringBuilder;", false);
|
||||||
|
mv.visitVarInsn(ALOAD, 2);
|
||||||
|
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "append", "(Ljava/lang/Object;)Ljava/lang/StringBuilder;", false);
|
||||||
|
mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/StringBuilder", "toString", "()Ljava/lang/String;", false);
|
||||||
|
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/IllegalStateException", "<init>", "(Ljava/lang/String;)V", false);
|
||||||
|
mv.visitInsn(ATHROW);
|
||||||
|
mv.visitLabel(label0);
|
||||||
|
mv.visitVarInsn(ILOAD, 3);
|
||||||
|
mv.visitInsn(IRETURN);
|
||||||
|
mv.visitMaxs(4, 4);
|
||||||
|
mv.visitEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
MethodVisitor mv = this.cv.visitMethod(ACC_PROTECTED, "sizeOf", "(Ljava/lang/Object;Ljava/lang/Object;)I", "(TK;TV;)I", null);
|
||||||
|
mv.visitCode();
|
||||||
|
mv.visitInsn(ICONST_1);
|
||||||
|
mv.visitInsn(IRETURN);
|
||||||
|
mv.visitMaxs(1, 3);
|
||||||
|
mv.visitEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
MethodVisitor mv = this.cv.visitMethod(ACC_PUBLIC | ACC_FINAL | ACC_SYNCHRONIZED, "evictAll", "()V", null, null);
|
||||||
|
mv.visitCode();
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitInsn(ICONST_M1);
|
||||||
|
mv.visitMethodInsn(INVOKESPECIAL, "com/licel/stringer/LruCachePrototype", "trimToSize", "(I)V", false);
|
||||||
|
mv.visitInsn(RETURN);
|
||||||
|
mv.visitMaxs(2, 1);
|
||||||
|
mv.visitEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
MethodVisitor mv = this.cv.visitMethod(ACC_PUBLIC | ACC_FINAL | ACC_SYNCHRONIZED, "size", "()I", null, null);
|
||||||
|
mv.visitCode();
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitFieldInsn(GETFIELD, "com/licel/stringer/LruCachePrototype", "size", "I");
|
||||||
|
mv.visitInsn(IRETURN);
|
||||||
|
mv.visitMaxs(1, 1);
|
||||||
|
mv.visitEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
MethodVisitor mv = this.cv.visitMethod(ACC_PUBLIC | ACC_FINAL | ACC_SYNCHRONIZED, "maxSize", "()I", null, null);
|
||||||
|
mv.visitCode();
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitFieldInsn(GETFIELD, "com/licel/stringer/LruCachePrototype", "maxSize", "I");
|
||||||
|
mv.visitInsn(IRETURN);
|
||||||
|
mv.visitMaxs(1, 1);
|
||||||
|
mv.visitEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
MethodVisitor mv = this.cv.visitMethod(ACC_PUBLIC | ACC_FINAL | ACC_SYNCHRONIZED, "hitCount", "()I", null, null);
|
||||||
|
mv.visitCode();
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitFieldInsn(GETFIELD, "com/licel/stringer/LruCachePrototype", "hitCount", "I");
|
||||||
|
mv.visitInsn(IRETURN);
|
||||||
|
mv.visitMaxs(1, 1);
|
||||||
|
mv.visitEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
MethodVisitor mv = this.cv.visitMethod(ACC_PUBLIC | ACC_FINAL | ACC_SYNCHRONIZED, "missCount", "()I", null, null);
|
||||||
|
mv.visitCode();
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitFieldInsn(GETFIELD, "com/licel/stringer/LruCachePrototype", "missCount", "I");
|
||||||
|
mv.visitInsn(IRETURN);
|
||||||
|
mv.visitMaxs(1, 1);
|
||||||
|
mv.visitEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
MethodVisitor mv = this.cv.visitMethod(ACC_PUBLIC | ACC_FINAL | ACC_SYNCHRONIZED, "createCount", "()I", null, null);
|
||||||
|
mv.visitCode();
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitFieldInsn(GETFIELD, "com/licel/stringer/LruCachePrototype", "createCount", "I");
|
||||||
|
mv.visitInsn(IRETURN);
|
||||||
|
mv.visitMaxs(1, 1);
|
||||||
|
mv.visitEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
MethodVisitor mv = this.cv.visitMethod(ACC_PUBLIC | ACC_FINAL | ACC_SYNCHRONIZED, "putCount", "()I", null, null);
|
||||||
|
mv.visitCode();
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitFieldInsn(GETFIELD, "com/licel/stringer/LruCachePrototype", "putCount", "I");
|
||||||
|
mv.visitInsn(IRETURN);
|
||||||
|
mv.visitMaxs(1, 1);
|
||||||
|
mv.visitEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
MethodVisitor mv = this.cv.visitMethod(ACC_PUBLIC | ACC_FINAL | ACC_SYNCHRONIZED, "evictionCount", "()I", null, null);
|
||||||
|
mv.visitCode();
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitFieldInsn(GETFIELD, "com/licel/stringer/LruCachePrototype", "evictionCount", "I");
|
||||||
|
mv.visitInsn(IRETURN);
|
||||||
|
mv.visitMaxs(1, 1);
|
||||||
|
mv.visitEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
MethodVisitor mv = this.cv.visitMethod(ACC_PUBLIC | ACC_FINAL | ACC_SYNCHRONIZED, "snapshot", "()Ljava/util/Map;", "()Ljava/util/Map<TK;TV;>;", null);
|
||||||
|
mv.visitCode();
|
||||||
|
mv.visitTypeInsn(NEW, "java/util/LinkedHashMap");
|
||||||
|
mv.visitInsn(DUP);
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitFieldInsn(GETFIELD, "com/licel/stringer/LruCachePrototype", "map", "Ljava/util/LinkedHashMap;");
|
||||||
|
mv.visitMethodInsn(INVOKESPECIAL, "java/util/LinkedHashMap", "<init>", "(Ljava/util/Map;)V", false);
|
||||||
|
mv.visitInsn(ARETURN);
|
||||||
|
mv.visitMaxs(3, 1);
|
||||||
|
mv.visitEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.cv.visitEnd();
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,100 @@
|
|||||||
|
package com.licel.stringer.runtime;
|
||||||
|
|
||||||
|
import com.licel.stringer.crypto.AESFast;
|
||||||
|
import com.licel.stringer.crypto.CryptoContainer;
|
||||||
|
import com.licel.stringer.model.ClassInfo;
|
||||||
|
import com.licel.stringer.util.StringerUtils;
|
||||||
|
import java.util.ResourceBundle;
|
||||||
|
import java.util.Set;
|
||||||
|
import org.objectweb.asm.ClassVisitor;
|
||||||
|
import org.objectweb.asm.MethodVisitor;
|
||||||
|
import org.objectweb.asm.Opcodes;
|
||||||
|
|
||||||
|
public class ResourceBundleCompiler extends ClassVisitor implements Opcodes {
|
||||||
|
private final ClassInfo classInfo;
|
||||||
|
private final ResourceBundle resourceBundle;
|
||||||
|
private final CryptoContainer cryptoContainer;
|
||||||
|
private final String decoderClassName;
|
||||||
|
private final String decoderMethodName;
|
||||||
|
|
||||||
|
public ResourceBundleCompiler(
|
||||||
|
ClassVisitor classVisitor,
|
||||||
|
ClassInfo classInfo,
|
||||||
|
ResourceBundle resourceBundle,
|
||||||
|
CryptoContainer cryptoContainer,
|
||||||
|
String decoderClassName,
|
||||||
|
String decoderMethodName) {
|
||||||
|
super(Opcodes.ASM9, classVisitor);
|
||||||
|
this.classInfo = classInfo;
|
||||||
|
this.resourceBundle = resourceBundle;
|
||||||
|
this.cryptoContainer = cryptoContainer;
|
||||||
|
this.decoderClassName = decoderClassName;
|
||||||
|
this.decoderMethodName = decoderMethodName;
|
||||||
|
this.generate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void generate() {
|
||||||
|
Set<String> keys = this.resourceBundle.keySet();
|
||||||
|
this.cv.visit(
|
||||||
|
this.classInfo.classFileVersion,
|
||||||
|
ACC_PUBLIC | ACC_SUPER,
|
||||||
|
this.classInfo.name,
|
||||||
|
null,
|
||||||
|
"java/util/ListResourceBundle",
|
||||||
|
null);
|
||||||
|
|
||||||
|
MethodVisitor mv = this.cv.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
|
||||||
|
mv.visitCode();
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitMethodInsn(INVOKESPECIAL, "java/util/ListResourceBundle", "<init>", "()V", false);
|
||||||
|
mv.visitInsn(RETURN);
|
||||||
|
mv.visitMaxs(1, 1);
|
||||||
|
mv.visitEnd();
|
||||||
|
|
||||||
|
mv = this.cv.visitMethod(ACC_PROTECTED, "getContents", "()[[Ljava/lang/Object;", null, null);
|
||||||
|
mv.visitCode();
|
||||||
|
StringerUtils.pushIntConstant(mv, keys.size());
|
||||||
|
mv.visitTypeInsn(ANEWARRAY, "[Ljava/lang/Object;");
|
||||||
|
int index = 0;
|
||||||
|
|
||||||
|
for (String key : keys) {
|
||||||
|
mv.visitInsn(DUP);
|
||||||
|
StringerUtils.pushIntConstant(mv, index++);
|
||||||
|
mv.visitInsn(ICONST_2);
|
||||||
|
mv.visitTypeInsn(ANEWARRAY, "java/lang/Object");
|
||||||
|
mv.visitInsn(DUP);
|
||||||
|
mv.visitInsn(ICONST_0);
|
||||||
|
String encryptedKey = AESFast.encryptString(
|
||||||
|
key, this.cryptoContainer.getRoundKeys(), this.cryptoContainer.getIvWords());
|
||||||
|
mv.visitLdcInsn(encryptedKey);
|
||||||
|
mv.visitMethodInsn(
|
||||||
|
INVOKESTATIC,
|
||||||
|
this.decoderClassName,
|
||||||
|
this.decoderMethodName,
|
||||||
|
"(Ljava/lang/Object;)Ljava/lang/String;",
|
||||||
|
false);
|
||||||
|
mv.visitInsn(AASTORE);
|
||||||
|
mv.visitInsn(DUP);
|
||||||
|
mv.visitInsn(ICONST_1);
|
||||||
|
String encryptedValue = AESFast.encryptString(
|
||||||
|
this.resourceBundle.getString(key),
|
||||||
|
this.cryptoContainer.getRoundKeys(),
|
||||||
|
this.cryptoContainer.getIvWords());
|
||||||
|
mv.visitLdcInsn(encryptedValue);
|
||||||
|
mv.visitMethodInsn(
|
||||||
|
INVOKESTATIC,
|
||||||
|
this.decoderClassName,
|
||||||
|
this.decoderMethodName,
|
||||||
|
"(Ljava/lang/Object;)Ljava/lang/String;",
|
||||||
|
false);
|
||||||
|
mv.visitInsn(AASTORE);
|
||||||
|
mv.visitInsn(AASTORE);
|
||||||
|
}
|
||||||
|
|
||||||
|
mv.visitInsn(ARETURN);
|
||||||
|
mv.visitMaxs(7, 1);
|
||||||
|
mv.visitEnd();
|
||||||
|
|
||||||
|
this.cv.visitEnd();
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,145 @@
|
|||||||
|
package com.licel.stringer.runtime;
|
||||||
|
|
||||||
|
import com.licel.stringer.model.ClassInfo;
|
||||||
|
import java.util.Properties;
|
||||||
|
import org.objectweb.asm.ClassVisitor;
|
||||||
|
import org.objectweb.asm.FieldVisitor;
|
||||||
|
import org.objectweb.asm.Label;
|
||||||
|
import org.objectweb.asm.MethodVisitor;
|
||||||
|
import org.objectweb.asm.Opcodes;
|
||||||
|
|
||||||
|
public class StringerFilterInputStreamCreator extends ClassVisitor implements Opcodes {
|
||||||
|
public static final Properties METHOD_MAPPINGS = new Properties();
|
||||||
|
public static final Properties FIELD_MAPPINGS = new Properties();
|
||||||
|
private final ClassInfo classInfo;
|
||||||
|
|
||||||
|
public StringerFilterInputStreamCreator(ClassVisitor classVisitor, ClassInfo classInfo) {
|
||||||
|
super(Opcodes.ASM9, classVisitor);
|
||||||
|
this.classInfo = classInfo;
|
||||||
|
this.generate();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void generate() {
|
||||||
|
this.cv.visit(
|
||||||
|
this.classInfo.classFileVersion,
|
||||||
|
ACC_PUBLIC | ACC_SUPER,
|
||||||
|
"com/licel/stringer/StringerFilterInputStreamPrototype",
|
||||||
|
null,
|
||||||
|
this.classInfo.superName,
|
||||||
|
null);
|
||||||
|
|
||||||
|
FieldVisitor fv = this.cv.visitField(0, "parent", "Lcom/licel/stringer/StringerInputStreamPrototype;", null, null);
|
||||||
|
fv.visitEnd();
|
||||||
|
fv = this.cv.visitField(ACC_PRIVATE, "singleByteBuf", "[B", null, null);
|
||||||
|
fv.visitEnd();
|
||||||
|
|
||||||
|
MethodVisitor mv = this.cv.visitMethod(
|
||||||
|
ACC_PUBLIC,
|
||||||
|
"<init>",
|
||||||
|
"(Ljava/io/InputStream;Lcom/licel/stringer/StringerInputStreamPrototype;)V",
|
||||||
|
null,
|
||||||
|
null);
|
||||||
|
mv.visitCode();
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitVarInsn(ALOAD, 1);
|
||||||
|
mv.visitMethodInsn(INVOKESPECIAL, "java/io/FilterInputStream", "<init>", "(Ljava/io/InputStream;)V", false);
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitInsn(ICONST_1);
|
||||||
|
mv.visitIntInsn(NEWARRAY, T_BYTE);
|
||||||
|
mv.visitFieldInsn(PUTFIELD, "com/licel/stringer/StringerFilterInputStreamPrototype", "singleByteBuf", "[B");
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitVarInsn(ALOAD, 2);
|
||||||
|
mv.visitFieldInsn(
|
||||||
|
PUTFIELD,
|
||||||
|
"com/licel/stringer/StringerFilterInputStreamPrototype",
|
||||||
|
"parent",
|
||||||
|
"Lcom/licel/stringer/StringerInputStreamPrototype;");
|
||||||
|
mv.visitInsn(RETURN);
|
||||||
|
mv.visitMaxs(2, 3);
|
||||||
|
mv.visitEnd();
|
||||||
|
|
||||||
|
mv = this.cv.visitMethod(
|
||||||
|
ACC_PUBLIC | ACC_SYNCHRONIZED,
|
||||||
|
"read",
|
||||||
|
"()I",
|
||||||
|
null,
|
||||||
|
new String[]{"java/io/IOException"});
|
||||||
|
mv.visitCode();
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitFieldInsn(GETFIELD, "com/licel/stringer/StringerFilterInputStreamPrototype", "singleByteBuf", "[B");
|
||||||
|
mv.visitInsn(ICONST_0);
|
||||||
|
mv.visitInsn(ICONST_1);
|
||||||
|
mv.visitMethodInsn(INVOKEVIRTUAL, "com/licel/stringer/StringerFilterInputStreamPrototype", "read", "([BII)I", false);
|
||||||
|
mv.visitInsn(ICONST_M1);
|
||||||
|
Label label0 = new Label();
|
||||||
|
mv.visitJumpInsn(IF_ICMPNE, label0);
|
||||||
|
mv.visitInsn(ICONST_M1);
|
||||||
|
Label label1 = new Label();
|
||||||
|
mv.visitJumpInsn(GOTO, label1);
|
||||||
|
mv.visitLabel(label0);
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitFieldInsn(GETFIELD, "com/licel/stringer/StringerFilterInputStreamPrototype", "singleByteBuf", "[B");
|
||||||
|
mv.visitInsn(ICONST_0);
|
||||||
|
mv.visitInsn(BALOAD);
|
||||||
|
mv.visitIntInsn(SIPUSH, 255);
|
||||||
|
mv.visitInsn(IAND);
|
||||||
|
mv.visitLabel(label1);
|
||||||
|
mv.visitInsn(IRETURN);
|
||||||
|
mv.visitMaxs(4, 1);
|
||||||
|
mv.visitEnd();
|
||||||
|
|
||||||
|
mv = this.cv.visitMethod(ACC_PUBLIC, "markSupported", "()Z", null, null);
|
||||||
|
mv.visitCode();
|
||||||
|
mv.visitInsn(ICONST_0);
|
||||||
|
mv.visitInsn(IRETURN);
|
||||||
|
mv.visitMaxs(1, 1);
|
||||||
|
mv.visitEnd();
|
||||||
|
|
||||||
|
mv = this.cv.visitMethod(ACC_PUBLIC, "read", "([B)I", null, new String[]{"java/io/IOException"});
|
||||||
|
mv.visitCode();
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitVarInsn(ALOAD, 1);
|
||||||
|
mv.visitInsn(ICONST_0);
|
||||||
|
mv.visitVarInsn(ALOAD, 1);
|
||||||
|
mv.visitInsn(ARRAYLENGTH);
|
||||||
|
mv.visitMethodInsn(INVOKEVIRTUAL, "com/licel/stringer/StringerFilterInputStreamPrototype", "read", "([BII)I", false);
|
||||||
|
mv.visitInsn(IRETURN);
|
||||||
|
mv.visitMaxs(4, 2);
|
||||||
|
mv.visitEnd();
|
||||||
|
|
||||||
|
mv = this.cv.visitMethod(ACC_PUBLIC, "read", "([BII)I", null, new String[]{"java/io/IOException"});
|
||||||
|
mv.visitCode();
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitVarInsn(ALOAD, 1);
|
||||||
|
mv.visitVarInsn(ILOAD, 2);
|
||||||
|
mv.visitVarInsn(ILOAD, 3);
|
||||||
|
mv.visitMethodInsn(INVOKESPECIAL, "java/io/FilterInputStream", "read", "([BII)I", false);
|
||||||
|
mv.visitVarInsn(ISTORE, 3);
|
||||||
|
mv.visitVarInsn(ILOAD, 3);
|
||||||
|
Label label2 = new Label();
|
||||||
|
mv.visitJumpInsn(IFLE, label2);
|
||||||
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
mv.visitFieldInsn(
|
||||||
|
GETFIELD,
|
||||||
|
"com/licel/stringer/StringerFilterInputStreamPrototype",
|
||||||
|
"parent",
|
||||||
|
"Lcom/licel/stringer/StringerInputStreamPrototype;");
|
||||||
|
mv.visitVarInsn(ALOAD, 1);
|
||||||
|
mv.visitVarInsn(ILOAD, 2);
|
||||||
|
mv.visitVarInsn(ILOAD, 3);
|
||||||
|
mv.visitMethodInsn(INVOKEVIRTUAL, "com/licel/stringer/StringerInputStreamPrototype", "decrypt", "([BII)V", false);
|
||||||
|
mv.visitLabel(label2);
|
||||||
|
mv.visitVarInsn(ILOAD, 3);
|
||||||
|
mv.visitInsn(IRETURN);
|
||||||
|
mv.visitMaxs(4, 4);
|
||||||
|
mv.visitEnd();
|
||||||
|
|
||||||
|
this.cv.visitEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
static {
|
||||||
|
FIELD_MAPPINGS.put("parent", "Lcom/licel/stringer/StringerInputStreamPrototype;");
|
||||||
|
FIELD_MAPPINGS.put("singleByteBuf", "[B");
|
||||||
|
}
|
||||||
|
}
|
||||||
Loaded 100 of 155 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user