2727import ghidra .app .util .importer .MessageLog ;
2828import ghidra .app .util .opinion .AbstractLibrarySupportLoader ;
2929import ghidra .app .util .opinion .LoadSpec ;
30- import ghidra .app .util .opinion .QueryOpinionService ;
31- import ghidra .app .util .opinion .QueryResult ;
3230import ghidra .framework .model .DomainObject ;
3331import ghidra .program .model .address .Address ;
3432import ghidra .program .model .address .AddressOverflowException ;
3533import ghidra .program .model .data .DataType ;
3634import ghidra .program .model .data .DataTypeConflictException ;
3735import ghidra .program .model .data .DataUtilities ;
3836import ghidra .program .model .data .DataUtilities .ClearDataMode ;
37+ import ghidra .program .model .lang .LanguageCompilerSpecPair ;
3938import ghidra .program .model .listing .Data ;
4039import ghidra .program .model .listing .Listing ;
4140import ghidra .program .model .listing .Program ;
41+ import ghidra .program .model .util .AddressSetPropertyMap ;
4242import ghidra .program .model .util .CodeUnitInsertionException ;
4343import ghidra .util .Msg ;
4444import ghidra .util .exception .CancelledException ;
@@ -62,15 +62,9 @@ public Collection<LoadSpec> findSupportedLoadSpecs(ByteProvider provider) throws
6262 BinaryReader reader = new BinaryReader (provider , true );
6363 ESP8266Header header = new ESP8266Header (reader );
6464 if (ESP8266Constants .ESP_MAGIC_BASE == header .getMagic ()) {
65- Msg .info (this , "Magic Matched" );
66- List <QueryResult > queries =
67- QueryOpinionService .query (getName (), ESP8266Constants .PRIMARY_KEY , null );
68- for (QueryResult result : queries ) {
69- loadSpecs .add (new LoadSpec (this , 0 , result ));
70- }
71- if (loadSpecs .isEmpty ()) {
72- loadSpecs .add (new LoadSpec (this , 0 , true ));
73- }
65+ Msg .info (this , "ESP Magic Matched" );
66+ loadSpecs .add (new LoadSpec (this , 0 ,
67+ new LanguageCompilerSpecPair ("Xtensa:LE:32:default" , "default" ), true ));
7468 }
7569 return loadSpecs ;
7670 }
@@ -102,24 +96,50 @@ private void markupHeader(Program program, ESP8266Header header, TaskMonitor mon
10296 }
10397 }
10498
99+ private void markAsCode (Program program , Address address ) {
100+ AddressSetPropertyMap codeProp = program .getAddressSetPropertyMap ("CodeMap" );
101+ if (codeProp == null ) {
102+ try {
103+ codeProp = program .createAddressSetPropertyMap ("CodeMap" );
104+ }
105+ catch (DuplicateNameException e ) {
106+ codeProp = program .getAddressSetPropertyMap ("CodeMap" );
107+ }
108+ }
109+
110+ if (codeProp != null ) {
111+ codeProp .add (address , address );
112+ }
113+ }
114+
105115 private void markupSections (Program program , ESP8266Module module , TaskMonitor monitor , InputStream reader ) throws DuplicateNameException , IOException , AddressOverflowException {
106116 boolean r = true ;
107117 boolean w = true ;
108118 boolean x = true ;
109119 String BLOCK_SOURCE_NAME = "ESP8266 Section" ;
110120 for (ESP8266Section section : module .getSections ()) {
111121 Address start = program .getAddressFactory ().getDefaultAddressSpace ().getAddress (section .getOffset ());
122+ Msg .info (this , String .format ("Section at offset %08x, size %d" , start .getOffset (), section .getSize ()));
112123 mbu .createInitializedBlock (section .getName (), start , reader , section .getSize (), "" , BLOCK_SOURCE_NAME , r , w , x , monitor );
113124 createData (program , program .getListing (), start , section .toDataType ());
125+ // Mark code sections
126+ if (section .getType () == ESP8266Constants .SECTION_TYPE_CODE )
127+ {
128+ Msg .info (this , "Section is code" );
129+ markAsCode (program , start );
130+ }
131+ else
132+ {
133+ Msg .info (this , "Section is not code" );
134+ }
114135 }
115136 }
116137
117138 public Data createData (Program program , Listing listing , Address address , DataType dt ) {
118139 try {
119140 Data d = listing .getDataAt (address );
120141 if (d == null || !dt .isEquivalent (d .getDataType ())) {
121- d = DataUtilities .createData (program , address , dt , -1 , false ,
122- ClearDataMode .CLEAR_ALL_UNDEFINED_CONFLICT_DATA );
142+ d = DataUtilities .createData (program , address , dt , -1 , false , ClearDataMode .CLEAR_ALL_UNDEFINED_CONFLICT_DATA );
123143 }
124144 return d ;
125145 }
@@ -148,15 +168,9 @@ protected void load(ByteProvider provider, LoadSpec loadSpec, List<Option> optio
148168 BinaryReader reader = new BinaryReader ( provider , true );
149169 ESP8266Module module = new ESP8266Module ( reader );
150170
151- // createMethodLookupMemoryBlock( program, monitor );
152- // createMethodByteCodeBlock( program, length, monitor);
153171 markupHeader (program , module .getHeader (), monitor , inputStream );
154172 markupSections (program , module , monitor , inputStream );
155- monitor .setMessage ( "ESP8266 Loader: Create byte code" );
156173
157- for (ESP8266Section section : module .getSections ()) {
158- monitor .setMessage ("Loaded " + section .getName ());
159- }
160174 // Create entry point
161175 Address entryAddress = program .getAddressFactory ().getDefaultAddressSpace ().getAddress (module .getHeader ().getEntrypoint (), true );
162176 program .getSymbolTable ().addExternalEntryPoint (entryAddress );
0 commit comments