Rellic هو تنفيذ خوارزمية الهيكلة المستقلة عن الأنماط لإنتاج خرج C الخالي من Goto من LLVM Bitcode.
تتمثل فلسفة التصميم وراء المشروع في توفير قاعدة كود صغيرة نسبيًا ويمكن اختراقها بسهولة مع قابلية التشغيل البيني الكبير مع مشاريع LLVM الأخرى.
| البرنامج الأصلي | تم تجميعها مع -emit-llvm -O0 و decomplized |
int main () {
for ( int i = 0 ; i < 30 ; ++ i ) {
if ( i % 3 == 0 && i % 5 == 0 ) {
printf ( "fizzbuzzn" );
} else if ( i % 3 == 0 ) {
printf ( "fizzn" );
} else if ( i % 5 == 0 ) {
printf ( "buzzn" );
} else {
printf ( "%dn" , i );
}
}
} | int main () {
unsigned int var0 ;
unsigned int i ;
var0 = 0U ;
i = 0U ;
while (( int ) i < 30 ) {
if (( int ) i % 3 != 0U || !(( int ) i % 5 == 0U || ( int ) i % 3 != 0U )) {
if (( int ) i % 3 != 0U ) {
if (( int ) i % 5 != 0U ) {
printf ( "%dn" , i );
} else {
printf ( "buzzn" );
}
} else {
printf ( "fizzn" );
}
} else {
printf ( "fizzbuzzn" );
}
i = i + 1U ;
}
return var0 ;
} |
int main () {
int i = 0 ;
start:
i ++ ;
switch ( i ) {
case 1 : printf ( "%dn" , i ); goto start; break ;
case 2 : printf ( "%dn" , i ); goto start; break ;
case 3 : printf ( "%dn" , i ); break ;
}
} | int main () {
unsigned int var0 ;
unsigned int i ;
var0 = 0U ;
i = 0U ;
do {
i = i + 1U ;
if (!( i != 3U && i != 2U && i != 1U ))
if ( i == 3U ) {
printf ( "%dn" , i );
break ;
} else if ( i == 2U ) {
printf ( "%dn" , i );
} else {
printf ( "%dn" , i );
}
} while (!( i != 3U && i != 2U && i != 1U ));
return var0 ;
} |
int main () {
int x = atoi ( "5" );
if ( x > 10 ) {
while ( x < 20 ) {
x = x + 1 ;
printf ( "loop1 x: %dn" , x );
}
}
while ( x < 20 ) {
x = x + 1 ;
printf ( "loop2 x: %dn" , x );
}
} | int main () {
unsigned int var0 ;
unsigned int x ;
unsigned int call2 ;
var0 = 0U ;
call2 = atoi ( "5" );
x = call2 ;
if (( int ) x > 10 ) {
while (( int ) x < 20 ) {
x = x + 1U ;
printf ( "loop1 x: %dn" , x );
}
}
if (( int ) x <= 10 || ( int ) x >= 20 ) {
while (( int ) x < 20 ) {
x = x + 1U ;
printf ( "loop2 x: %dn" , x );
}
}
if (( int ) x >= 20 && (( int ) x <= 10 || ( int ) x >= 20 )) {
return var0 ;
}
} |
ج هياكل البيانات الخاصة بك مع rellic-headergen
فك تفاعلية مع rellic-xref
Machifier: تجربة مع إلغاء التثبيت التفاعلي
| يتقن | |
|---|---|
| Linux |
إذا كنت تعاني من مشاكل غير موثقة مع Rellic ، فاطلب المساعدة في قناة #binary-lifting في Slack Hacking Slack.
يتم دعم Rellic على منصات Linux وتم اختبارها على Ubuntu 22.04.
يمكن توفير معظم تبعيات Rellic بواسطة مستودع CXX-Common. يستضيف Trail of Bits إصدارات قابلة للتنزيل ، مصنوعة مسبقًا من CXX-Common ، مما يجعل من الأسهل بكثير الاستيلاء على Rellic. ومع ذلك ، فإن الجدول التالي يمثل معظم تبعيات Rellic.
| اسم | إصدار |
|---|---|
| غيت | أحدث |
| cmake | 3.21+ |
| أعلام Google | أحدث |
| سجل جوجل | أحدث |
| LLVM | 16 |
| كلانج | 16 |
| Z3 | 4.7.1+ |
تتوفر صور Docker التي تم تصميمها مسبقًا على Docker Hub و Github Package.
أولاً ، قم بتحديث الكفاءة واحصل على التبعيات الأساسية.
sudo apt update
sudo apt upgrade
sudo apt install
git
python3
wget
unzip
pixz
xz-utils
cmake
curl
build-essential
lsb-release
zlib1g-dev
libomp-dev
doctest-devإذا لم يتضمن التوزيع الذي تم تشغيله إصدارًا حديثًا من CMake (3.21 أو أحدث) ، فستحتاج إلى تثبيته. لصالح Ubuntu ، انظر هنا https://apt.kitware.com/.
والخطوة التالية هي استنساخ مستودع Rellic.
git clone --recurse-submodules https://github.com/lifting-bits/rellic.git أخيرًا ، نحن نبني ونحزم Rellic. سيقوم هذا البرنامج النصي بإنشاء دليل آخر ، rellic-build ، في دليل العمل الحالي. سيتم تنزيل جميع التبعيات المتبقية التي تحتاجها Rellic ووضعها في الدليل الأصل إلى جانب الخروج من الريبو في lifting-bits-downloads (انظر خيار البرنامج -h لمزيد من التفاصيل). ينشئ هذا البرنامج النصي أيضًا حزم Deb و RPM و TGZ القابلة للتثبيت.
cd rellic
./scripts/build.sh --llvm-version 16
# to install the deb package, then do:
sudo dpkg -i rellic-build/ * .debلتجربة Rellic ، يمكنك القيام بما يلي ، بالنظر إلى ملف Bitcode LLVM من اختيارك.
# Create some sample bitcode or your own
clang-16 -emit-llvm -c ./tests/tools/decomp/issue_4.c -o ./tests/tools/decomp/issue_4.bc
./rellic-build/tools/rellic-decomp --input ./tests/tools/decomp/issue_4.bc --output /dev/stdoutتأكد من الحصول على أحدث إصدار من CXX-Common لـ LLVM 16. ثم بناء مع
cmake
-DCMAKE_BUILD_TYPE=RelWithDebInfo
-DCMAKE_TOOLCHAIN_FILE=/path/to/vcpkg/scripts/buildsystems/vcpkg.cmake
-DVCPKG_TARGET_TRIPLET=x64-osx-rel
-DRELLIC_ENABLE_TESTING=OFF
-DCMAKE_C_COMPILER= ` which clang `
-DCMAKE_CXX_COMPILER= ` which clang++ `
/path/to/rellic
make -j8يجب أن توفر صورة Docker بيئة يمكنها إعداد وإنشاء وتشغيل Rellic. يتم تحديد صور Docker بواسطة إصدار Ubuntu Verison ، LLVM ، والهندسة المعمارية.
لبناء صورة Docker باستخدام LLVM 16 لـ Ubuntu 22.04 ، يمكنك تشغيل الأمر التالي:
UBUNTU=22.04 ; LLVM=16 ; docker build .
-t rellic:llvm ${LLVM} -ubuntu ${UBUNTU}
-f Dockerfile
--build-arg UBUNTU_VERSION= ${UBUNTU}
--build-arg LLVM_VERSION= ${LLVM}لتشغيل Decompiler ، تم بالفعل تعيين نقطة الدخول ، ولكن تأكد من أن الرمز البري الذي تخفضه هو نفس إصدار LLVM مثل Decompiler ، وتشغيله:
# Get the bc file
clang-16 -emit-llvm -c ./tests/tools/decomp/issue_4.c -o ./tests/tools/decomp/issue_4.bc
# Decompile
docker run --rm -t -i
-v $( pwd ) :/test -w /test
-u $( id -u ) : $( id -g )
rellic:llvm16-ubuntu22.04 --input ./tests/tools/decomp/issue_4.bc --output /dev/stdoutلشرح الأمر أعلاه أكثر:
# Mount current directory and change working directory
-v $( pwd ) :/test -w /testو
# Set the user to current user to ensure correct permissions
-u $( id -u ) : $( id -g ) نستخدم العديد من اختبارات التكامل والوحدة لاختبار Rellic.
ستأخذ اختبارات RoundTrip رمز C ، وإنشاءه إلى LLVM IR ، ثم ترجم أن IR مرة أخرى إلى C. الاختبار ثم يرى ما إذا كان يمكن بناء C الناتج وما إذا كان الرمز المترجم (تقريبًا) نفس الشيء مثل الأصل. لتشغيل هذه ، استخدم:
cd rellic-build # or your rellic build directory
CTEST_OUTPUT_ON_FAILURE=1 cmake --build . --verbose --target test Anghabench 1000 عبارة عن عينة من 1000 ملف (× 4 بنيات ، وبالتالي ما مجموعه 4000 اختبار) من المليون من البرامج التي تأتي مع Anghabench. يتحقق هذا الاختبار فقط ما إذا كان رمز البتات لهذه البرامج يترجم إلى C ، وليس الجاذبية أو وظائف الترجمة الناتجة. لتشغيل هذا الاختبار ، قم أولاً بتثبيت تبعيات Python المطلوبة الموجودة في scripts/requirements.txt .
scripts/test-angha-1k.sh --rellic-cmd < path_to_rellic_decompiler_exe > يرجى استخدام مقتطف Bibtex التالي للاستشهاد Rellic:
@online{rellic,
title={Rellic},
author={Surovič, Marek and Bertolaccini, Francesco},
organization={Trail of Bits},
url={https://github.com/lifting-bits/rellic}
}