-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
1,454 additions
and
1,074 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
src/main/java/adubbz/switchloader/common/MemoryBlockHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
627 changes: 627 additions & 0 deletions
627
src/main/java/adubbz/switchloader/common/NXProgramBuilder.java
Large diffs are not rendered by default.
Oops, something went wrong.
25 changes: 25 additions & 0 deletions
25
src/main/java/adubbz/switchloader/common/NXRelocation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/** | ||
* Copyright 2019 Adubbz | ||
* Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
*/ | ||
package adubbz.switchloader.common; | ||
|
||
import ghidra.app.util.bin.format.elf.ElfSymbol; | ||
|
||
public class NXRelocation | ||
{ | ||
public NXRelocation(long offset, long r_type, ElfSymbol sym, long addend) | ||
{ | ||
this.offset = offset; | ||
this.r_type = r_type; | ||
this.sym = sym; | ||
this.addend = addend; | ||
} | ||
|
||
public long offset; | ||
public long r_type; | ||
public ElfSymbol sym; | ||
public long addend; | ||
} |
808 changes: 0 additions & 808 deletions
808
src/main/java/adubbz/switchloader/common/SwitchProgramBuilder.java
This file was deleted.
Oops, something went wrong.
120 changes: 120 additions & 0 deletions
120
src/main/java/adubbz/switchloader/kip1/KIP1Adapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/** | ||
* Copyright 2019 Adubbz | ||
* Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
*/ | ||
package adubbz.switchloader.kip1; | ||
|
||
import java.io.IOException; | ||
|
||
import adubbz.switchloader.nxo.NXOAdapter; | ||
import adubbz.switchloader.nxo.NXOSection; | ||
import adubbz.switchloader.nxo.NXOSectionType; | ||
import adubbz.switchloader.util.ByteUtil; | ||
import ghidra.app.util.bin.BinaryReader; | ||
import ghidra.app.util.bin.ByteArrayProvider; | ||
import ghidra.app.util.bin.ByteProvider; | ||
import ghidra.util.Msg; | ||
|
||
public class KIP1Adapter extends NXOAdapter | ||
{ | ||
protected ByteProvider fileProvider; | ||
protected BinaryReader fileReader; | ||
protected KIP1Header kip1; | ||
|
||
protected ByteProvider memoryProvider; | ||
protected NXOSection[] sections; | ||
|
||
public KIP1Adapter(ByteProvider fileProvider) | ||
{ | ||
this.fileProvider = fileProvider; | ||
this.fileReader = new BinaryReader(this.fileProvider, true); | ||
|
||
try | ||
{ | ||
this.read(); | ||
} | ||
catch (IOException e) | ||
{ | ||
Msg.error(this, "Failed to read KIP1"); | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
private void read() throws IOException | ||
{ | ||
this.kip1 = new KIP1Header(this.fileReader, 0x0); | ||
|
||
KIP1SectionHeader textHeader = this.kip1.getSectionHeader(NXOSectionType.TEXT); | ||
KIP1SectionHeader rodataHeader = this.kip1.getSectionHeader(NXOSectionType.RODATA); | ||
KIP1SectionHeader dataHeader = this.kip1.getSectionHeader(NXOSectionType.DATA); | ||
|
||
int textOffset = textHeader.getOutOffset(); | ||
int rodataOffset = rodataHeader.getOutOffset(); | ||
int dataOffset = dataHeader.getOutOffset(); | ||
int textSize = textHeader.getDecompressedSize(); | ||
int rodataSize = rodataHeader.getDecompressedSize(); | ||
int dataSize = dataHeader.getDecompressedSize(); | ||
|
||
// The data section is last, so we use its offset + decompressed size | ||
byte[] full = new byte[dataOffset + dataSize]; | ||
byte[] decompressedText; | ||
byte[] decompressedRodata; | ||
byte[] decompressedData; | ||
|
||
if (this.kip1.isSectionCompressed(NXOSectionType.TEXT)) | ||
{ | ||
byte[] compressedText = this.fileProvider.readBytes(this.kip1.getSectionFileOffset(NXOSectionType.TEXT), this.kip1.getCompressedSectionSize(NXOSectionType.TEXT)); | ||
decompressedText = ByteUtil.kip1BlzDecompress(compressedText, textSize); | ||
} | ||
else | ||
{ | ||
decompressedText = this.fileProvider.readBytes(this.kip1.getSectionFileOffset(NXOSectionType.TEXT), textSize); | ||
} | ||
|
||
System.arraycopy(decompressedText, 0, full, textOffset, textSize); | ||
|
||
if (this.kip1.isSectionCompressed(NXOSectionType.RODATA)) | ||
{ | ||
byte[] compressedRodata = this.fileProvider.readBytes(this.kip1.getSectionFileOffset(NXOSectionType.RODATA), this.kip1.getCompressedSectionSize(NXOSectionType.RODATA)); | ||
decompressedRodata = ByteUtil.kip1BlzDecompress(compressedRodata, rodataSize); | ||
} | ||
else | ||
{ | ||
decompressedRodata = this.fileProvider.readBytes(this.kip1.getSectionFileOffset(NXOSectionType.RODATA), rodataSize); | ||
} | ||
|
||
System.arraycopy(decompressedRodata, 0, full, rodataOffset, rodataSize); | ||
|
||
if (this.kip1.isSectionCompressed(NXOSectionType.DATA)) | ||
{ | ||
byte[] compressedData = this.fileProvider.readBytes(this.kip1.getSectionFileOffset(NXOSectionType.DATA), this.kip1.getCompressedSectionSize(NXOSectionType.DATA)); | ||
decompressedData = ByteUtil.kip1BlzDecompress(compressedData, dataSize); | ||
} | ||
else | ||
{ | ||
decompressedData = this.fileProvider.readBytes(this.kip1.getSectionFileOffset(NXOSectionType.DATA), dataSize); | ||
} | ||
|
||
System.arraycopy(decompressedData, 0, full, dataOffset, dataSize); | ||
this.memoryProvider = new ByteArrayProvider(full); | ||
|
||
this.sections = new NXOSection[3]; | ||
this.sections[NXOSectionType.TEXT.ordinal()] = new NXOSection(NXOSectionType.TEXT, textOffset, textSize); | ||
this.sections[NXOSectionType.RODATA.ordinal()] = new NXOSection(NXOSectionType.RODATA, rodataOffset, rodataSize); | ||
this.sections[NXOSectionType.DATA.ordinal()] = new NXOSection(NXOSectionType.DATA, dataOffset, dataSize); | ||
} | ||
|
||
@Override | ||
public ByteProvider getMemoryProvider() | ||
{ | ||
return this.memoryProvider; | ||
} | ||
|
||
@Override | ||
public NXOSection[] getSections() | ||
{ | ||
return this.sections; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.