-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Various changes to support automatically pulling sets of paths to use… #30
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,3 +100,6 @@ build/ | |
|
||
# Gradle | ||
.gradle/ | ||
|
||
.idea/.name | ||
.idea/compiler.xml |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -385,6 +385,9 @@ public void injectFakeKeys() { | |
int sizeValue = Utils.getRandomNumberInRange(10, 30); | ||
String randomValue = TextUtils.getRandomString(sizeValue, TextUtils.KEY_CHARACTERS); | ||
|
||
System.out.println("Injecting fake param: " + fakeParamName); | ||
System.out.println("Injecting fake randomValue: " + randomValue); | ||
|
||
injectFakeKeys(fakeParamName, randomValue); | ||
} | ||
|
||
|
@@ -398,8 +401,13 @@ public void injectFakeKeys(String fakeParamName, String randomValue) { | |
ArrayList<CodeBlock> classBlocks = getBlocksByType(CodeBlock.BlockType.Class); | ||
ArrayList<CodeBlock> functions = getFunctions(); | ||
|
||
System.out.println("classBlocks size: " + classBlocks.size()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||
System.out.println("functions size: " + functions.size()); | ||
|
||
if (Utils.arrayNotEmpty(classBlocks) && Utils.arrayNotEmpty(functions)) { | ||
|
||
System.out.println("Utils.arrayNotEmpty(classBlocks) && Utils.arrayNotEmpty(functions) PASSED"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||
|
||
// Generate fake code: | ||
String fakeAttribute = getFakeAttribute(fakeParamName, randomValue); | ||
CodeBlock fakeCode = getFakeCode(fakeParamName); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
import org.gradle.api.DefaultTask; | ||
import org.gradle.api.tasks.TaskAction; | ||
import org.apache.commons.io.FileUtils; | ||
import org.gradle.internal.Pair; | ||
|
||
import javax.inject.Inject; | ||
import java.io.File; | ||
|
@@ -47,16 +48,19 @@ public void encrypt() throws Exception { | |
return; | ||
} | ||
|
||
for (File javaFile : this.getAllJavaFiles()) { | ||
for (Pair<Integer, File> pair : this.getAllJavaFiles()) { | ||
File javaFile = pair.right; | ||
assert javaFile != null; | ||
if (!isSelected(javaFile) || isIgnored(javaFile)) { | ||
System.out.println("\uD83D\uDEAB️ " + javaFile.getName() + " ignored"); | ||
} else { | ||
encryptJavaFile(javaFile); | ||
encryptJavaFile(pair); | ||
} | ||
} | ||
} | ||
|
||
private boolean isSelected(File javaFile) { | ||
System.out.println("Enigma: Checking isSelected: " + javaFile.getAbsolutePath()); | ||
if (this.classes != null) { | ||
for (String ignored : this.classes) { | ||
String path = ignored.replace(".", File.separator) | ||
|
@@ -71,6 +75,7 @@ private boolean isSelected(File javaFile) { | |
} | ||
|
||
private boolean isIgnored(File javaFile) { | ||
System.out.println("Enigma: Checking isIgnored: " + javaFile.getAbsolutePath()); | ||
if (this.ignoredClasses != null) { | ||
for (String ignored : this.ignoredClasses) { | ||
String path = ignored.replace(".", File.separator) | ||
|
@@ -83,7 +88,13 @@ private boolean isIgnored(File javaFile) { | |
return false; | ||
} | ||
|
||
private void encryptJavaFile(File srcFile) throws Exception { | ||
private void encryptJavaFile(Pair<Integer, File> pair) throws Exception { | ||
assert pair != null; | ||
assert pair.right != null; | ||
assert pair.left != null; | ||
|
||
File srcFile = pair.right; | ||
int srcIteration = pair.left; | ||
|
||
if (isEnigmaFile(srcFile)) return; | ||
if (isEnigmatized(srcFile)) { | ||
|
@@ -96,10 +107,16 @@ private void encryptJavaFile(File srcFile) throws Exception { | |
JavaParser p = new JavaParser(); | ||
JavaCode code = p.parse(contents); | ||
|
||
code.addImport(InjectCodeTask.PACKAGE_NAME + "." + InjectCodeTask.CLASS_NAME); | ||
// Change the statement per the 'iteration' of the src | ||
String importPackageStatement = InjectCodeTask.PACKAGE_NAME + "_" + srcIteration + "." + InjectCodeTask.CLASS_NAME; | ||
|
||
code.addImport(importPackageStatement); | ||
code.encryptStrings(hash, InjectCodeTask.FUNCTION_NAME); | ||
|
||
if (injectFakeKeys) code.injectFakeKeys(); | ||
if (injectFakeKeys) { | ||
System.out.println("INJECTING FAKE KEYS"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above. |
||
code.injectFakeKeys(); | ||
} | ||
|
||
String contentSecured = code.toCode(); | ||
FileUtils.writeStringToFile(srcFile, contentSecured, "UTF-8"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debugging stuff, to be removed.