‏הצגת רשומות עם תוויות Java. הצג את כל הרשומות
‏הצגת רשומות עם תוויות Java. הצג את כל הרשומות

יום שבת, אוגוסט 06, 2016

פוסט ביקורת עמיתים - הכנת תשתית הקוד לביצוע מחקר

פוסט זה נועד לאפשר חזרה על הפעולות שביצעתי במהלך ביצוע המחקר בנושא חבילת תוכנה מסויימת.

ע"י מעבר על השלבים שמפורסמים פה ובפוסטים נוספים אני מקווה כי ניתן יהיה לשחזר ולבצע ביקורת עמיתים פשוטה.

כלים דרושים:

מערכת דביאן סיד , הפעולות בוצעו ע"י משתמש בשם user הקבצים הורדו לתיקיות pikud ו tmp.


apktool
unzip
grep
גישה לאינטרנט.

קבלת התוכנה עצמה:
הפעולה הראשונה היא הורדת ה APK עצמו ללא שימוש בחנות האפליקציות, במאמר עצמו אני מתייחס לנקודה הזאת שחוסמים את האפשרות של אנשים להם אין אפשרות להוריד מחנות האפליקציות (מכשיר ללא גישה לחנות האפליקציות, אין להם באמת מכשיר המקושר לחשבון).

ניתן להשתמש ב apkpure.com או apk-dl כל מערכת אחרת שמאפשרת הורדת אפצליקציות שלא מהסטור עצמו. ראויי לציין כי מכיוון שאנו מורידים מצד שלישי קוד המקור יכול להיות שעבר שינוי.
מסיבה זו אני מפרסם את ההאשים שקיבלתי (דרך שתי האתרים האלה הם היו זהים).


ההאשים של הAPK שלי הם :

user@laptop:~/pikud$ sha512sum Home%20Front%20Command_1.2_apk-dl.com.apk
28da60bf0e2941d632a65fe\
76960f45a715835d0567f0a\
3840eded45de7c63cef41d45\
817b5853d496b005d81b5e70\
713559957cf842daaaa0656ceb9ab6d075  Home%20Front%20Command_1.2_apk-dl.com.apk 
 
 
user@laptop:~/pikud$ md5sum Home%20Front%20Command_1.2_apk-dl.com.apk
81282187c7395e0cf1c72cabeeaa8b87  Home%20Front%20Command_1.2_apk-dl.com.apk

פריסת נתונים:

ביצוע פריסת הקבצים ופיענוח התוכן בוצעה ע"י apktool

Apktool v2.1.1-dirty - a tool for reengineering Android apk files
with smali v2.1.3-dev and baksmali v2.1.3-dev
Copyright 2014 Ryszard Wiśniewski 
Updated by Connor Tumbleson 
הותקן ע"י חבילה סטנדרטית :
apt-cache policy apktool 
apktool:
  Installed: 2.1.1+dfsg-3
  Candidate: 2.1.1+dfsg-3
  Version table:  

ביצוע הפריסה התבצע ע"י

user@laptop:~/pikud/$apktool d Home%20Front%20Command_1.2_apk-dl.com.apk 
I: Using Apktool 2.1.1-dirty on Home%20Front%20Command_1.2_apk-dl.com.apk
I: Loading resource table...
I: Decoding AndroidManifest.xml with resources...
I: Loading resource table from file: /home/user/.local/share/apktool/framework/1.apk
I: Regular manifest package...
I: Decoding file-resources...
I: Decoding values */* XMLs...
I: Baksmaling classes.dex...
I: Copying assets and libs...
I: Copying unknown files...
I: Copying original files...

לאחר הפעולה תתקבל תיקייה Home%20Front%20Command_1.2_apk-dl.com מציאת הכתובת בוצעה ע"י :
user@laptop:~/pikud$ grep mailto -rn *
js/appObjs/globalMethods.js:60: 
 window.location = "mailto:itayg@elad.co.il?subject=Ioref%20Bug%20Report&body="+mailBoady;
js/controllers/contactUsController.js:51:                                                                       window.plugins.inAppBrowswer.open('mailto:info-oref@idf.gov.il?subject=Something to share with you...','_system');
grep .co.il -rn *

AndroidManifest.xml:20:        <meta-data android:name="server_url" 
android:value="https://ioref.co.il">
AndroidManifest.xml:21:        <meta-data android:name="dr_server_url" 
android:value="https://dr.ioref.co.il">

assets/www/js/appObjs/globalMethods.js:60: 
 window.location = "mailto:itayg@elad.co.il?subject=Ioref%20Bug%20Report&body="+mailBoady;

grep .org.il -rn *
assets/www/js/controllers/contactUsController.js:41:                                                                    window.plugins.inAppBrowswer.open('http://www.oref.org.il','_system');
assets/www/js/controllers/contactUsController.js:45:                                                                    window.location = "http://www.oref.org.il";


לאחר ביצוע הפיענוח הראשוני מתקבלים קבצי .smali שהם המקבילה (?) של קבצי אסמבלי לbytecode בעולם האנדרויד.

אימות הממצאים בוצע ע"י בידקה מתוצרי ה jadx.

פריסה ופיענוח באמצעות jadx

  • שימוש שימוש באתרים שמבצעים jadx , לשם שימוש מעלים את קובץ הapk שהורד קודם לאתר והוא מבצע המרת החבילה לקוד java שהוא קריא טיפה יותר מקבצי smali.

  • ביצוע פריסת jadx עצמאית
ככל קבצי הapk הם לא הרבה יותר מאשר ארכיב מסוג zip שמכיל מבנה קבצים מיוחד.
נשמור את הקובץ בתת תיקיה (בשביל להקל בדיקות לאחר מכן).

 הפיכת קובץ ה APK ל zip וביצוע פריסה שלו:
user@laptop:~/pikud/zip$ mv Home\ Front\ Command_v1.2.apk Home\ Front\ Command_v1.2.apk.zip

ביצוע פריסה שלו (השתמשתי בתוכנת ה unzip שמגיעה מחבילת unzip בדביאן):

user@laptop:~/pikud/zip$ unzip -x Home\ Front\ Command_v1.2.apk.zip 
Archive:  Home Front Command_v1.2.apk.zip
 extracting: assets/www/css/images/ajax-loader.gif  
  inflating: assets/www/css/idangerous.swiper.css  
  inflating: assets/www/css/index.css  
  inflating: assets/www/css/jquery.mobile-1.4.2.min.css  
  inflating: assets/www/css/toggle-switch.css  
 extracting: assets/www/img/A_minus.png  
 extracting: assets/www/img/A_plus.png  
 extracting: assets/www/img/AntennaRed.png  
 extracting: assets/www/img/Locate.png  
 extracting: assets/www/img/antenna.png  
 extracting: assets/www/img/arrow1.png  
 extracting: assets/www/img/arrow1Right.png  
 extracting: assets/www/img/arrowDown.png  
 extracting: assets/www/img/arrowLeft.png  
 extracting: assets/www/img/arrowRight.png  
 extracting: assets/www/img/back.png  
 extracting: assets/www/img/background.png  
 extracting: assets/www/img/call.png  
 extracting: assets/www/img/call2.png  
 extracting: assets/www/img/cellBlue.png  
 extracting: assets/www/img/cellOrange.png  
 extracting: assets/www/img/cellRed.png  
 extracting: assets/www/img/cellyellow.png  
 extracting: assets/www/img/checkBox1Off.png  
 extracting: assets/www/img/checkBox1On.png  
 extracting: assets/www/img/choosingShelter.jpg  
 extracting: assets/www/img/close.png  
 extracting: assets/www/img/earthquake.jpg  
 extracting: assets/www/img/emergencyBag.jpg  
 extracting: assets/www/img/facebook.png  
 extracting: assets/www/img/familyReadiness.jpg  
 extracting: assets/www/img/filterBar.png  
 extracting: assets/www/img/forbiddenMaterials.jpg  
 extracting: assets/www/img/home.png  
 extracting: assets/www/img/info.png  
 extracting: assets/www/img/key1.png  
 extracting: assets/www/img/location2.png  
 extracting: assets/www/img/locationIcon.png  
 extracting: assets/www/img/logo.png  
 extracting: assets/www/img/mail.png  
 extracting: assets/www/img/menu.png  
 extracting: assets/www/img/navBar.png  
 extracting: assets/www/img/news_icon_Yellow.png  
 extracting: assets/www/img/onAlarm.jpg  
 extracting: assets/www/img/progressBig0.png  
 extracting: assets/www/img/progressBig100.png  
 extracting: assets/www/img/progressBig20.png  
 extracting: assets/www/img/progressBig40.png  
 extracting: assets/www/img/progressBig60.png  
 extracting: assets/www/img/progressBig80.png  
 extracting: assets/www/img/progressSmall0.png  
 extracting: assets/www/img/progressSmall100.png  
 extracting: assets/www/img/progressSmall20.png  
 extracting: assets/www/img/progressSmall40.png  
 extracting: assets/www/img/progressSmall60.png  
 extracting: assets/www/img/progressSmall80.png  
 extracting: assets/www/img/protectiveZonesMap.jpg  
 extracting: assets/www/img/radio.png  
 extracting: assets/www/img/radio2.png  
 extracting: assets/www/img/ready.png  
 extracting: assets/www/img/settings.png  
 extracting: assets/www/img/situation.png  
 extracting: assets/www/img/textBox2.png  
 extracting: assets/www/img/textBox3.png  
 extracting: assets/www/img/time2.png  
 extracting: assets/www/img/timeIcon.png  
 extracting: assets/www/img/twitter.png  
 extracting: assets/www/img/update.png  
 extracting: assets/www/img/web.png  
 extracting: assets/www/img/youtube.png  
  inflating: assets/www/js/appObjs/appMenu.js  
 extracting: assets/www/js/appObjs/appMessages.js  
  inflating: assets/www/js/appObjs/contentLoader.js  
  inflating: assets/www/js/appObjs/errorsManager.js  
  inflating: assets/www/js/appObjs/globalMethods.js  
  inflating: assets/www/js/appObjs/globalVariables.js  
  inflating: assets/www/js/appObjs/languageManager.js  
  inflating: assets/www/js/appObjs/locationManager.js  
  inflating: assets/www/js/appObjs/navigationManager.js  
  inflating: assets/www/js/appObjs/requireConfig.js  
  inflating: assets/www/js/controllers/appLobbyController.js  
  inflating: assets/www/js/controllers/contactUsController.js  
  inflating: assets/www/js/controllers/messageDetailsController.js  
  inflating: assets/www/js/controllers/readinessController.js  
  inflating: assets/www/js/controllers/readinessDetailsController.js  
  inflating: assets/www/js/controllers/settingsController.js  
  inflating: assets/www/js/controllers/situationRoomController.js  
  inflating: assets/www/js/controllers/wizard_chooseLocationController.js  
  inflating: assets/www/js/controllers/wizard_choosingShelterController.js  
  inflating: assets/www/js/controllers/wizard_earthquakeReadinessController.js  
  inflating: assets/www/js/controllers/wizard_emergencyBagController.js  
  inflating: assets/www/js/controllers/wizard_progressStateController.js  
  inflating: assets/www/js/lib/idangerous.swiper.js  
  inflating: assets/www/js/lib/idangerous.swiper.min.js  
  inflating: assets/www/js/lib/jquery-1.7.1.min.js  
  inflating: assets/www/js/lib/jquery.blockUI.js  
  inflating: assets/www/js/lib/jquery.js  
  inflating: assets/www/js/lib/jquery.mobile-1.4.2.js  
  inflating: assets/www/js/lib/jquery.mobile-1.4.2.min.js  
  inflating: assets/www/js/lib/jquery.scrollTo.js  
  inflating: assets/www/js/lib/jquery.touchSwipe.min.js  
  inflating: assets/www/js/lib/require.js  
  inflating: assets/www/js/lib/rtl.jquery.mobile-1.2.0.min.js  
  inflating: assets/www/js/lib/rtl.jquery.mobile-1.4.0.js  
  inflating: assets/www/js/lib/text.js  
  inflating: assets/www/js/lib/underscore.js  
  inflating: assets/www/js/localization/ar/offlineContent/appTerms.html  
  inflating: assets/www/js/localization/ar/offlineContent/offlineContent_about.html  
  inflating: assets/www/js/localization/ar/offlineContent/offlineContent_choosingShelter.html  
  inflating: assets/www/js/localization/ar/offlineContent/offlineContent_earthquakeReadiness.html  
  inflating: assets/www/js/localization/ar/offlineContent/offlineContent_emergencyBag.html  
  inflating: assets/www/js/localization/ar/offlineContent/offlineContent_familyReadiness.html  
  inflating: assets/www/js/localization/ar/offlineContent/offlineContent_forbiddenMaterials.html  
  inflating: assets/www/js/localization/ar/offlineContent/offlineContent_onAlarmBehavior.html  
  inflating: assets/www/js/localization/ar/offlineContent/offlineContent_protectiveZonesMap.html  
  inflating: assets/www/js/localization/ar/arabic.js  
  inflating: assets/www/js/localization/ar/cities_ar_EG  
  inflating: assets/www/js/localization/ar/situationRoomMessagesAR.js  
  inflating: assets/www/js/localization/en/offlineContent/appTerms.html  
  inflating: assets/www/js/localization/en/offlineContent/offlineContent_about.html  
  inflating: assets/www/js/localization/en/offlineContent/offlineContent_choosingShelter.html  
  inflating: assets/www/js/localization/en/offlineContent/offlineContent_earthquakeReadiness.html  
  inflating: assets/www/js/localization/en/offlineContent/offlineContent_emergencyBag.html  
  inflating: assets/www/js/localization/en/offlineContent/offlineContent_familyReadiness.html  
  inflating: assets/www/js/localization/en/offlineContent/offlineContent_forbiddenMaterials.html  
  inflating: assets/www/js/localization/en/offlineContent/offlineContent_onAlarmBehavior.html  
  inflating: assets/www/js/localization/en/offlineContent/offlineContent_protectiveZonesMap.html  
  inflating: assets/www/js/localization/en/cities_en_US  
  inflating: assets/www/js/localization/en/english.js  
  inflating: assets/www/js/localization/en/situationRoomMessagesEN.js  
  inflating: assets/www/js/localization/he/offlineContent/appTerms.html  
  inflating: assets/www/js/localization/he/offlineContent/offlineContent_about.html  
  inflating: assets/www/js/localization/he/offlineContent/offlineContent_choosingShelter.html  
  inflating: assets/www/js/localization/he/offlineContent/offlineContent_earthquakeReadiness.html  
  inflating: assets/www/js/localization/he/offlineContent/offlineContent_emergencyBag.html  
  inflating: assets/www/js/localization/he/offlineContent/offlineContent_familyReadiness.html  
  inflating: assets/www/js/localization/he/offlineContent/offlineContent_forbiddenMaterials.html  
  inflating: assets/www/js/localization/he/offlineContent/offlineContent_onAlarmBehavior.html  
  inflating: assets/www/js/localization/he/offlineContent/offlineContent_protectiveZonesMap.html  
  inflating: assets/www/js/localization/he/cities_iw_IL  
  inflating: assets/www/js/localization/he/hebrew.js  
  inflating: assets/www/js/localization/he/situationRoomMessagesHE.js  
  inflating: assets/www/js/localization/ru/offlineContent/appTerms.html  
  inflating: assets/www/js/localization/ru/offlineContent/offlineContent_about.html  
  inflating: assets/www/js/localization/ru/offlineContent/offlineContent_choosingShelter.html  
  inflating: assets/www/js/localization/ru/offlineContent/offlineContent_earthquakeReadiness.html  
  inflating: assets/www/js/localization/ru/offlineContent/offlineContent_emergencyBag.html  
  inflating: assets/www/js/localization/ru/offlineContent/offlineContent_familyReadiness.html  
  inflating: assets/www/js/localization/ru/offlineContent/offlineContent_forbiddenMaterials.html  
  inflating: assets/www/js/localization/ru/offlineContent/offlineContent_onAlarmBehavior.html  
  inflating: assets/www/js/localization/ru/offlineContent/offlineContent_protectiveZonesMap.html  
  inflating: assets/www/js/localization/ru/cities_ru_RU  
  inflating: assets/www/js/localization/ru/russian.js  
  inflating: assets/www/js/localization/ru/situationRoomMessagesRU.js  
  inflating: assets/www/js/models/getCityName.js  
  inflating: assets/www/js/app.js    
  inflating: assets/www/plugins/org.apache.cordova.dialogs/www/android/notification.js  
  inflating: assets/www/plugins/org.apache.cordova.dialogs/www/notification.js  
  inflating: assets/www/plugins/appSettings.js  
  inflating: assets/www/plugins/appStorage.js  
  inflating: assets/www/plugins/debuggerPlugin.js  
  inflating: assets/www/plugins/errorsManagerPlugin.js  
  inflating: assets/www/plugins/geoLocation.js  
  inflating: assets/www/plugins/getAboutInfo.js  
  inflating: assets/www/plugins/getMessages.js  
  inflating: assets/www/plugins/getSegments.js  
  inflating: assets/www/plugins/getShelterEstimateTime.js  
  inflating: assets/www/plugins/inappbrowser.js  
  inflating: assets/www/plugins/login.js  
  inflating: assets/www/plugins/softKeyBoard.js  
  inflating: assets/www/plugins/updateServer.js  
  inflating: assets/www/plugins/updateStatistics.js  
  inflating: assets/www/plugins/video.js  
  inflating: assets/www/templates/pages/appLobbyTemplate.html  
  inflating: assets/www/templates/pages/chooseLocationTemplate.html  
  inflating: assets/www/templates/pages/choosingShelterTemplate.html  
  inflating: assets/www/templates/pages/contactUsTemplate.html  
  inflating: assets/www/templates/pages/earthquakeReadinessTemplate.html  
  inflating: assets/www/templates/pages/emergencyBagTemplate.html  
  inflating: assets/www/templates/pages/messageDetailsTemplate.html  
  inflating: assets/www/templates/pages/progressStateTemplate.html  
  inflating: assets/www/templates/pages/readinessDetailsTemplate.html  
  inflating: assets/www/templates/pages/readinessTemplate.html  
  inflating: assets/www/templates/pages/settingsTemplate.html  
  inflating: assets/www/templates/pages/situationRoomTemplate.html  
  inflating: assets/www/templates/emergencyBagItem.html  
  inflating: assets/www/templates/menuTemplate.html  
  inflating: assets/www/templates/readinessItem.html  
  inflating: assets/www/templates/situationRoomMessage.html  
 extracting: assets/www/config.xml   
  inflating: assets/www/cordova.js   
  inflating: assets/www/cordova_plugins.js  
  inflating: assets/www/index.html   
 extracting: assets/alert.mp3        
 extracting: assets/info.mp3         
  inflating: res/color/common_signin_btn_text_dark.xml  
  inflating: res/color/common_signin_btn_text_light.xml  
 extracting: res/drawable/alert_icon.png  
  inflating: res/drawable/button_border.xml  
  inflating: res/drawable/common_signin_btn_icon_dark.xml  
  inflating: res/drawable/common_signin_btn_icon_light.xml  
  inflating: res/drawable/common_signin_btn_text_dark.xml  
  inflating: res/drawable/common_signin_btn_text_light.xml  
  inflating: res/drawable/dialog_border.xml  
  inflating: res/drawable/dialog_header_border.xml  
 extracting: res/drawable/ic_notification.png  
 extracting: res/drawable/icon.png   
 extracting: res/drawable/info_circle.png  
 extracting: res/drawable/ioref_logo.png  
 extracting: res/drawable/splash.png  
  inflating: res/drawable/toast_border.xml  
  inflating: res/layout/dialog_push_message.xml  
  inflating: res/layout/splash.xml   
  inflating: res/layout/toast.xml    
  inflating: res/raw/smart_trust_store.bks  
  inflating: res/xml/config.xml      
  inflating: AndroidManifest.xml     
 extracting: resources.arsc          
 extracting: res/drawable-hdpi-v4/common_signin_btn_icon_disabled_dark.9.png  
 extracting: res/drawable-hdpi-v4/common_signin_btn_icon_disabled_focus_dark.9.png  
 extracting: res/drawable-hdpi-v4/common_signin_btn_icon_disabled_focus_light.9.png  
 extracting: res/drawable-hdpi-v4/common_signin_btn_icon_disabled_light.9.png  
 extracting: res/drawable-hdpi-v4/common_signin_btn_icon_focus_dark.9.png  
 extracting: res/drawable-hdpi-v4/common_signin_btn_icon_focus_light.9.png  
 extracting: res/drawable-hdpi-v4/common_signin_btn_icon_normal_dark.9.png  
 extracting: res/drawable-hdpi-v4/common_signin_btn_icon_normal_light.9.png  
 extracting: res/drawable-hdpi-v4/common_signin_btn_icon_pressed_dark.9.png  
 extracting: res/drawable-hdpi-v4/common_signin_btn_icon_pressed_light.9.png  
 extracting: res/drawable-hdpi-v4/common_signin_btn_text_disabled_dark.9.png  
 extracting: res/drawable-hdpi-v4/common_signin_btn_text_disabled_focus_dark.9.png  
 extracting: res/drawable-hdpi-v4/common_signin_btn_text_disabled_focus_light.9.png  
 extracting: res/drawable-hdpi-v4/common_signin_btn_text_disabled_light.9.png  
 extracting: res/drawable-hdpi-v4/common_signin_btn_text_focus_dark.9.png  
 extracting: res/drawable-hdpi-v4/common_signin_btn_text_focus_light.9.png  
 extracting: res/drawable-hdpi-v4/common_signin_btn_text_normal_dark.9.png  
 extracting: res/drawable-hdpi-v4/common_signin_btn_text_normal_light.9.png  
 extracting: res/drawable-hdpi-v4/common_signin_btn_text_pressed_dark.9.png  
 extracting: res/drawable-hdpi-v4/common_signin_btn_text_pressed_light.9.png  
 extracting: res/drawable-hdpi-v4/ic_plusone_medium_off_client.png  
 extracting: res/drawable-hdpi-v4/ic_plusone_small_off_client.png  
 extracting: res/drawable-hdpi-v4/ic_plusone_standard_off_client.png  
 extracting: res/drawable-hdpi-v4/ic_plusone_tall_off_client.png  
 extracting: res/drawable-hdpi-v4/icon.png  
 extracting: res/drawable-hdpi-v4/splash.png  
 extracting: res/drawable-ldpi-v4/icon.png  
 extracting: res/drawable-mdpi-v4/common_signin_btn_icon_disabled_dark.9.png  
 extracting: res/drawable-mdpi-v4/common_signin_btn_icon_disabled_focus_dark.9.png  
 extracting: res/drawable-mdpi-v4/common_signin_btn_icon_disabled_focus_light.9.png  
 extracting: res/drawable-mdpi-v4/common_signin_btn_icon_disabled_light.9.png  
 extracting: res/drawable-mdpi-v4/common_signin_btn_icon_focus_dark.9.png  
 extracting: res/drawable-mdpi-v4/common_signin_btn_icon_focus_light.9.png  
 extracting: res/drawable-mdpi-v4/common_signin_btn_icon_normal_dark.9.png  
 extracting: res/drawable-mdpi-v4/common_signin_btn_icon_normal_light.9.png  
 extracting: res/drawable-mdpi-v4/common_signin_btn_icon_pressed_dark.9.png  
 extracting: res/drawable-mdpi-v4/common_signin_btn_icon_pressed_light.9.png  
 extracting: res/drawable-mdpi-v4/common_signin_btn_text_disabled_dark.9.png  
 extracting: res/drawable-mdpi-v4/common_signin_btn_text_disabled_focus_dark.9.png  
 extracting: res/drawable-mdpi-v4/common_signin_btn_text_disabled_focus_light.9.png  
 extracting: res/drawable-mdpi-v4/common_signin_btn_text_disabled_light.9.png  
 extracting: res/drawable-mdpi-v4/common_signin_btn_text_focus_dark.9.png  
 extracting: res/drawable-mdpi-v4/common_signin_btn_text_focus_light.9.png  
 extracting: res/drawable-mdpi-v4/common_signin_btn_text_normal_dark.9.png  
 extracting: res/drawable-mdpi-v4/common_signin_btn_text_normal_light.9.png  
 extracting: res/drawable-mdpi-v4/common_signin_btn_text_pressed_dark.9.png  
 extracting: res/drawable-mdpi-v4/common_signin_btn_text_pressed_light.9.png  
 extracting: res/drawable-mdpi-v4/ic_plusone_medium_off_client.png  
 extracting: res/drawable-mdpi-v4/ic_plusone_small_off_client.png  
 extracting: res/drawable-mdpi-v4/ic_plusone_standard_off_client.png  
 extracting: res/drawable-mdpi-v4/ic_plusone_tall_off_client.png  
 extracting: res/drawable-mdpi-v4/icon.png  
 extracting: res/drawable-mdpi-v4/splash.png  
 extracting: res/drawable-xhdpi-v4/common_signin_btn_icon_disabled_dark.9.png  
 extracting: res/drawable-xhdpi-v4/common_signin_btn_icon_disabled_focus_dark.9.png  
 extracting: res/drawable-xhdpi-v4/common_signin_btn_icon_disabled_focus_light.9.png  
 extracting: res/drawable-xhdpi-v4/common_signin_btn_icon_disabled_light.9.png  
 extracting: res/drawable-xhdpi-v4/common_signin_btn_icon_focus_dark.9.png  
 extracting: res/drawable-xhdpi-v4/common_signin_btn_icon_focus_light.9.png  
 extracting: res/drawable-xhdpi-v4/common_signin_btn_icon_normal_dark.9.png  
 extracting: res/drawable-xhdpi-v4/common_signin_btn_icon_normal_light.9.png  
 extracting: res/drawable-xhdpi-v4/common_signin_btn_icon_pressed_dark.9.png  
 extracting: res/drawable-xhdpi-v4/common_signin_btn_icon_pressed_light.9.png  
 extracting: res/drawable-xhdpi-v4/common_signin_btn_text_disabled_dark.9.png  
 extracting: res/drawable-xhdpi-v4/common_signin_btn_text_disabled_focus_dark.9.png  
 extracting: res/drawable-xhdpi-v4/common_signin_btn_text_disabled_focus_light.9.png  
 extracting: res/drawable-xhdpi-v4/common_signin_btn_text_disabled_light.9.png  
 extracting: res/drawable-xhdpi-v4/common_signin_btn_text_focus_dark.9.png  
 extracting: res/drawable-xhdpi-v4/common_signin_btn_text_focus_light.9.png  
 extracting: res/drawable-xhdpi-v4/common_signin_btn_text_normal_dark.9.png  
 extracting: res/drawable-xhdpi-v4/common_signin_btn_text_normal_light.9.png  
 extracting: res/drawable-xhdpi-v4/common_signin_btn_text_pressed_dark.9.png  
 extracting: res/drawable-xhdpi-v4/common_signin_btn_text_pressed_light.9.png  
 extracting: res/drawable-xhdpi-v4/ic_plusone_medium_off_client.png  
 extracting: res/drawable-xhdpi-v4/ic_plusone_small_off_client.png  
 extracting: res/drawable-xhdpi-v4/ic_plusone_standard_off_client.png  
 extracting: res/drawable-xhdpi-v4/ic_plusone_tall_off_client.png  
 extracting: res/drawable-xhdpi-v4/icon.png  
 extracting: res/drawable-xxhdpi-v4/common_signin_btn_icon_disabled_dark.9.png  
 extracting: res/drawable-xxhdpi-v4/common_signin_btn_icon_disabled_focus_dark.9.png  
 extracting: res/drawable-xxhdpi-v4/common_signin_btn_icon_disabled_focus_light.9.png  
 extracting: res/drawable-xxhdpi-v4/common_signin_btn_icon_disabled_light.9.png  
 extracting: res/drawable-xxhdpi-v4/common_signin_btn_icon_focus_dark.9.png  
 extracting: res/drawable-xxhdpi-v4/common_signin_btn_icon_focus_light.9.png  
 extracting: res/drawable-xxhdpi-v4/common_signin_btn_icon_normal_dark.9.png  
 extracting: res/drawable-xxhdpi-v4/common_signin_btn_icon_normal_light.9.png  
 extracting: res/drawable-xxhdpi-v4/common_signin_btn_icon_pressed_dark.9.png  
 extracting: res/drawable-xxhdpi-v4/common_signin_btn_icon_pressed_light.9.png  
 extracting: res/drawable-xxhdpi-v4/common_signin_btn_text_disabled_dark.9.png  
 extracting: res/drawable-xxhdpi-v4/common_signin_btn_text_disabled_focus_dark.9.png  
 extracting: res/drawable-xxhdpi-v4/common_signin_btn_text_disabled_focus_light.9.png  
 extracting: res/drawable-xxhdpi-v4/common_signin_btn_text_disabled_light.9.png  
 extracting: res/drawable-xxhdpi-v4/common_signin_btn_text_focus_dark.9.png  
 extracting: res/drawable-xxhdpi-v4/common_signin_btn_text_focus_light.9.png  
 extracting: res/drawable-xxhdpi-v4/common_signin_btn_text_normal_dark.9.png  
 extracting: res/drawable-xxhdpi-v4/common_signin_btn_text_normal_light.9.png  
 extracting: res/drawable-xxhdpi-v4/common_signin_btn_text_pressed_dark.9.png  
 extracting: res/drawable-xxhdpi-v4/common_signin_btn_text_pressed_light.9.png  
 extracting: res/drawable-xxhdpi-v4/ic_plusone_medium_off_client.png  
 extracting: res/drawable-xxhdpi-v4/ic_plusone_small_off_client.png  
 extracting: res/drawable-xxhdpi-v4/ic_plusone_standard_off_client.png  
 extracting: res/drawable-xxhdpi-v4/ic_plusone_tall_off_client.png  
  inflating: classes.dex             
  inflating: org/apache/http/entity/mime/version.properties  
  inflating: META-INF/MANIFEST.MF    
  inflating: META-INF/CERT.SF     

בשונה מקבצי smali את קבצי ה dex נאלץ להמיר לקוד קריא יותר כך :
jadx -d out classes.dex

יום חמישי, אוגוסט 20, 2015

בדיקות דרך קומפילציה

לא מזמן יצא לי לדבר על בדיקות עם ידידי משכבר הימים ויצא לי להציג שיטות תאומות שאני אוהב לדחוף -

היום הרבה מידידי משתמשים בכלים מצויינים כמו ג'נקינס ו TFS (יש הרבה אחרים אבל הרעיון דומה), מאוד בגדול מדובר על מערכות שדוגמת גרסה מסויימת מריצה מספר בדיקות ונותנת את תוצאת הבדיקות (אצלי המצב טיפה שונה כי יש פתרון in-house) ומדווחת למתכנתים .

השיטה הקלאסית שאני מכיר מדברת על מודל בדיקות שמופעל חיצונית למודל הפנימי שלך או מופעלים בזמן ריצה (מקרה קלאסי של gtest):


#include <iostream>
#include <gtest/gtest.h>

struct foo
{
  int random(){return 4;};//chosen by fair dice roll.
                          //guarnteed to be random :P
                          //by xkcd 221

};



TEST(foo, random) {
  foo f;
  EXPECT_EQ(0, f.random());
}



int main (int argc, char **argv)

{
  ::testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}

שיטה נוספת מדברת על בנייה ספציפית לקומפיילר בה מקפלים מקרה בודד לבד כל פעם (מה שעושים עם lit ו QTest הרבה מאוד פעמים) , אמנם זה פתרון טוב הרבה מאוד פעמים זה לא עונה על הצרכים שלי (לא להחזיק מקטעי קוד נפרדים).

הבעייה בגישה של בדיקה בזמן ריצה (אפילו בתחילת ריצה) או בזמן בנייה כטסריט חיצוני  היא שזה עדיין משאיר פתח עצום למתכנת לעשות קומיט לדחוף אותו לרפוסטורי כשהוא לא נבנה (אני באמת רוצה לראות את איש ה IT שיצליח לדחוף הוק שמבצע בנייה על מכונה של מפתח שתמנע ממנו לעשות push אם בנייה נכשלת).

עכשיו בגלל שאני חי בעולם יחסית טוב (בכל זאת כותב בשפות מקומפלת) יש לי אפשרות נוספת שהתרגלתי להשתמש בה - כתיבת בדיקות שמכשילות קומפילציה שזה בשונה מבניית פרוייקט כן מתקבלת כקרס (גם ב git ו גם svn) בצד מפתח.

אני יודע זה נשמע עקום מאוד בהתחלה אבל ברגע שמתרגלים לזה זה נהיה מאוד נוח, דבר ראשון זה לא דורש שום סיפריה חיצונית (וחברי שנתקלו בבירוקרטיה לינקוקית יודעים על מה אני מדבר) ודבר שני זה מרגיש מאוד טבעי בקוד.

דוגמה קלאסית למטה דטה של מבנים (שתכשיל קומפילציה ) :



#include <iostream>
#include <cstddef>
#include <type_traits>

struct mytype_t
{
   //these are just example for some fields 
   int field1;
   int field2;

//   int non_declared_field_in_cmo_field_table_name;//this field had not been declared in cmo_field_table_name

   char y[3];
};

struct metadata_t
{
   size_t size;       
   size_t offset;     
   size_t allignment; 
   const char *  name;

} ;

//we have macro that fill metadata_t
//

static constexpr const struct metadata_t cmo_field_table_name[] = 
{
  {sizeof(mytype_t::field1),offsetof(mytype_t,field1) , std::alignment_of < decltype (mytype_t::field1 )> :: value,"1"},
  {sizeof(mytype_t::field2),offsetof(mytype_t,field2) , std::alignment_of < decltype (mytype_t::field2 )> :: value,"bla"},
  {sizeof(mytype_t::y),offsetof(mytype_t,y), std::alignment_of <decltype( mytype_t::y) > :: value,"2"},
};



//We declare a type that will fail compilation in case
template <bool>

struct check_struct_for_missing_field
{

};

template <>

struct check_struct_for_missing_field<true>
{
 //I named this field as field and not anything else so the compiler error will be more understandble 
 enum {field = 0};
};


//the magic start here 
//a recursive defintion that check on compile time if all the previous fields had been declared correctly
//in case of non declared fields this will fail compilation and will give us an error that will prevent a person commiting errosly like this mornign
//
//compile_type_check.cc: In instantiation of ‘struct check_if_all_fields_for_struct_correctly_declared_argument_is_field_number<((const metadata_t*)(& cmo_field_table_name)), 2>’:
//compile_type_check.cc:74:178:   required from here
//compile_type_check.cc:62:9: error: ‘field’ is not a member of ‘check_struct_for_missing_field<false>’
//    enum {check =  check_struct_for_missing_field < check_if_all_fields_for_struct_correctly_declared_argument_is_field_number < ptr,index_in_ptr - 1> :: value == ptr[index_in_ptr].offset  > ::field};
//             ^
//             compile_type_check.cc:74:1: error: static assertion failed: missing fields in tab
//              static_assert(check_if_all_fields_for_struct_correctly_declared_argument_is_field_number <cmo_field_table_name, sizeof(cmo_field_table_name)/sizeof(cmo_field_table_name[0]) -1 >::value == sizeof(mytype_t) , "missing fields in tab");
//
//
template < const struct metadata_t * ptr, int index_in_ptr>
struct check_if_all_fields_for_struct_correctly_declared_argument_is_field_number
{
  //incorrect declartion (type mismatchs) are found here
  //a correct offset of field N is  (alligment + size + offset ) for field N - 1
  enum {value =
        (
          ( ptr[index_in_ptr].allignment != ptr[index_in_ptr].size)?

            ptr[index_in_ptr].size + ptr[index_in_ptr].allignment
            :
            ptr[index_in_ptr].size)
            //this will iterate for the previous fields until the first declared in ptr
          + check_if_all_fields_for_struct_correctly_declared_argument_is_field_number<ptr,index_in_ptr-1>::value};
   //in case we have a missing field the next will fail compilation saying : 
   //
   enum {check =  check_struct_for_missing_field < check_if_all_fields_for_struct_correctly_declared_argument_is_field_number < ptr,index_in_ptr - 1> :: value == ptr[index_in_ptr].offset  > ::field};



};

//this is the final step of fields (the zero in the index

template <const struct metadata_t * ptr>

struct check_if_all_fields_for_struct_correctly_declared_argument_is_field_number <ptr,0>
{
 public:
   enum {value = //cmo_field_table_name[0].offset + 
        ( ptr[0].allignment != ptr[0].size)? ptr[0].size +   ptr[0].allignment :ptr[0].size
       };
};


static_assert(check_if_all_fields_for_struct_correctly_declared_argument_is_field_number <cmo_field_table_name, sizeof(cmo_field_table_name)/sizeof(cmo_field_table_name[0]) -1 >::value == sizeof(mytype_t) , "missing fields in tab");



int main(int argc, char *argv[])
{
  for (auto & r: cmo_field_table_name)
  {

    std::cout << "name:" << r.name<< " offset:" << r.offset << " allignment: " << r.allignment << " size:" << r.size << "total: " << r.size + r.allignment << std::endl;

  };

  return 0;

};

בחרתי ב C++  כי לדעתי היא פשוטה מספיק להבנה אבל דבר מאוד דומה ניתן לבצע גם בשפות אחרות.

JAVA: כן אני זוכר את הנושא של המרה לobject ובעיית הstatic הנקודה היא שימוש בטיפוסי הנתונים כמשתנים.

C: יחי המקרו ! יאפ בנייה על בסיס מקרו.

FPC: אם משהו עדיין משתמש בזה - "

FPC 2.4.0 is neither complete nor practically usable yet. Until that is so, templates can be used." אבל אני די בטוח שיש פתרון אחר.

הכשלת קימפול בגלל בדיקות מאפשרת יכולת נבוט טובות יותר ואני מאמין עם ערך wtf/minute נמוך יחסית.