Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions GhidraESP8266_2/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ bin
.settings
.classpath
.project
build/
dist/
.gradle
gradle.properties
.vscode/
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
import java.io.InputStream;
import java.util.*;

import ghidra.app.util.MemoryBlockUtil;
import ghidra.app.util.MemoryBlockUtils;
import ghidra.app.util.Option;
import ghidra.app.util.bin.BinaryReader;
import ghidra.app.util.bin.ByteProvider;
import ghidra.app.util.importer.MemoryConflictHandler;
import ghidra.app.util.importer.MessageLog;
import ghidra.app.util.opinion.AbstractLibrarySupportLoader;
import ghidra.app.util.opinion.LoadSpec;
Expand All @@ -49,7 +48,6 @@
* TODO: Provide class-level documentation that describes what this loader does.
*/
public class GhidraESP8266_2Loader extends AbstractLibrarySupportLoader {
private MemoryBlockUtil mbu;

@Override
public String getName() {
Expand Down Expand Up @@ -81,14 +79,14 @@ public List<Option> getDefaultOptions(ByteProvider provider, LoadSpec loadSpec,
return list;
}

private void markupHeader(Program program, ESP8266Header header, TaskMonitor monitor, InputStream reader) throws DuplicateNameException, IOException {
private void markupHeader(Program program, ESP8266Header header, TaskMonitor monitor, InputStream reader, MessageLog log) throws DuplicateNameException, IOException {
boolean r = true;
boolean w = true;
boolean x = true;
String BLOCK_SOURCE_NAME = "ESP8266 Header";
Address start = program.getAddressFactory().getDefaultAddressSpace().getAddress( 0x0 );
try {
mbu.createInitializedBlock(".header", start, reader, 8, "", BLOCK_SOURCE_NAME, r, w, x, monitor);
MemoryBlockUtils.createInitializedBlock(program, false, ".header", start, reader, 8, "", BLOCK_SOURCE_NAME, r, w, x, log, monitor);
createData(program, program.getListing(), start, header.toDataType());
} catch (AddressOverflowException e) {
// TODO Auto-generated catch block
Expand All @@ -112,15 +110,16 @@ private void markAsCode(Program program, Address address) {
}
}

private void markupSections(Program program, ESP8266Module module, TaskMonitor monitor, InputStream reader) throws DuplicateNameException, IOException, AddressOverflowException {
private void markupSections(Program program, ESP8266Module module, TaskMonitor monitor, InputStream reader, MessageLog log) throws DuplicateNameException, IOException, AddressOverflowException {
boolean r = true;
boolean w = true;
boolean x = true;
String BLOCK_SOURCE_NAME = "ESP8266 Section";
for (ESP8266Section section: module.getSections()) {
Address start = program.getAddressFactory().getDefaultAddressSpace().getAddress(section.getOffset());
Msg.info(this, String.format("Section at offset %08x, size %d", start.getOffset(), section.getSize()));
mbu.createInitializedBlock(section.getName(), start, reader, section.getSize(), "", BLOCK_SOURCE_NAME, r, w, x, monitor);
MemoryBlockUtils.createInitializedBlock(program, false,
section.getName(), start, reader, section.getSize(), "", BLOCK_SOURCE_NAME, r, w, x, log, monitor);
createData(program, program.getListing(), start, section.toDataType());
// Mark code sections
if(section.getType() == ESP8266Constants.SECTION_TYPE_CODE)
Expand Down Expand Up @@ -153,23 +152,21 @@ public Data createData(Program program, Listing listing, Address address, DataTy
}

@Override
protected void load(ByteProvider provider, LoadSpec loadSpec, List<Option> options,
Program program, MemoryConflictHandler handler, TaskMonitor monitor, MessageLog log)
throws CancelledException, IOException {
protected void load(ByteProvider provider, LoadSpec loadSpec, List<Option> options, Program program,
TaskMonitor monitor, MessageLog log) throws CancelledException, IOException {

monitor.setMessage( "ESP8266 Loader: Start loading" );

try {
InputStream inputStream;
inputStream = provider.getInputStream(0);
mbu = new MemoryBlockUtil(program, handler);


BinaryReader reader = new BinaryReader( provider, true );
ESP8266Module module = new ESP8266Module( reader );

markupHeader(program, module.getHeader(), monitor, inputStream);
markupSections(program, module, monitor, inputStream);
markupHeader(program, module.getHeader(), monitor, inputStream, log);
markupSections(program, module, monitor, inputStream, log);

// Create entry point
Address entryAddress = program.getAddressFactory().getDefaultAddressSpace().getAddress(module.getHeader().getEntrypoint(), true);
Expand All @@ -180,11 +177,12 @@ protected void load(ByteProvider provider, LoadSpec loadSpec, List<Option> optio
}

@Override
public String validateOptions(ByteProvider provider, LoadSpec loadSpec, List<Option> options) {
public String validateOptions(ByteProvider provider, LoadSpec loadSpec, List<Option> options, Program program) {

// TODO: If this loader has custom options, validate them here. Not all options require
// TODO: If this loader has custom options, validate them here. Not all options
// require
// validation.

return super.validateOptions(provider, loadSpec, options);
return super.validateOptions(provider, loadSpec, options, program);
}
}