Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update bb to use pvec #55

Merged
merged 3 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions .ci-scripts/ci-build-linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ set -e

CI_BRANCH="$1"
CI_JSDEC="$PWD"
CI_RZ_VERSION=$(curl -s GET https://api.github.com/repos/rizinorg/rizin/tags\?per_page\=1 | jq -r '.[].name')
CI_RZ_VERSION=$2

if [ "$CI_BRANCH" != "dev" ]; then
# master branch always build against latest release of rizin
CI_RZ_VERSION=$(curl -s GET https://api.github.com/repos/rizinorg/rizin/tags\?per_page\=1 | jq -r '.[].name')
else
CI_RZ_VERSION="$CI_BRANCH"
fi

echo "CI_BRANCH: $CI_BRANCH"
echo "CI_RZ_VERSION: $CI_RZ_VERSION"
Expand All @@ -12,11 +19,19 @@ echo "CI_JSDEC: $CI_JSDEC"
# avoid placing rizin in the same folder.
cd ..

# download the latest tagged rizin version and install it
wget -O "rizin.tar.xz" "https://github.com/rizinorg/rizin/releases/download/$CI_RZ_VERSION/rizin-src-$CI_RZ_VERSION.tar.xz"
tar xf "rizin.tar.xz"
cd "rizin-$CI_RZ_VERSION"
# download rizin
if [ "$CI_BRANCH" == "dev" ]; then
# dev branch always build against latest commit of rizin
wget -O "rizin.tar.gz" "https://github.com/rizinorg/rizin/archive/refs/heads/dev.tar.gz"
tar xf "rizin.tar.gz"
else
# master branch always build against latest release of rizin
wget -O "rizin.tar.xz" "https://github.com/rizinorg/rizin/releases/download/$CI_RZ_VERSION/rizin-src-$CI_RZ_VERSION.tar.xz"
tar xf "rizin.tar.xz"
fi

# build rizin and install it.
cd "rizin-$CI_RZ_VERSION"
meson setup --buildtype=release -Denable_tests=false build
sudo ninja -C build install

Expand Down
11 changes: 0 additions & 11 deletions .ci-scripts/ci-build-win.bat

This file was deleted.

33 changes: 33 additions & 0 deletions .ci-scripts/ci-build-win.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
.ci-scripts\vsdevenv.ps1 64

function Invoke-NativeCommand() {
if ($args.Count -eq 0) {
throw "Must supply some arguments."
}

$command = $args[0]
$commandArgs = @()
if ($args.Count -gt 1) {
$commandArgs = $args[1..($args.Count - 1)]
}

& $command $commandArgs
$result = $LASTEXITCODE

if ($result -ne 0) {
throw "$command $commandArgs exited with code $result."
}
}


$rizin_path = "C:$env:HOMEPATH\AppData\Local\Programs\rizin"
$env:PATH = "$env:PATH;C:$env:HOMEPATH\AppData\Local\Programs\rizin\bin"
$env:PKG_CONFIG_PATH = "C:$env:HOMEPATH\AppData\Local\Programs\rizin\lib\pkgconfig"
$env:CFLAGS = "-IC:$env:HOMEPATH\AppData\Local\Programs\rizin\include\librz -IC:$env:HOMEPATH\AppData\Local\Programs\rizin\include\librz\sdb"
$env:LDFLAGS = "-LC:$env:HOMEPATH\AppData\Local\Programs\rizin\lib"


Invoke-NativeCommand meson setup --buildtype=release --prefix="$rizin_path" build
Invoke-NativeCommand ninja -C build install
rizin.exe -e log.level=2 -Qc "Lc"
rizin.exe -Qc "af ; pdd" "C:\Windows\System32\calc.exe"
24 changes: 13 additions & 11 deletions .ci-scripts/ci-rizin-dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@
import sys
import os

file_name = sys.argv[1]
_, file_extension = os.path.splitext(file_name)
out_file = f"rizin{file_extension}"
print(file_name, out_file)
out_file = "rizin.zip"

tags = None
with urllib.request.urlopen('https://api.github.com/repos/rizinorg/rizin/tags?per_page=1') as f:
tags = json.load(f)
latest = tags[0]['name']
latest = "master" if len(sys.argv) < 1 else sys.argv[1]

url = f"https://github.com/rizinorg/rizin/releases/download/{latest}/{file_name}"
url = url.format(version=latest)
if latest != "dev":
# master branch always build against latest release of rizin
tags = None
with urllib.request.urlopen('https://api.github.com/repos/rizinorg/rizin/tags?per_page=1') as f:
tags = json.load(f)
latest = tags[0]['name']
url = f"https://github.com/rizinorg/rizin/archive/refs/tags/{latest}.zip"
else:
# dev branch always build against latest commit of rizin
url = "https://github.com/rizinorg/rizin/archive/refs/heads/dev.zip"

print(f"Latest rizin tag: {latest}")
print(f"Using rizin branch: {latest}")
print(f"{url} as {out_file}")

urllib.request.urlretrieve(url, out_file)
13 changes: 8 additions & 5 deletions .ci-scripts/vsdevenv.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
$bits = $args[0]
$installationPath = vswhere.exe -latest -property installationPath
if ($installationPath -and (test-path "$installationPath\Common7\Tools\vsdevcmd.bat")) {
& "${env:COMSPEC}" /s /c "`"$installationPath\Common7\Tools\vsdevcmd.bat`" -no_logo && set" | foreach-object {
$name, $value = $_ -split '=', 2
set-content env:\"$name" $value
if (-not $installationPath -or -not (test-path "$installationPath\VC\Auxiliary\Build\vcvars$bits.bat")) {
throw "vcvars$bits.bat file not found"
}
& "${env:COMSPEC}" /s /c "`"$installationPath\VC\Auxiliary\Build\vcvars$bits.bat`" > nul 2>&1 && set" | . { process {
if ($_ -match '^([^=]+)=(.*)') {
[System.Environment]::SetEnvironmentVariable($matches[1], $matches[2])
}
}
}}
24 changes: 14 additions & 10 deletions .github/workflows/build-plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ jobs:
uses: actions/checkout@v4
- name: Install dependencies
run: sudo apt -y install meson ninja-build
- name: Build & run the plugin
run: bash .ci-scripts/ci-build-linux.sh "${{ github.ref_name }}"
- name: Build & run jsdec as rizin plugin
run: bash .ci-scripts/ci-build-linux.sh "${{ github.event.pull_request.base.ref || github.ref_name }}"

windows-64:
runs-on: windows-latest
Expand All @@ -44,19 +44,23 @@ jobs:
- name: Install dependencies
shell: bash
run: |
pip install ninja meson
pip install ninja meson PyYAML
choco install pkgconfiglite
choco install zip
- name: Install rizin
- name: Fetch & build rizin
shell: bash
run: |
WORKDIR="$PWD"
cd ..
python "$WORKDIR/.ci-scripts/ci-rizin-dl.py" 'rizin-${{ matrix.release }}-{version}.zip'
unzip rizin.zip
python "$WORKDIR/.ci-scripts/ci-rizin-dl.py" '${{ github.event.pull_request.base.ref || github.ref_name }}'
unzip -q rizin.zip
rm *.zip
mv rizin* rizin
mv rizin* rizin-build
cd rizin-build
powershell.exe ".\dist\windows\build_windows_installer.ps1 vs2019_static 64 --default-library=shared -Dportable=true"
ls ./dist/windows/Output
powershell.exe '.\dist\windows\Output\rizin.exe /SP- /SILENT /CURRENTUSER'
cd "$WORKDIR"
- name: Build & run the plugin
shell: cmd
run: .ci-scripts/ci-build-win.bat x64
- name: Build & run jsdec as rizin plugin
shell: pwsh
run: .ci-scripts\ci-build-win.ps1 64
5 changes: 3 additions & 2 deletions c/jsdec-cutter.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,12 @@ static JSValue js_analysis_opcodes(JSContext *ctx, RzCore *core) {
static JSValue js_function_bbs(JSContext *ctx, RzCore *core, RzAnalysisFunction *fcn) {
JSValue bbs = JS_NewArray(ctx);
RzAnalysisBlock *bbi;
RzListIter *iter;
void **iter;
st64 bbs_idx = 0;
ut64 old_offset = core->offset;
ut64 old_bsize = core->blocksize;
rz_list_foreach (fcn->bbs, iter, bbi) {
rz_pvector_foreach (fcn->bbs, iter) {
bbi = (RzAnalysisBlock *)*iter;
rz_core_block_size(core, bbi->size);
rz_core_seek(core, bbi->addr, true);

Expand Down
5 changes: 3 additions & 2 deletions c/jsdec-plugin.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,12 @@ static JSValue js_analysis_opcodes(JSContext *ctx, RzCore *core) {
static JSValue js_function_bbs(JSContext *ctx, RzCore *core, RzAnalysisFunction *fcn) {
JSValue bbs = JS_NewArray(ctx);
RzAnalysisBlock *bbi;
RzListIter *iter;
void **iter;
st64 bbs_idx = 0;
ut64 old_offset = core->offset;
ut64 old_bsize = core->blocksize;
rz_list_foreach (fcn->bbs, iter, bbi) {
rz_pvector_foreach (fcn->bbs, iter) {
bbi = (RzAnalysisBlock *)*iter;
rz_core_block_size(core, bbi->size);
rz_core_seek(core, bbi->addr, true);

Expand Down