Skip to content

Commit

Permalink
Use dependency instead of find_library and avoid relying on rizin exec (
Browse files Browse the repository at this point in the history
#14)

pkg-config files already contain all the required include and library
dependencies (plus optional CFLAGS) necessary to compile against Rizin
libraries. One can specify --pkg-config-path to specify the pkg-config
path to use if not in the standard directory. Also, by setting the
plugdir to prefix/lib/rizin/plugins (instead of RZ_USER_PLUGINS from the
rizin executable) the person compiling the plugin can choose whether to
install the plugin in a system-wide location (e.g. a maintainer of a
linux distro who wants to ship jsdec as a package would want to install
it in /usr/lib64/rizin/plugins and not in ~/.local/lib64/rizin/plugins)
or in the home location.
  • Loading branch information
ret2libc authored Dec 17, 2021
1 parent 7aa6e58 commit eea3555
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 40 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,23 @@ Converts asm to pseudo-C code.

Requires [rizin](https://github.com/rizinorg/rizin).

# Install
# Install system wide

Follow the following steps to install jsdec
- clone this repository
- Run `cd p`
- Run `meson -Djsc_folder=".." build` to create the build folder
- Run `meson -Djsc_folder=".." --prefix=/usr build` to create the build folder
- Run `ninja -C build install` to build the shared library and to install it


# Install in home folder (or in other paths)

If you want to install in the HOME folder or in other non standard paths, just
set the `prefix` to a different value
- Run `cd p`
- Run ``meson -Djsc_folder=".." --prefix=~/.local build``
- Run `ninja -C build install`

# Usage

* Open your file with rizin
Expand Down
52 changes: 16 additions & 36 deletions p/meson.build
Original file line number Diff line number Diff line change
@@ -1,46 +1,28 @@
project('jsdec', 'c', meson_version: '>=0.46.0')
project('jsdec', 'c', meson_version: '>=0.51.0')

pyth = import('python').find_installation()
rizin = find_program('rizin', required: false)
cc = meson.get_compiler('c')

incs = ['.']
incs = ['.', 'duktape']
deps = []
c_args = []

rizin_incdir = get_option('rizin_incdir')
if rizin_incdir == '' and rizin.found()
rizin_incdir = run_command(rizin, '-H', 'RZ_INCDIR').stdout().strip()
endif

rizin_libdir = get_option('rizin_libdir')
if rizin_libdir == '' and rizin.found()
rizin_libdir = run_command(rizin, '-H', 'RZ_LIBDIR').stdout().strip()
endif

rizin_plugdir = get_option('rizin_plugdir')
if rizin_plugdir == '' and rizin.found()
rizin_plugdir = run_command(rizin, '-H', 'RZ_USER_PLUGINS').stdout().strip()
if rizin_plugdir == ''
rizin_plugdir = get_option('libdir')
endif
endif

plugin_jsdec_dir = join_paths(rizin_plugdir, 'jsdec')

libs = ['rz_core', 'rz_util', 'rz_cons', 'rz_config', 'rz_io']
foreach lib : libs
deps += cc.find_library(lib, dirs: rizin_libdir)
endforeach

rz_core_dep = dependency('rz_core')
deps += rz_core_dep
deps += dependency('rz_util')
deps += dependency('rz_cons')
deps += dependency('rz_config')
deps += dependency('rz_io')
deps += cc.find_library('m', required: false)

if rizin_incdir != ''
incs += rizin_incdir
incs += rizin_incdir + '/sdb'
rizin_plugdir = get_option('rizin_plugdir')
if rizin_plugdir == ''
rizin_plugdir = rz_core_dep.get_variable(pkgconfig: 'plugindir', cmake: 'rz_core_PLUGINDIR')
plugin_jsdec_dir = join_paths(get_option('prefix'), rizin_plugdir, 'jsdec')
else
plugin_jsdec_dir = join_paths(rizin_plugdir, 'jsdec')
endif

incs += 'duktape'

files = [
'core_pdd.c',
Expand All @@ -67,9 +49,7 @@ if jsc_folder != ''
)
endif

message('Rizin Include Dir: ' + rizin_incdir)
message('Rizin Library Dir: ' + rizin_libdir)
message('Rizin Plugin Dir: ' + rizin_plugdir)
message('Rizin Plugin Dir: ' + plugin_jsdec_dir)
if jsc_folder != ''
message('JS to C Folder: ' + jsc_folder)
endif
Expand All @@ -88,4 +68,4 @@ if jsc_folder == ''
install_subdir(join_paths('..', 'themes'), install_dir: plugin_jsdec_dir)
install_data(join_paths('..', 'jsdec-duk.js'), install_dir: plugin_jsdec_dir)
install_data(join_paths('..', 'require.js'), install_dir: plugin_jsdec_dir)
endif
endif
2 changes: 0 additions & 2 deletions p/meson_options.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
option('rizin_libdir', type: 'string', value: '', description: 'rizin library directory')
option('rizin_incdir', type: 'string', value: '', description: 'rizin include directory')
option('rizin_plugdir', type: 'string', value: '', description: 'rizin install directory')
option('jsc_folder', type: 'string', value: '', description: 'When a path is defined, the js code, found in its subfolders, is embedded into the C code.')

0 comments on commit eea3555

Please sign in to comment.