GP-0: ignore scan test

This commit is contained in:
d-millar
2022-03-25 13:14:46 +00:00
parent 82c103faae
commit 3e6f6770f4
@@ -49,17 +49,21 @@ public abstract class AbstractModelForFridaMethodsTest extends AbstractDebuggerM
public FridaLinuxSpecimen getLaunchSpecimen() { public FridaLinuxSpecimen getLaunchSpecimen() {
return FridaLinuxSpecimen.PRINT; return FridaLinuxSpecimen.PRINT;
} }
public FridaLinuxSpecimen getPrintSpecimen() { public FridaLinuxSpecimen getPrintSpecimen() {
return FridaLinuxSpecimen.PRINT; return FridaLinuxSpecimen.PRINT;
} }
public FridaLinuxSpecimen getStackSpecimen() { public FridaLinuxSpecimen getStackSpecimen() {
return FridaLinuxSpecimen.STACK; return FridaLinuxSpecimen.STACK;
} }
public FridaLinuxSpecimen getSpinSpecimen() { public FridaLinuxSpecimen getSpinSpecimen() {
return FridaLinuxSpecimen.SPIN_STRIPPED; return FridaLinuxSpecimen.SPIN_STRIPPED;
} }
protected TargetProcess runTestLaunch(DebuggerTestSpecimen specimen, TargetLauncher launcher) throws Throwable { protected TargetProcess runTestLaunch(DebuggerTestSpecimen specimen, TargetLauncher launcher)
throws Throwable {
waitAcc(launcher); waitAcc(launcher);
waitOn(launcher.launch(specimen.getLauncherArgs())); waitOn(launcher.launch(specimen.getLauncherArgs()));
@@ -67,7 +71,8 @@ public abstract class AbstractModelForFridaMethodsTest extends AbstractDebuggerM
TargetObject session = process.getParent().getParent(); TargetObject session = process.getParent().getParent();
TargetModuleContainer modules = m.find(TargetModuleContainer.class, session.getPath()); TargetModuleContainer modules = m.find(TargetModuleContainer.class, session.getPath());
TargetModule binMod = (TargetModule) waitOn(m.getAddedWaiter() TargetModule binMod = (TargetModule) waitOn(m.getAddedWaiter()
.wait(PathUtils.index(modules.getPath(), ((FridaLinuxSpecimen)specimen).getShortName()))); .wait(PathUtils.index(modules.getPath(),
((FridaLinuxSpecimen) specimen).getShortName())));
// NB. this heuristic assumes all function bodies are contiguous in memory // NB. this heuristic assumes all function bodies are contiguous in memory
TargetSymbolNamespace symbols = m.find(TargetSymbolNamespace.class, binMod.getPath()); TargetSymbolNamespace symbols = m.find(TargetSymbolNamespace.class, binMod.getPath());
@@ -75,10 +80,10 @@ public abstract class AbstractModelForFridaMethodsTest extends AbstractDebuggerM
for (Entry<String, ? extends TargetObject> entry : waitOn(symbols.fetchElements()) for (Entry<String, ? extends TargetObject> entry : waitOn(symbols.fetchElements())
.entrySet()) { .entrySet()) {
symbolsByKey.put(entry.getKey(), entry.getValue().as(TargetSymbol.class)); symbolsByKey.put(entry.getKey(), entry.getValue().as(TargetSymbol.class));
} }
return process; return process;
} }
protected void runTestResume(DebuggerTestSpecimen specimen) throws Throwable { protected void runTestResume(DebuggerTestSpecimen specimen) throws Throwable {
TargetProcess process = retryForProcessRunning(specimen, this); TargetProcess process = retryForProcessRunning(specimen, this);
@@ -91,13 +96,13 @@ public abstract class AbstractModelForFridaMethodsTest extends AbstractDebuggerM
retryVoid(() -> assertTrue(DebugModelConventions.isProcessAlive(process)), retryVoid(() -> assertTrue(DebugModelConventions.isProcessAlive(process)),
List.of(AssertionError.class)); List.of(AssertionError.class));
} }
protected void runTestKill(DebuggerTestSpecimen specimen) throws Throwable { protected void runTestKill(DebuggerTestSpecimen specimen) throws Throwable {
TargetProcess process = retryForProcessRunning(specimen, this); TargetProcess process = retryForProcessRunning(specimen, this);
TargetKillable killable = m.suitable(TargetKillable.class, process.getPath()); TargetKillable killable = m.suitable(TargetKillable.class, process.getPath());
waitOn(killable.kill()); waitOn(killable.kill());
} }
protected void runTestLaunchThenResume(TargetLauncher launcher) throws Throwable { protected void runTestLaunchThenResume(TargetLauncher launcher) throws Throwable {
DebuggerTestSpecimen specimen = getPrintSpecimen(); DebuggerTestSpecimen specimen = getPrintSpecimen();
assertNull(getProcessRunning(specimen, this)); assertNull(getProcessRunning(specimen, this));
@@ -118,6 +123,7 @@ public abstract class AbstractModelForFridaMethodsTest extends AbstractDebuggerM
runTestKill(specimen); runTestKill(specimen);
} }
@Ignore
@Test @Test
public void testScan() throws Throwable { public void testScan() throws Throwable {
assumeTrue(m.hasKillableProcesses()); assumeTrue(m.hasKillableProcesses());
@@ -127,13 +133,15 @@ public abstract class AbstractModelForFridaMethodsTest extends AbstractDebuggerM
DebuggerTestSpecimen specimen = getPrintSpecimen(); DebuggerTestSpecimen specimen = getPrintSpecimen();
assertNull(getProcessRunning(specimen, this)); assertNull(getProcessRunning(specimen, this));
TargetProcess process = runTestLaunch(specimen, launcher); TargetProcess process = runTestLaunch(specimen, launcher);
FridaModelTargetProcess fproc = (FridaModelTargetProcess) process; FridaModelTargetProcess fproc = (FridaModelTargetProcess) process;
ConsoleEventListener listener = new ConsoleEventListener("Found match at"); ConsoleEventListener listener = new ConsoleEventListener("Found match at");
fproc.getManager().addEventsListener(listener); fproc.getManager().addEventsListener(listener);
FridaModelTargetMemoryContainerImpl memory = (FridaModelTargetMemoryContainerImpl) fproc.getCachedAttribute("Memory"); FridaModelTargetMemoryContainerImpl memory =
FridaModelTargetMemoryScanImpl scan = (FridaModelTargetMemoryScanImpl) memory.getCachedAttribute("scan"); (FridaModelTargetMemoryContainerImpl) fproc.getCachedAttribute("Memory");
FridaModelTargetMemoryScanImpl scan =
(FridaModelTargetMemoryScanImpl) memory.getCachedAttribute("scan");
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
Address address = symbolsByKey.get("overwrite").getValue(); Address address = symbolsByKey.get("overwrite").getValue();
map.put("Address", address.toString()); map.put("Address", address.toString());
@@ -141,14 +149,14 @@ public abstract class AbstractModelForFridaMethodsTest extends AbstractDebuggerM
map.put("Pattern", "48 65 6C 6C 6F"); map.put("Pattern", "48 65 6C 6C 6F");
map.put("Stop", true); map.put("Stop", true);
scan.invoke(map); scan.invoke(map);
waitForCondition(() -> { waitForCondition(() -> {
return listener.foundMatch(); return listener.foundMatch();
}, "Console output timed out"); }, "Console output timed out");
assertTrue(listener.getMatchingOutput().contains(address.toString())); assertTrue(listener.getMatchingOutput().contains(address.toString()));
runTestKill(specimen); runTestKill(specimen);
} }
@Ignore @Ignore
@Test @Test
public void testWatch() throws Throwable { public void testWatch() throws Throwable {
@@ -159,13 +167,15 @@ public abstract class AbstractModelForFridaMethodsTest extends AbstractDebuggerM
DebuggerTestSpecimen specimen = getPrintSpecimen(); DebuggerTestSpecimen specimen = getPrintSpecimen();
assertNull(getProcessRunning(specimen, this)); assertNull(getProcessRunning(specimen, this));
TargetProcess process = runTestLaunch(specimen, launcher); TargetProcess process = runTestLaunch(specimen, launcher);
FridaModelTargetProcess fproc = (FridaModelTargetProcess) process; FridaModelTargetProcess fproc = (FridaModelTargetProcess) process;
ConsoleEventListener listener = new ConsoleEventListener("read"); ConsoleEventListener listener = new ConsoleEventListener("read");
fproc.getManager().addEventsListener(listener); fproc.getManager().addEventsListener(listener);
FridaModelTargetMemoryContainerImpl memory = (FridaModelTargetMemoryContainerImpl) fproc.getCachedAttribute("Memory"); FridaModelTargetMemoryContainerImpl memory =
FridaModelTargetMemoryWatchImpl watch = (FridaModelTargetMemoryWatchImpl) memory.getCachedAttribute("watch"); (FridaModelTargetMemoryContainerImpl) fproc.getCachedAttribute("Memory");
FridaModelTargetMemoryWatchImpl watch =
(FridaModelTargetMemoryWatchImpl) memory.getCachedAttribute("watch");
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
Address address = symbolsByKey.get("overwrite").getValue(); Address address = symbolsByKey.get("overwrite").getValue();
map.put("Address", address.toString()); map.put("Address", address.toString());
@@ -174,14 +184,14 @@ public abstract class AbstractModelForFridaMethodsTest extends AbstractDebuggerM
map.put("OnAccess", script.getAbsolutePath()); map.put("OnAccess", script.getAbsolutePath());
watch.invoke(map); watch.invoke(map);
runTestResume(specimen); runTestResume(specimen);
waitForCondition(() -> { waitForCondition(() -> {
return listener.foundMatch(); return listener.foundMatch();
}, "Console output timed out"); }, "Console output timed out");
assertTrue(listener.getMatchingOutput().contains(address.toString())); assertTrue(listener.getMatchingOutput().contains(address.toString()));
runTestKill(specimen); runTestKill(specimen);
} }
@Test @Test
public void testInterceptor() throws Throwable { public void testInterceptor() throws Throwable {
assumeTrue(m.hasKillableProcesses()); assumeTrue(m.hasKillableProcesses());
@@ -191,27 +201,27 @@ public abstract class AbstractModelForFridaMethodsTest extends AbstractDebuggerM
DebuggerTestSpecimen specimen = getStackSpecimen(); DebuggerTestSpecimen specimen = getStackSpecimen();
assertNull(getProcessRunning(specimen, this)); assertNull(getProcessRunning(specimen, this));
TargetProcess process = runTestLaunch(specimen, launcher); TargetProcess process = runTestLaunch(specimen, launcher);
FridaModelTargetProcess fproc = (FridaModelTargetProcess) process; FridaModelTargetProcess fproc = (FridaModelTargetProcess) process;
ConsoleEventListener listener = new ConsoleEventListener("entering"); ConsoleEventListener listener = new ConsoleEventListener("entering");
fproc.getManager().addEventsListener(listener); fproc.getManager().addEventsListener(listener);
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
FridaModelTargetSymbol symbol = (FridaModelTargetSymbol) symbolsByKey.get("break_here"); FridaModelTargetSymbol symbol = (FridaModelTargetSymbol) symbolsByKey.get("break_here");
FridaModelTargetFunctionInterceptorImpl intercept = FridaModelTargetFunctionInterceptorImpl intercept =
(FridaModelTargetFunctionInterceptorImpl) symbol.getCachedAttribute("intercept"); (FridaModelTargetFunctionInterceptorImpl) symbol.getCachedAttribute("intercept");
ResourceFile script = Application.getModuleDataFile("/scripts/onEnter.js"); ResourceFile script = Application.getModuleDataFile("/scripts/onEnter.js");
map.put("OnEnter", script.getAbsolutePath()); map.put("OnEnter", script.getAbsolutePath());
map.put("OnLeave", ""); map.put("OnLeave", "");
intercept.invoke(map); intercept.invoke(map);
runTestResume(specimen); runTestResume(specimen);
waitForCondition(() -> { waitForCondition(() -> {
return listener.foundMatch(); return listener.foundMatch();
}, "Console output timed out"); }, "Console output timed out");
runTestKill(specimen); runTestKill(specimen);
} }
@Test @Test
public void testStalker() throws Throwable { public void testStalker() throws Throwable {
assumeTrue(m.hasKillableProcesses()); assumeTrue(m.hasKillableProcesses());
@@ -221,18 +231,21 @@ public abstract class AbstractModelForFridaMethodsTest extends AbstractDebuggerM
DebuggerTestSpecimen specimen = getSpinSpecimen(); DebuggerTestSpecimen specimen = getSpinSpecimen();
assertNull(getProcessRunning(specimen, this)); assertNull(getProcessRunning(specimen, this));
TargetProcess process = runTestLaunch(specimen, launcher); TargetProcess process = runTestLaunch(specimen, launcher);
FridaModelTargetProcess fproc = (FridaModelTargetProcess) process; FridaModelTargetProcess fproc = (FridaModelTargetProcess) process;
waitOn(fproc.resume()); waitOn(fproc.resume());
ConsoleEventListener listener = new ConsoleEventListener(":1"); ConsoleEventListener listener = new ConsoleEventListener(":1");
fproc.getManager().addEventsListener(listener); fproc.getManager().addEventsListener(listener);
FridaModelTargetThreadContainerImpl threads = (FridaModelTargetThreadContainerImpl) fproc.getCachedAttribute("Threads"); FridaModelTargetThreadContainerImpl threads =
Map<String, TargetObject> elements = (Map<String, TargetObject>) waitOn(threads.fetchElements()); (FridaModelTargetThreadContainerImpl) fproc.getCachedAttribute("Threads");
FridaModelTargetThreadImpl thread = (FridaModelTargetThreadImpl) elements.values().iterator().next(); Map<String, TargetObject> elements =
(Map<String, TargetObject>) waitOn(threads.fetchElements());
FridaModelTargetThreadImpl thread =
(FridaModelTargetThreadImpl) elements.values().iterator().next();
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
FridaModelTargetThreadStalkImpl stalk = FridaModelTargetThreadStalkImpl stalk =
(FridaModelTargetThreadStalkImpl) thread.getCachedAttribute("stalk"); (FridaModelTargetThreadStalkImpl) thread.getCachedAttribute("stalk");
ResourceFile script = Application.getModuleDataFile("/scripts/onCallSummary.js"); ResourceFile script = Application.getModuleDataFile("/scripts/onCallSummary.js");
map.put("OnCallSummary", script.getAbsolutePath()); map.put("OnCallSummary", script.getAbsolutePath());
map.put("EventCall", true); map.put("EventCall", true);
@@ -243,19 +256,19 @@ public abstract class AbstractModelForFridaMethodsTest extends AbstractDebuggerM
map.put("OnReceive", ""); map.put("OnReceive", "");
stalk.invoke(map); stalk.invoke(map);
//runTestResume(specimen); //runTestResume(specimen);
waitForCondition(() -> { waitForCondition(() -> {
return listener.foundMatch(); return listener.foundMatch();
}, "Console output timed out"); }, "Console output timed out");
runTestKill(specimen); runTestKill(specimen);
} }
private class ConsoleEventListener implements FridaEventsListenerAdapter { private class ConsoleEventListener implements FridaEventsListenerAdapter {
private String match; private String match;
private boolean foundMatch = false; private boolean foundMatch = false;
private String matchingOutput; private String matchingOutput;
public ConsoleEventListener(String match) { public ConsoleEventListener(String match) {
this.match = match; this.match = match;
} }
@@ -267,10 +280,11 @@ public abstract class AbstractModelForFridaMethodsTest extends AbstractDebuggerM
matchingOutput = output; matchingOutput = output;
} }
} }
public boolean foundMatch() { public boolean foundMatch() {
return foundMatch; return foundMatch;
} }
public String getMatchingOutput() { public String getMatchingOutput() {
return matchingOutput; return matchingOutput;
} }