Skip to content

Commit

Permalink
Adress requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cvonelm committed Sep 26, 2023
1 parent 572bb43 commit 71f6a07
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ find_package(PkgConfig)

if(PkgConfig_FOUND)
pkg_check_modules(Audit audit)
pkg_check_modules(Radare r_main)
pkg_check_modules(Radare IMPORTED_TARGET r_main>=5.8.0)
endif()


Expand Down Expand Up @@ -268,7 +268,7 @@ endif()
if (USE_RADARE)
if (Radare_FOUND)
target_compile_definitions(lo2s PUBLIC HAVE_RADARE)
target_link_libraries(lo2s PRIVATE ${Radare_LIBRARIES})
target_link_libraries(lo2s PRIVATE PkgConfig::Radare)
target_sources(lo2s PRIVATE
src/radare.cpp
)
Expand Down
34 changes: 22 additions & 12 deletions src/radare.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@

namespace lo2s
{
Radare::Radare() : r_lib_(r_lib_new(NULL, NULL)), r_anal_(r_anal_new()), r_asm_(r_asm_new())
Radare::Radare() : r_lib_(r_lib_new(nullptr, nullptr)), r_anal_(r_anal_new()), r_asm_(r_asm_new())
{
r_unref(r_anal_->config);

r_asm_->num = r_num_new(NULL, NULL, NULL);
r_asm_->num = r_num_new(nullptr, nullptr, nullptr);
r_anal_->config = r_ref_ptr(r_asm_->config);
r_anal_bind(r_anal_, &r_asm_->analb);

Expand All @@ -41,20 +41,24 @@ Radare::Radare() : r_lib_(r_lib_new(NULL, NULL)), r_anal_(r_anal_new()), r_asm_(

std::string Radare::single_instruction(char* buf)
{
auto len = strlen(buf);
if (len == 0)
if (buf == nullptr)
{
throw Error("empty instruction");
throw Error("code->assembly is NULL");
}

auto it = buf;

while (*it != '\0' && *it != '\n')
{
it++;
}
for (size_t i = 0; i < len; i++)

if (it == buf)
{
if (buf[i] == '\n')
{
buf[i] = '\0';
break;
}
throw Error("empty instruction");
}
return std::string(buf);

return std::string(buf, it - 1);
}

std::string Radare::operator()(Address ip, std::istream& obj)
Expand All @@ -77,6 +81,12 @@ std::string Radare::operator()(Address ip, std::istream& obj)

r_asm_set_pc(r_asm_, offset);
auto code = r_asm_mdisassemble(r_asm_, (unsigned char*)buffer, read_bytes);

if (code == nullptr)
{
throw Error("could not disassemble instruction");
}

auto ret = single_instruction(code->assembly);

r_asm_code_free(code);
Expand Down

0 comments on commit 71f6a07

Please sign in to comment.