Skip to content

Commit 3fa1cc7

Browse files
Bundle r2 on macOS
1 parent a20f368 commit 3fa1cc7

File tree

8 files changed

+151
-40
lines changed

8 files changed

+151
-40
lines changed

.github/workflows/ci.yml

+11-11
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,20 @@ jobs:
8181
echo $(brew --prefix qt@5)/bin >> $GITHUB_PATH
8282
pip3 install meson ninja
8383
- name: install r2
84+
working-directory: dist/macos
8485
run: |
85-
wget -q https://github.com/radareorg/radare2/releases/download/${{env.R2V}}/radare2-x64-${{env.R2V}}.pkg
86-
sudo installer -pkg *.pkg -target /
86+
curl -Lo radare2.pkg "https://github.com/radareorg/radare2/releases/download/${{env.R2V}}/radare2-x64-${{env.R2V}}.pkg"
87+
sudo installer -pkg radare2.pkg -target /
8788
- name: build iaito
8889
run: |
8990
./configure
90-
make -j4
91+
make -j4 QMAKE_FLAGS=IAITO_BUNDLE_R2_APPBUNDLE=true
9192
- name: packaging
92-
working-directory: build
93-
run: macdeployqt iaito.app -dmg -verbose=2
93+
run: make -C dist/macos
9494
- uses: actions/upload-artifact@v4
9595
with:
9696
name: iaito-x64.dmg
97-
path: build/iaito.dmg
97+
path: dist/macos/iaito.dmg
9898
acr-macos-arm64:
9999
runs-on: macos-latest
100100
steps:
@@ -113,20 +113,20 @@ jobs:
113113
echo $(brew --prefix qt@5)/bin >> $GITHUB_PATH
114114
pip3 install meson ninja
115115
- name: install r2
116+
working-directory: dist/macos
116117
run: |
117-
wget -q https://github.com/radareorg/radare2/releases/download/${{env.R2V}}/radare2-m1-${{env.R2V}}.pkg
118-
sudo installer -pkg *.pkg -target /
118+
curl -Lo radare2.pkg "https://github.com/radareorg/radare2/releases/download/${{env.R2V}}/radare2-m1-${{env.R2V}}.pkg"
119+
sudo installer -pkg radare2.pkg -target /
119120
- name: build iaito
120121
run: |
121122
./configure
122123
make -j4
123124
- name: packaging
124-
working-directory: build
125-
run: macdeployqt iaito.app -dmg -verbose=2
125+
run: make -C dist/macos
126126
- uses: actions/upload-artifact@v4
127127
with:
128128
name: iaito-arm64.dmg
129-
path: build/iaito.dmg
129+
path: dist/macos/iaito.dmg
130130
meson:
131131
runs-on: ${{ matrix.os }}
132132
strategy:

.gitignore

+7-1
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,10 @@ src/out
9191
*.orig
9292

9393
# Translations
94-
src/translations
94+
src/translations
95+
96+
# macOS package
97+
/dist/macos/radare2.pkg
98+
/dist/macos/radare2-unpkg
99+
/dist/macos/disk
100+
/dist/macos/*.dmg

dist/macos/Makefile

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
.PHONY: all app clean mrproper
2+
3+
all: app
4+
5+
app: ../../build/iaito.app radare2-unpkg
6+
mkdir disk
7+
cp -a ../../build/iaito.app disk/
8+
scripts/embed-radare2.sh radare2-unpkg disk/iaito.app
9+
cd disk && macdeployqt iaito.app -dmg -verbose=2
10+
mv disk/*.dmg .
11+
12+
radare2-unpkg: radare2.pkg
13+
pkgutil --expand-full $< $@
14+
15+
radare2.pkg:
16+
echo "Download first radare2.pkg from https://github.com/radareorg/radare2/releases"
17+
@false
18+
19+
../../build/iaito.app:
20+
echo "Building iaito..."
21+
$(MAKE) -C ../.. QMAKE_FLAGS=IAITO_BUNDLE_R2_APPBUNDLE=true
22+
23+
clean:
24+
rm -rf disk radare2-unpkg
25+
26+
mrproper: clean
27+
rm -f radare2.pkg

dist/macos/scripts/command.sh

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/bin/sh
2+
3+
CMD=$(basename "$0")
4+
APPDIR=$(cd "$(dirname "$0")/../../../.."; pwd)
5+
6+
R2_BINDIR="${APPDIR}/Contents/Helpers"
7+
R2_LIBDIR="${APPDIR}/Contents/Frameworks"
8+
R2_LIBR_PLUGINS="${APPDIR}/Contents/PlugIns/radare2"
9+
R2_PREFIX="${APPDIR}/Contents/Resources/radare2"
10+
11+
export R2_BINDIR
12+
export R2_LIBDIR
13+
export R2_LIBR_PLUGINS
14+
export R2_PREFIX
15+
16+
exec "${R2_BINDIR}/${CMD}" "$@"

dist/macos/scripts/embed-radare2.sh

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/bin/sh -e
2+
3+
R2PKGDIR="$1"
4+
APPDIR="$2"
5+
6+
SCRIPTS="$(dirname "$0")"
7+
R2DIR="${R2PKGDIR}/Payload/usr/local"
8+
R2V=$(readlink "${R2DIR}/lib/radare2/last")
9+
10+
fix_binary() {
11+
echo "Change library paths for \"$1\"..."
12+
ARGS=$(otool -L "$1" | awk '/\/usr\/local\/lib\/libr_/{dst=$1; sub(/\/usr\/local\/lib/,"@executable_path/../Frameworks", dst); print "-change "$1" "dst}')
13+
[ -n "$ARGS" ] && install_name_tool $ARGS "$1"
14+
}
15+
16+
mkdir -p \
17+
"${APPDIR}/Contents/Helpers" \
18+
"${APPDIR}/Contents/Frameworks" \
19+
"${APPDIR}/Contents/PlugIns/radare2" \
20+
"${APPDIR}/Contents/Resources/radare2/bin" \
21+
"${APPDIR}/Contents/Resources/radare2/lib/radare2"
22+
23+
cp -a "${R2DIR}/bin/"* "${APPDIR}/Contents/Helpers/"
24+
cp -a "${R2DIR}/lib/radare2/${R2V}/"* "${APPDIR}/Contents/PlugIns/radare2/"
25+
cp -a "${R2DIR}/lib/"*.dylib "${APPDIR}/Contents/Frameworks/"
26+
cp -a "${R2DIR}/include" "${APPDIR}/Contents/Resources/radare2/"
27+
cp -a "${R2DIR}/share" "${APPDIR}/Contents/Resources/radare2/"
28+
#cp -a "${R2DIR}/lib/pkgconfig" "${APPDIR}/Contents/Resources/radare2/lib/"
29+
cp -p "${SCRIPTS}/command.sh" "${APPDIR}/Contents/Resources/radare2/bin/radare2"
30+
cp -a "${R2DIR}/lib/radare2/last" "${APPDIR}/Contents/Resources/radare2/lib/radare2/"
31+
ln -s "../../../../PlugIns/radare2" "${APPDIR}/Contents/Resources/radare2/lib/radare2/${R2V}"
32+
33+
(
34+
cd "${APPDIR}/Contents/MacOS"
35+
fix_binary "iaito"
36+
)
37+
38+
(
39+
cd "${APPDIR}/Contents/Helpers"
40+
for c in *; do
41+
[ -L "$c" ] || fix_binary "$c"
42+
[ "$c" != "radare2" ] && ln -s radare2 "../Resources/radare2/bin/$c"
43+
done
44+
)
45+
46+
(
47+
LIBS=$(cd "${R2DIR}/lib"; ls *.dylib)
48+
cd "${APPDIR}/Contents/Frameworks"
49+
for c in $LIBS; do
50+
[ -L "$c" ] || fix_binary "$c"
51+
c2=$c # Resolve upto 2 link levels
52+
[ -L "$c2" ] && c2=$(readlink "$c2")
53+
[ -L "$c2" ] && c2=$(readlink "$c2")
54+
ln -s "../../../Frameworks/$c2" "../Resources/radare2/lib/$c"
55+
done
56+
)
57+
58+
(
59+
cd "${APPDIR}/Contents/PlugIns/radare2"
60+
for c in *; do
61+
[ -L "$c" ] || fix_binary "$c"
62+
done
63+
)

src/Iaito.pro

+5-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ CONFIG+=app_bundle
1212

1313
CONFIG += sdk_no_version_check
1414

15-
unix:QMAKE_RPATHDIR += /usr/local/lib
16-
unix:QMAKE_LFLAGS_RPATH=
17-
unix:QMAKE_LFLAGS += "-Wl,-rpath,/usr/local/lib"
15+
unix:!macx|macx:!IAITO_BUNDLE_R2_APPBUNDLE {
16+
QMAKE_RPATHDIR += /usr/local/lib
17+
QMAKE_LFLAGS_RPATH=
18+
QMAKE_LFLAGS += "-Wl,-rpath,/usr/local/lib"
19+
}
1820

1921
QMAKE_CXXFLAGS += $$(CXXFLAGS)
2022
QMAKE_CFLAGS += $$(CFLAGS)

src/IaitoApplication.cpp

+21-16
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,27 @@ IaitoApplication::IaitoApplication(int &argc, char **argv)
142142
qputenv("R_ALT_SRC_DIR", "1");
143143
#endif
144144

145+
#ifdef MACOS_R2_BUNDLED
146+
{
147+
auto appdir = QDir(QCoreApplication::applicationDirPath()); // Contents/MacOS
148+
appdir.cdUp(); // Contents
149+
150+
auto r2prefix = appdir; // Contents
151+
r2prefix.cd("Resources/radare2"); // Contents/Resources/radare2
152+
qputenv("R2_PREFIX", r2prefix.absolutePath().toLocal8Bit());
153+
154+
auto r2bin = appdir; // Contents
155+
r2bin.cd("Helpers"); // Contents/Helpers
156+
auto paths = QStringList(QString::fromLocal8Bit(qgetenv("PATH")));
157+
paths.prepend(r2bin.absolutePath());
158+
qputenv("PATH", paths.join(QLatin1Char(':')).toLocal8Bit());
159+
160+
// auto sleighHome = appdir; // Contents
161+
// sleighHome.cd("PlugIns/radare2/r2ghidra_sleigh"); // Contents/PlugIns/radare2/r2ghidra_sleigh
162+
// qputenv("SLEIGHHOME", sleighHome.absolutePath().toLocal8Bit());
163+
}
164+
#endif
165+
145166
Core()->initialize(clOptions.enableR2Plugins);
146167
Core()->setSettings();
147168
Config()->loadInitial();
@@ -219,22 +240,6 @@ IaitoApplication::IaitoApplication(int &argc, char **argv)
219240
}
220241
#endif
221242

222-
#ifdef Q_OS_MACOS
223-
{
224-
auto r2prefix = QDir(QCoreApplication::applicationDirPath()); // Contents/MacOS
225-
r2prefix.cdUp(); // Contents
226-
r2prefix.cd("Resources/r2"); // Contents/Resources/r2
227-
228-
auto sleighHome = r2prefix;
229-
sleighHome.cd("share/radare2/plugins/r2ghidra_sleigh"); // Contents/Resources/r2/share/radare2/plugins/r2ghidra_sleigh
230-
Core()->setConfig("r2ghidra.sleighhome", sleighHome.absolutePath());
231-
232-
auto r2decHome = r2prefix;
233-
r2decHome.cd("share/radare2/plugins/r2dec-js"); // Contents/Resources/r2/share/radare2/plugins/r2dec-js
234-
qputenv("R2DEC_HOME", r2decHome.absolutePath().toLocal8Bit());
235-
}
236-
#endif
237-
238243
#ifdef IAITO_APPVEYOR_R2DEC
239244
qputenv("R2DEC_HOME", "lib\\plugins\\r2dec-js");
240245
#endif

src/core/Iaito.cpp

+1-9
Original file line numberDiff line numberDiff line change
@@ -211,19 +211,11 @@ void IaitoCore::initialize(bool loadPlugins)
211211

212212
r_event_hook(core_->anal->ev, R_EVENT_ALL, cutterREventCallback, this);
213213
#if 0
214-
#if defined(APPIMAGE) || defined(MACOS_R2_BUNDLED)
215-
auto prefix = QDir(QCoreApplication::applicationDirPath());
216214
#ifdef APPIMAGE
215+
auto prefix = QDir(QCoreApplication::applicationDirPath());
217216
// Executable is in appdir/bin
218217
prefix.cdUp();
219218
qInfo() << "Setting r2 prefix =" << prefix.absolutePath() << " for AppImage.";
220-
#else // MACOS_R2_BUNDLED \
221-
// Executable is in Contents/MacOS, prefix is Contents/Resources/r2
222-
prefix.cdUp();
223-
prefix.cd("Resources");
224-
prefix.cd("r2");
225-
qInfo() << "Setting r2 prefix =" << prefix.absolutePath() << " for macOS Application Bundle.";
226-
#endif
227219
setConfig("dir.prefix", prefix.absolutePath());
228220

229221
auto pluginsDir = prefix;

0 commit comments

Comments
 (0)