-
Notifications
You must be signed in to change notification settings - Fork 18
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
15 changed files
with
685 additions
and
67 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright 2019-2020 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.bin.ByteProvider; | ||
import ghidra.util.HashUtilities; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.util.regex.Pattern; | ||
|
||
public final class Sha256 { | ||
public final String value; | ||
|
||
private Sha256(String value) { | ||
this.value = value; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Sha256 sha256 = (Sha256) o; | ||
return value.equals(sha256.value); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return value.hashCode(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return this.value; | ||
} | ||
|
||
private static final Pattern SHA256_HEX = Pattern.compile("^[0-9a-z]{64}$"); | ||
|
||
public static Sha256 parse(String sha256Hex) { | ||
if (!SHA256_HEX.matcher(sha256Hex).matches()) { | ||
throw new IllegalArgumentException("Invalid SHA256 " + sha256Hex); | ||
} | ||
return new Sha256(sha256Hex); | ||
} | ||
|
||
public static Sha256 of(ByteProvider provider) throws IOException { | ||
try (var stream = provider.getInputStream(0)) { | ||
return new Sha256(HashUtilities.getHash(HashUtilities.SHA256_ALGORITHM, stream)); | ||
} | ||
} | ||
|
||
public static Sha256 of(byte[] bytes) throws IOException { | ||
try (var stream = new ByteArrayInputStream(bytes)) { | ||
return new Sha256(HashUtilities.getHash(HashUtilities.SHA256_ALGORITHM, stream)); | ||
} | ||
} | ||
} |
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
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,45 @@ | ||
// Copyright 2019-2020 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 generic.jar.ResourceFile | ||
import ghidra.app.plugin.processors.sleigh.SleighLanguageProvider | ||
import ghidra.program.model.address.Address | ||
import ghidra.program.model.lang.Language | ||
import org.junit.jupiter.api.Assertions | ||
import org.junit.jupiter.api.BeforeAll | ||
import org.junit.jupiter.api.TestInstance | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
import java.io.File | ||
|
||
@ExtendWith(GhidraApplication::class) | ||
@TestInstance(TestInstance.Lifecycle.PER_CLASS) | ||
open class IntegrationTest { | ||
protected lateinit var language: Language | ||
|
||
@BeforeAll | ||
private fun beforeAll() { | ||
val defs = ResourceFile(File("data/languages/sm83.ldefs")) | ||
val provider = SleighLanguageProvider(defs) | ||
Assertions.assertFalse(provider.hadLoadFailure()) | ||
val languageDescription = provider.languageDescriptions.single() | ||
|
||
Assertions.assertEquals("Sharp SM83", languageDescription.description) | ||
Assertions.assertEquals("SM83", languageDescription.processor.toString()) | ||
|
||
language = provider.getLanguage(languageDescription.languageID) | ||
} | ||
|
||
protected fun address(offset: Long): Address = language.addressFactory.defaultAddressSpace.getAddress(offset) | ||
} |
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.