Skip to content

Commit

Permalink
Byteman now hav its (not working) tab in upload dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
judovana committed Oct 7, 2023
1 parent 27e4bde commit c89b28b
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ boolean isAdditionalSrcBufferVisible() {
return buffers.getSelectedComponent().equals(additionalSrcBuffer);
}

private boolean isBytemanBufferVisible() {
boolean isBytemanBufferVisible() {
return buffers.getSelectedComponent().equals(bytemanScript);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ class ClassOverwriter {
this.decompilationController = decompilationController;
}

void overwriteClass(DecompilerWrapper selectedDecompiler, String name, String buffer, byte[] binBuffer, boolean isBinary) {
void overwriteClass(DecompilerWrapper selectedDecompiler, String name, String buffer, byte[] binBuffer, int tab) {
if (name == null || name.trim().isEmpty()) {
name = "???";
}

final OverwriteClassDialog overwriteClassDialog = new OverwriteClassDialog(
name, lastLoaded, buffer, binBuffer, decompilationController.getVmInfo(), decompilationController.getVmManager(),
decompilationController.getPluginManager(), selectedDecompiler, isBinary, decompilationController.isVerbose()
decompilationController.getPluginManager(), selectedDecompiler, tab, decompilationController.isVerbose()
);

ScreenFinder.centerWindowToCurrentScreen(overwriteClassDialog);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,28 @@ class OverwriteActionListener implements ActionListener {

@Override
public void actionPerformed(ActionEvent actionEvent) {
int tab = getTab();
if (
bytecodeDecompilerView.isBinaryBufferVisible() || bytecodeDecompilerView.isDecompiledBytecodeBufferVisible()) {
isAnyPrimaryTabSelected()) {
worker.overwriteClass(
bytecodeDecompilerView.getSelectedDecompiler(), bytecodeDecompilerView.getLastDecompiledClass(),
bytecodeDecompilerView.getBytecodeBuffer().getText(), bytecodeDecompilerView.getBinary().get(),
bytecodeDecompilerView.isBinaryBufferVisible()
bytecodeDecompilerView.getBytecodeBuffer().getText(), bytecodeDecompilerView.getBinary().get(), tab
);
} else if (
bytecodeDecompilerView.isAdditionalBinaryBufferVisible() ||
bytecodeDecompilerView.isAdditionalDecompiledBytecodeBufferVisible()) {
isSecondaryTabSelected()) {
worker.overwriteClass(
bytecodeDecompilerView.getSelectedDecompiler(), bytecodeDecompilerView.getLastDecompiledClass(),
bytecodeDecompilerView.getAdditionalBytecodeBuffer().getText(), bytecodeDecompilerView.getAdditionalBinary().get(),
bytecodeDecompilerView.isAdditionalBinaryBufferVisible()
bytecodeDecompilerView.getAdditionalBytecodeBuffer().getText(), bytecodeDecompilerView.getAdditionalBinary().get(), tab
);
} else if (bytecodeDecompilerView.isAdditionalSrcBufferVisible()) {
worker.overwriteClass(
bytecodeDecompilerView.getSelectedDecompiler(), bytecodeDecompilerView.getLastDecompiledClass(),
bytecodeDecompilerView.getAdditionalSrcBuffer().getText(), new byte[0],
bytecodeDecompilerView.isAdditionalBinaryBufferVisible()
bytecodeDecompilerView.getAdditionalSrcBuffer().getText(), new byte[0], tab
);
} else if (bytecodeDecompilerView.isBytemanBufferVisible()) {
worker.overwriteClass(
bytecodeDecompilerView.getSelectedDecompiler(), bytecodeDecompilerView.getLastDecompiledClass(),
bytecodeDecompilerView.getBytemanScript().getText(), new byte[0], tab
);
} else {
JOptionPane.showMessageDialog(
Expand All @@ -44,4 +46,30 @@ public void actionPerformed(ActionEvent actionEvent) {
}

}

private boolean isSecondaryTabSelected() {
return bytecodeDecompilerView.isAdditionalBinaryBufferVisible() ||
bytecodeDecompilerView.isAdditionalDecompiledBytecodeBufferVisible();
}

private boolean isAnyPrimaryTabSelected() {
return bytecodeDecompilerView.isBinaryBufferVisible() || bytecodeDecompilerView.isDecompiledBytecodeBufferVisible();
}

private int getTab() {
int tab = -1;
if (bytecodeDecompilerView.isBytemanBufferVisible()) {
tab = 3;
}
if (bytecodeDecompilerView.isBinaryBufferVisible() || bytecodeDecompilerView.isAdditionalBinaryBufferVisible()) {
tab = 2;
}
if (bytecodeDecompilerView.isDecompiledBytecodeBufferVisible() ||
bytecodeDecompilerView.isAdditionalDecompiledBytecodeBufferVisible() ||
bytecodeDecompilerView.isAdditionalSrcBufferVisible()
) {
tab = 1;
}
return tab;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ public void onException(Exception ex) {
private final JButton uploadBinary;
private final JTextField statusBinary;

private final JPanel bytemanView;
private final JTextField saveBytemanAsFile; //read only!
private final JTextField bytemanStatus; //read only!
private final JButton saveByteman;
private final JButton saveBytemanAs;
private final JButton loadByteman;
private final JButton compileByteman;
private final JButton compileAndUploadByteman;
private final JButton unloadByteman;
private final JButton unloadAllBytemans;
private final String origName;
private final String origBuffer;
private final byte[] origBin;
Expand All @@ -137,8 +147,7 @@ public void onException(Exception ex) {

public OverwriteClassDialog(
final String name, final LatestPaths latestPaths, final String currentBuffer, final byte[] cBinBuffer, VmInfo vmInfo,
VmManager vmManager, PluginManager pluginManager, DecompilerWrapper selectedDecompiler, boolean isBinaryVisible,
boolean isVerbose
VmManager vmManager, PluginManager pluginManager, DecompilerWrapper selectedDecompiler, int tab, boolean isVerbose
) {
super((JFrame) null, "Specify class and selectSrc its bytecode", true);
this.setSize(400, 400);
Expand Down Expand Up @@ -238,11 +247,42 @@ public OverwriteClassDialog(
binaryView.add(uploadBinary);
binaryView.add(statusBinary);

bytemanView = new JPanel(new GridLayout(5, 1));
bytemanView.setName("Current byteman script");
saveBytemanAsFile = new JTextField(Config.getConfig().getBytemanScriptFile(name).getAbsolutePath());
saveBytemanAsFile.setEditable(false);
saveByteman = new JButton("Save");
saveBytemanAs = new JButton("Save copy as");
loadByteman = new JButton("Replace from file");
compileByteman = new JButton("Type check");
compileAndUploadByteman = new JButton("Inject to vm: " + vmInfo.getVmPid());
compileAndUploadByteman.setFont(compileAndUploadByteman.getFont().deriveFont(Font.BOLD));
unloadByteman = new JButton("Unload rules from this file");
unloadAllBytemans = new JButton("Unload all byteman rules");
bytemanView.add(saveBytemanAsFile);
JPanel saveBytemanButtons = new JPanel(new GridLayout(1, 3));
saveBytemanButtons.add(saveByteman);
saveBytemanButtons.add(saveBytemanAs);
saveBytemanButtons.add(loadByteman);
bytemanView.add(saveBytemanButtons);
JPanel compileBytemanButtons = new JPanel(new GridLayout(1, 2));
compileBytemanButtons.add(compileByteman);
compileBytemanButtons.add(compileAndUploadByteman);
bytemanView.add(compileBytemanButtons);
JPanel unloadBytemanButtons = new JPanel(new GridLayout(1, 2));
unloadBytemanButtons.add(unloadByteman);
unloadBytemanButtons.add(unloadAllBytemans);
bytemanView.add(unloadBytemanButtons);
bytemanStatus = new JTextField("check/install status");
bytemanStatus.setEditable(false);
bytemanView.add(bytemanStatus);

setLocationRelativeTo(null);
setValidation();
setSelectListener();
setOkListener(isVerbose);
addComponentsToPanels();
addComponentsToPanels(vmInfo.getType() == VmInfo.Type.LOCAL/*FIXME byteman shouldbe made available also for
remote vms.. Byteman companion for remote vms?*/);

this.pluginManager = pluginManager;
this.decompiler = selectedDecompiler;
Expand All @@ -255,8 +295,15 @@ public OverwriteClassDialog(
statusCompileCurrentBuffer.setText(ex.getMessage());
dualPane.setSelectedIndex(1);
}
if (isBinaryVisible) {

if (tab == 1) {
dualPane.setSelectedIndex(0);
} else if (tab == 2) {
dualPane.setSelectedIndex(3);
} else if (tab == 3) {
dualPane.setSelectedIndex(4);
} else {
dualPane.setSelectedIndex(2);
}

saveSrcBuffer.addActionListener(new ActionListener() {
Expand Down Expand Up @@ -488,7 +535,7 @@ static void purgeSourceTarget(List<String> compilerArgs) {
compilerArgs.add(3, "" + Config.getConfig().getBestSourceTarget().get());
}

private void addComponentsToPanels() {
private void addComponentsToPanels(boolean bytemanTab) {
inputs.add(filePath);
inputs.add(className);
inputs.add(className);
Expand Down Expand Up @@ -522,6 +569,9 @@ private void addComponentsToPanels() {
dualPane.add(manualPane);
dualPane.add(externalFiles);
dualPane.add(binaryView);
if (bytemanTab) {
dualPane.add(bytemanView);
}
this.add(dualPane);
this.pack();
}
Expand Down

0 comments on commit c89b28b

Please sign in to comment.