convert ?E to API (#3025)

This commit is contained in:
billow 2022-08-18 06:52:50 +08:00 committed by GitHub
parent cab85d204e
commit 7a83001a06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 12 deletions

View File

@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 3.12)
project(cutter-sample-plugin) project(cutter-sample-plugin)
find_package(Cutter REQUIRED) find_package(Cutter REQUIRED)
find_package(Rizin REQUIRED)
set(CUTTER_INSTALL_PLUGDIR "${Cutter_USER_PLUGINDIR}" CACHE STRING "Directory to install Cutter plugin into") set(CUTTER_INSTALL_PLUGDIR "${Cutter_USER_PLUGINDIR}" CACHE STRING "Directory to install Cutter plugin into")
set(CMAKE_AUTOMOC ON) set(CMAKE_AUTOMOC ON)
@ -9,5 +10,5 @@ set(CMAKE_AUTOMOC ON)
add_library(sample_plugin MODULE add_library(sample_plugin MODULE
CutterSamplePlugin.h CutterSamplePlugin.h
CutterSamplePlugin.cpp) CutterSamplePlugin.cpp)
target_link_libraries(sample_plugin PRIVATE Cutter::Cutter) target_link_libraries(sample_plugin PRIVATE Cutter::Cutter Rizin::Core)
install(TARGETS sample_plugin DESTINATION "${CUTTER_INSTALL_PLUGDIR}") install(TARGETS sample_plugin DESTINATION "${CUTTER_INSTALL_PLUGDIR}")

View File

@ -8,6 +8,7 @@
#include <common/TempConfig.h> #include <common/TempConfig.h>
#include <common/Configuration.h> #include <common/Configuration.h>
#include <MainWindow.h> #include <MainWindow.h>
#include <librz/rz_core.h>
void CutterSamplePlugin::setupPlugin() {} void CutterSamplePlugin::setupPlugin() {}
@ -46,25 +47,21 @@ CutterSamplePluginWidget::CutterSamplePluginWidget(MainWindow *main) : CutterDoc
void CutterSamplePluginWidget::on_seekChanged(RVA addr) void CutterSamplePluginWidget::on_seekChanged(RVA addr)
{ {
Q_UNUSED(addr); Q_UNUSED(addr);
QString res; RzCoreLocked core(Core());
{
TempConfig tempConfig; TempConfig tempConfig;
tempConfig.set("scr.color", 0); tempConfig.set("scr.color", 0);
res = Core()->cmd("?E `pi 1`"); QString disasm = Core()->disassembleSingleInstruction(Core()->getOffset());
} QString res = fromOwnedCharPtr(rz_core_clippy(core, disasm.toUtf8().constData()));
text->setText(res); text->setText(res);
} }
void CutterSamplePluginWidget::on_buttonClicked() void CutterSamplePluginWidget::on_buttonClicked()
{ {
RzCoreLocked core(Core()); RzCoreLocked core(Core());
char *fortune = rz_core_fortune_get_random(core); auto fortune = fromOwned(rz_core_fortune_get_random(core));
if (!fortune) { if (!fortune) {
return; return;
} }
// cmdRaw can be used to execute single raw commands QString res = fromOwnedCharPtr(rz_core_clippy(core, fortune.get()));
// this is especially good for user-controlled input
QString res = Core()->cmdRaw("?E " + QString::fromUtf8(fortune));
text->setText(res); text->setText(res);
rz_mem_free(fortune);
} }