15
15
*/
16
16
package ghidra .app .plugin .core .analysis ;
17
17
18
- import java .io .IOException ;
19
- import java .util .ArrayList ;
20
- import java .util .List ;
21
-
22
18
import ghidra .app .services .*;
23
19
import ghidra .app .util .importer .MessageLog ;
24
- import ghidra .app .util .opinion .* ;
25
- import ghidra .framework . model .* ;
20
+ import ghidra .app .util .opinion .ElfLoader ;
21
+ import ghidra .app . util . opinion . MachoLoader ;
26
22
import ghidra .framework .options .Options ;
27
23
import ghidra .program .model .address .AddressSetView ;
28
- import ghidra .program .model .listing .Library ;
29
24
import ghidra .program .model .listing .Program ;
30
25
import ghidra .program .util .ExternalSymbolResolver ;
26
+ import ghidra .util .Msg ;
31
27
import ghidra .util .exception .CancelledException ;
32
- import ghidra .util .exception .VersionException ;
33
28
import ghidra .util .task .TaskMonitor ;
34
29
35
30
/**
@@ -61,7 +56,7 @@ public boolean canAnalyze(Program program) {
61
56
if (program .getDomainFile ().getParent () == null ) {
62
57
return false ;
63
58
}
64
-
59
+
65
60
Options options = program .getOptions (Program .PROGRAM_INFO );
66
61
String format = options .getString ("Executable Format" , null );
67
62
return ElfLoader .ELF_NAME .equals (format ) || MachoLoader .MACH_O_NAME .equals (format );
@@ -71,65 +66,16 @@ public boolean canAnalyze(Program program) {
71
66
public boolean added (Program program , AddressSetView set , TaskMonitor monitor , MessageLog log )
72
67
throws CancelledException {
73
68
74
- Object consumer = new Object ();
75
- log = new MessageLog (); // For now, we don't want the analysis log spammed
76
- ProjectData projectData = program .getDomainFile ().getParent ().getProjectData ();
77
- List <Loaded <Program >> loadedPrograms = new ArrayList <>();
78
-
79
- // Add program to list
80
- loadedPrograms .add (new Loaded <>(program , program .getName (),
81
- program .getDomainFile ().getParent ().getPathname ()));
82
-
83
- // Add external libraries to list
84
- for (Library extLibrary : ExternalSymbolResolver .getLibrarySearchList (program )) {
85
- monitor .checkCancelled ();
86
- String libPath = extLibrary .getAssociatedProgramPath ();
87
- if (libPath == null ) {
88
- continue ;
89
- }
90
-
91
- DomainFile libDomainFile = projectData .getFile (libPath );
92
- if (libDomainFile == null ) {
93
- log .appendMsg ("Referenced external program not found: " + libPath );
94
- continue ;
95
- }
96
-
97
- try {
98
- DomainObject libDomainObject =
99
- libDomainFile .getDomainObject (consumer , false , false , monitor );
100
- if (libDomainObject instanceof Program p ) {
101
- loadedPrograms .add (new Loaded <>(p , libDomainFile .getName (),
102
- libDomainFile .getParent ().getPathname ()));
103
- }
104
- else {
105
- libDomainObject .release (consumer );
106
- log .appendMsg ("Referenced external program is not a program: " + libPath );
107
- }
69
+ try (ExternalSymbolResolver esr = new ExternalSymbolResolver (
70
+ program .getDomainFile ().getParent ().getProjectData (), monitor )) {
71
+ esr .addProgramToFixup (program );
72
+ esr .fixUnresolvedExternalSymbols ();
73
+ esr .logInfo (s -> Msg .info (this , s ), false );
74
+ if (esr .hasProblemLibraries ()) {
75
+ // causes a popup message at end of analysis session
76
+ esr .logInfo (log ::appendMsg , true );
108
77
}
109
- catch (IOException e ) {
110
- log .appendMsg ("Failed to open library dependency project file: " +
111
- libDomainFile .getPathname ());
112
- }
113
- catch (VersionException e ) {
114
- log .appendMsg (
115
- "Referenced external program requires updgrade, unable to consider symbols: " +
116
- libPath );
117
- }
118
- }
119
-
120
- // Resolve symbols
121
- try {
122
- ExternalSymbolResolver .fixUnresolvedExternalSymbols (loadedPrograms , false , log ,
123
- monitor );
124
78
return true ;
125
79
}
126
- catch (IOException e ) {
127
- return false ;
128
- }
129
- finally {
130
- for (int i = 1 ; i < loadedPrograms .size (); i ++) {
131
- loadedPrograms .get (i ).release (consumer );
132
- }
133
- }
134
80
}
135
81
}
0 commit comments