Ruby IDB(iOS App 보안분석 도구) Select App 시 죽는 현상 해결 방법(iOS10, Error downloading file)

예전에 idb라는 iOS 분석도구를 공유드린적이 있습니다. 최근에 테스트 시 Select App 시 앱 리스트를 가져오는 과정에서 죽는 현상이 있었느데요, 예전에 가까운곳에서 동일한 문제가 있었고 해결방법 공유해주셨던게 기억나서 저 또한 쉽게 해결헀네요.

iOS 10 이상의 디바이스에서 사용 시 발생하는 에러이고 겸사겸사 글로 남겨둡니다. 우선 앱 선택 시 idb가 죽을 때 로그를 보면 이렇습니다.

Error downloading file.
/usr/local/lib/ruby/gems/2.3.0/gems/plist4r-1.2.2/lib/plist4r/plist.rb:294:in `open': No filename specified (RuntimeError)

ios에서 pc로 데이터를 가져오는 과정에서 plist4r gem 부근에 에러가 발생합니다.

이유인즉슨 iOS 10부턴 LastLaunchServicesMap.plist를 사용하지 않는데, idb에선 해당 파일을 참조해서 App data를 읽어오려 하기 때문에 에러가 발생합니다.

https://github.com/dmayer/idb/issues/91

App data를 읽어오는 SQL Query를 조정하면 에러를 해결할 수 있습니다. (아니면, 별도로 분기 처리해줘야합니다. 코드 작성해서 pull 하시는것도 좋은 방법)

idb의 lib/lib 하위의 ios10_application_state_db_wrapper.rb 파일을 열어 코드를 수정합시다.

코드 내 sql query(SELECT문) 중 where 의 kvs.key=2kvs.key=1로 변경합니다.

 def data_path_by_bundle_id(bundle_id)

    #puts @cache_path
    db = SQLite3::Database.open @cache_path
    #puts db.inspect

    #puts bundle_id
    plist = ""

    # kvs.key=2를 kvs.key=1로 변경합니다.
    # I fail to get prepared statements to work with SQLite... So using strig concatenation instead. here be dragons
    stmnt = db.prepare "SELECT kvs.value FROM application_identifier_tab left join kvs on application_identifier_tab.id = kvs.application_identifier where kvs.key = 2 and application_identifier_tab.application_identifier='#{bundle_id}'"
    # stmnt.bind_params(bundle_id)
    rs = stmnt.execute
    #
    #binding.pry
    # ... 생략 ...
 end

그러고 재 실행 후 다시 앱을 로드해보면 잘 됩니다 :)