Skip to content

Commit

Permalink
Backport to Ghidra 9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Gekkio committed Aug 2, 2019
1 parent dd6dcfa commit 8327d60
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

**Very experimental! No compatibility guarantees!**

Ghidra version: 9.1 (git master)
Ghidra version: 9.0.4

![Tetris disassembly](screenshot.png)

Expand Down
14 changes: 7 additions & 7 deletions src/main/java/fi/gekkio/ghidraboy/GameBoyLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
// limitations under the License.
package fi.gekkio.ghidraboy;

import ghidra.app.util.MemoryBlockUtils;
import ghidra.app.util.Option;
import ghidra.app.util.OptionUtils;
import ghidra.app.util.bin.ByteProvider;
import ghidra.app.util.importer.MemoryConflictHandler;
import ghidra.app.util.importer.MessageLog;
import ghidra.app.util.opinion.AbstractProgramLoader;
import ghidra.app.util.opinion.LoadSpec;
Expand All @@ -43,9 +43,9 @@
import static fi.gekkio.ghidraboy.BootRomUtils.detectBootRom;
import static fi.gekkio.ghidraboy.GameBoyUtils.addHardwareBlocks;
import static fi.gekkio.ghidraboy.GameBoyUtils.populateHardwareBlocks;
import static fi.gekkio.ghidraboy.Ghidra90Compat.createInitializedBlock;
import static fi.gekkio.ghidraboy.Ghidra90Compat.createUninitializedBlock;
import static fi.gekkio.ghidraboy.RomUtils.detectRom;
import static ghidra.app.util.MemoryBlockUtils.createInitializedBlock;
import static ghidra.app.util.MemoryBlockUtils.createUninitializedBlock;
import static ghidra.program.model.data.DataUtilities.createData;

public class GameBoyLoader extends AbstractProgramLoader {
Expand Down Expand Up @@ -124,7 +124,7 @@ protected List<Program> loadProgram(ByteProvider provider, String programName, D
program.endTransaction(id, true);
}
}
if (loadInto(provider, loadSpec, options, log, program, monitor)) {
if (loadInto(provider, loadSpec, options, log, program, monitor, MemoryConflictHandler.ALWAYS_OVERWRITE)) {
createDefaultMemoryBlocks(program, language, log);

if (OptionUtils.getBooleanOptionValue(OPT_HW_BLOCKS, options, true)) {
Expand All @@ -149,11 +149,11 @@ protected List<Program> loadProgram(ByteProvider provider, String programName, D
}

@Override
protected boolean loadProgramInto(ByteProvider provider, LoadSpec loadSpec, List<Option> options, MessageLog log, Program program, TaskMonitor monitor) throws IOException, CancelledException {
protected boolean loadProgramInto(ByteProvider provider, LoadSpec loadSpec, List<Option> options, MessageLog log, Program program, TaskMonitor monitor, MemoryConflictHandler memoryConflictHandler) throws IOException, CancelledException {
var as = program.getAddressFactory().getDefaultAddressSpace();

var bootRom = detectBootRom(provider);
var rom = MemoryBlockUtils.createFileBytes(program, provider);
var rom = provider.readBytes(0, provider.length());

if (bootRom.isPresent()) {
var cgb = GameBoyKind.CGB.equals(bootRom.get());
Expand Down Expand Up @@ -200,7 +200,7 @@ protected boolean loadProgramInto(ByteProvider provider, LoadSpec loadSpec, List
var romX = as.getAddress(0x4000);
var offset = 0x4000;
var bank = 1;
while (offset < rom.getSize()) {
while (offset < rom.length) {
createInitializedBlock(program, true, "rom" + bank, romX, rom, offset, 0x4000, "", getName(), true, false, true, log);
offset += 0x4000;
bank += 1;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/fi/gekkio/ghidraboy/GameBoyUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import static fi.gekkio.ghidraboy.DataTypes.array;
import static fi.gekkio.ghidraboy.DataTypes.u8;
import static ghidra.app.util.MemoryBlockUtils.createUninitializedBlock;
import static fi.gekkio.ghidraboy.Ghidra90Compat.createUninitializedBlock;
import static ghidra.program.model.data.DataUtilities.createData;

public final class GameBoyUtils {
Expand Down
41 changes: 41 additions & 0 deletions src/main/java/fi/gekkio/ghidraboy/Ghidra90Compat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2019 Joonas Javanainen <[email protected]>
//
// 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.
package fi.gekkio.ghidraboy;

import ghidra.app.util.MemoryBlockUtil;
import ghidra.app.util.importer.MemoryConflictHandler;
import ghidra.app.util.importer.MessageLog;
import ghidra.program.model.address.Address;
import ghidra.program.model.address.AddressOverflowException;
import ghidra.program.model.listing.Program;
import ghidra.program.model.mem.MemoryBlock;
import ghidra.util.task.TaskMonitor;

import java.io.ByteArrayInputStream;

public final class Ghidra90Compat {
private Ghidra90Compat() {
}

public static MemoryBlock createUninitializedBlock(Program program, boolean isOverlay, String name, Address start, long length, String comment, String source, boolean r, boolean w, boolean x, MessageLog log) {
var util = new MemoryBlockUtil(program, MemoryConflictHandler.NEVER_OVERWRITE);
return util.createUninitializedBlock(isOverlay, name, start, length, comment, source, r, w, x);
}

public static MemoryBlock createInitializedBlock(Program program, boolean isOverlay, String name, Address start, byte[] rom, long offset, long length, String comment, String source, boolean r, boolean w, boolean x, MessageLog log) throws AddressOverflowException {
var util = new MemoryBlockUtil(program, MemoryConflictHandler.NEVER_OVERWRITE);
var dataInput = new ByteArrayInputStream(rom, (int) offset, (int) length);
return util.createInitializedBlock(name, start, dataInput, length, comment, source, r, w, x, TaskMonitor.DUMMY);
}
}

0 comments on commit 8327d60

Please sign in to comment.