-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for configuration file (#41)
* init commit Ghidrathon configuration * adding default configuration file * adding comments and unit tests
- Loading branch information
1 parent
d1182c0
commit 939952c
Showing
9 changed files
with
400 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<GHIDRATHON_CONFIG> | ||
<ARRAY NAME="JAVA_EXCLUDE_LIBS" TYPE="string"> | ||
<A VALUE="pdb" /> | ||
</ARRAY> | ||
<ARRAY NAME="PYTHON_SHARED_MODULES" TYPE="string"> | ||
<A VALUE="numpy" /> | ||
</ARRAY> | ||
<ARRAY NAME="PYTHON_INCLUDE_PATHS" TYPE="string"> | ||
</ARRAY> | ||
</GHIDRATHON_CONFIG> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Copyright (C) 2022 Mandiant, Inc. All Rights Reserved. | ||
# 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: [package root]/LICENSE.txt | ||
# 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. | ||
|
||
"""Unit tests to verify CPython modules | ||
Note: you must run these tests from the Ghidra script manager or headless mode | ||
""" | ||
|
||
import unittest | ||
import warnings | ||
|
||
|
||
class TestCPython(unittest.TestCase): | ||
def test_numpy(self): | ||
try: | ||
import numpy | ||
|
||
a = numpy.array(["cat", "dog"]) | ||
except ImportError: | ||
warnings.warn("numpy module is not installed - ignoring test") | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (C) 2022 Mandiant, Inc. All Rights Reserved. | ||
// 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: [package root]/LICENSE.txt | ||
// 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. | ||
|
||
package ghidrathon; | ||
|
||
import java.util.List; | ||
import java.util.ArrayList; | ||
|
||
import jep.ClassList; | ||
import jep.ClassEnquirer; | ||
|
||
/** | ||
* Implements Jep ClassEnquirer used to handle Java imports from Python - specifically we | ||
* use this class to handle naming conflicts, e.g. pdb | ||
*/ | ||
public class GhidrathonClassEnquirer implements ClassEnquirer { | ||
|
||
private final List<String> javaExcludeLibs = new ArrayList<String>(); | ||
private final ClassEnquirer classList = ClassList.getInstance(); | ||
|
||
public void addJavaExcludeLib(String name) { | ||
javaExcludeLibs.add(name); | ||
} | ||
|
||
public void addJavaExcludeLibs(List<String> names) { | ||
javaExcludeLibs.addAll(names); | ||
} | ||
|
||
public boolean isJavaPackage(String name) { | ||
if (javaExcludeLibs.contains(name)) { | ||
return false; | ||
} | ||
|
||
return classList.isJavaPackage(name); | ||
} | ||
|
||
public String[] getClassNames(String name) { | ||
return classList.getClassNames(name); | ||
} | ||
|
||
public String[] getSubPackages(String name) { | ||
return classList.getSubPackages(name); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Copyright (C) 2022 Mandiant, Inc. All Rights Reserved. | ||
// 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: [package root]/LICENSE.txt | ||
// 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. | ||
|
||
package ghidrathon; | ||
|
||
import java.util.List; | ||
import java.io.PrintWriter; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
|
||
/** | ||
* Ghidrathon's configuration class | ||
* | ||
* Stores | ||
* - stdout and stderr | ||
* - Python modules to handle as shared modules - relevant to CPython modules | ||
* - Java package names to exclude from Python imports | ||
* - Python include paths to add to Python interpreter environment | ||
*/ | ||
public class GhidrathonConfig { | ||
|
||
private final List<String> javaExcludeLibs = new ArrayList<String>(); | ||
private final List<String> pyIncludePaths = new ArrayList<String>(); | ||
private final List<String> pySharedModules = new ArrayList<String>(); | ||
|
||
private PrintWriter out = null; | ||
private PrintWriter err = null; | ||
|
||
public void addStdOut(PrintWriter out) { | ||
this.out = out; | ||
} | ||
|
||
public void addStdErr(PrintWriter err) { | ||
this.err = err; | ||
} | ||
|
||
public PrintWriter getStdOut() { | ||
return out; | ||
} | ||
|
||
public PrintWriter getStdErr() { | ||
return err; | ||
} | ||
|
||
public void addPythonSharedModule(String name) { | ||
pySharedModules.add(name); | ||
} | ||
|
||
public void addPythonSharedModules(List<String> names) { | ||
pySharedModules.addAll(names); | ||
} | ||
|
||
public Iterable<String> getPythonSharedModules() { | ||
return Collections.unmodifiableList(pySharedModules); | ||
} | ||
|
||
public void addJavaExcludeLib(String name) { | ||
javaExcludeLibs.add(name); | ||
} | ||
|
||
public void addJavaExcludeLibs(List<String> names) { | ||
javaExcludeLibs.addAll(names); | ||
} | ||
|
||
public Iterable<String> getJavaExcludeLibs() { | ||
return Collections.unmodifiableList(javaExcludeLibs); | ||
} | ||
|
||
public void addPythonIncludePath(String path) { | ||
pyIncludePaths.add(path); | ||
} | ||
|
||
public void addPythonIncludePaths(List<String> paths) { | ||
pyIncludePaths.addAll(paths); | ||
} | ||
|
||
public Iterable<String> getPythonIncludePaths() { | ||
return Collections.unmodifiableList(pyIncludePaths); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.