Skip to content

Commit

Permalink
Version 1.10
Browse files Browse the repository at this point in the history
Possible fix to CustomLogger not logging as UTF-8
Functions without parameters should now be parsed properly
Added a TODO comment to StatementFactory
Added comment to IdFetcherTool
Fixed an exception in the JavaAnalyzer tool
Fixed an issue in FilesCodeAnalyzer where other code blocks would get ran even though they weren't supposed to
Fixed typo in SQLCodeAnalyzer
Fixed casting issue in ThreadCodeAnalyzer
Fixed typo in ZipEntryCodeAnalyzer
Fixed issue in VBSAnalyzer where comments weren't being logged properly
  • Loading branch information
OpticFusion1 committed Oct 6, 2022
1 parent 2957dac commit 9280117
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>optic_fusion1</groupId>
<artifactId>Kitsune</artifactId>
<version>1.9</version>
<version>1.10</version>

<build>
<resources>
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/optic_fusion1/kitsune/logging/CustomLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.text.MessageFormat;
import java.time.LocalDate;
Expand Down Expand Up @@ -86,7 +87,7 @@ private void startAsyncWriter() {

private void createNewFileWriter() {
try {
fileWriter = new BufferedWriter(new FileWriter(currentLogFile, true));
fileWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(currentLogFile), StandardCharsets.UTF_8));
} catch (IOException e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,22 +47,25 @@ Public Property Set AutomationSecurity(objMsoAutomationSecurity)
Set p_Excel.AutomationSecurity = objMsoAutomationSecurity
End Property
*/
*/
public class StatementFactory {


/*
TODO: Implement support for
Function FUNCTIONNAME
// Statements
End Function
*/
// TODO: Find a way to make a private static final Pattern variable for this classes's regex
// TODO: Add support for getting if the function is Public, Private, or neither
// TODO: Verify this works w/ every function statement possibility
public static Function buildFunctionStatements(int index, String line) {
Pattern pattern = Pattern.compile("( +.*?)\\(", Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(line);
matcher.find();
if (matcher.groupCount() == 1) {
pattern = Pattern.compile("Function (.+)", Pattern.CASE_INSENSITIVE);
matcher = pattern.matcher(line);
matcher.find();
Function function = new Function(matcher.group(1));
function.setLineNumber(index);
function.setText(line);
return function;
}
Function func = new Function(matcher.group(1));
func.setLineNumber(index);
func.setText(line);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ private List<String> visitContainersAndExtractRecursively(List<String> stmtList,
return parsedStmtList;

}

public ConstantPool getConstantPool() {
return CONSTANT_POOL;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import static optic_fusion1.kitsune.Kitsune.LOGGER;
import optic_fusion1.kitsune.tool.Tool;
import static optic_fusion1.kitsune.util.I18n.tl;
import optic_fusion1.kitsune.util.Utils;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.IOUtils;
Expand Down Expand Up @@ -96,7 +97,8 @@ private void handleFile(File file) {
// TODO: Handle nested entries
LOGGER.info(entry.getName() + " is actually a ZipFile.");
}
LOGGER.info(entry.getName() + ": " + DigestUtils.sha1Hex(entry.getName()));
// Don't SHA1 the entry itself. While it's possible there'll be false-positives depending on how this is used, it'll at least stay consistent
LOGGER.info(entry.getName() + ": " + DigestUtils.sha1Hex(Utils.normalize(entry.getName())));
}
} catch (IOException ex) {
LOGGER.exception(ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,12 @@ public void analyze(File file) {
analyzer.analyze(file);
}
LOGGER.info(tl("ja_gathering_class_nodes", file.toPath()));
List<ClassNode> classNodes = getClassNodesFromFile(file);
List<ClassNode> classNodes = new ArrayList<>();
try {
classNodes = getClassNodesFromFile(file);
} catch (Exception e) {

}
if (classNodes.isEmpty()) {
LOGGER.warn(tl("ja_class_nodes_not_found", file.toPath()));
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,18 @@ public void analyze(ClassNode classNode, MethodNode methodNode, MethodInsnNode m
}
if (isMethodInsnNodeCorrect(methodInsnNode, "createFile", "(Ljava/nio/file/Path;[Ljava/nio/file/attribute/FileAttribute;)Ljava/nio/file/Path;")) {
log(classNode, methodNode, methodInsnNode, tl("fsca_creates_file"));
return;
}
if (isMethodInsnNodeCorrect(methodInsnNode, "setAttribute",
"(Ljava/nio/file/Path;Ljava/lang/String;Ljava/lang/Object;[Ljava/nio/file/LinkOption;)Ljava/nio/file/Path;")) {
AbstractInsnNode minus5 = methodInsnNode.getPrevious().getPrevious().getPrevious().getPrevious().getPrevious();
if (!(isAbstractNodeString(minus5))) {
log(classNode, methodNode, methodInsnNode, tl("fsca_file_attribute_set"));
return;
}
String attribute = (String) ((LdcInsnNode) minus5).cst;
log(classNode, methodNode, methodInsnNode, tl("fsca_known_file_attribute_set", attribute));
return;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void analyze(ClassNode classNode, MethodNode methodNode, MethodInsnNode m
if (isMethodInsnNodeCorrect(methodInsnNode, "prepareStatement", "(Ljava/lang/String;)Ljava/sql/PreparedStatement;")) {
AbstractInsnNode minus1 = methodInsnNode.getPrevious();
if (!isAbstractNodeString(minus1)) {
log(classNode, methodNode, methodInsnNode, tl("sqlca_pa_credted"));
log(classNode, methodNode, methodInsnNode, tl("sqlca_ps_created"));
return;
}
String statement = (String) ((LdcInsnNode) minus1).cst;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public void analyze(ClassNode classNode, MethodNode methodNode, MethodInsnNode m
log(classNode, methodNode, methodInsnNode, tl("thread_interrupted"));
return;
}
if (!(minus1 instanceof MethodInsnNode)) {
log(classNode, methodNode, methodInsnNode, tl("thread_interrupted"));
return;
}
if (isMethodInsnNodeCorrect((MethodInsnNode) minus1, "currentThread", "()Ljava/lang/Thread;")) {
log(classNode, methodNode, methodInsnNode, tl("current_thread_interrupted"));
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void analyze(ClassNode classNode, MethodNode methodNode, MethodInsnNode m
return;
}
String zipEntryName = (String) ((LdcInsnNode) minus1).cst;
log(classNode, methodNode, methodInsnNode, tl("zeca_named_zipentry_initalized", zipEntryName));
log(classNode, methodNode, methodInsnNode, tl("zeca_named_zipentry_initialized", zipEntryName));
return;
}
if (isMethodInsnNodeCorrect(methodInsnNode, "getName", "()Ljava/lang/String;")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void analyze(File input) {
continue;
}
if (statement instanceof Comment comment) {
LOGGER.info("Comment: " + comment.getText());
LOGGER.info("Comment: " + comment.value());
}
if (statement instanceof VariableInit stmnt) {
LOGGER.info("Name: " + stmnt.getName() + " Variable Type: " + stmnt.getVariableType());
Expand Down

0 comments on commit 9280117

Please sign in to comment.