GP-4198: Distribute Trace RMI clients (python).

ASIDE: Fix terminal buffer overflow.
This commit is contained in:
Dan
2024-01-04 11:01:07 -05:00
parent a9e7ad1da2
commit 01ae06d0f8
6 changed files with 86 additions and 18 deletions
@@ -18,14 +18,17 @@
@echo off
if exist "%GHIDRA_HOME%\ghidra\.git\" (
set PYTHONPATH=%GHIDRA_HOME%\ghidra\Ghidra\Debug\Debugger-agent-dbgeng\build\pypkg\src;%GHIDRA_HOME%\ghidra\Ghidra\Debug\Debugger-rmi-trace\build\pypkg\src;%PYTHONPATH%
set PYTHONPATH=%GHIDRA_HOME%\ghidra\Ghidra\Debug\Debugger-agent-dbgeng\build\pypkg\src;%PYTHONPATH%
set PYTHONPATH=%GHIDRA_HOME%\ghidra\Ghidra\Debug\Debugger-rmi-trace\build\pypkg\src;%PYTHONPATH%
) else if exist "%GHIDRA_HOME%\.git\" (
set PYTHONPATH=%GHIDRA_HOME%\Ghidra\Debug\Debugger-agent-dbgeng\build\pypkg\src;%GHIDRA_HOME%\Ghidra\Debug\Debugger-rmi-trace\build\pypkg\src;%PYTHONPATH%
set PYTHONPATH=%GHIDRA_HOME%\Ghidra\Debug\Debugger-agent-dbgeng\build\pypkg\src;%PYTHONPATH%
set PYTHONPATH=%GHIDRA_HOME%\Ghidra\Debug\Debugger-rmi-trace\build\pypkg\src;%PYTHONPATH%
) else (
set PYTHONPATH=%GHIDRA_HOME%\Ghidra\Debug\Debugger-agent-dbgeng\pypkg\src;%GHIDRA_HOME%\Ghidra\Debug\Debugger-rmi-trace\pypkg\src;%PYTHONPATH%
set PYTHONPATH=%GHIDRA_HOME%\Ghidra\Debug\Debugger-agent-dbgeng\pypkg\src;%PYTHONPATH%
set PYTHONPATH=%GHIDRA_HOME%\Ghidra\Debug\Debugger-rmi-trace\pypkg\src;%PYTHONPATH%
)
echo PYTHONPATH is %PYTHONPATH%
echo bat OPT_TARGET_IMG is [%OPT_TARGET_IMG%]
echo OPT_TARGET_IMG is [%OPT_TARGET_IMG%]
"%OPT_PYTHON_EXE%" -i ..\support\local-dbgeng.py
@@ -33,12 +33,15 @@
if [ -d ${GHIDRA_HOME}/ghidra/.git ]
then
export PYTHONPATH=$GHIDRA_HOME/ghidra/Ghidra/Debug/Debugger-agent-gdb/build/pypkg/src:$GHIDRA_HOME/ghidra/Ghidra/Debug/Debugger-rmi-trace/build/pypkg/src:$PYTHONPATH
export PYTHONPATH=$GHIDRA_HOME/ghidra/Ghidra/Debug/Debugger-agent-gdb/build/pypkg/src:$PYTHONPATH
export PYTHONPATH=$GHIDRA_HOME/ghidra/Ghidra/Debug/Debugger-rmi-trace/build/pypkg/src:$PYTHONPATH
elif [ -d ${GHIDRA_HOME}/.git ]
then
export PYTHONPATH=$GHIDRA_HOME/Ghidra/Debug/Debugger-agent-gdb/build/pypkg/src:$GHIDRA_HOME/Ghidra/Debug/Debugger-rmi-trace/build/pypkg/src:$PYTHONPATH
export PYTHONPATH=$GHIDRA_HOME/Ghidra/Debug/Debugger-agent-gdb/build/pypkg/src:$PYTHONPATH
export PYTHONPATH=$GHIDRA_HOME/Ghidra/Debug/Debugger-rmi-trace/build/pypkg/src:$PYTHONPATH
else
export PYTHONPATH=$GHIDRA_HOME/Ghidra/Debug/Debugger-agent-gdb/pypkg/src:$GHIDRA_HOME/Ghidra/Debug/Debugger-rmi-trace/build/pypkg/src:$PYTHONPATH
export PYTHONPATH=$GHIDRA_HOME/Ghidra/Debug/Debugger-agent-gdb/pypkg/src:$PYTHONPATH
export PYTHONPATH=$GHIDRA_HOME/Ghidra/Debug/Debugger-rmi-trace/pypkg/src:$PYTHONPATH
fi
target_image="$1"
@@ -86,8 +86,8 @@ public class ThreadedTerminal extends DefaultTerminal {
}
protected void pump() {
try {
while (!closed) {
while (!closed) {
try {
if (-1 == in.read(buffer) || closed) {
return;
}
@@ -98,10 +98,15 @@ public class ThreadedTerminal extends DefaultTerminal {
}
buffer.clear();
}
}
catch (IOException e) {
Msg.error(this, "Console input closed unexpectedly: " + e);
closed = true;
catch (IOException e) {
Msg.error(this, "Console input closed unexpectedly: " + e);
closed = true;
return;
}
catch (Exception e) {
Msg.error(this, "Unexpected error processing terminal input", e);
continue;
}
}
}
@@ -43,6 +43,49 @@ public class VtParser {
this.handler = handler;
}
protected static ByteBuffer copyDoubledCapacity(ByteBuffer oldBuf) {
ByteBuffer newBuf = ByteBuffer.allocate(oldBuf.capacity() * 2);
oldBuf.flip();
newBuf.put(oldBuf);
return newBuf;
}
/**
* Append a byte to {@link #csiParam}, resizing if necessary
*
* @param b the byte
*/
protected void putCsiParamByte(byte b) {
if (!csiParam.hasRemaining()) {
csiParam = copyDoubledCapacity(csiParam);
}
csiParam.put(b);
}
/**
* Append a byte to {@link #csiInter}, resizing if necessary
*
* @param b the byte
*/
protected void putCsiInterByte(byte b) {
if (!csiInter.hasRemaining()) {
csiInter = copyDoubledCapacity(csiInter);
}
csiInter.put(b);
}
/**
* Append a byte to {@link #oscParam}, resizing if necessary
*
* @param b the byte
*/
protected void putOscParamByte(byte b) {
if (!oscParam.hasRemaining()) {
oscParam = copyDoubledCapacity(oscParam);
}
oscParam.put(b);
}
/**
* Create a copy of the CSI buffers, reconstructed as they were in the original stream.
*
@@ -226,11 +226,11 @@ public enum VtState {
@Override
protected VtState handleNext(byte b, VtParser parser, VtHandler handler) {
if (0x30 <= b && b <= 0x3f) {
parser.csiParam.put(b);
parser.putCsiParamByte(b);
return CSI_PARAM;
}
if (0x20 <= b && b <= 0x2f) {
parser.csiInter.put(b);
parser.putCsiInterByte(b);
return CSI_INTER;
}
if (0x40 <= b && b <= 0x7e) {
@@ -249,7 +249,7 @@ public enum VtState {
@Override
protected VtState handleNext(byte b, VtParser parser, VtHandler handler) {
if (0x20 <= b && b <= 0x2f) {
parser.csiInter.put(b);
parser.putCsiInterByte(b);
return CSI_INTER;
}
if (0x40 <= b && b <= 0x7e) {
@@ -269,7 +269,7 @@ public enum VtState {
protected VtState handleNext(byte b, VtParser parser, VtHandler handler) {
// For whatever reason, Windows includes the null terminator in titles
if (0x20 <= b && b <= 0x7f || b == 0) {
parser.oscParam.put(b);
parser.putOscParamByte(b);
return OSC_PARAM;
}
if (b == 0x07) {
+15 -1
View File
@@ -25,5 +25,19 @@ task buildPyPackage(type: Exec) {
outputs.dir(dist)
workingDir { "build/pypkg" }
commandLine "python", "-m", "build"
commandLine "python3", "-m", "build"
}
// At the moment, any module with a python package also distributes it.
// We can separate this into `distributePythonPackage` later, if necessary.
rootProject.assembleDistribution {
def p = this.project
def zipPath = getZipPath(p)
from (p.assemblePyPackage) {
exclude '**/*.pyc'
exclude '**/*.pyo'
exclude '**/__pycache__/**'
into { zipPath + "/pypkg" }
}
}