mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-05-27 21:15:32 +08:00
Merge branch 'GP-3551_ghidra1_InternalProjectLinks'
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
/* ###
|
||||
* IP: GHIDRA
|
||||
* REVIEWED: YES
|
||||
*
|
||||
* 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.
|
||||
@@ -20,48 +19,56 @@
|
||||
import ghidra.app.script.GhidraScript;
|
||||
import ghidra.framework.model.*;
|
||||
import ghidra.framework.plugintool.PluginTool;
|
||||
import ghidra.program.database.ProgramContentHandler;
|
||||
import ghidra.util.InvalidNameException;
|
||||
import ghidra.util.exception.CancelledException;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class RenameProgramsInProjectScript extends GhidraScript {
|
||||
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
|
||||
if ( currentProgram != null ) {
|
||||
popup( "This script should be run from a tool with no open programs" );
|
||||
return;
|
||||
}
|
||||
|
||||
PluginTool tool = state.getTool();
|
||||
Project project = tool.getProject();
|
||||
ProjectData projectData = project.getProjectData();
|
||||
DomainFolder rootFolder = projectData.getRootFolder();
|
||||
recurseProjectFolder( rootFolder );
|
||||
}
|
||||
|
||||
private void recurseProjectFolder( DomainFolder domainFolder ) {
|
||||
DomainFile[] files = domainFolder.getFiles();
|
||||
for ( DomainFile domainFile : files ) {
|
||||
processDomainFile( domainFile );
|
||||
}
|
||||
DomainFolder[] folders = domainFolder.getFolders();
|
||||
for ( DomainFolder folder : folders ) {
|
||||
recurseProjectFolder( folder );
|
||||
}
|
||||
}
|
||||
|
||||
private void processDomainFile( DomainFile domainFile ) {
|
||||
String oldName = domainFile.getName();
|
||||
try {
|
||||
domainFile.setName( oldName + "_renamed" );
|
||||
}
|
||||
catch ( InvalidNameException e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch ( IOException e ) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
|
||||
if (currentProgram != null) {
|
||||
popup("This script should be run from a tool with no open programs.\n" +
|
||||
"Warning! If using file-links to programs within this project such linkages will break.");
|
||||
return;
|
||||
}
|
||||
|
||||
PluginTool tool = state.getTool();
|
||||
Project project = tool.getProject();
|
||||
ProjectData projectData = project.getProjectData();
|
||||
DomainFolder rootFolder = projectData.getRootFolder();
|
||||
recurseProjectFolder(rootFolder);
|
||||
}
|
||||
|
||||
private void recurseProjectFolder(DomainFolder domainFolder) throws CancelledException {
|
||||
DomainFile[] files = domainFolder.getFiles();
|
||||
for (DomainFile domainFile : files) {
|
||||
monitor.checkCancelled();
|
||||
processDomainFile(domainFile);
|
||||
}
|
||||
DomainFolder[] folders = domainFolder.getFolders();
|
||||
for (DomainFolder folder : folders) {
|
||||
monitor.checkCancelled();
|
||||
recurseProjectFolder(folder);
|
||||
}
|
||||
}
|
||||
|
||||
private void processDomainFile(DomainFile domainFile) {
|
||||
if (!ProgramContentHandler.PROGRAM_CONTENT_TYPE.equals(domainFile.getContentType())) {
|
||||
return;
|
||||
}
|
||||
String oldName = domainFile.getName();
|
||||
try {
|
||||
domainFile.setName(oldName + "_renamed");
|
||||
}
|
||||
catch (InvalidNameException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,6 +102,8 @@ public class RepositoryFileUpgradeScript extends GhidraScript {
|
||||
}
|
||||
|
||||
private int listCheckouts(DomainFolder folder) throws IOException, CancelledException {
|
||||
// Avoid following folder-links so we don't count the same file more than once.
|
||||
// Link-files will never be in a checked-out state.
|
||||
int count = 0;
|
||||
for (DomainFile df : folder.getFiles()) {
|
||||
monitor.checkCancelled();
|
||||
@@ -115,8 +117,8 @@ public class RepositoryFileUpgradeScript extends GhidraScript {
|
||||
}
|
||||
|
||||
private int listCheckouts(DomainFile df) throws IOException {
|
||||
if (!df.isVersioned()) {
|
||||
return 0;
|
||||
if (!df.isVersioned() || df.isLink()) {
|
||||
return 0; // ignore non-versioned files and link-files
|
||||
}
|
||||
int count = 0;
|
||||
for (ItemCheckoutStatus checkout : df.getCheckouts()) {
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
* 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.
|
||||
@@ -27,7 +27,6 @@ public class VersionControl_ResetAll extends GhidraScript {
|
||||
public VersionControl_ResetAll() {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void run() throws Exception {
|
||||
|
||||
@@ -54,7 +53,8 @@ public class VersionControl_ResetAll extends GhidraScript {
|
||||
if (monitor.isCancelled()) {
|
||||
break;
|
||||
}
|
||||
|
||||
// Do not follow folder-links or consider program links. Checking the content type
|
||||
// is the best way to restrict this.
|
||||
if (!ProgramContentHandler.PROGRAM_CONTENT_TYPE.equals(file.getContentType()) ||
|
||||
!file.isVersioned() || file.getLatestVersion() < 2) {
|
||||
continue;// skip
|
||||
|
||||
Reference in New Issue
Block a user