mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-09-28 17:11:11 -09:00
GP-0: Fix tests (frame display. wrap-around check)
This commit is contained in:
@@ -171,7 +171,8 @@ public class BytesPcodeExecutorStateSpace<B> {
|
|||||||
*/
|
*/
|
||||||
protected ULongSpanSet computeUninitialized(long offset, int size) {
|
protected ULongSpanSet computeUninitialized(long offset, int size) {
|
||||||
long max = offset + size - 1;
|
long max = offset + size - 1;
|
||||||
if (max <= space.getMaxAddress().getOffset()) {
|
if (Long.compareUnsigned(max, space.getMaxAddress().getOffset()) <= 0 &&
|
||||||
|
Long.compareUnsigned(offset, max) <= 0) {
|
||||||
return bytes.getUninitialized(offset, max);
|
return bytes.getUninitialized(offset, max);
|
||||||
}
|
}
|
||||||
long end = space.getMinAddress().getOffset() + max - space.getMaxAddress().getOffset() - 1;
|
long end = space.getMinAddress().getOffset() + max - space.getMaxAddress().getOffset() - 1;
|
||||||
|
|||||||
@@ -0,0 +1,99 @@
|
|||||||
|
/* ###
|
||||||
|
* IP: GHIDRA
|
||||||
|
*
|
||||||
|
* 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 ghidra.pcode.exec;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import generic.ULongSpan;
|
||||||
|
import generic.ULongSpan.ULongSpanSet;
|
||||||
|
import generic.test.AbstractGTest;
|
||||||
|
import ghidra.GhidraTestApplicationLayout;
|
||||||
|
import ghidra.app.plugin.processors.sleigh.SleighLanguage;
|
||||||
|
import ghidra.app.plugin.processors.sleigh.SleighLanguageHelper;
|
||||||
|
import ghidra.framework.Application;
|
||||||
|
import ghidra.framework.ApplicationConfiguration;
|
||||||
|
import ghidra.program.model.address.AddressSpace;
|
||||||
|
|
||||||
|
public class BytesPcodeExecutorStateSpaceTest extends AbstractGTest {
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() throws Exception {
|
||||||
|
if (!Application.isInitialized()) {
|
||||||
|
Application.initializeApplication(
|
||||||
|
new GhidraTestApplicationLayout(new File(getTestDirectoryPath())),
|
||||||
|
new ApplicationConfiguration());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testComputeUninitialized64() throws Exception {
|
||||||
|
SleighLanguage language = SleighLanguageHelper.getMockBE64Language();
|
||||||
|
AddressSpace space = language.getDefaultSpace();
|
||||||
|
BytesPcodeExecutorStateSpace<Void> stateSpace =
|
||||||
|
new BytesPcodeExecutorStateSpace<Void>(language, space, null);
|
||||||
|
|
||||||
|
ULongSpanSet.of(ULongSpan.span(0, 9));
|
||||||
|
|
||||||
|
assertEquals(ULongSpanSet.of(
|
||||||
|
ULongSpan.span(0, 7)),
|
||||||
|
stateSpace.computeUninitialized(0, 8));
|
||||||
|
assertEquals(ULongSpanSet.of(
|
||||||
|
ULongSpan.span(0x7fff_ffff_ffff_fff8L, 0x7fff_ffff_ffff_ffffL)),
|
||||||
|
stateSpace.computeUninitialized(0x7fff_ffff_ffff_fff8L, 8));
|
||||||
|
assertEquals(ULongSpanSet.of(
|
||||||
|
ULongSpan.span(0x7fff_ffff_ffff_fffcL, 0x8000_0000_0000_0003L)),
|
||||||
|
stateSpace.computeUninitialized(0x7fff_ffff_ffff_fffcL, 8));
|
||||||
|
assertEquals(ULongSpanSet.of(
|
||||||
|
ULongSpan.span(0x8000_0000_0000_0008L, 0x8000_0000_0000_000fL)),
|
||||||
|
stateSpace.computeUninitialized(0x8000_0000_0000_0008L, 8));
|
||||||
|
assertEquals(ULongSpanSet.of(
|
||||||
|
ULongSpan.span(0xffff_ffff_ffff_fffcL, 0xffff_ffff_ffff_ffffL),
|
||||||
|
ULongSpan.span(0, 3)),
|
||||||
|
stateSpace.computeUninitialized(0xffff_ffff_ffff_fffcL, 8));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testComputeUninitialized32() throws Exception {
|
||||||
|
SleighLanguage language = SleighLanguageHelper.getMockBE64Language();
|
||||||
|
AddressSpace space = language.getAddressFactory().getRegisterSpace();
|
||||||
|
BytesPcodeExecutorStateSpace<Void> stateSpace =
|
||||||
|
new BytesPcodeExecutorStateSpace<Void>(language, space, null);
|
||||||
|
|
||||||
|
ULongSpanSet.of(ULongSpan.span(0, 9));
|
||||||
|
|
||||||
|
assertEquals(ULongSpanSet.of(
|
||||||
|
ULongSpan.span(0, 7)),
|
||||||
|
stateSpace.computeUninitialized(0, 8));
|
||||||
|
assertEquals(ULongSpanSet.of(
|
||||||
|
ULongSpan.span(0x7fff_fff8L, 0x7fff_ffffL)),
|
||||||
|
stateSpace.computeUninitialized(0x7fff_fff8L, 8));
|
||||||
|
assertEquals(ULongSpanSet.of(
|
||||||
|
ULongSpan.span(0x7fff_fffcL, 0x8000_0003L)),
|
||||||
|
stateSpace.computeUninitialized(0x7fff_fffcL, 8));
|
||||||
|
assertEquals(ULongSpanSet.of(
|
||||||
|
ULongSpan.span(0x8000_0008L, 0x8000_000fL)),
|
||||||
|
stateSpace.computeUninitialized(0x8000_0008L, 8));
|
||||||
|
assertEquals(ULongSpanSet.of(
|
||||||
|
ULongSpan.span(0xffff_fffcL, 0xffff_ffffL),
|
||||||
|
ULongSpan.span(0, 3)),
|
||||||
|
stateSpace.computeUninitialized(0xffff_fffcL, 8));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,9 +4,9 @@
|
|||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
@@ -226,7 +226,7 @@ public class PcodeFrameTest extends AbstractGTest {
|
|||||||
PcodeFrame frame = frame(SAMPLE_BRANCH);
|
PcodeFrame frame = frame(SAMPLE_BRANCH);
|
||||||
assertEquals("""
|
assertEquals("""
|
||||||
<p-code frame: index=0 {
|
<p-code frame: index=0 {
|
||||||
-> BRANCH *[ram]0x1234:8
|
-> BRANCH *[NO ADDRESS]0x1234
|
||||||
}>""",
|
}>""",
|
||||||
frame.toString());
|
frame.toString());
|
||||||
|
|
||||||
@@ -234,7 +234,7 @@ public class PcodeFrameTest extends AbstractGTest {
|
|||||||
frame.finishAsBranch();
|
frame.finishAsBranch();
|
||||||
assertEquals("""
|
assertEquals("""
|
||||||
<p-code frame: index=-1 branched=0 {
|
<p-code frame: index=-1 branched=0 {
|
||||||
*> BRANCH *[ram]0x1234:8
|
*> BRANCH *[NO ADDRESS]0x1234
|
||||||
}>""",
|
}>""",
|
||||||
frame.toString());
|
frame.toString());
|
||||||
}
|
}
|
||||||
@@ -244,7 +244,7 @@ public class PcodeFrameTest extends AbstractGTest {
|
|||||||
PcodeFrame frame = frame(SAMPLE_LANG_USEROP);
|
PcodeFrame frame = frame(SAMPLE_LANG_USEROP);
|
||||||
assertEquals("""
|
assertEquals("""
|
||||||
<p-code frame: index=0 {
|
<p-code frame: index=0 {
|
||||||
-> CALLOTHER \"pcodeop_one\", r0
|
-> CALLOTHER "pcodeop_one", r0
|
||||||
}>""",
|
}>""",
|
||||||
frame.toString());
|
frame.toString());
|
||||||
}
|
}
|
||||||
@@ -254,7 +254,7 @@ public class PcodeFrameTest extends AbstractGTest {
|
|||||||
PcodeFrame frame = frame(SAMPLE_LIB_USEROP);
|
PcodeFrame frame = frame(SAMPLE_LIB_USEROP);
|
||||||
assertEquals("""
|
assertEquals("""
|
||||||
<p-code frame: index=0 {
|
<p-code frame: index=0 {
|
||||||
-> CALLOTHER \"__lib_userop\", r0
|
-> CALLOTHER "__lib_userop", r0
|
||||||
}>""",
|
}>""",
|
||||||
frame.toString());
|
frame.toString());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user