Skip to content

Commit

Permalink
Handle changes to allow for certification headers on bash type source
Browse files Browse the repository at this point in the history
files (e.g., *.py) and gradle files
  • Loading branch information
ghidra1 committed Mar 17, 2021
1 parent cafa27a commit d2c3951
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 10 deletions.
1 change: 0 additions & 1 deletion gradle/certification.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ support/distributionCommon.gradle||GHIDRA||||END|
support/eclipseLauncher.gradle||GHIDRA||||END|
support/extensionCommon.gradle||GHIDRA||||END|
support/fetchDependencies.gradle||GHIDRA||||END|
support/ip.gradle||GHIDRA||||END|
support/jacoco.excludes.src.txt||GHIDRA||||END|
support/loadApplicationProperties.gradle||GHIDRA||||END|
support/settingsUtil.gradle||GHIDRA||||END|
Expand Down
57 changes: 48 additions & 9 deletions gradle/support/ip.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@

/* ###
* IP: GHIDRA
*
* 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
*
* http://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.
*/
/*********************************************************************************
* ip.gradle
*
Expand Down Expand Up @@ -152,12 +166,13 @@ def addToMap(Map<String, List<String>> map, String ip, String path) {
/*********************************************************************************
* checks if a file supports a C style header based on its extension.
*********************************************************************************/
def isSourceFile(File file) {
def isCSourceFile(File file) {

String filename = file.getName().toLowerCase();

return filename.endsWith(".java") ||
filename.endsWith(".c") ||
filename.endsWith(".gradle") ||
filename.endsWith(".groovy") ||
filename.endsWith(".cpp") ||
filename.endsWith(".cc") ||
Expand All @@ -166,29 +181,53 @@ def isSourceFile(File file) {
filename.endsWith(".l") ||
filename.endsWith(".hh") ||
filename.endsWith(".css") ||
filename.endsWith(".jj");
filename.endsWith(".jj") ||
filename.endsWith(".proto");
}

/*********************************************************************************
* checks if a file supports a Bash style header based on its extension.
*********************************************************************************/
def isBashSourceFile(File file) {

String filename = file.getName().toLowerCase();

// NOTE: bash/shell scripts without extension will not utilize a header
return filename.endsWith(".py") ||
filename.endsWith(".sh") ||
filename.endsWith(".bash") ||
filename.endsWith(".command");
}


/*********************************************************************************
* Gets the ip for a file in the module from its header (or certification.manifest
* Gets the ip for a file in the module from its header (or certification.manifest)
*********************************************************************************/
def getIp(File projectDir, File file) {
if (isSourceFile(file)) {
return getIpForSourceFile(file);
if (isCSourceFile(file)) {
return getIpForSourceFile(file, " * IP:");
}
if (isBashSourceFile(file)) {
String ip = getIpForSourceFile(file, "# IP:");
// allow transition from certification.manifest entry
if (ip != null) {
return ip;
}
}
return getIpForNonSourceFile(projectDir, file);
}

/*********************************************************************************
* Gets the ip from a file that has a certification header
*********************************************************************************/
def getIpForSourceFile(File file) {
def getIpForSourceFile(File file, String prefix) {
// IP marking occurs within first 4-lines of file
String ip =null
String line;
int lineNum = 0;
file.withReader { reader ->
while((line = reader.readLine()) != null) {
if (line.startsWith(" * IP:")) {
while(++lineNum < 5 && (line = reader.readLine()) != null) {
if (line.startsWith(prefix)) {
ip = line.substring(7).trim();
break;
}
Expand Down

0 comments on commit d2c3951

Please sign in to comment.